2323
2424package processing .app ;
2525
26+ import processing .app .debug .Runner ;
27+ import processing .app .debug .RunnerException ;
2628import processing .app .syntax .*;
2729import processing .app .tools .*;
2830import processing .core .*;
@@ -104,8 +106,8 @@ public class Editor extends JFrame {
104106 EditorListener listener ;
105107
106108 // runtime information and window placement
107- Point appletLocation ;
108- RunButtonWatcher watcher ;
109+ Point sketchWindowLocation ;
110+ // RunButtonWatcher watcher;
109111 Runner runtime ;
110112
111113 JMenuItem exportAppItem ;
@@ -1106,19 +1108,28 @@ public void handleRun(boolean present) {
11061108 }
11071109
11081110 try {
1109- if (!sketch .handleRun ()) return ;
1111+ if (!sketch .handleCompile ()) return ;
11101112
1111- runtime = new Runner (sketch , Editor .this );
1112- runtime .start (appletLocation );
1113+ //SwingUtilities.invokeLater(new Runnable() {
1114+ Thread t = new Thread (new Runnable () {
1115+ public void run () {
1116+ try {
1117+ runtime = new Runner (Editor .this , presenting );
1118+ //runtime.go();
1119+ } catch (RunnerException e ) {
1120+ error (e );
1121+ }
1122+ }
1123+ });
1124+ t .start ();
1125+ //runtime.start(appletLocation);
11131126
11141127 // run button watcher not currently enabled
11151128 // it was contributing to the external vm hanging
1116- watcher = new RunButtonWatcher ();
1117-
1118- } catch (RunnerException e ) {
1119- error (e );
1129+ //watcher = new RunButtonWatcher();
11201130
11211131 } catch (Exception e ) {
1132+ System .err .println ("exception reached editor" );
11221133 e .printStackTrace ();
11231134 }
11241135
@@ -1147,7 +1158,18 @@ public Object construct() {
11471158 //sketch.cleanup(); // where does this go?
11481159 }
11491160
1161+
1162+ public void setSketchLocation (Point p ) {
1163+ sketchWindowLocation = p ;
1164+ }
1165+
1166+
1167+ public Point getSketchLocation () {
1168+ return sketchWindowLocation ;
1169+ }
11501170
1171+
1172+ /*
11511173 class RunButtonWatcher implements Runnable {
11521174 Thread thread;
11531175
@@ -1188,33 +1210,42 @@ public void stop() {
11881210 thread = null;
11891211 }
11901212 }
1213+ */
11911214
11921215
11931216 public void handleStop () { // called by menu or buttons
1217+ // System.out.println("stopping");
1218+ toolbar .activate (EditorToolbar .STOP );
1219+
11941220 if (presenting ) {
11951221 closeRunner ();
1196- } else if (runtime .window != null ) {
1197- // When run externally, kill the applet window,
1198- // otherwise things may not stop properly with libraries.
1199- closeRunner ();
1222+ // } else if (runtime.window != null) {
1223+ // // When run externally, kill the applet window,
1224+ // // otherwise things may not stop properly with libraries.
1225+ // closeRunner();
12001226 } else {
12011227 stopRunner ();
12021228 }
1203- toolbar .clear ();
1229+ //System.out.println("clearing toolbar");
1230+ //toolbar.clear();
1231+ toolbar .deactivate (EditorToolbar .RUN );
1232+ toolbar .deactivate (EditorToolbar .STOP );
12041233 }
12051234
12061235
12071236 /**
12081237 * Stop the applet but don't kill its window.
12091238 */
12101239 public void stopRunner () {
1240+ //System.out.println("stopRunner 1");
12111241 if (runtime != null ) runtime .stop ();
1212- if (watcher != null ) watcher .stop ();
1242+ //System.out.println("stopRunner 2");
1243+ //if (watcher != null) watcher.stop();
12131244 message (EMPTY );
12141245
12151246 // the buttons are sometimes still null during the constructor
12161247 // is this still true? are people still hitting this error?
1217- /*if (buttons != null)*/ toolbar .clear ();
1248+ /*if (buttons != null)*/ // toolbar.clear();
12181249
12191250 running = false ;
12201251 }
@@ -1225,19 +1256,21 @@ public void stopRunner() {
12251256 * mode, this will always be called instead of doStop().
12261257 */
12271258 public void closeRunner () {
1259+ //System.out.println("closing runner");
1260+
12281261 //if (presenting) {
12291262 //presentationWindow.hide();
12301263 //} else {
1231- try {
1232- // the window will also be null the process was running
1233- // externally. so don't even try setting if window is null
1234- // since Runner will set the appletLocation when an
1235- // external process is in use.
1236- if (runtime .window != null ) {
1237- appletLocation = runtime .window .getLocation ();
1238- }
1239- } catch (NullPointerException e ) { }
1240- //}
1264+ // try {
1265+ // // the window will also be null the process was running
1266+ // // externally. so don't even try setting if window is null
1267+ // // since Runner will set the appletLocation when an
1268+ // // external process is in use.
1269+ // if (runtime.window != null) {
1270+ // appletLocation = runtime.window.getLocation();
1271+ // }
1272+ // } catch (NullPointerException e) { }
1273+ // //}
12411274
12421275 //if (running) doStop();
12431276 stopRunner (); // need to stop if runtime error
@@ -1252,8 +1285,7 @@ public void closeRunner() {
12521285
12531286 sketch .cleanup ();
12541287
1255- // [toxi 030903]
1256- // focus the PDE again after quitting presentation mode
1288+ // focus the PDE again after quitting presentation mode [toxi 030903]
12571289 toFront ();
12581290 }
12591291
@@ -1464,7 +1496,8 @@ protected boolean handleOpenInternal(String path) {
14641496 * <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=276">Bug 276</A>.
14651497 */
14661498 public boolean handleSave (boolean immediately ) {
1467- stopRunner ();
1499+ //stopRunner();
1500+ handleStop (); // 0136
14681501
14691502 if (untitled ) {
14701503 return handleSaveAs ();
@@ -1509,12 +1542,15 @@ protected void handleSave2() {
15091542 //checkModifiedMode = 0;
15101543 // this is used when another operation calls a save
15111544 }
1512- toolbar .clear ();
1545+ //toolbar.clear();
1546+ toolbar .deactivate (EditorToolbar .SAVE );
15131547 }
15141548
15151549
15161550 public boolean handleSaveAs () {
1517- stopRunner ();
1551+ //stopRunner(); // formerly from 0135
1552+ handleStop ();
1553+
15181554 toolbar .activate (EditorToolbar .SAVE );
15191555
15201556 //SwingUtilities.invokeLater(new Runnable() {
@@ -1534,9 +1570,11 @@ public boolean handleSaveAs() {
15341570 } catch (Exception e ) {
15351571 // show the error as a message in the window
15361572 error (e );
1573+
1574+ } finally {
1575+ // make sure the toolbar button deactivates
1576+ toolbar .deactivate (EditorToolbar .SAVE );
15371577 }
1538- toolbar .clear ();
1539- //}});
15401578
15411579 return true ;
15421580 }
@@ -1567,7 +1605,8 @@ public void run() {
15671605 } catch (Exception e ) {
15681606 error (e );
15691607 }
1570- toolbar .clear ();
1608+ //toolbar.clear();
1609+ toolbar .deactivate (EditorToolbar .EXPORT );
15711610 }});
15721611 }
15731612
@@ -1592,7 +1631,8 @@ public void run() {
15921631 message ("Error during export." );
15931632 e .printStackTrace ();
15941633 }
1595- toolbar .clear ();
1634+ //toolbar.clear();
1635+ toolbar .deactivate (EditorToolbar .EXPORT );
15961636 }});
15971637 }
15981638
@@ -1625,7 +1665,7 @@ public boolean handleExportCheckModified() {
16251665 // but f-- it.. let's get this shite done..
16261666 //} else if (result == JOptionPane.CANCEL_OPTION) {
16271667 message ("Export canceled, changes must first be saved." );
1628- toolbar .clear ();
1668+ // toolbar.clear();
16291669 return false ;
16301670 }
16311671 return true ;
@@ -1853,7 +1893,7 @@ public void error(RunnerException e) {
18531893 mess = mess .substring (javaLang .length ());
18541894 }
18551895 error (mess );
1856- toolbar .clear ();
1896+ // toolbar.clear();
18571897 }
18581898
18591899
0 commit comments