001: package org.jacorb.poa.gui.poa;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import org.jacorb.poa.gui.*;
024: import org.jacorb.poa.gui.beans.*;
025: import org.jacorb.poa.util.*;
026:
027: import java.awt.Label;
028: import java.awt.Color;
029:
030: /**
031: * Implements the org.jacorb.poa.gui.POAView interface
032: *
033: * @author Reimo Tiedemann, FU Berlin
034: * @version 1.01, 06/11/99, RT
035: */
036: public class POAFrame extends java.awt.Frame implements
037: org.jacorb.poa.gui.beans.CloseButtonPanelController,
038: DetailsButtonController, ObjectListItemController,
039: QueueListItemController, org.jacorb.poa.gui.POAMonitorView,
040: java.awt.event.WindowListener {
041:
042: private POAMonitorController controller = null;
043: private static Color aomBarColor = new java.awt.Color(196, 196, 0);
044: private static Color queueBarColor = new java.awt.Color(0, 128, 128);
045: private static Color activeRequestsBarColor1 = new java.awt.Color(
046: 0, 128, 0);
047: private static Color activeRequestsBarColor2 = new java.awt.Color(
048: 128, 0, 0);
049: private static Color threadPoolBarColor = new java.awt.Color(0,
050: 128, 0);
051: private String poaName = "";
052: private FillLevelBar aomBar = null;
053: private FillLevelBar queueBar = null;
054: private FillLevelBar activeRequestsBar = null;
055: private FillLevelBar threadPoolBar = null;
056: private Label stateLabel = null;
057: private Label threadLabel = null;
058: private Label lifespanLabel = null;
059: private Label idUniquenessLabel = null;
060: private Label idAssignmentLabel = null;
061: private Label servantRetentionLabel = null;
062: private Label requestProcessingLabel = null;
063: private Label implicitActivationLabel = null;
064: private java.awt.FontMetrics fontMetrics1 = null;
065: private org.jacorb.poa.gui.beans.CloseButtonPanel ivjButtonPanel = null;
066: private org.jacorb.poa.gui.beans.ConsolePanel ivjConsolePanel = null;
067: private java.awt.Panel ivjContentsPane = null;
068: private POAStatePanel ivjPOAStatePanel = null;
069:
070: public void _actionCloseButtonPressed() {
071: if (controller != null) {
072: controller.actionCloseView();
073: }
074: }
075:
076: public void _actionDeactivateObject(String oidStr) {
077: if (controller != null) {
078: controller.actionDeactivateObject(oidStr);
079: }
080: }
081:
082: public void _actionDetailsButtonPressed(String source) {
083: if (source.equals("aom")) {
084: _showAOMDialog();
085: } else if (source.equals("queue")) {
086: _showQueueDialog();
087: } else {
088: System.err.println("details unknown source: " + source);
089: }
090: }
091:
092: /**
093: * connEtoC1: (POAFrame.window.windowClosing(java.awt.event.WindowEvent) --> POAFrame.dispose()V)
094: * @param arg1 java.awt.event.WindowEvent
095: */
096: /* WARNING: THIS METHOD WILL BE REGENERATED. */
097: private void connEtoC1(java.awt.event.WindowEvent arg1) {
098: try {
099: // user code begin {1}
100: // user code end
101: this ._actionCloseButtonPressed();
102: // user code begin {2}
103: // user code end
104: } catch (java.lang.Throwable ivjExc) {
105: // user code begin {3}
106: // user code end
107: handleException(ivjExc);
108: }
109: }
110:
111: public void _destroy() {
112: dispose();
113: }
114:
115: private java.awt.FontMetrics _fontMetrics1() {
116: if (fontMetrics1 == null) {
117: fontMetrics1 = getPOAStatePanel()._getPolicyPanel()
118: ._getThreadLabel().getGraphics().getFontMetrics();
119: }
120: return fontMetrics1;
121: }
122:
123: private FillLevelBar _getActiveRequestsBar() {
124: if (activeRequestsBar == null) {
125: activeRequestsBar = getPOAStatePanel()._getTMPanel()
126: ._getActiveRequestsBar();
127: }
128: return activeRequestsBar;
129: }
130:
131: private FillLevelBar _getAOMBar() {
132: if (aomBar == null) {
133: aomBar = getPOAStatePanel()._getAOMPanel()._getAOMBar();
134: }
135: return aomBar;
136: }
137:
138: /**
139: * Return the ButtonPanel property value.
140: * @return org.jacorb.poa.gui.beans.CloseButtonPanel
141: */
142: /* WARNING: THIS METHOD WILL BE REGENERATED. */
143: private org.jacorb.poa.gui.beans.CloseButtonPanel getButtonPanel() {
144: if (ivjButtonPanel == null) {
145: try {
146: ivjButtonPanel = new org.jacorb.poa.gui.beans.CloseButtonPanel();
147: ivjButtonPanel.setName("ButtonPanel");
148: // user code begin {1}
149: // user code end
150: } catch (java.lang.Throwable ivjExc) {
151: // user code begin {2}
152: // user code end
153: handleException(ivjExc);
154: }
155: }
156: ;
157: return ivjButtonPanel;
158: }
159:
160: /**
161: * Return the ConsolePanel property value.
162: * @return org.jacorb.poa.gui.beans.ConsolePanel
163: */
164: /* WARNING: THIS METHOD WILL BE REGENERATED. */
165: private org.jacorb.poa.gui.beans.ConsolePanel getConsolePanel() {
166: if (ivjConsolePanel == null) {
167: try {
168: ivjConsolePanel = new org.jacorb.poa.gui.beans.ConsolePanel();
169: ivjConsolePanel.setName("ConsolePanel");
170: // user code begin {1}
171: // user code end
172: } catch (java.lang.Throwable ivjExc) {
173: // user code begin {2}
174: // user code end
175: handleException(ivjExc);
176: }
177: }
178: ;
179: return ivjConsolePanel;
180: }
181:
182: /**
183: * Return the ContentsPane property value.
184: * @return java.awt.Panel
185: */
186: /* WARNING: THIS METHOD WILL BE REGENERATED. */
187: private java.awt.Panel getContentsPane() {
188: if (ivjContentsPane == null) {
189: try {
190: ivjContentsPane = new java.awt.Panel();
191: ivjContentsPane.setName("ContentsPane");
192: ivjContentsPane.setLayout(new java.awt.BorderLayout());
193: ivjContentsPane
194: .setBackground(java.awt.SystemColor.control);
195: getContentsPane().add(getButtonPanel(), "South");
196: getContentsPane().add(getConsolePanel(), "Center");
197: getContentsPane().add(getPOAStatePanel(), "North");
198: // user code begin {1}
199: // user code end
200: } catch (java.lang.Throwable ivjExc) {
201: // user code begin {2}
202: // user code end
203: handleException(ivjExc);
204: }
205: }
206: ;
207: return ivjContentsPane;
208: }
209:
210: private Label _getIdAssignmentLabel() {
211: if (idAssignmentLabel == null) {
212: idAssignmentLabel = getPOAStatePanel()._getPolicyPanel()
213: ._getIdAssignmentLabel();
214: }
215: return idAssignmentLabel;
216: }
217:
218: private Label _getIdUniquenessLabel() {
219: if (idUniquenessLabel == null) {
220: idUniquenessLabel = getPOAStatePanel()._getPolicyPanel()
221: ._getIdUniquenessLabel();
222: }
223: return idUniquenessLabel;
224: }
225:
226: private Label _getImplicitActivationLabel() {
227: if (implicitActivationLabel == null) {
228: implicitActivationLabel = getPOAStatePanel()
229: ._getPolicyPanel()._getImplicitActivationLabel();
230: }
231: return implicitActivationLabel;
232: }
233:
234: private Label _getLifespanLabel() {
235: if (lifespanLabel == null) {
236: lifespanLabel = getPOAStatePanel()._getPolicyPanel()
237: ._getLifespanLabel();
238: }
239: return lifespanLabel;
240: }
241:
242: /**
243: * Return the POAStatePanel property value.
244: * @return org.jacorb.poa.gui.poa.POAStatePanel
245: */
246: /* WARNING: THIS METHOD WILL BE REGENERATED. */
247: private POAStatePanel getPOAStatePanel() {
248: if (ivjPOAStatePanel == null) {
249: try {
250: ivjPOAStatePanel = new org.jacorb.poa.gui.poa.POAStatePanel();
251: ivjPOAStatePanel.setName("POAStatePanel");
252: // user code begin {1}
253: // user code end
254: } catch (java.lang.Throwable ivjExc) {
255: // user code begin {2}
256: // user code end
257: handleException(ivjExc);
258: }
259: }
260: ;
261: return ivjPOAStatePanel;
262: }
263:
264: private FillLevelBar _getQueueBar() {
265: if (queueBar == null) {
266: queueBar = getPOAStatePanel()._getQueuePanel()
267: ._getQueueBar();
268: }
269: return queueBar;
270: }
271:
272: private Label _getRequestProcessingLabel() {
273: if (requestProcessingLabel == null) {
274: requestProcessingLabel = getPOAStatePanel()
275: ._getPolicyPanel()._getRequestProcessingLabel();
276: }
277: return requestProcessingLabel;
278: }
279:
280: private Label _getServantRetentionLabel() {
281: if (servantRetentionLabel == null) {
282: servantRetentionLabel = getPOAStatePanel()
283: ._getPolicyPanel()._getServantRetentionLabel();
284: }
285: return servantRetentionLabel;
286: }
287:
288: private Label _getStateLabel() {
289: if (stateLabel == null) {
290: stateLabel = getPOAStatePanel()._getStatePanel()
291: ._getStateLabel();
292: }
293: return stateLabel;
294: }
295:
296: private Label _getThreadLabel() {
297: if (threadLabel == null) {
298: threadLabel = getPOAStatePanel()._getPolicyPanel()
299: ._getThreadLabel();
300: }
301: return threadLabel;
302: }
303:
304: private FillLevelBar _getThreadPoolBar() {
305: if (threadPoolBar == null) {
306: threadPoolBar = getPOAStatePanel()._getTMPanel()
307: ._getThreadPoolBar();
308: }
309: return threadPoolBar;
310: }
311:
312: /**
313: * Called whenever the part throws an exception.
314: * @param exception java.lang.Throwable
315: */
316: private void handleException(Throwable exception) {
317:
318: /* Uncomment the following lines to print uncaught exceptions to stdout */
319: // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
320: // exception.printStackTrace(System.out);
321: }
322:
323: public void _initActiveRequestsBar(int avg, int max) {
324: _getActiveRequestsBar().init(0, avg, max,
325: activeRequestsBarColor1, activeRequestsBarColor2, true,
326: false);
327: }
328:
329: public void _initAOMBar(int max, boolean isVariable) {
330: _getAOMBar().init(0, 0, max, aomBarColor, null, false,
331: isVariable);
332: }
333:
334: /**
335: * Initializes connections
336: */
337: /* WARNING: THIS METHOD WILL BE REGENERATED. */
338: private void initConnections() {
339: // user code begin {1}
340: // user code end
341: this .addWindowListener(this );
342: }
343:
344: /**
345: * Initialize the class.
346: */
347: /* WARNING: THIS METHOD WILL BE REGENERATED. */
348: private void initialize() {
349: // user code begin {1}
350: // user code end
351: setName("POAFrame");
352: setLayout(new java.awt.BorderLayout());
353: setSize(698, 310);
354: setTitle("POA Monitor");
355: add(getContentsPane(), "Center");
356: initConnections();
357: // user code begin {2}
358: getButtonPanel()._init(this , "Close");
359: getPOAStatePanel()._getAOMPanel()._init(this );
360: getPOAStatePanel()._getQueuePanel()._init(this );
361: // user code end
362: }
363:
364: public void _initQueueBar(int max, boolean isVariable) {
365: _getQueueBar().init(0, 0, max, queueBarColor, null, false,
366: isVariable);
367: }
368:
369: public void _initThreadPoolBar(int max) {
370: _getThreadPoolBar().init(0, 0, max, threadPoolBarColor, null,
371: false, false);
372: }
373:
374: public void _inspectRequest(String oidStr) {
375: new MessageDialog(this , "Message",
376: "This function is not yet implemented!")
377: .setVisible(true);
378: }
379:
380: public void _inspectServantClass(String oidStr) {
381: new MessageDialog(this , "Message",
382: "This function is not yet implemented!")
383: .setVisible(true);
384: }
385:
386: public POAFrame(POAMonitorController _controller) {
387: super ();
388: controller = _controller;
389: initialize();
390: }
391:
392: /**
393: * POAFrame constructor comment.
394: * @param title java.lang.String
395: */
396: public POAFrame(String title) {
397: super (title);
398: }
399:
400: /**
401: * main entrypoint - starts the part when it is run as an application
402: * @param args java.lang.String[]
403: */
404: public static void main(java.lang.String[] args) {
405: try {
406: POAFrame aPOAFrame;
407: aPOAFrame = new POAFrame();
408: try {
409: Class aCloserClass = Class
410: .forName("com.ibm.uvm.abt.edit.WindowCloser");
411: Class parmTypes[] = { java.awt.Window.class };
412: Object parms[] = { aPOAFrame };
413: java.lang.reflect.Constructor aCtor = aCloserClass
414: .getConstructor(parmTypes);
415: aCtor.newInstance(parms);
416: } catch (java.lang.Throwable exc) {
417: }
418: ;
419: aPOAFrame.setVisible(true);
420: } catch (Throwable exception) {
421: System.err
422: .println("Exception occurred in main() of java.awt.Frame");
423: exception.printStackTrace(System.out);
424: }
425: }
426:
427: public void _printMessage(String str) {
428: getConsolePanel()._printMessage(str);
429: }
430:
431: public void _removeRequest(String ridStr) {
432: if (controller != null) {
433: controller.actionRemoveRequestFromQueue(ridStr);
434: }
435: }
436:
437: public void _setMaxThreadPoolBar(int value) {
438: _getThreadPoolBar().setMaxValue(value);
439: }
440:
441: public void _setName(String str) {
442: poaName = str;
443: setTitle(poaName + " Monitor (" + _getStateLabel().getText()
444: + ")");
445: }
446:
447: public void _setPolicyIdAssignment(String str) {
448: _getIdAssignmentLabel().setText(" " + str);
449: }
450:
451: public void _setPolicyIdUniqueness(String str) {
452: _getIdUniquenessLabel().setText(" " + str);
453: }
454:
455: public void _setPolicyImplicitActivation(String str) {
456: _getImplicitActivationLabel().setText(" " + str);
457: }
458:
459: public void _setPolicyLifespan(String str) {
460: _getLifespanLabel().setText(" " + str);
461: }
462:
463: public void _setPolicyRequestProcessing(String str) {
464: _getRequestProcessingLabel().setText(" " + str);
465: }
466:
467: public void _setPolicyServantRetention(String str) {
468: _getServantRetentionLabel().setText(" " + str);
469: }
470:
471: public void _setPolicyThread(String str) {
472: _getThreadLabel().setText(" " + str);
473: }
474:
475: public void _setState(String str) {
476: _getStateLabel().setText(str);
477: setTitle(poaName + " Monitor (" + str + ")");
478: }
479:
480: public void _setValueActiveRequestsBar(int value) {
481: _getActiveRequestsBar().setCurrentValue(value);
482: }
483:
484: public void _setValueAOMBar(int value) {
485: _getAOMBar().setCurrentValue(value);
486: }
487:
488: public void _setValueQueueBar(int value) {
489: _getQueueBar().setCurrentValue(value);
490: }
491:
492: public void _setValueThreadPoolBar(int value) {
493: _getThreadPoolBar().setCurrentValue(value);
494: }
495:
496: public void _setVisible(boolean visible) {
497: setVisible(visible);
498: }
499:
500: private void _showAOMDialog() {
501:
502: if (controller == null)
503: return;
504:
505: StringPair[] data = controller.actionRetrieveAOMContent();
506:
507: DoubleListDialog showDialog = new DoubleListDialog(this ,
508: "Active Object Map Snapshot");
509: showDialog._setHeaderLabel1("Object ID");
510: showDialog._setHeaderLabel2("Servant Class");
511:
512: if (data != null) {
513:
514: ObjectListItem[] items = new ObjectListItem[data.length];
515: String helpStr;
516: int firstMax = 100;
517: int secondMax = 100;
518: int helpInt;
519: for (int i = 0; i < data.length; i++) {
520: items[i] = new ObjectListItem();
521: items[i]._init(this , data[i].first);
522: helpStr = POAUtil.convert(data[i].first.getBytes());
523: items[i]._getFirstLabel().setText(helpStr);
524: items[i]._getSecondLabel().setText(data[i].second);
525:
526: helpInt = _fontMetrics1().stringWidth(
527: items[i]._getFirstLabel().getText());
528: if (helpInt > firstMax)
529: firstMax = helpInt;
530:
531: helpInt = _fontMetrics1().stringWidth(
532: items[i]._getSecondLabel().getText());
533: if (helpInt > secondMax)
534: secondMax = helpInt;
535: }
536:
537: showDialog._setSize(firstMax + 20, secondMax + 20);
538:
539: for (int i = 0; i < data.length; i++) {
540: items[i]._setWidth(firstMax + 20, secondMax + 20);
541: showDialog._addItem(items[i]);
542: }
543: }
544:
545: showDialog.setVisible(true);
546: }
547:
548: private void _showQueueDialog() {
549: if (controller == null)
550: return;
551:
552: StringPair[] data = controller.actionRetrieveQueueContent();
553:
554: DoubleListDialog showDialog = new DoubleListDialog(this ,
555: "Queue Snapshot");
556: showDialog._setHeaderLabel1("Request ID");
557: showDialog._setHeaderLabel2("Object ID");
558:
559: if (data != null) {
560:
561: QueueListItem[] items = new QueueListItem[data.length];
562: String helpStr;
563: int firstMax = 100;
564: int secondMax = 100;
565: int helpInt;
566: for (int i = 0; i < data.length; i++) {
567: items[i] = new QueueListItem();
568: items[i]._init(this , data[i].first);
569: items[i]._getFirstLabel().setText(data[i].first);
570: helpStr = POAUtil.convert(data[i].second.getBytes());
571: items[i]._getSecondLabel().setText(helpStr);
572:
573: helpInt = _fontMetrics1().stringWidth(
574: items[i]._getFirstLabel().getText());
575: if (helpInt > firstMax)
576: firstMax = helpInt;
577:
578: helpInt = _fontMetrics1().stringWidth(
579: items[i]._getSecondLabel().getText());
580: if (helpInt > secondMax)
581: secondMax = helpInt;
582: }
583:
584: showDialog._setSize(firstMax + 20, secondMax + 20);
585:
586: for (int i = 0; i < data.length; i++) {
587: items[i]._setWidth(firstMax + 20, secondMax + 20);
588: showDialog._addItem(items[i]);
589: }
590: }
591:
592: showDialog.setVisible(true);
593: }
594:
595: /**
596: * Constructor
597: */
598: /* WARNING: THIS METHOD WILL BE REGENERATED. */
599: public POAFrame() {
600: super ();
601: initialize();
602: }
603:
604: /**
605: * Method to handle events for the WindowListener interface.
606: * @param e java.awt.event.WindowEvent
607: */
608: /* WARNING: THIS METHOD WILL BE REGENERATED. */
609: public void windowActivated(java.awt.event.WindowEvent e) {
610: // user code begin {1}
611: // user code end
612: // user code begin {2}
613: // user code end
614: }
615:
616: /**
617: * Method to handle events for the WindowListener interface.
618: * @param e java.awt.event.WindowEvent
619: */
620: public void windowClosed(java.awt.event.WindowEvent e) {
621: // user code begin {1}
622: // user code end
623: // user code begin {2}
624: // user code end
625: }
626:
627: /**
628: * Method to handle events for the WindowListener interface.
629: * @param e java.awt.event.WindowEvent
630: */
631: /* WARNING: THIS METHOD WILL BE REGENERATED. */
632: public void windowClosing(java.awt.event.WindowEvent e) {
633: // user code begin {1}
634: // user code end
635: if ((e.getSource() == this )) {
636: connEtoC1(e);
637: }
638: // user code begin {2}
639: // user code end
640: }
641:
642: /**
643: * Method to handle events for the WindowListener interface.
644: * @param e java.awt.event.WindowEvent
645: */
646: public void windowDeactivated(java.awt.event.WindowEvent e) {
647: }
648:
649: /**
650: * Method to handle events for the WindowListener interface.
651: * @param e java.awt.event.WindowEvent
652: */
653: public void windowDeiconified(java.awt.event.WindowEvent e) {
654: }
655:
656: /**
657: * Method to handle events for the WindowListener interface.
658: * @param e java.awt.event.WindowEvent
659: */
660: public void windowIconified(java.awt.event.WindowEvent e) {
661: }
662:
663: /**
664: * Method to handle events for the WindowListener interface.
665: * @param e java.awt.event.WindowEvent
666: */
667: public void windowOpened(java.awt.event.WindowEvent e) {
668: }
669: }
|