2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.debugger.jpda.ui;
44
import java.io.IOException;
45
import java.util.Hashtable;
46
import java.util.LinkedList;
47
import org.netbeans.api.debugger.jpda.JPDADebugger;
48
import org.openide.awt.StatusDisplayer;
49
import org.openide.util.RequestProcessor;
50
import org.openide.windows.IOProvider;
51
import org.openide.windows.InputOutput;
52
import org.openide.windows.OutputEvent;
53
import org.openide.windows.OutputListener;
54
import org.openide.windows.OutputWriter;
56
public class IOManager {
58
// /** DebuggerManager output constant. */
59
// public static final int DEBUGGER_OUT = 1;
60
// /** Process output constant. */
61
// public static final int PROCESS_OUT = 2;
62
// /** Status line output constant. */
63
// public static final int STATUS_OUT = 4;
64
// /** All outputs constant. */
65
// public static final int ALL_OUT = DEBUGGER_OUT +
66
// PROCESS_OUT + STATUS_OUT;
67
// /** Standart process output constant. */
68
// public static final int STD_OUT = 1;
69
// /** Error process output constant. */
70
// public static final int ERR_OUT = 2;
73
// variables ...............................................................
75
protected InputOutput debuggerIO = null;
76
private OutputWriter debuggerOut;
77
private OutputWriter debuggerErr;
79
private boolean closed = false;
81
/** output writer Thread */
82
private Hashtable lines = new Hashtable ();
83
private Listener listener = new Listener ();
86
// init ....................................................................
88
public IOManager(String title) {
89
debuggerIO = IOProvider.getDefault ().getIO (title, true);
90
debuggerIO.setFocusTaken (false);
91
debuggerIO.setErrSeparated(false);
92
debuggerOut = debuggerIO.getOut ();
93
debuggerErr = debuggerIO.getErr();
98
// public interface ........................................................
100
private LinkedList buffer = new LinkedList ();
101
private RequestProcessor.Task task;
104
* Prints given text to the output.
106
public void println (
110
println(text, line, false);
114
* Prints given text to the output.
116
public void println (
122
throw new NullPointerException ();
123
synchronized (buffer) {
124
buffer.addLast (new Text (text, line, important));
126
task = new RequestProcessor("Debugger Output", 1).post (new Runnable () {
128
synchronized (buffer) {
129
int i, k = buffer.size ();
130
for (i = 0; i < k; i++) {
131
Text t = (Text) buffer.removeFirst ();
133
//if ((t.where & DEBUGGER_OUT) != 0) {
135
if (t.line != null) {
136
listener = IOManager.this.listener;
137
lines.put (t.text, t.line);
142
if (listener != null) {
143
debuggerErr.println(t.text, listener, t.important);
145
debuggerErr.println(t.text);
150
if (listener != null) {
151
debuggerOut.println(t.text, listener, t.important);
153
debuggerOut.println(t.text);
158
// if ((t.where & STATUS_OUT) != 0)
159
StatusDisplayer.getDefault ().setStatusText (t.text);
160
} catch (IOException ex) {
161
ex.printStackTrace ();
165
debuggerOut.close ();
170
}, 500, Thread.MIN_PRIORITY);
176
void closeStream () {
177
synchronized (buffer) {
186
debuggerIO.closeInputOutput ();
190
// innerclasses ............................................................
192
private class Listener implements OutputListener {
193
public void outputLineSelected (OutputEvent ev) {
195
public void outputLineAction (OutputEvent ev) {
196
String t = ev.getLine ();
197
Line l = (Line) lines.get (t);
198
if (l == null) return;
201
public void outputLineCleared (OutputEvent ev) {
202
lines = new Hashtable ();
206
private static class Text {
209
private boolean important;
211
private Text (String text, Line line, boolean important) {
214
this.important = important;
220
private int lineNumber;
221
private JPDADebugger debugger;
223
Line (String url, int lineNumber, JPDADebugger debugger) {
225
this.lineNumber = lineNumber;
229
EditorContextBridge.getContext().showSource (url, lineNumber, debugger);