KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > poa > gui > beans > ConsolePanel


1 package org.jacorb.poa.gui.beans;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22  
23 import java.util.Calendar JavaDoc;
24
25 /**
26  * Provides the functionality of a Console.
27  *
28  * @author Reimo Tiedemann, FU Berlin
29  * @version 1.01, 06/11/99, RT
30  */

31 public class ConsolePanel extends java.awt.Panel JavaDoc implements java.awt.event.ActionListener JavaDoc
32 {
33     private static int ROW_BUFFER = 256;
34     private int rowCount = 0;
35     private java.awt.Panel JavaDoc ivjButtonPanel = null;
36     private java.awt.FlowLayout JavaDoc ivjButtonPanelFlowLayout = null;
37     private java.awt.Button JavaDoc ivjClearButton = null;
38     private java.awt.TextArea JavaDoc ivjConsole = null;
39     private java.awt.Button JavaDoc ivjHideButton = null;
40     private java.awt.Button JavaDoc ivjShowButton = null;
41     private java.awt.BorderLayout JavaDoc ivjConsolePanelBorderLayout = null;
42     private java.awt.Panel JavaDoc ivjLeftPanel = null;
43     private java.awt.Panel JavaDoc ivjRightPanel = null;
44
45 /**
46  * Constructor
47  */

48 /* WARNING: THIS METHOD WILL BE REGENERATED. */
49 public ConsolePanel() {
50     super();
51     initialize();
52 }
53 /**
54  * ConsolePanel constructor comment.
55  * @param layout java.awt.LayoutManager
56  */

57 public ConsolePanel(java.awt.LayoutManager JavaDoc layout) {
58     super(layout);
59 }
60 private void _actionHideConsole() {
61     int height = getBounds().height;
62     
63     remove(getConsole());
64     getButtonPanel().remove(getHideButton());
65     getButtonPanel().remove(getClearButton());
66     getButtonPanel().add(getShowButton(), getShowButton().getName());
67     
68     java.awt.Component JavaDoc c = this;
69     while ((c = c.getParent()) != null) if (c instanceof java.awt.Frame JavaDoc) break;
70     c.setSize(c.getBounds().width, c.getBounds().height-height+33);
71     c.validate();
72 }
73 private void _actionShowConsole() {
74     add(getConsole(), "Center");
75     getButtonPanel().remove(getShowButton());
76     getButtonPanel().add(getHideButton(), getHideButton().getName());
77     getButtonPanel().add(getClearButton(), getClearButton().getName());
78     
79     java.awt.Component JavaDoc c = this;
80     while ((c = c.getParent()) != null) if (c instanceof java.awt.Frame JavaDoc) break;
81     c.setSize(c.getBounds().width, c.getBounds().height+100);
82     c.validate();
83 }
84 synchronized public void _printMessage(String JavaDoc text) {
85     if (rowCount++ > ROW_BUFFER) {
86         getConsole().setText("");
87         rowCount = 1;
88     }
89     getConsole().append(text + "\n");
90 }
91 /**
92  * Method to handle events for the ActionListener interface.
93  * @param e java.awt.event.ActionEvent
94  */

95 /* WARNING: THIS METHOD WILL BE REGENERATED. */
96 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
97     // user code begin {1}
98
// user code end
99
if ((e.getSource() == getClearButton()) ) {
100         connEtoM1(e);
101     }
102     if ((e.getSource() == getHideButton()) ) {
103         connEtoC1(e);
104     }
105     if ((e.getSource() == getShowButton()) ) {
106         connEtoC2(e);
107     }
108     // user code begin {2}
109
// user code end
110
}
111 /**
112  * connEtoC1: (HideButton.action.actionPerformed(java.awt.event.ActionEvent) --> ConsolePanel._actionHideConsole()V)
113  * @param arg1 java.awt.event.ActionEvent
114  */

115 /* WARNING: THIS METHOD WILL BE REGENERATED. */
116 private void connEtoC1(java.awt.event.ActionEvent JavaDoc arg1) {
117     try {
118         // user code begin {1}
119
// user code end
120
this._actionHideConsole();
121         // user code begin {2}
122
// user code end
123
} catch (java.lang.Throwable JavaDoc ivjExc) {
124         // user code begin {3}
125
// user code end
126
handleException(ivjExc);
127     }
128 }
129 /**
130  * connEtoC2: (ShowButton.action.actionPerformed(java.awt.event.ActionEvent) --> ConsolePanel._actionShowConsole()V)
131  * @param arg1 java.awt.event.ActionEvent
132  */

133 /* WARNING: THIS METHOD WILL BE REGENERATED. */
134 private void connEtoC2(java.awt.event.ActionEvent JavaDoc arg1) {
135     try {
136         // user code begin {1}
137
// user code end
138
this._actionShowConsole();
139         // user code begin {2}
140
// user code end
141
} catch (java.lang.Throwable JavaDoc ivjExc) {
142         // user code begin {3}
143
// user code end
144
handleException(ivjExc);
145     }
146 }
147 /**
148  * connEtoM1: (ClearButton.action.actionPerformed(java.awt.event.ActionEvent) --> Console.setText(Ljava.lang.String;)V)
149  * @param arg1 java.awt.event.ActionEvent
150  */

