Changeset 758


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

Change JSWidget to just use a single init() method instead of preCreate(), constructor(), postCreate() methods (since all those 3 methods actually did was set up and return a JComponent, they can all be handled at once)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/widgets/JSWidget.java

    r752 r758  
    2323public class JSWidget extends DataFrameWidget {
    2424       
    25         // a method to run before running the constructor
    26         private final String preCreate;
    27         // a method to run that will return a JComponent
    28         private final String constructor;
    29         // a method to run after running the constructor
    30         private final String postCreate;
     25        // a method to run that will set up and return the root JComponent for this Widget
     26        private final String init;
    3127        // a method to run to generate a List<String> to save the state
    3228        private final String save;
     
    4743        }
    4844       
    49         private JSWidget(Text source, String preCreate, String constructor, String postCreate, String save, String load) throws Exception {
     45        private JSWidget(Text source, String init, String save, String load) throws Exception {
    5046                super(source, new JPanel(new BorderLayout()), -1, 100, -1, -1, 100, -1);
    51                 this.preCreate = preCreate;
    52                 this.constructor = constructor;
    53                 this.postCreate = postCreate;
     47                this.init = init;
    5448                this.save = save;
    5549                this.load = load;
     
    5953                this.scriptEngine.put("widget", this);
    6054                this.scriptEngine.put("container", this.container);
    61                 System.out.println(this.preCreate);
    62         this.scriptEngine.eval("var pre = " + this.preCreate + "\npre()");
    63         System.out.println(this.constructor);
    64         this.component = (JComponent) this.scriptEngine.eval("var constructor = " + this.constructor + "\nconstructor()");
     55        System.out.println(this.init);
     56        this.component = (JComponent) this.scriptEngine.eval("var init = " + this.init + "\ninit()");
    6557        this.container.add(component);
    6658        this.scriptEngine.put("component", this.component);
    67         System.out.println(this.postCreate);
    68         this.scriptEngine.eval("var post = " + this.postCreate + "\npost()");
    6959        }
    7060       
     
    7262                this(source, source.getData().get(0).replaceAll("\\\\n", "\n"),
    7363                                source.getData().get(1).replaceAll("\\\\n", "\n"),
    74                                 source.getData().get(2).replaceAll("\\\\n", "\n"),
    75                                 source.getData().get(3).replaceAll("\\\\n", "\n"),
    76                                 source.getData().get(4).replaceAll("\\\\n", "\n"));
     64                                source.getData().get(2).replaceAll("\\\\n", "\n"));
    7765                this.scriptEngine.eval("var load = " + this.load);
    7866                ((Invocable)this.scriptEngine).invokeFunction("load", (Object) args);
    7967        }
    8068       
    81         public JSWidget(String preCreate, String constructor, String postCreate, String save, String load) throws Exception {
    82                 this(getSauce(), preCreate, constructor, postCreate, save, load);
     69        public JSWidget(String init, String save, String load) throws Exception {
     70                this(getSauce(), init, save, load);
    8371        }
    8472       
     
    8674        protected List<String> getData() {
    8775                List<String> value = new LinkedList<String>();
    88                 value.add(this.preCreate.replaceAll("[\n\r]", "\\\\n"));
    89                 value.add(this.constructor.replaceAll("[\n\r]", "\\\\n"));
    90                 value.add(this.postCreate.replaceAll("[\n\r]", "\\\\n"));
     76                value.add(this.init.replaceAll("[\n\r]", "\\\\n"));
    9177                value.add(this.save.replaceAll("[\n\r]", "\\\\n"));
    9278                value.add(this.load.replaceAll("[\n\r]", "\\\\n"));
Note: See TracChangeset for help on using the changeset viewer.