Ignore:
Timestamp:
01/28/14 11:58:55 (10 years ago)
Author:
jts21
Message:

Add global variable to widgets so they can share state. Tried to make widgets all use the same ScriptEngine with different ScriptContexts, but there doesn't seem to be a way to explicitly invoke a method within a specific script context, which was required for save/load. Also changed save() method so it takes a List<String> as a parameter and populates that rather than having to create one itself.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Javascript2.java

    r752 r765  
    66import java.util.List;
    77
     8import javax.script.Bindings;
    89import javax.script.Invocable;
     10import javax.script.ScriptContext;
    911import javax.script.ScriptEngine;
    1012import javax.script.ScriptEngineManager;
    1113import javax.script.ScriptException;
     14import javax.script.SimpleScriptContext;
    1215
    1316import org.expeditee.gui.Frame;
     
    1821import org.expeditee.items.Item;
    1922import org.expeditee.items.ItemUtils;
    20 import org.expeditee.items.Line;
    2123import org.expeditee.items.Text;
    2224
     
    3335       
    3436        public static final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    35         private static ScriptEngine se = scriptEngineManager.getEngineByMimeType("application/javascript");
     37        public static final ScriptEngine scriptEngine = scriptEngineManager.getEngineByMimeType("application/javascript");
    3638        static {
    37                 se.put("invocable", (Invocable) se);
     39                scriptEngine.put("invocable", (Invocable) scriptEngine);
    3840        }
    3941       
     
    8486        public static Object eval(String code) {
    8587                try {
    86                 return se.eval(code);
     88                return scriptEngine.eval(code);
    8789        } catch (ScriptException e) {
    8890                e.printStackTrace();
     
    9597                try {
    9698                try {
    97                 se.eval(js.toString());
     99                scriptEngine.eval(js.toString());
    98100            } catch (ScriptException e) {
    99101                        js.handleError(e.getMessage(), e.getLineNumber());
Note: See TracChangeset for help on using the changeset viewer.