KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > data > VMPanel


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.ic2d.gui.data;
32
33 import java.awt.Color JavaDoc;
34
35 import org.objectweb.proactive.ic2d.data.AbstractDataObject;
36 import org.objectweb.proactive.ic2d.data.NodeObject;
37 import org.objectweb.proactive.ic2d.data.SpyListenerImpl;
38 import org.objectweb.proactive.ic2d.data.VMObject;
39 import org.objectweb.proactive.ic2d.event.VMObjectListener;
40
41 public class VMPanel extends AbstractDataObjectPanel implements VMObjectListener {
42
43   private VMObject vmObject;
44   
45   //
46
// -- CONSTRUCTORS -----------------------------------------------
47
//
48

49   public VMPanel(AbstractDataObjectPanel parentDataObjectPanel, VMObject targetVMObject) {
50     super(parentDataObjectPanel, "VM id="+targetVMObject.getID().toString(), "VMObject");
51     activeObjectFilter.addClass(SpyListenerImpl.class.getName());
52     this.vmObject = targetVMObject;
53     this.setLayout(new java.awt.GridLayout JavaDoc(1, 0, 4, 4));
54     if (targetVMObject.getProtocolId().indexOf("globus")>=0){
55         this.setBackground(new Color JavaDoc(0xff, 0xd0, 0xd0));
56     }
57     createBorder(name);
58     
59     // The popup
60
PanelPopupMenu popup = new PanelPopupMenu(name);
61     popup.add(new javax.swing.AbstractAction JavaDoc("Look for new Active Objects", null) {
62       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
63         vmObject.sendEventsForAllActiveObjects();
64       }
65     });
66     popup.add(new javax.swing.AbstractAction JavaDoc("Set update frequence", null) {
67       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
68         changeUpdateFrequence();
69       }
70     });
71     popup.addSeparator();
72     popup.add(new javax.swing.AbstractAction JavaDoc("Stop monitoring this VM", null) {
73       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
74         vmObject.destroyObject();
75       }
76     });
77
78     addMouseListener(popup.getMenuMouseListener());
79   }
80
81
82
83   //
84
// -- PUBLIC METHODS -----------------------------------------------
85
//
86

87   //
88
// -- implements VMObjectListener -----------------------------------------------
89
//
90

91   public void nodeObjectAdded(NodeObject nodeObject) {
92     NodePanel panel = new NodePanel(this, nodeObject);
93     addChild(nodeObject, panel);
94     nodeObject.registerListener(panel);
95   }
96   
97   
98   public void nodeObjectRemoved(NodeObject nodeObject) {
99     removeChild(nodeObject);
100   }
101   
102   
103   
104   //
105
// -- PROTECTED METHODS -----------------------------------------------
106
//
107

108   protected AbstractDataObject getAbstractDataObject() {
109     return vmObject;
110   }
111   
112   
113   protected NodePanel getNodePanel(NodeObject nodeObject) {
114     return (NodePanel) getChild(nodeObject);
115   }
116
117
118   protected Object JavaDoc[][] getDataObjectInfo() {
119     return new Object JavaDoc[][] {
120         {"ID",vmObject.getID()},
121         {"Active objects",new Integer JavaDoc(vmObject.getActiveObjectsCount())},
122         {"Protocol identifier",vmObject.getProtocolId()}
123       };
124   }
125
126
127   protected void setFontSize(java.awt.Font JavaDoc font) {
128     super.setFontSize(font);
129     createBorder(name);
130   }
131
132
133   //
134
// -- PRIVATE METHODS -----------------------------------------------
135
//
136

137   private void changeUpdateFrequence() {
138     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(
139           parentFrame, // Component parentComponent,
140
"Please enter the new value for the frequence of the update for vm id="+vmObject.getID(), // Object message,
141
"Spy updates frequence", // String title,
142
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
143
null, // Icon icon,
144
null, // Object[] selectionValues,
145
new Long JavaDoc(vmObject.getUpdateFrequence()) // Object initialSelectionValue)
146
);
147     if (result == null || (! (result instanceof String JavaDoc))) return;
148     try {
149       long f = Long.parseLong((String JavaDoc) result);
150       controller.log("Setting spy update frequence for VM " + vmObject.getID() + " to " + f + " ms");
151       vmObject.setUpdateFrequence(f);
152     } catch (NumberFormatException JavaDoc e) {
153     }
154   }
155
156
157   private void createBorder(String JavaDoc name) {
158     setBorder(javax.swing.BorderFactory.createTitledBorder(null, name,
159        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, defaultFont));
160   }
161
162 }
163
Popular Tags