]> gitweb.factorcode.org Git - factor.git/blobdiff - factor/listener/FactorDesktop.java
Factor jEdit plugin!
[factor.git] / factor / listener / FactorDesktop.java
index e3e8075aab1d3336940172a456cad9f5e830bd56..4308b07df2f811f0b21bfb977f2d5b6a45e98d82 100644 (file)
@@ -39,11 +39,6 @@ import javax.swing.text.html.*;
 
 public class FactorDesktop extends JFrame
 {
-       private JTabbedPane tabs;
-       private FactorInterpreter interp;
-       private boolean standalone;
-       private Map listeners;
-
        //{{{ main() method
        public static void main(String[] args)
        {
@@ -54,26 +49,10 @@ public class FactorDesktop extends JFrame
        public FactorDesktop(String[] args, boolean standalone)
        {
                super("Factor");
-               tabs = new JTabbedPane();
-               this.standalone = standalone;
-               listeners = new HashMap();
-
-               getContentPane().add(BorderLayout.CENTER,tabs);
 
-               try
-               {
-                       interp = new FactorInterpreter();
-                       interp.interactive = false;
-                       interp.init(args,null);
-                       interp.global.setVariable("desktop",this);
-               }
-               catch(Exception e)
-               {
-                       System.err.println("Failed to initialize interpreter:");
-                       e.printStackTrace();
-               }
-
-               newListener();
+               getContentPane().add(BorderLayout.CENTER,
+                       new FactorListenerPanel(
+                       FactorListenerPanel.newInterpreter(args)));
 
                setSize(640,480);
                setDefaultCloseOperation(standalone
@@ -81,100 +60,4 @@ public class FactorDesktop extends JFrame
                        : DISPOSE_ON_CLOSE);
                show();
        } //}}}
-
-       //{{{ newListener() method
-       public FactorListener newListener()
-       {
-               final FactorListener listener = new FactorListener();
-               listener.addEvalListener(new EvalHandler());
-
-               try
-               {
-                       interp.call(new Cons(listener,
-                               new Cons(interp.searchVocabulary(
-                                       "listener","new-listener-hook"),
-                               null)));
-                       interp.run();
-               }
-               catch(Exception e)
-               {
-                       System.err.println("Failed to initialize listener:");
-                       e.printStackTrace();
-               }
-
-               JScrollPane scroller = new JScrollPane(listener);
-               listeners.put(listener,scroller);
-               tabs.addTab("Listener",scroller);
-
-               SwingUtilities.invokeLater(new Runnable()
-               {
-                       public void run()
-                       {
-                               listener.requestFocus();
-                       }
-               });
-
-               return listener;
-       } //}}}
-
-       //{{{ closeListener() method
-       public void closeListener(FactorListener listener)
-       {
-               // remove tab containing the listener
-               tabs.remove((Component)listeners.get(listener));
-               if(tabs.getTabCount() == 0)
-               {
-                       if(standalone)
-                               System.exit(0);
-                       else
-                               dispose();
-               }
-       } //}}}
-
-       //{{{ getInterpreter() method
-       public FactorInterpreter getInterpreter()
-       {
-               return interp;
-       } //}}}
-
-       //{{{ eval() method
-       public void eval(Cons cmd)
-       {
-               try
-               {
-                       interp.call(cmd);
-                       interp.run();
-               }
-               catch(Exception e)
-               {
-                       System.err.println("Failed to eval " + cmd + ":");
-                       e.printStackTrace();
-               }
-       } //}}}
-
-       //{{{ EvalHandler class
-       class EvalHandler implements EvalListener
-       {
-               public void eval(Cons cmd)
-               {
-                       FactorDesktop.this.eval(cmd);
-               }
-       } //}}}
-
-       //{{{ EvalAction class
-       class EvalAction extends AbstractAction
-       {
-               private Cons code;
-
-               public EvalAction(String label, Cons code)
-               {
-                       super(label);
-                       this.code = code;
-               }
-
-               public void actionPerformed(ActionEvent evt)
-               {
-                       FactorDesktop.this.eval(code);
-               }
-       } //}}}
 }