1 19 20 package org.netbeans.modules.ant.debugger; 21 22 import java.io.IOException ; 23 import java.util.Hashtable ; 24 import java.util.LinkedList ; 25 import javax.swing.SwingUtilities ; 26 import org.openide.awt.StatusDisplayer; 27 import org.openide.text.Annotatable; 28 import org.openide.text.Line; 29 import org.openide.util.NbBundle; 30 import org.openide.util.RequestProcessor; 31 import org.openide.windows.IOProvider; 32 import org.openide.windows.InputOutput; 33 import org.openide.windows.OutputEvent; 34 import org.openide.windows.OutputListener; 35 import org.openide.windows.OutputWriter; 36 37 38 public class IOManager { 39 40 42 protected InputOutput debuggerIO = null; 43 private OutputWriter debuggerOut; 44 private String name; 45 private boolean closed = false; 46 47 48 49 private Hashtable lines = new Hashtable (); 50 private Listener listener = new Listener (); 51 52 53 55 public IOManager ( 56 String title 57 ) { 58 debuggerIO = IOProvider.getDefault ().getIO (title, true); 59 debuggerIO.setFocusTaken (false); 60 debuggerOut = debuggerIO.getOut (); 61 } 62 63 64 66 private LinkedList buffer = new LinkedList (); 67 private RequestProcessor.Task task; 68 69 72 public void println ( 73 final String text, 74 final Object line 75 ) { 76 if (text == null) 77 throw new NullPointerException (); 78 synchronized (buffer) { 79 buffer.addLast (new Text (text, line)); 80 } 81 if (task == null) 82 task = RequestProcessor.getDefault ().post (new Runnable () { 83 public void run () { 84 synchronized (buffer) { 85 int i, k = buffer.size (); 86 for (i = 0; i < k; i++) { 87 Text t = (Text) buffer.removeFirst (); 88 try { 89 if (t.line != null) { 90 debuggerOut.println (t.text, listener); 91 lines.put (t.text, t.line); 92 } else 93 debuggerOut.println (t.text); 94 debuggerOut.flush (); 95 if (closed) 96 debuggerOut.close (); 97 StatusDisplayer.getDefault ().setStatusText (t.text); 98 } catch (IOException ex) { 99 ex.printStackTrace (); 100 } 101 } 102 } 103 } 104 }, 100, Thread.MIN_PRIORITY); 105 else 106 task.schedule (100); 107 } 108 109 void closeStream () { 110 debuggerOut.close (); 111 closed = true; 112 close(); 113 } 114 115 void close () { 116 debuggerIO.closeInputOutput (); 117 } 118 119 120 122 private class Listener implements OutputListener { 123 public void outputLineSelected (OutputEvent ev) { 124 } 125 public void outputLineAction (final OutputEvent ev) { 126 SwingUtilities.invokeLater (new Runnable () { 127 public void run () { 128 String t = ev.getLine (); 129 Object a = lines.get (t); 130 if (a == null) return; 131 Utils.showLine (a); 132 } 133 }); 134 } 135 public void outputLineCleared (OutputEvent ev) { 136 lines = new Hashtable (); 137 } 138 } 139 140 private static class Text { 141 private String text; 142 private Object line; 143 144 private Text (String text, Object line) { 145 this.text = text; 146 this.line = line; 147 } 148 } 149 } 150 | Popular Tags |