KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > poa > gui > poa > POAFrame


1 package org.jacorb.poa.gui.poa;
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 org.jacorb.poa.gui.*;
24 import org.jacorb.poa.gui.beans.*;
25 import org.jacorb.poa.util.*;
26
27 import java.awt.Label JavaDoc;
28 import java.awt.Color JavaDoc;
29
30 /**
31  * Implements the org.jacorb.poa.gui.POAView interface
32  *
33  * @author Reimo Tiedemann, FU Berlin
34  * @version 1.01, 06/11/99, RT
35  */

36 public class POAFrame
37     extends java.awt.Frame JavaDoc
38     implements org.jacorb.poa.gui.beans.CloseButtonPanelController,
39                 DetailsButtonController, ObjectListItemController,
40                 QueueListItemController,
41                 org.jacorb.poa.gui.POAMonitorView, java.awt.event.WindowListener JavaDoc
42 {
43
44     private POAMonitorController controller = null;
45     private static Color JavaDoc aomBarColor = new java.awt.Color JavaDoc(196,196,0);
46     private static Color JavaDoc queueBarColor = new java.awt.Color JavaDoc(0,128,128);
47     private static Color JavaDoc activeRequestsBarColor1 = new java.awt.Color JavaDoc(0,128,0);
48     private static Color JavaDoc activeRequestsBarColor2 = new java.awt.Color JavaDoc(128,0,0);
49     private static Color JavaDoc threadPoolBarColor = new java.awt.Color JavaDoc(0,128,0);
50     private String JavaDoc poaName = "";
51     private FillLevelBar aomBar = null;
52     private FillLevelBar queueBar = null;
53     private FillLevelBar activeRequestsBar = null;
54     private FillLevelBar threadPoolBar = null;
55     private Label JavaDoc stateLabel = null;
56     private Label JavaDoc threadLabel = null;
57     private Label JavaDoc lifespanLabel = null;
58     private Label JavaDoc idUniquenessLabel = null;
59     private Label JavaDoc idAssignmentLabel = null;
60     private Label JavaDoc servantRetentionLabel = null;
61     private Label JavaDoc requestProcessingLabel = null;
62     private Label JavaDoc implicitActivationLabel = null;
63     private java.awt.FontMetrics JavaDoc fontMetrics1 = null;
64     private org.jacorb.poa.gui.beans.CloseButtonPanel ivjButtonPanel = null;
65     private org.jacorb.poa.gui.beans.ConsolePanel ivjConsolePanel = null;
66     private java.awt.Panel JavaDoc ivjContentsPane = null;
67     private POAStatePanel ivjPOAStatePanel = null;
68     public void _actionCloseButtonPressed() {
69     if (controller != null) {
70             controller.actionCloseView();
71     }
72     }
73     public void _actionDeactivateObject(String JavaDoc oidStr) {
74     if (controller != null) {
75             controller.actionDeactivateObject(oidStr);
76     }
77     }
78     public void _actionDetailsButtonPressed(String JavaDoc source) {
79     if (source.equals("aom")) {
80             _showAOMDialog();
81     } else if (source.equals("queue")) {
82             _showQueueDialog();
83     } else {
84             System.err.println("details unknown source: "+source);
85     }
86     }
87     /**
88      * connEtoC1: (POAFrame.window.windowClosing(java.awt.event.WindowEvent) --> POAFrame.dispose()V)
89      * @param arg1 java.awt.event.WindowEvent
90      */

91     /* WARNING: THIS METHOD WILL BE REGENERATED. */
92     private void connEtoC1(java.awt.event.WindowEvent JavaDoc arg1) {
93     try {
94             // user code begin {1}
95
// user code end
96
this._actionCloseButtonPressed();
97             // user code begin {2}
98
// user code end
99
} catch (java.lang.Throwable JavaDoc ivjExc) {
100             // user code begin {3}
101
// user code end
102
handleException(ivjExc);
103     }
104     }
105     public void _destroy() {
106     dispose();
107     }
108     private java.awt.FontMetrics JavaDoc _fontMetrics1() {
109     if (fontMetrics1 == null) {
110             fontMetrics1 = getPOAStatePanel()._getPolicyPanel()._getThreadLabel().getGraphics().getFontMetrics();
111     }
112     return fontMetrics1;
113     }
114     private FillLevelBar _getActiveRequestsBar() {
115     if (activeRequestsBar == null) {
116             activeRequestsBar = getPOAStatePanel()._getTMPanel()._getActiveRequestsBar();
117     }
118     return activeRequestsBar;
119     }
120     private FillLevelBar _getAOMBar() {
121     if (aomBar == null) {
122             aomBar = getPOAStatePanel()._getAOMPanel()._getAOMBar();
123     }
124     return aomBar;
125     }
126     /**
127      * Return the ButtonPanel property value.
128      * @return org.jacorb.poa.gui.beans.CloseButtonPanel
129      */

130     /* WARNING: THIS METHOD WILL BE REGENERATED. */
131     private org.jacorb.poa.gui.beans.CloseButtonPanel getButtonPanel() {
132     if (ivjButtonPanel == null) {
133             try {
134                 ivjButtonPanel = new org.jacorb.poa.gui.beans.CloseButtonPanel();
135                 ivjButtonPanel.setName("ButtonPanel");
136                 // user code begin {1}
137
// user code end
138
} catch (java.lang.Throwable JavaDoc ivjExc) {
139                 // user code begin {2}
140
// user code end
141
handleException(ivjExc);
142             }
143     };
144     return ivjButtonPanel;
145     }
146     /**
147      * Return the ConsolePanel property value.
148      * @return org.jacorb.poa.gui.beans.ConsolePanel
149      */

150     /* WARNING: THIS METHOD WILL BE REGENERATED. */
151     private org.jacorb.poa.gui.beans.ConsolePanel getConsolePanel() {
152     if (ivjConsolePanel == null) {
153             try {
154                 ivjConsolePanel = new org.jacorb.poa.gui.beans.ConsolePanel();
155                 ivjConsolePanel.setName("ConsolePanel");
156                 // user code begin {1}
157
// user code end
158
} catch (java.lang.Throwable JavaDoc ivjExc) {
159                 // user code begin {2}
160
// user code end
161
handleException(ivjExc);
162             }
163     };
164     return ivjConsolePanel;
165     }
166     /**
167      * Return the ContentsPane property value.
168      * @return java.awt.Panel
169      */

170     /* WARNING: THIS METHOD WILL BE REGENERATED. */
171     private java.awt.Panel JavaDoc getContentsPane() {
172     if (ivjContentsPane == null) {
173             try {
174                 ivjContentsPane = new java.awt.Panel JavaDoc();
175                 ivjContentsPane.setName("ContentsPane");
176                 ivjContentsPane.setLayout(new java.awt.BorderLayout JavaDoc());
177                 ivjContentsPane.setBackground(java.awt.SystemColor.control);
178                 getContentsPane().add(getButtonPanel(), "South");
179                 getContentsPane().add(getConsolePanel(), "Center");
180                 getContentsPane().add(getPOAStatePanel(), "North");
181                 // user code begin {1}
182
// user code end
183
} catch (java.lang.Throwable JavaDoc ivjExc) {
184                 // user code begin {2}
185
// user code end
186
handleException(ivjExc);
187             }
188     };
189     return ivjContentsPane;
190     }
191     private Label JavaDoc _getIdAssignmentLabel() {
192     if (idAssignmentLabel == null) {
193             idAssignmentLabel = getPOAStatePanel()._getPolicyPanel()._getIdAssignmentLabel();
194     }
195     return idAssignmentLabel;
196     }
197     private Label JavaDoc _getIdUniquenessLabel() {
198     if (idUniquenessLabel == null) {
199             idUniquenessLabel = getPOAStatePanel()._getPolicyPanel()._getIdUniquenessLabel();
200     }
201     return idUniquenessLabel;
202     }
203     private Label JavaDoc _getImplicitActivationLabel() {
204     if (implicitActivationLabel == null) {
205             implicitActivationLabel = getPOAStatePanel()._getPolicyPanel()._getImplicitActivationLabel();
206     }
207     return implicitActivationLabel;
208     }
209     private Label JavaDoc _getLifespanLabel() {
210     if (lifespanLabel == null) {
211             lifespanLabel = getPOAStatePanel()._getPolicyPanel()._getLifespanLabel();
212     }
213     return lifespanLabel;
214     }
215     /**
216      * Return the POAStatePanel property value.
217      * @return org.jacorb.poa.gui.poa.POAStatePanel
218      */

219     /* WARNING: THIS METHOD WILL BE REGENERATED. */
220     private POAStatePanel getPOAStatePanel() {
221     if (ivjPOAStatePanel == null) {
222             try {
223                 ivjPOAStatePanel = new org.jacorb.poa.gui.poa.POAStatePanel();
224                 ivjPOAStatePanel.setName("POAStatePanel");
225                 // user code begin {1}
226
// user code end
227
} catch (java.lang.Throwable JavaDoc ivjExc) {
228                 // user code begin {2}
229
// user code end
230
handleException(ivjExc);
231             }
232     };
233     return ivjPOAStatePanel;
234     }
235     private FillLevelBar _getQueueBar() {
236     if (queueBar == null) {
237             queueBar = getPOAStatePanel()._getQueuePanel()._getQueueBar();
238     }
239     return queueBar;
240     }
241     private Label JavaDoc _getRequestProcessingLabel() {
242     if (requestProcessingLabel == null) {
243             requestProcessingLabel = getPOAStatePanel()._getPolicyPanel()._getRequestProcessingLabel();
244     }
245     return requestProcessingLabel;
246     }
247     private Label JavaDoc _getServantRetentionLabel() {
248     if (servantRetentionLabel == null) {
249             servantRetentionLabel = getPOAStatePanel()._getPolicyPanel()._getServantRetentionLabel();
250     }
251     return servantRetentionLabel;
252     }
253     private Label JavaDoc _getStateLabel() {
254     if (stateLabel == null) {
255             stateLabel = getPOAStatePanel()._getStatePanel()._getStateLabel();
256     }
257     return stateLabel;
258     }
259     private Label JavaDoc _getThreadLabel() {
260     if (threadLabel == null) {
261             threadLabel = getPOAStatePanel()._getPolicyPanel()._getThreadLabel();
262     }
263     return threadLabel;
264     }
265     private FillLevelBar _getThreadPoolBar() {
266     if (threadPoolBar == null) {
267             threadPoolBar = getPOAStatePanel()._getTMPanel()._getThreadPoolBar();
268     }
269     return threadPoolBar;
270     }
271     /**
272      * Called whenever the part throws an exception.
273      * @param exception java.lang.Throwable
274      */

275     private void handleException(Throwable JavaDoc exception) {
276
277     /* Uncomment the following lines to print uncaught exceptions to stdout */
278     // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
279
// exception.printStackTrace(System.out);
280
}
281     public void _initActiveRequestsBar(int avg, int max) {
282     _getActiveRequestsBar().init(0, avg, max, activeRequestsBarColor1, activeRequestsBarColor2, true, false);
283     }
284     public void _initAOMBar(int max, boolean isVariable) {
285     _getAOMBar().init(0, 0, max, aomBarColor, null, false, isVariable);
286     }
287     /**
288      * Initializes connections
289      */

290     /* WARNING: THIS METHOD WILL BE REGENERATED. */
291     private void initConnections() {
292     // user code begin {1}
293
// user code end
294
this.addWindowListener(this);
295     }
296     /**
297      * Initialize the class.
298      */

299     /* WARNING: THIS METHOD WILL BE REGENERATED. */
300     private void initialize() {
301     // user code begin {1}
302
// user code end
303
setName("POAFrame");
304     setLayout(new java.awt.BorderLayout JavaDoc());
305     setSize(698, 310);
306     setTitle("POA Monitor");
307     add(getContentsPane(), "Center");
308     initConnections();
309     // user code begin {2}
310
getButtonPanel()._init(this, "Close");
311     getPOAStatePanel()._getAOMPanel()._init(this);
312     getPOAStatePanel()._getQueuePanel()._init(this);
313     // user code end
314
}
315     public void _initQueueBar(int max, boolean isVariable) {
316     _getQueueBar().init(0, 0, max, queueBarColor, null, false, isVariable);
317     }
318     public void _initThreadPoolBar(int max) {
319     _getThreadPoolBar().init(0, 0, max, threadPoolBarColor, null, false, false);
320     }
321     public void _inspectRequest(String JavaDoc oidStr) {
322     new MessageDialog(this, "Message", "This function is not yet implemented!").setVisible(true);
323     }
324     public void _inspectServantClass(String JavaDoc oidStr) {
325     new MessageDialog(this, "Message", "This function is not yet implemented!").setVisible(true);
326     }
327     public POAFrame(POAMonitorController _controller) {
328     super();
329     controller = _controller;
330     initialize();
331     }
332     /**
333      * POAFrame constructor comment.
334      * @param title java.lang.String
335      */

336     public POAFrame(String JavaDoc title) {
337     super(title);
338     }
339     /**
340      * main entrypoint - starts the part when it is run as an application
341      * @param args java.lang.String[]
342      */

343     public static void main(java.lang.String JavaDoc[] args) {
344     try {
345             POAFrame aPOAFrame;
346             aPOAFrame = new POAFrame();
347             try {
348                 Class JavaDoc aCloserClass = Class.forName("com.ibm.uvm.abt.edit.WindowCloser");
349                 Class JavaDoc parmTypes[] = { java.awt.Window JavaDoc.class };
350                 Object JavaDoc parms[] = { aPOAFrame };
351                 java.lang.reflect.Constructor JavaDoc aCtor = aCloserClass.getConstructor(parmTypes);
352                 aCtor.newInstance(parms);
353             } catch (java.lang.Throwable JavaDoc exc) {};
354             aPOAFrame.setVisible(true);
355     } catch (Throwable JavaDoc exception) {
356             System.err.println("Exception occurred in main() of java.awt.Frame");
357             exception.printStackTrace(System.out);
358     }
359     }
360     public void _printMessage(String JavaDoc str) {
361     getConsolePanel()._printMessage(str);
362     }
363     public void _removeRequest(String JavaDoc ridStr) {
364     if (controller != null) {
365             controller.actionRemoveRequestFromQueue(ridStr);
366     }
367     }
368     public void _setMaxThreadPoolBar(int value) {
369     _getThreadPoolBar().setMaxValue(value);
370     }
371     public void _setName(String JavaDoc str) {
372     poaName = str;
373     setTitle(poaName+" Monitor ("+_getStateLabel().getText()+")");
374     }
375     public void _setPolicyIdAssignment(String JavaDoc str) {
376     _getIdAssignmentLabel().setText(" "+str);
377     }
378     public void _setPolicyIdUniqueness(String JavaDoc str) {
379     _getIdUniquenessLabel().setText(" "+str);
380     }
381     public void _setPolicyImplicitActivation(String JavaDoc str) {
382     _getImplicitActivationLabel().setText(" "+str);
383     }
384     public void _setPolicyLifespan(String JavaDoc str) {
385     _getLifespanLabel().setText(" "+str);
386     }
387     public void _setPolicyRequestProcessing(String JavaDoc str) {
388     _getRequestProcessingLabel().setText(" "+str);
389     }
390     public void _setPolicyServantRetention(String JavaDoc str) {
391     _getServantRetentionLabel().setText(" "+str);
392     }
393     public void _setPolicyThread(String JavaDoc str) {
394     _getThreadLabel().setText(" "+str);
395     }
396     public void _setState(String JavaDoc str) {
397     _getStateLabel().setText(str);
398     setTitle(poaName+" Monitor ("+str+")");
399     }
400     public void _setValueActiveRequestsBar(int value) {
401     _getActiveRequestsBar().setCurrentValue(value);
402     }
403     public void _setValueAOMBar(int value) {
404     _getAOMBar().setCurrentValue(value);
405     }
406     public void _setValueQueueBar(int value) {
407     _getQueueBar().setCurrentValue(value);
408     }
409     public void _setValueThreadPoolBar(int value) {
410     _getThreadPoolBar().setCurrentValue(value);
411     }
412     public void _setVisible(boolean visible) {
413     setVisible(visible);
414     }
415     private void _showAOMDialog() {
416
417     if (controller == null) return;
418
419     StringPair[] data = controller.actionRetrieveAOMContent();
420
421     DoubleListDialog showDialog = new DoubleListDialog(this, "Active Object Map Snapshot");
422     showDialog._setHeaderLabel1("Object ID");
423     showDialog._setHeaderLabel2("Servant Class");
424
425     if (data != null) {
426
427             ObjectListItem[] items = new ObjectListItem[data.length];
428             String JavaDoc helpStr;
429             int firstMax = 100;
430             int secondMax = 100;
431             int helpInt;
432             for (int i=0; i<data.length; i++) {
433                 items[i] = new ObjectListItem();
434                 items[i]._init(this, data[i].first);
435                 helpStr = POAUtil.convert(data[i].first.getBytes());
436                 items[i]._getFirstLabel().setText(helpStr);
437                 items[i]._getSecondLabel().setText(data[i].second);
438
439                 helpInt = _fontMetrics1().stringWidth(items[i]._getFirstLabel().getText());
440                 if (helpInt > firstMax) firstMax = helpInt;
441
442                 helpInt = _fontMetrics1().stringWidth(items[i]._getSecondLabel().getText());
443                 if (helpInt > secondMax) secondMax = helpInt;
444             }
445
446             showDialog._setSize(firstMax+20, secondMax+20);
447
448             for (int i=0; i<data.length; i++) {
449                 items[i]._setWidth(firstMax+20, secondMax+20);
450                 showDialog._addItem(items[i]);
451             }
452     }
453
454     showDialog.setVisible(true);
455     }
456     private void _showQueueDialog() {
457     if (controller == null) return;
458
459     StringPair[] data = controller.actionRetrieveQueueContent();
460
461     DoubleListDialog showDialog = new DoubleListDialog(this, "Queue Snapshot");
462     showDialog._setHeaderLabel1("Request ID");
463     showDialog._setHeaderLabel2("Object ID");
464
465     if (data != null) {
466
467             QueueListItem[] items = new QueueListItem[data.length];
468             String JavaDoc helpStr;
469             int firstMax = 100;
470             int secondMax = 100;
471             int helpInt;
472             for (int i=0; i<data.length; i++) {
473                 items[i] = new QueueListItem();
474                 items[i]._init(this, data[i].first);
475                 items[i]._getFirstLabel().setText(data[i].first);
476                 helpStr = POAUtil.convert(data[i].second.getBytes());
477                 items[i]._getSecondLabel().setText(helpStr);
478
479                 helpInt = _fontMetrics1().stringWidth(items[i]._getFirstLabel().getText());
480                 if (helpInt > firstMax) firstMax = helpInt;
481
482                 helpInt = _fontMetrics1().stringWidth(items[i]._getSecondLabel().getText());
483                 if (helpInt > secondMax) secondMax = helpInt;
484             }
485
486             showDialog._setSize(firstMax+20, secondMax+20);
487
488             for (int i=0; i<data.length; i++) {
489                 items[i]._setWidth(firstMax+20, secondMax+20);
490                 showDialog._addItem(items[i]);
491             }
492     }
493
494     showDialog.setVisible(true);
495     }
496     /**
497      * Constructor
498      */

499     /* WARNING: THIS METHOD WILL BE REGENERATED. */
500     public POAFrame() {
501     super();
502     initialize();
503     }
504     /**
505      * Method to handle events for the WindowListener interface.
506      * @param e java.awt.event.WindowEvent
507      */

508     /* WARNING: THIS METHOD WILL BE REGENERATED. */
509     public void windowActivated(java.awt.event.WindowEvent JavaDoc e) {
510     // user code begin {1}
511
// user code end
512
// user code begin {2}
513
// user code end
514
}
515     /**
516      * Method to handle events for the WindowListener interface.
517      * @param e java.awt.event.WindowEvent
518      */

519     public void windowClosed(java.awt.event.WindowEvent JavaDoc e) {
520     // user code begin {1}
521
// user code end
522
// user code begin {2}
523
// user code end
524
}
525     /**
526      * Method to handle events for the WindowListener interface.
527      * @param e java.awt.event.WindowEvent
528      */

529     /* WARNING: THIS METHOD WILL BE REGENERATED. */
530     public void windowClosing(java.awt.event.WindowEvent JavaDoc e) {
531     // user code begin {1}
532
// user code end
533
if ((e.getSource() == this) ) {
534             connEtoC1(e);
535     }
536     // user code begin {2}
537
// user code end
538
}
539     /**
540      * Method to handle events for the WindowListener interface.
541      * @param e java.awt.event.WindowEvent
542      */

543     public void windowDeactivated(java.awt.event.WindowEvent JavaDoc e) {
544     }
545     /**
546      * Method to handle events for the WindowListener interface.
547      * @param e java.awt.event.WindowEvent
548      */

549     public void windowDeiconified(java.awt.event.WindowEvent JavaDoc e) {
550     }
551     /**
552      * Method to handle events for the WindowListener interface.
553      * @param e java.awt.event.WindowEvent
554      */

555     public void windowIconified(java.awt.event.WindowEvent JavaDoc e) {
556     }
557     /**
558      * Method to handle events for the WindowListener interface.
559      * @param e java.awt.event.WindowEvent
560      */

561     public void windowOpened(java.awt.event.WindowEvent JavaDoc e) {
562     }
563 }
564
565
566
567
568
569
570
571
572
573
574
575
576
577
Popular Tags