1 19 20 package org.netbeans.modules.debugger.jpda.ui; 21 22 import java.io.IOException ; 23 import java.util.Hashtable ; 24 import java.util.LinkedList ; 25 import org.netbeans.api.debugger.jpda.JPDADebugger; 26 import org.openide.awt.StatusDisplayer; 27 import org.openide.util.NbBundle; 28 import org.openide.util.RequestProcessor; 29 import org.openide.windows.IOProvider; 30 import org.openide.windows.InputOutput; 31 import org.openide.windows.OutputEvent; 32 import org.openide.windows.OutputListener; 33 import org.openide.windows.OutputWriter; 34 35 public class IOManager { 36 37 51 52 54 protected InputOutput debuggerIO = null; 55 private OutputWriter debuggerOut; 56 private OutputWriter debuggerErr; 57 private String name; 58 private boolean closed = false; 59 60 61 private Hashtable lines = new Hashtable (); 62 private Listener listener = new Listener (); 63 64 65 67 public IOManager(String title) { 68 debuggerIO = IOProvider.getDefault ().getIO (title, true); 69 debuggerIO.setFocusTaken (false); 70 debuggerIO.setErrSeparated(false); 71 debuggerOut = debuggerIO.getOut (); 72 debuggerErr = debuggerIO.getErr(); 73 debuggerIO.select(); 74 } 75 76 77 79 private LinkedList buffer = new LinkedList (); 80 private RequestProcessor.Task task; 81 82 85 public void println ( 86 String text, 87 Line line 88 ) { 89 println(text, line, false); 90 } 91 92 95 public void println ( 96 String text, 97 Line line, 98 boolean important 99 ) { 100 if (text == null) 101 throw new NullPointerException (); 102 synchronized (buffer) { 103 buffer.addLast (new Text (text, line, important)); 104 } 105 if (task == null) 106 task = RequestProcessor.getDefault ().post (new Runnable () { 107 public void run () { 108 synchronized (buffer) { 109 int i, k = buffer.size (); 110 for (i = 0; i < k; i++) { 111 Text t = (Text) buffer.removeFirst (); 112 try { 113 Listener listener; 115 if (t.line != null) { 116 listener = IOManager.this.listener; 117 lines.put (t.text, t.line); 118 } else { 119 listener = null; 120 } 121 if (t.important) { 122 debuggerErr.println (t.text, listener, t.important); 123 debuggerIO.select(); 124 debuggerErr.flush(); 125 } else { 126 debuggerOut.println (t.text, listener, t.important); 127 debuggerOut.flush(); 128 } 129 if (closed) { 130 debuggerOut.close (); 131 debuggerErr.close(); 132 } 133 StatusDisplayer.getDefault ().setStatusText (t.text); 136 } catch (IOException ex) { 137 ex.printStackTrace (); 138 } 139 } 140 } 141 } 142 }, 500, Thread.MIN_PRIORITY); 143 else 144 task.schedule (500); 145 } 146 147 void closeStream () { 148 debuggerOut.close (); 149 closed = true; 150 } 151 152 void close () { 153 debuggerIO.closeInputOutput (); 154 } 155 156 157 159 private class Listener implements OutputListener { 160 public void outputLineSelected (OutputEvent ev) { 161 } 162 public void outputLineAction (OutputEvent ev) { 163 String t = ev.getLine (); 164 Line l = (Line) lines.get (t); 165 if (l == null) return; 166 l.show (); 167 } 168 public void outputLineCleared (OutputEvent ev) { 169 lines = new Hashtable (); 170 } 171 } 172 173 private static class Text { 174 private String text; 175 private Line line; 176 private boolean important; 177 178 private Text (String text, Line line, boolean important) { 179 this.text = text; 180 this.line = line; 181 this.important = important; 182 } 183 } 184 185 static class Line { 186 private String url; 187 private int lineNumber; 188 private JPDADebugger debugger; 189 190 Line (String url, int lineNumber, JPDADebugger debugger) { 191 this.url = url; 192 this.lineNumber = lineNumber; 193 } 194 195 void show () { 196 EditorContextBridge.showSource (url, lineNumber, debugger); 197 } 198 } 199 } 200 | Popular Tags |