001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.core.output2;
042:
043: import javax.swing.*;
044: import java.awt.*;
045: import org.netbeans.core.output2.ui.*;
046: import org.openide.windows.*;
047:
048: /** Demo class for interactively testing changes */
049: public class TestFrame extends JFrame implements Runnable {
050: public static void main(String[] ignored) {
051: // try {
052: // UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
053: // } catch (Exception e) {}
054:
055: new TestFrame().setVisible(true);
056: }
057:
058: public TestFrame() {
059: init();
060: setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
061: }
062:
063: private void writeContent() {
064: // io.setInputVisible(true);
065: // io.setToolbarActions (new Action[] {new StopAction("STOP!!")});
066: validate();
067: System.err.println("Writing content");
068: for (int i = 0; i < 10000; i++) {
069: io.getErr().println("Scroll me " + i);
070: if (i % 20 == 0) {
071: io
072: .getOut()
073: .println(
074: "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");
075: io
076: .getErr()
077: .println(
078: "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!");
079: }
080: if (i % 73 == 0) {
081: io.getErr().println(
082: "Grumble, grumble, I am a multiple of 73");
083: // io.getErr().println("file:/tmp/file:23");
084: }
085: try {
086: Thread.currentThread().sleep(100);
087: } catch (Exception e) {
088: }
089: ;
090: }
091:
092: out.println("4 This is another short line");
093:
094: out.println("5 And now we are done");
095: out.flush();
096: io.getErr().close();
097: out.close();
098: written = true;
099: System.err.println("DONE");
100: }
101:
102: private static boolean written = false;
103:
104: public void setVisible(boolean val) {
105: boolean go = val != isVisible();
106: super .setVisible(val);
107: if (!SwingUtilities.isEventDispatchThread() && go) {
108: try {
109: Thread.currentThread().sleep(500);
110: SwingUtilities.invokeLater(this );
111: } catch (Exception e) {
112: }
113: }
114: }
115:
116: private OutputWindow win;
117: private NbIO io;
118: private NbWriter out = null;
119:
120: private void init() {
121: win = new OutputWindow();
122: OutputWindow.DEFAULT = win;
123: getContentPane().setLayout(new BorderLayout());
124: getContentPane().add(win, BorderLayout.CENTER);
125: setBounds(20, 20, 335, 300);
126: io = (NbIO) new NbIOProvider().getIO("Test", false);
127: }
128:
129: private static int ct = 5;
130:
131: public void run() {
132: if (SwingUtilities.isEventDispatchThread()) {
133: out = ((NbWriter) io.getOut());
134: Thread t = new Thread(this );
135: t.setName("Thread " + ct + " - ");
136: t.start();
137: ct--;
138: out
139: .println("This is the first text "
140: + ct
141: + " and even it might be long enough to be word wrapped. We should make sure that doesn't cause any strange problems, shouldn't we?");
142: ((OutputPane) win.getSelectedTab().getOutputPane())
143: .setWrapped(true);
144: if (ct > 0) {
145: SwingUtilities.invokeLater(this );
146: }
147: } else {
148: try {
149: Thread.currentThread().sleep(3000);
150: } catch (Exception e) {
151: }
152: writeContent();
153: }
154: }
155:
156: private static Action ac = null;
157:
158: private class StopAction extends AbstractAction {
159: public StopAction(String name) {
160: putValue(NAME, name);
161: putValue(Action.SMALL_ICON, new StopIcon());
162: ac = this ;
163: }
164:
165: public void actionPerformed(java.awt.event.ActionEvent e) {
166: stopped = true;
167: System.err.println("Stop action performed");
168: }
169: }
170:
171: private static boolean stopped = false;
172:
173: private class StopIcon implements Icon {
174:
175: public int getIconHeight() {
176: return 16;
177: }
178:
179: public int getIconWidth() {
180: return 16;
181: }
182:
183: public void paintIcon(Component c, Graphics g, int x, int y) {
184: g.setColor(Color.ORANGE);
185: g.fillRect(x + 2, x + 2, 12, 12);
186: g.setColor(Color.BLACK);
187: g.drawRect(x + 2, x + 2, 12, 12);
188:
189: }
190:
191: }
192:
193: public class L implements OutputListener {
194:
195: public void outputLineSelected(OutputEvent ev) {
196: }
197:
198: public void outputLineAction(OutputEvent ev) {
199: }
200:
201: public void outputLineCleared(OutputEvent ev) {
202: }
203:
204: }
205:
206: }
|