Index: demosrc/org/netbeans/core/output2/TestFrame.java =================================================================== RCS file: /cvs/core/output2/demosrc/org/netbeans/core/output2/TestFrame.java,v retrieving revision 1.15 diff -u -u -r1.15 TestFrame.java --- demosrc/org/netbeans/core/output2/TestFrame.java 25 Aug 2004 00:41:36 -0000 1.15 +++ demosrc/org/netbeans/core/output2/TestFrame.java 31 Aug 2005 07:58:40 -0000 @@ -35,15 +35,15 @@ // io.setInputVisible(true); // io.setToolbarActions (new Action[] {new StopAction("STOP!!")}); validate(); - System.err.println ("Writing content"); - for (int i=0; i < 10000; i++) { - io.getErr().println("Scroll me " + i); - if (i %20 == 0) { - io.getOut().println("STDOUT: This is a longer line. A much longer line. A very long line. You'd be surprised how long it would be - maybe long enought to wrap - or at least that's the idea and the master plan, right? Well, we'll hope so"); - io.getErr().println("STDERR: This Well, this one isn't so bad. But it could be long too. I mean, then we'd have more long lines. Are we sure that's a good idea? I'm not. So just go away, why don't you! I don't want to do this anyways!"); - } + for (int i=0; i < 10; i++) { +// io.getErr().println("Scroll me " + i); +// if (i %20 == 0) { + ((LineColoredOutputWriter)io.getOut()).println("Orange Line! This is a longer line. A much longer line. A very long line. You'd be surprised how long it would be - maybe long enought to wrap - or at least that's the idea and the master plan, right? Well, we'll hope so", Color.ORANGE); + ((LineColoredOutputWriter)io.getOut()).println("Green Line! This line is green with greenness", Color.GREEN); +// io.getErr().println("STDERR: This Well, this one isn't so bad. But it could be long too. I mean, then we'd have more long lines. Are we sure that's a good idea? I'm not. So just go away, why don't you! I don't want to do this anyways!"); +// } if (i % 73 == 0) { - io.getErr().println("Grumble, grumble, I am a multiple of 73"); + io.getErr().println("MOO! Grumble, grumble, I am a multiple of 73"); // io.getErr().println("file:/tmp/file:23"); } try { @@ -85,7 +85,7 @@ io = (NbIO) new NbIOProvider().getIO ("Test", false); } - private static int ct = 5; + private static int ct = 1; public void run () { if (SwingUtilities.isEventDispatchThread()) { out = ((NbWriter) io.getOut()); Index: src/org/netbeans/core/output2/AbstractLines.java =================================================================== RCS file: /cvs/core/output2/src/org/netbeans/core/output2/AbstractLines.java,v retrieving revision 1.10 diff -u -u -r1.10 AbstractLines.java --- src/org/netbeans/core/output2/AbstractLines.java 18 Apr 2005 07:23:02 -0000 1.10 +++ src/org/netbeans/core/output2/AbstractLines.java 31 Aug 2005 07:58:40 -0000 @@ -11,9 +11,7 @@ * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core.output2; - -import java.util.HashSet; -import java.util.Set; +import java.awt.Color; import org.openide.windows.OutputListener; import org.openide.ErrorManager; import org.openide.util.Mutex; @@ -329,6 +327,15 @@ public OutputListener getListenerForLine (int line) { return (OutputListener) linesToListeners.get(line); } + + private IntMap linesToColors = new IntMap(); + public Color getLineColor (int line) { + return (Color) linesToColors.get(line); + } + + public void setLineColor(int line, Color c) { + linesToColors.put (line, c); + } public int firstListenerLine () { if (isDisposed() || isTrouble()) return -1; @@ -667,7 +674,8 @@ } } - public void lineFinished(int lineLength) { + public int lineFinished(int lineLength) { + int lastline; synchronized (readLock()) { setLastWrappedLineCount(-1); setLastCharCountForWrapAboveCalculation(-1); @@ -676,9 +684,10 @@ int lineCount = lineStartList.size(); //This is the index of the getLine we just added - int lastline = lineCount-1; + lastline = lineCount-1; checkLogicalLineCount(lastline); } + return lastline; } private void checkLogicalLineCount(int lastline) { @@ -710,9 +719,10 @@ } - public void lineWritten(int start, int lineLength) { + public int lineWritten(int start, int lineLength) { if (Controller.verbose) Controller.log("AbstractLines.lineWritten " + start + " length:" + lineLength); //NOI18N - int lineCount = 0; + int lastline; + int lineCount; synchronized (readLock()) { setLastWrappedLineCount(-1); setLastCharCountForWrapAboveCalculation(-1); @@ -722,7 +732,7 @@ lineCount = lineStartList.size(); //This is the index of the getLine we just added - int lastline = lineCount-1; + lastline = lineCount-1; checkLogicalLineCount(lastline); } @@ -731,6 +741,7 @@ if (Controller.log) Controller.log("Firing initial write event"); fire(); } + return lastline; } /** Convert an index from chars to byte count (*2). Simple math, but it Index: src/org/netbeans/core/output2/ExtPlainView.java =================================================================== RCS file: /cvs/core/output2/src/org/netbeans/core/output2/ExtPlainView.java,v retrieving revision 1.8 diff -u -u -r1.8 ExtPlainView.java --- src/org/netbeans/core/output2/ExtPlainView.java 18 Nov 2004 09:15:25 -0000 1.8 +++ src/org/netbeans/core/output2/ExtPlainView.java 31 Aug 2005 07:58:41 -0000 @@ -113,8 +113,9 @@ boolean hyperlink = od.getLines().isHyperlink(line); boolean important = hyperlink ? od.getLines().isImportantHyperlink(line) : false; boolean isErr = od.getLines().isErr(line); + Color c = od.getLines().getLineColor(line); - return hyperlink ? + return c != null && !selected ? c : hyperlink ? (important ? (selected ? WrappedTextView.selectedImportantLinkFg : Index: src/org/netbeans/core/output2/LineColoredOutputWriter.java =================================================================== RCS file: src/org/netbeans/core/output2/LineColoredOutputWriter.java diff -N src/org/netbeans/core/output2/LineColoredOutputWriter.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/core/output2/LineColoredOutputWriter.java 31 Aug 2005 07:58:41 -0000 @@ -0,0 +1,20 @@ +/* + * LineColoredOutputWriter.java + * + * Created on August 30, 2005, 11:44 PM + * + * To change this template, choose Tools | Options and locate the template under + * the Source Creation and Management node. Right-click the template and choose + * Open. You can then make changes to the template in the Source Editor. + */ + +package org.netbeans.core.output2; +import java.awt.Color; + +/** + * + * @author tim + */ +public interface LineColoredOutputWriter { + public void println (String line, Color c); +} Index: src/org/netbeans/core/output2/Lines.java =================================================================== RCS file: /cvs/core/output2/src/org/netbeans/core/output2/Lines.java,v retrieving revision 1.3 diff -u -u -r1.3 Lines.java --- src/org/netbeans/core/output2/Lines.java 18 Nov 2004 09:15:25 -0000 1.3 +++ src/org/netbeans/core/output2/Lines.java 31 Aug 2005 07:58:41 -0000 @@ -12,6 +12,7 @@ */ package org.netbeans.core.output2; +import java.awt.Color; import org.openide.windows.OutputListener; import javax.swing.event.ChangeListener; @@ -284,4 +285,11 @@ * @return True if there is still an open stream which may write to the backing storage and no error has occured */ boolean isGrowing(); + + /** + * Get the color that was passed to LineColoredOutputWriter for a line. + * @param line the line number + * @return the color + */ + Color getLineColor(int line); } Index: src/org/netbeans/core/output2/NbWriter.java =================================================================== RCS file: /cvs/core/output2/src/org/netbeans/core/output2/NbWriter.java,v retrieving revision 1.5 diff -u -u -r1.5 NbWriter.java --- src/org/netbeans/core/output2/NbWriter.java 18 Nov 2004 09:15:26 -0000 1.5 +++ src/org/netbeans/core/output2/NbWriter.java 31 Aug 2005 07:58:41 -0000 @@ -13,11 +13,10 @@ package org.netbeans.core.output2; +import java.awt.Color; import org.openide.windows.OutputWriter; import org.openide.windows.OutputListener; import org.openide.ErrorManager; - -import javax.swing.plaf.basic.BasicTabbedPaneUI; import java.io.IOException; @@ -28,7 +27,7 @@ * which it replaces when reset() is called; an OutputDocument is implemented directly over an * OutWriter, so the immutable OutWriter lasts until the OutputDocument is destroyed. */ -class NbWriter extends OutputWriter { +class NbWriter extends OutputWriter implements LineColoredOutputWriter { private final NbIO owner; /** * Make an output writer. @@ -140,5 +139,10 @@ synchronized (lock) { ((OutWriter) out).println(s); } + } + + public void println(String line, Color c) { + OutWriter ow = (OutWriter) out; + ow.println (line, c); } } Index: src/org/netbeans/core/output2/OutWriter.java =================================================================== RCS file: /cvs/core/output2/src/org/netbeans/core/output2/OutWriter.java,v retrieving revision 1.28 diff -u -u -r1.28 OutWriter.java --- src/org/netbeans/core/output2/OutWriter.java 30 Jun 2005 16:44:16 -0000 1.28 +++ src/org/netbeans/core/output2/OutWriter.java 31 Aug 2005 07:58:41 -0000 @@ -18,6 +18,7 @@ package org.netbeans.core.output2; +import java.awt.Color; import org.openide.ErrorManager; import org.openide.util.Mutex; import org.openide.util.NbBundle; @@ -43,7 +44,7 @@ * * @author Tim Boudreau */ -class OutWriter extends PrintWriter { +class OutWriter extends PrintWriter implements LineColoredOutputWriter { /** A flag indicating an io exception occured */ private boolean trouble = false; @@ -128,7 +129,7 @@ return "OutWriter@" + System.identityHashCode(this) + " for " + owner + " closed "; } - private int doPrintln (String s) { + private int doPrintln (String s, Color color) { try { int idx = s.indexOf("\n"); int result = 1; @@ -141,13 +142,13 @@ String token = tok.nextToken(); if (token.equals("\n")) { if (lastWasNewLine) { - doPrintln(""); + doPrintln("", color); result++; } lastWasNewLine = true; } else { lastWasNewLine = false; - doPrintln(token); + doPrintln(token, color); result++; } } @@ -173,7 +174,7 @@ buf = getStorage().getWriteBuffer(AbstractLines.toByteIndex(s.length())); buf.asCharBuffer().put(s); buf.position (buf.position() + AbstractLines.toByteIndex(s.length())); - write (buf, true); + write (buf, true, color); } } return result; @@ -209,7 +210,7 @@ * @param bb * @throws IOException */ - public synchronized void write(ByteBuffer bb, boolean completeLine) throws IOException { + public synchronized void write(ByteBuffer bb, boolean completeLine, Color color) throws IOException { if (checkError() || terminated) { return; } @@ -256,10 +257,11 @@ if (lineStart >= 0 && !terminated && lines != null) { if (Controller.verbose) Controller.log (this + ": Wrote " + ((ByteBuffer)bb.flip()).asCharBuffer() + " at " + start); + int line; if (startedNow) { - lines.lineWritten (lineStart, lineLength); + line = lines.lineWritten (lineStart, lineLength); } else { - lines.lineFinished(lineLength); + line = lines.lineFinished(lineLength); } lineStart = -1; lineLength = 0; @@ -267,6 +269,9 @@ owner.setStreamClosed(false); lines.fire(); } + if (color != null) { + lines.setLineColor(line, color); + } } } else { if (startedNow && lineStart >= 0 && !terminated && lines != null) { @@ -384,7 +389,7 @@ if (checkError()) { return; } - doPrintln(s); + doPrintln(s, null); } public synchronized void flush() { @@ -418,7 +423,7 @@ ByteBuffer buf = getStorage().getWriteBuffer(AbstractLines.toByteIndex(1)); buf.asCharBuffer().put((char)c); buf.position (buf.position() + AbstractLines.toByteIndex(1)); - write (buf, false); + write (buf, false, null); } catch (IOException ioe) { handleException (ioe); } @@ -469,7 +474,7 @@ ByteBuffer buf = getStorage().getWriteBuffer(AbstractLines.toByteIndex(lenght)); buf.asCharBuffer().put(data, start, lenght); buf.position(buf.position() + AbstractLines.toByteIndex(lenght)); - write(buf, false); + write(buf, false, null); } } catch (IOException ioe) { handleException(ioe); @@ -482,7 +487,7 @@ } public synchronized void println() { - doPrintln(""); + doPrintln("", null); } /** @@ -509,7 +514,7 @@ if (checkError()) { return; } - int addedCount = doPrintln (s); + int addedCount = doPrintln (s, null); int newCount = lines.getLineCount(); for (int i=newCount - addedCount; i < newCount; i++) { lines.addListener (i, l, important); @@ -518,6 +523,13 @@ lines.fire(); } } + + public void println(String line, Color c) { + if (checkError()) { + return; + } + doPrintln (line, c); + } /** * A useless writer object to pass to the superclass constructor. We override all methods Index: src/org/netbeans/core/output2/WrappedTextView.java =================================================================== RCS file: /cvs/core/output2/src/org/netbeans/core/output2/WrappedTextView.java,v retrieving revision 1.16 diff -u -u -r1.16 WrappedTextView.java --- src/org/netbeans/core/output2/WrappedTextView.java 18 Mar 2005 09:23:34 -0000 1.16 +++ src/org/netbeans/core/output2/WrappedTextView.java 31 Aug 2005 07:58:42 -0000 @@ -606,7 +606,10 @@ boolean hyperlink = od.getLines().isHyperlink(line); boolean important = hyperlink ? od.getLines().isImportantHyperlink(line) : false; boolean isErr = od.getLines().isErr(line); - return hyperlink ? (important ? (selected ? selectedImportantLinkFg : unselectedImportantLinkFg) : + Color c = od.getLines().getLineColor(line); + + return c != null ? c : + hyperlink ? (important ? (selected ? selectedImportantLinkFg : unselectedImportantLinkFg) : (selected ? selectedLinkFg : unselectedLinkFg)) : (selected ? (isErr ? selectedErr : selectedFg) : (isErr ? unselectedErr : unselectedFg));