KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output2 > TestFrame


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  package org.netbeans.core.output2;
20  import javax.swing.*;
21  import java.awt.*;
22  import org.netbeans.core.output2.ui.*;
23  import org.openide.windows.*;
24
25 /** Demo class for interactively testing changes */
26  public class TestFrame extends JFrame implements Runnable JavaDoc {
27     public static void main (String JavaDoc[] ignored) {
28 // try {
29
// UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
30
// } catch (Exception e) {}
31

32         new TestFrame().setVisible(true);
33     }
34
35     public TestFrame() {
36         init();
37         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
38     }
39
40     private void writeContent() {
41 // io.setInputVisible(true);
42
// io.setToolbarActions (new Action[] {new StopAction("STOP!!")});
43
validate();
44         System.err.println ("Writing content");
45         for (int i=0; i < 10000; i++) {
46             io.getErr().println("Scroll me " + i);
47             if (i %20 == 0) {
48                 io.getOut().println("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");
49                 io.getErr().println("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!");
50             }
51             if (i % 73 == 0) {
52                 io.getErr().println("Grumble, grumble, I am a multiple of 73");
53 // io.getErr().println("file:/tmp/file:23");
54
}
55             try {
56                 Thread.currentThread().sleep(100);
57             } catch (Exception JavaDoc e){};
58         }
59         
60         out.println ("4 This is another short line");
61         
62         out.println("5 And now we are done");
63         out.flush();
64         io.getErr().close();
65         out.close();
66         written = true;
67         System.err.println("DONE");
68     }
69
70     private static boolean written = false;
71     public void setVisible (boolean val) {
72        boolean go = val != isVisible();
73        super.setVisible(val);
74        if (!SwingUtilities.isEventDispatchThread() && go) {
75            try {
76                Thread.currentThread().sleep (500);
77                 SwingUtilities.invokeLater(this);
78            } catch (Exception JavaDoc e) {}
79        }
80     }
81
82     private OutputWindow win;
83     private NbIO io;
84     private NbWriter out = null;
85     private void init() {
86         win = new OutputWindow();
87         OutputWindow.DEFAULT = win;
88         getContentPane().setLayout (new BorderLayout());
89         getContentPane().add (win, BorderLayout.CENTER);
90         setBounds (20, 20, 335, 300);
91         io = (NbIO) new NbIOProvider().getIO ("Test", false);
92     }
93
94     private static int ct = 5;
95     public void run () {
96         if (SwingUtilities.isEventDispatchThread()) {
97             out = ((NbWriter) io.getOut());
98            Thread JavaDoc t = new Thread JavaDoc(this);
99            t.setName ("Thread " + ct + " - ");
100            t.start();
101            ct--;
102            out.println ("This is the first text " + ct + " 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?");
103            ((OutputPane) win.getSelectedTab().getOutputPane()).setWrapped(true);
104            if (ct > 0) {
105                SwingUtilities.invokeLater (this);
106            }
107         } else {
108         try {
109             Thread.currentThread().sleep(3000);
110             } catch (Exception JavaDoc e) {}
111             writeContent();
112         }
113     }
114     private static Action ac = null;
115     private class StopAction extends AbstractAction {
116         public StopAction (String JavaDoc name) {
117             putValue(NAME, name);
118             putValue (Action.SMALL_ICON, new StopIcon());
119             ac = this;
120         }
121         
122         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
123             stopped = true;
124             System.err.println("Stop action performed");
125         }
126     }
127     
128     private static boolean stopped = false;
129     
130     private class StopIcon implements Icon {
131         
132         public int getIconHeight() {
133             return 16;
134         }
135         
136         public int getIconWidth() {
137             return 16;
138         }
139         
140         public void paintIcon(Component c, Graphics g, int x, int y) {
141             g.setColor (Color.ORANGE);
142             g.fillRect ( x+2, x+2, 12, 12);
143             g.setColor (Color.BLACK);
144             g.drawRect ( x+2, x+2, 12, 12);
145             
146         }
147         
148     }
149
150
151     public class L implements OutputListener {
152
153         public void outputLineSelected(OutputEvent ev) {
154         }
155
156         public void outputLineAction(OutputEvent ev) {
157         }
158
159         public void outputLineCleared(OutputEvent ev) {
160         }
161
162     }
163
164
165  }
166
Popular Tags