diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 8484d2b86..92de0078d 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -364,6 +364,7 @@ public class Base { activeEditor = whichEditor; // set the current window to be the console that's getting output + EditorConsole.setEditor(activeEditor); } diff --git a/app/src/processing/app/EditorConsole.java b/app/src/processing/app/EditorConsole.java index b13f0f89a..928f7b85a 100644 --- a/app/src/processing/app/EditorConsole.java +++ b/app/src/processing/app/EditorConsole.java @@ -65,6 +65,8 @@ public class EditorConsole extends JScrollPane { static OutputStream stdoutFile; static OutputStream stderrFile; + static EditorConsole currentConsole; + public EditorConsole(Editor editor) { this.editor = editor; @@ -142,10 +144,12 @@ public class EditorConsole extends JScrollPane { } //tempFolder.deleteOnExit(); - consoleOut = - new PrintStream(new EditorConsoleStream(this, false, stdoutFile)); - consoleErr = - new PrintStream(new EditorConsoleStream(this, true, stderrFile)); +// consoleOut = +// new PrintStream(new EditorConsoleStream(this, false, stdoutFile)); +// consoleErr = +// new PrintStream(new EditorConsoleStream(this, true, stderrFile)); + consoleOut = new PrintStream(new EditorConsoleStream(false)); + consoleErr = new PrintStream(new EditorConsoleStream(true)); if (Preferences.getBoolean("console")) { try { @@ -178,6 +182,11 @@ public class EditorConsole extends JScrollPane { }).start(); } + + static public void setEditor(Editor editor) { + currentConsole = editor.console; + } + /** * Close the streams so that the temporary files can be deleted. @@ -277,68 +286,76 @@ public class EditorConsole extends JScrollPane { // maybe not a good idea in the long run? } } -} + + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + + class EditorConsoleStream extends OutputStream { + //static EditorConsole current; + boolean err; // whether stderr or stdout + byte single[] = new byte[1]; + public EditorConsoleStream(boolean err) { + this.err = err; + } -class EditorConsoleStream extends OutputStream { - EditorConsole parent; - boolean err; // whether stderr or stdout - byte single[] = new byte[1]; - OutputStream echo; + public void close() { } - public EditorConsoleStream(EditorConsole parent, - boolean err, OutputStream echo) { - this.parent = parent; - this.err = err; - this.echo = echo; - } + public void flush() { } - public void close() { } + public void write(byte b[]) { // appears never to be used + currentConsole.write(b, 0, b.length, err); - public void flush() { } - - public void write(byte b[]) { // appears never to be used - parent.write(b, 0, b.length, err); - if (echo != null) { - try { - echo.write(b); //, 0, b.length); - echo.flush(); - } catch (IOException e) { - e.printStackTrace(); - echo = null; + OutputStream echo = err ? stderrFile : stdoutFile; + if (echo != null) { + try { + echo.write(b); + echo.flush(); + } catch (IOException e) { + e.printStackTrace(); + echo = null; + } } } - } - public void write(byte b[], int offset, int length) { - parent.write(b, offset, length, err); - if (echo != null) { - try { - echo.write(b, offset, length); - echo.flush(); - } catch (IOException e) { - e.printStackTrace(); - echo = null; + public void write(byte b[], int offset, int length) { + currentConsole.write(b, offset, length, err); + + OutputStream echo = err ? stderrFile : stdoutFile; + if (echo != null) { + try { + echo.write(b, offset, length); + echo.flush(); + } catch (IOException e) { + e.printStackTrace(); + echo = null; + } } } - } - public void write(int b) { - single[0] = (byte)b; - parent.write(single, 0, 1, err); - if (echo != null) { - try { - echo.write(b); - echo.flush(); - } catch (IOException e) { - e.printStackTrace(); - echo = null; + public void write(int b) { + single[0] = (byte)b; + currentConsole.write(single, 0, 1, err); + + OutputStream echo = err ? stderrFile : stdoutFile; + if (echo != null) { + try { + echo.write(b); + echo.flush(); + } catch (IOException e) { + e.printStackTrace(); + echo = null; + } } } } } +// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + /** * Buffer updates to the console and output them in batches. For info, see: * http://java.sun.com/products/jfc/tsc/articles/text/element_buffer and diff --git a/todo.txt b/todo.txt index 7e58d3d40..a80e0a984 100644 --- a/todo.txt +++ b/todo.txt @@ -89,7 +89,7 @@ X tough to do with the multiple directories/submenus o add methods for "add" and "remove" for sketches o also a rename method, which could just be a remove and add X libraries and examples won't be rebuilt during the session -_ editor console is broken, because re-routes System.out +X editor console is broken, because re-routes System.out _ test on windows _ test on linux _ make sure quit being handled properly on windows/linux @@ -890,6 +890,7 @@ PDE / Runner _ make the p5 icon show up for the window (and in the dock) _ when launching a new sketch +_ can embed icon.gif as byte array in PApplet, and use Toolkit.createImage _ does closing the window call stop()? _ need to make sure hitting stop button and closing window explicitly call _ stop() not working very well