151 /* WARNING: THIS METHOD WILL BE REGENERATED. */
152 private void connEtoM1(java.awt.event.ActionEvent JavaDoc arg1) {
153     try {
154         // user code begin {1}
155
// user code end
156
getConsole().setText("");
157         // user code begin {2}
158
// user code end
159
} catch (java.lang.Throwable JavaDoc ivjExc) {
160         // user code begin {3}
161
// user code end
162
handleException(ivjExc);
163     }
164 }
165 /**
166  * Return the ButtonPanel property value.
167  * @return java.awt.Panel
168  */

169 /* WARNING: THIS METHOD WILL BE REGENERATED. */
170 private java.awt.Panel JavaDoc getButtonPanel() {
171     if (ivjButtonPanel == null) {
172         try {
173         ivjButtonPanel = new java.awt.Panel JavaDoc();
174         ivjButtonPanel.setName("ButtonPanel");
175         ivjButtonPanel.setLayout(getButtonPanelFlowLayout());
176         getButtonPanel().add(getHideButton(), getHideButton().getName());
177         getButtonPanel().add(getClearButton(), getClearButton().getName());
178         // user code begin {1}
179
// user code end
180
} catch (java.lang.Throwable JavaDoc ivjExc) {
181         // user code begin {2}
182
// user code end
183
handleException(ivjExc);
184         }
185     };
186     return ivjButtonPanel;
187 }
188 /**
189  * Return the ButtonPanelFlowLayout property value.
190  * @return java.awt.FlowLayout
191  */

192 /* WARNING: THIS METHOD WILL BE REGENERATED. */
193 private java.awt.FlowLayout JavaDoc getButtonPanelFlowLayout() {
194     java.awt.FlowLayout JavaDoc ivjButtonPanelFlowLayout = null;
195     try {
196         /* Create part */
197         ivjButtonPanelFlowLayout = new java.awt.FlowLayout JavaDoc();
198         ivjButtonPanelFlowLayout.setAlignment(java.awt.FlowLayout.LEFT);
199         ivjButtonPanelFlowLayout.setVgap(5);
200         ivjButtonPanelFlowLayout.setHgap(10);
201     } catch (java.lang.Throwable JavaDoc ivjExc) {
202         handleException(ivjExc);
203     };
204     return ivjButtonPanelFlowLayout;
205 }
206 /**
207  * Return the ClearButton property value.
208  * @return java.awt.Button
209  */

210 /* WARNING: THIS METHOD WILL BE REGENERATED. */
211 private java.awt.Button JavaDoc getClearButton() {
212     if (ivjClearButton == null) {
213         try {
214         ivjClearButton = new java.awt.Button JavaDoc();
215         ivjClearButton.setName("ClearButton");
216         ivjClearButton.setLabel(" Clear ");
217         // user code begin {1}
218
// user code end
219
} catch (java.lang.Throwable JavaDoc ivjExc) {
220         // user code begin {2}
221
// user code end
222
handleException(ivjExc);
223         }
224     };
225     return ivjClearButton;
226 }
227 /**
228  * Return the Console property value.
229  * @return java.awt.TextArea
230  */

231 /* WARNING: THIS METHOD WILL BE REGENERATED. */
232 private java.awt.TextArea JavaDoc getConsole() {
233     if (ivjConsole == null) {
234         try {
235         ivjConsole = new java.awt.TextArea JavaDoc();
236         ivjConsole.setName("Console");
237         ivjConsole.setFont(new java.awt.Font JavaDoc("dialog", 0, 10));
238         ivjConsole.setBackground(java.awt.SystemColor.window);
239         // user code begin {1}
240
// user code end
241
} catch (java.lang.Throwable JavaDoc ivjExc) {
242         // user code begin {2}
243
// user code end
244
handleException(ivjExc);
245         }
246     };
247     return ivjConsole;
248 }
249 /**
250  * Return the ConsolePanelBorderLayout property value.
251  * @return java.awt.BorderLayout
252  */

253 /* WARNING: THIS METHOD WILL BE REGENERATED. */
254 private java.awt.BorderLayout JavaDoc getConsolePanelBorderLayout() {
255     java.awt.BorderLayout JavaDoc ivjConsolePanelBorderLayout = null;
256     try {
257         /* Create part */
258         ivjConsolePanelBorderLayout = new java.awt.BorderLayout JavaDoc();
259         ivjConsolePanelBorderLayout.setVgap(0);
260         ivjConsolePanelBorderLayout.setHgap(10);
261     } catch (java.lang.Throwable JavaDoc ivjExc) {
262         handleException(ivjExc);
263     };
264     return ivjConsolePanelBorderLayout;
265 }
266 /**
267  * Return the HideButton property value.
268  * @return java.awt.Button
269  */

