diff --git a/app/src/processing/app/Console.java b/app/src/processing/app/Console.java index 178fce716..b65aa1c89 100644 --- a/app/src/processing/app/Console.java +++ b/app/src/processing/app/Console.java @@ -30,7 +30,7 @@ import java.util.Date; /** - * Message console that sits below the editing area. + * Non-GUI handling of System.out and System.err redirection. *
* Be careful when debugging this class, because if it's throwing exceptions, * don't take over System.err, and debug while watching just System.out @@ -43,9 +43,6 @@ import java.util.Date; * get along with one another. Use 'ant run' to work on encoding-related issues. */ public class Console { -// PrintStream sketchOut; -// PrintStream sketchErr; - // Single static instance shared because there's only one real System.out. // Within the input handlers, the currentConsole variable will be used to // echo things to the correct location. @@ -72,6 +69,13 @@ public class Console { static public void startup() { + if (systemOut != null) { + // TODO fix this dreadful style choice in how the Console is initialized + // (This is not good code.. startup() should gracefully deal with this. + // It's just a low priority relative to the likelihood of trouble.) + new Exception("startup() called more than once").printStackTrace(systemErr); + return; + } systemOut = System.out; systemErr = System.err; @@ -115,8 +119,6 @@ public class Console { File errFile = new File(consoleDir, stamp + ".err"); stderrFile = new FileOutputStream(errFile); -// consoleOut = new PrintStream(new EditorConsoleStream(false, null)); -// consoleErr = new PrintStream(new EditorConsoleStream(true, null)); consoleOut = new PrintStream(new ConsoleStream(false)); consoleErr = new PrintStream(new ConsoleStream(true)); @@ -144,20 +146,14 @@ public class Console { } -// public Console() { -// sketchOut = new PrintStream(new EditorConsoleStream(false, this)); -// sketchErr = new PrintStream(new EditorConsoleStream(true, this)); -// } + static public void systemOut(String what) { + systemOut.println(what); + } -// public PrintStream getOut() { -// return sketchOut; -// } - - -// public PrintStream getErr() { -// return sketchErr; -// } + static public void systemErr(String what) { + systemErr.println(what); + } /** diff --git a/app/src/processing/app/exec/StreamRedirectThread.java b/app/src/processing/app/exec/StreamRedirectThread.java index c3140d872..ee6d7ed00 100644 --- a/app/src/processing/app/exec/StreamRedirectThread.java +++ b/app/src/processing/app/exec/StreamRedirectThread.java @@ -7,13 +7,13 @@ */ /* * Copyright (c) 1997-2001 by Sun Microsystems, Inc. All Rights Reserved. - * + * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. - * + * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR @@ -25,7 +25,7 @@ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. - * + * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear @@ -50,7 +50,7 @@ public class StreamRedirectThread extends Thread { private static final int BUFFER_SIZE = 2048; - + /** * Set up for copy. * @param name Name of the thread @@ -63,15 +63,15 @@ public class StreamRedirectThread extends Thread { this.out = new OutputStreamWriter(out); setPriority(Thread.MAX_PRIORITY-1); } - - + + public StreamRedirectThread(String name, Reader in, Writer out) { super(name); this.in = in; this.out = out; setPriority(Thread.MAX_PRIORITY-1); } - + /** * Copy. @@ -80,16 +80,15 @@ public class StreamRedirectThread extends Thread { try { char[] cbuf = new char[BUFFER_SIZE]; int count; - //System.out.println("opening streamredirectthread"); while ((count = in.read(cbuf, 0, BUFFER_SIZE)) >= 0) { out.write(cbuf, 0, count); // had to add the flush() here.. maybe shouldn't be using writer? [fry] out.flush(); } - //System.out.println("exiting streamredirectthread"); out.flush(); - } catch(IOException exc) { - System.err.println("Child I/O Transfer - " + exc); + + } catch (IOException exc) { + processing.app.Console.systemErr("Child I/O Transfer - " + exc); } } } diff --git a/app/src/processing/app/ui/EditorConsole.java b/app/src/processing/app/ui/EditorConsole.java index 005f12405..d27d17d05 100644 --- a/app/src/processing/app/ui/EditorConsole.java +++ b/app/src/processing/app/ui/EditorConsole.java @@ -32,8 +32,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.OutputStream; import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; import javax.swing.*; import javax.swing.border.MatteBorder; @@ -46,16 +45,6 @@ import processing.app.Preferences; /** * Message console that sits below the editing area. - * - * Be careful when debugging this class, because if it's throwing exceptions, - * don't take over System.err, and debug while watching just System.out - * or just call println() or whatever directly to systemOut or systemErr. - * - * Also note that encodings will not work properly when run from Eclipse. This - * means that if you use non-ASCII characters in a println() or some such, - * the characters won't print properly in the Processing and/or Eclipse console. - * It seems that Eclipse's console-grabbing and that of Processing don't - * get along with one another. Use 'ant run' to work on encoding-related issues. */ public class EditorConsole extends JScrollPane { Editor editor; @@ -69,6 +58,7 @@ public class EditorConsole extends JScrollPane { MutableAttributeSet errStyle; int maxLineCount; + int maxCharCount; PrintStream sketchOut; PrintStream sketchErr; @@ -79,9 +69,10 @@ public class EditorConsole extends JScrollPane { public EditorConsole(Editor editor) { this.editor = editor; - maxLineCount = Preferences.getInteger("console.length"); + maxLineCount = Preferences.getInteger("console.lines"); + maxCharCount = Preferences.getInteger("console.chars"); - consoleDoc = new BufferedStyledDocument(10000, maxLineCount); + consoleDoc = new BufferedStyledDocument(10000, maxLineCount, maxCharCount); consoleTextPane = new JTextPane(consoleDoc); consoleTextPane.setEditable(false); @@ -98,7 +89,7 @@ public class EditorConsole extends JScrollPane { protected void flush() { // only if new text has been added - if (consoleDoc.hasAppendage) { + if (consoleDoc.hasAppendage()) { // insert the text that's been added in the meantime consoleDoc.insertAll(); // always move to the end of the text as it's added @@ -150,8 +141,7 @@ public class EditorConsole extends JScrollPane { */ protected void updateAppearance() { String fontFamily = Preferences.get("editor.font.family"); - int fontSize = - Toolkit.zoom(Preferences.getInteger("console.font.size")); + int fontSize = Toolkit.zoom(Preferences.getInteger("console.font.size")); StyleConstants.setFontFamily(stdStyle, fontFamily); StyleConstants.setFontSize(stdStyle, fontSize); StyleConstants.setFontFamily(errStyle, fontFamily); @@ -232,7 +222,7 @@ public class EditorConsole extends JScrollPane { } - synchronized public void message(String what, boolean err) { + public void message(String what, boolean err) { if (err && (what.contains("invalid context 0x0") || (what.contains("invalid drawable")))) { // Respectfully declining... This is a quirk of more recent releases of // Java on Mac OS X, but is widely reported as the source of any other @@ -302,22 +292,32 @@ public class EditorConsole extends JScrollPane { * swing event thread, so they need to be synchronized */ class BufferedStyledDocument extends DefaultStyledDocument { - List