KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > windows > InputOutput


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.windows;
21
22 import java.io.InputStreamReader JavaDoc;
23 import java.io.OutputStreamWriter JavaDoc;
24 import java.io.Reader JavaDoc;
25 import org.openide.util.io.NullOutputStream;
26 import org.openide.util.io.NullInputStream;
27
28 /** An I/O connection to one tab on the Output Window. To acquire an instance
29  * to write to, call, e.g.,
30  * <code>IOProvider.getDefault().getInputOutput("someName", false)</code>.
31  * To get actual streams to write to, call <code>getOut()</code> or <code>
32  * getErr()</code> on the returned instance.
33  * <p>
34  * Generally it is preferable not to hold a reference to an instance of
35  * {@link org.openide.windows.InputOutput}, but rather to fetch it by name from {@link org.openide.windows.IOProvider} as
36  * needed.<p>
37  * <b>Note:</b> For historical reasons, the mechanism to clear an output tab
38  * is via the method {@link org.openide.windows.OutputWriter#reset}, though it would have
39  * made more sense implemented here.
40  *
41  * @see OutputWriter
42  * @author Ian Formanek, Jaroslav Tulach, Petr Hamernik, Ales Novak, Jan Jancura
43  */

44 public interface InputOutput {
45
46
47     /** Null InputOutput */
48     /*public static final*/ InputOutput NULL = new InputOutput$Null();
49
50     /** Acquire an output writer to write to the tab.
51     * This is the usual use of a tab--it writes to the main output pane.
52     * @return the writer
53     */

54     public OutputWriter getOut();
55
56     /** Get a reader to read from the tab.
57     * If a reader is ever requested, an input line is added to the
58     * tab and used to read one line at a time.
59     * @return the reader
60     */

61     public Reader JavaDoc getIn();
62
63     /** Get an output writer to write to the tab in error mode.
64     * This might show up in a different color than the regular output, e.g., or
65     * appear in a separate pane.
66     * @return the writer
67     */

68     public OutputWriter getErr();
69
70     /** Closes this tab. The effect of calling any method on an instance
71      * of InputOutput after calling <code>closeInputOutput()</code> on it is undefined.
72      */

73     public void closeInputOutput();
74
75     /** Test whether this tab has been closed, either by a call to <code>closeInputOutput()</code>
76     * or by the user closing the tab in the UI.
77     *
78     * @see #closeInputOutput
79     * @return <code>true</code> if it is closed
80     */

81     public boolean isClosed();
82
83     /** Show or hide the standard output pane, if separated. Does nothing in either
84     * of the available implementations of this API.
85     * @param value <code>true</code> to show, <code>false</code> to hide
86     */

87     public void setOutputVisible(boolean value);
88
89     /** Show or hide the error pane, if separated. Does nothing in either
90     * of the available implementations of this API.
91     * @param value <code>true</code> to show, <code>false</code> to hide
92     */

93     public void setErrVisible(boolean value);
94
95     /** Show or hide the input line.
96     * @param value <code>true</code> to show, <code>false</code> to hide
97     */

98     public void setInputVisible(boolean value);
99
100     /**
101     * Ensure this pane is visible.
102     */

103     public void select ();
104
105     /** Test whether the error output is mixed into the regular output or not.
106     * Always true for both available implementations of this API.
107     * @return <code>true</code> if separate, <code>false</code> if mixed in
108     */

109     public boolean isErrSeparated();
110
111     /** Set whether the error output should be mixed into the regular output or not.
112     * Note that this method is optional and is not supported by either of the
113     * current implementations of InputOutput (core/output and core/output2).
114     * @param value <code>true</code> to separate, <code>false</code> to mix in
115     */

116     public void setErrSeparated(boolean value);
117
118     /** Test whether the output window takes focus when anything is written to it.
119     * @return <code>true</code> if any write to the tab should cause it to gain
120     * keyboard focus <strong>(not recommended)</strong>
121     */

122     public boolean isFocusTaken();
123
124     /** Set whether the output window should take focus when anything is written to it.
125     * <strong>Note that this really means the output window will steal keyboard
126     * focus whenever a line of output is written. This is generally an extremely
127     * bad idea and strongly recommended against by most UI guidelines.</strong>
128     * @param value <code>true</code> to take focus
129     */

130     public void setFocusTaken(boolean value);
131
132     /** Flush pending data in the input-line's reader.
133     * Called when the reader is about to be reused.
134     * @return the flushed reader
135     * @deprecated meaningless, does nothing
136     */

137     public Reader JavaDoc flushReader();
138
139     /** @deprecated Use {@link #NULL} instead. */
140     /*public static final*/ Reader JavaDoc nullReader = new InputStreamReader JavaDoc(new NullInputStream());
141
142     /** @deprecated Use {@link #NULL} instead. */
143     /*public static final*/ OutputWriter nullWriter = new InputOutput$NullOutputWriter();
144
145 }
146
147 final class InputOutput$Null extends Object JavaDoc implements InputOutput {
148     public InputOutput$Null () {
149     }
150     
151     public OutputWriter getOut() {
152         return nullWriter;
153     }
154     public Reader JavaDoc getIn() {
155         return nullReader;
156     }
157     public OutputWriter getErr() {
158         return nullWriter;
159     }
160     public void closeInputOutput() {
161     }
162     public boolean isClosed() {
163         return true;
164     }
165     public void setOutputVisible(boolean value) {
166     }
167     public void setErrVisible(boolean value) {
168     }
169     public void setInputVisible(boolean value) {
170     }
171     public void select () {
172     }
173     public boolean isErrSeparated() {
174         return false;
175     }
176     public void setErrSeparated(boolean value) {
177     }
178     public boolean isFocusTaken() {
179         return false;
180     }
181     public void setFocusTaken(boolean value) {
182     }
183     public Reader JavaDoc flushReader() {
184         return nullReader;
185     }
186 }
187
188 final class InputOutput$NullOutputWriter extends OutputWriter {
189     InputOutput$NullOutputWriter() {
190         super(new OutputStreamWriter JavaDoc(new NullOutputStream()));
191     }
192     public void reset() {
193     }
194     public void println(String JavaDoc s, OutputListener l) {
195     }
196 }
197
198
Popular Tags