270 /* WARNING: THIS METHOD WILL BE REGENERATED. */
271 private java.awt.Button JavaDoc getHideButton() {
272     if (ivjHideButton == null) {
273         try {
274         ivjHideButton = new java.awt.Button JavaDoc();
275         ivjHideButton.setName("HideButton");
276         ivjHideButton.setLabel("Hide Console");
277         // user code begin {1}
278
// user code end
279
} catch (java.lang.Throwable JavaDoc ivjExc) {
280         // user code begin {2}
281
// user code end
282
handleException(ivjExc);
283         }
284     };
285     return ivjHideButton;
286 }
287 /**
288  * Return the LeftPanel property value.
289  * @return java.awt.Panel
290  */

291 /* WARNING: THIS METHOD WILL BE REGENERATED. */
292 private java.awt.Panel JavaDoc getLeftPanel() {
293     if (ivjLeftPanel == null) {
294         try {
295         ivjLeftPanel = new java.awt.Panel JavaDoc();
296         ivjLeftPanel.setName("LeftPanel");
297         ivjLeftPanel.setLayout(null);
298         // user code begin {1}
299
// user code end
300
} catch (java.lang.Throwable JavaDoc ivjExc) {
301         // user code begin {2}
302
// user code end
303
handleException(ivjExc);
304         }
305     };
306     return ivjLeftPanel;
307 }
308 /**
309  * Return the RightPanel property value.
310  * @return java.awt.Panel
311  */

312 /* WARNING: THIS METHOD WILL BE REGENERATED. */
313 private java.awt.Panel JavaDoc getRightPanel() {
314     if (ivjRightPanel == null) {
315         try {
316         ivjRightPanel = new java.awt.Panel JavaDoc();
317         ivjRightPanel.setName("RightPanel");
318         ivjRightPanel.setLayout(null);
319         // user code begin {1}
320
// user code end
321
} catch (java.lang.Throwable JavaDoc ivjExc) {
322         // user code begin {2}
323
// user code end
324
handleException(ivjExc);
325         }
326     };
327     return ivjRightPanel;
328 }
329 /**
330  * Return the ShowButton property value.
331  * @return java.awt.Button
332  */

333 /* WARNING: THIS METHOD WILL BE REGENERATED. */
334 private java.awt.Button JavaDoc getShowButton() {
335     if (ivjShowButton == null) {
336         try {
337         ivjShowButton = new java.awt.Button JavaDoc();
338         ivjShowButton.setName("ShowButton");
339         ivjShowButton.setBounds(27, 384, 90, 23);
340         ivjShowButton.setLabel("Show Console");
341         // user code begin {1}
342
// user code end
343
} catch (java.lang.Throwable JavaDoc ivjExc) {
344         // user code begin {2}
345
// user code end
346
handleException(ivjExc);
347         }
348     };
349     return ivjShowButton;
350 }
351 /**
352  * Called whenever the part throws an exception.
353  * @param exception java.lang.Throwable
354  */

355 private void handleException(Throwable JavaDoc exception) {
356
357     /* Uncomment the following lines to print uncaught exceptions to stdout */
358     // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
359
// exception.printStackTrace(System.out);
360
}
361 /**
362  * Initializes connections
363  */

364 /* WARNING: THIS METHOD WILL BE REGENERATED. */
365 private void initConnections() {
366     // user code begin {1}
367
// user code end
368
getClearButton().addActionListener(this);
369     getHideButton().addActionListener(this);
370     getShowButton().addActionListener(this);
371 }
372 /**
373  * Initialize the class.
374  */

375 /* WARNING: THIS METHOD WILL BE REGENERATED. */
376 private void initialize() {
377     // user code begin {1}
378
// user code end
379
setName("ConsolePanel");
380     setLayout(getConsolePanelBorderLayout());
381     setBackground(java.awt.SystemColor.control);
382     setSize(426, 240);
383     add(getButtonPanel(), "South");
384     add(getConsole(), "Center");
385     add(getLeftPanel(), "West");
386     add(getRightPanel(), "East");
387     initConnections();
388     // user code begin {2}
389
remove(getConsole());
390     getButtonPanel().remove(getHideButton());
391     getButtonPanel().remove(getClearButton());
392     getButtonPanel().add(getShowButton(), getShowButton().getName());
393     // user code end
394
}
395     /**
396      * main entrypoint - starts the part when it is run as an application
397      * @param args java.lang.String[]
398      */

399     public static void main(java.lang.String JavaDoc[] args) {
400     try {
401         java.awt.Frame JavaDoc frame;
402         try {
403         Class JavaDoc aFrameClass = Class.forName("com.ibm.uvm.abt.edit.TestFrame");
404         frame = (java.awt.Frame JavaDoc)aFrameClass.newInstance();
405         } catch (java.lang.Throwable JavaDoc ivjExc) {
406         frame = new java.awt.Frame JavaDoc();
407         }
408         ConsolePanel aConsolePanel;
409         aConsolePanel = new ConsolePanel();
410         frame.add("Center", aConsolePanel);
411         frame.setSize(aConsolePanel.getSize());
412         frame.setVisible(true);
413     } catch (Throwable JavaDoc exception) {
414         System.err.println("Exception occurred in main() of java.awt.Panel");
415         exception.printStackTrace(System.out);
416     }
417     }
418
419 }
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
Popular Tags