KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.proactive.ic2d.data.AbstractDataObject;
34 import org.objectweb.proactive.ic2d.data.HostObject;
35 import org.objectweb.proactive.ic2d.data.VMObject;
36 import org.objectweb.proactive.ic2d.event.HostObjectListener;
37
38 public class HostPanel extends AbstractDataObjectPanel implements HostObjectListener {
39
40   private HostObject hostObject;
41   protected java.awt.Dimension JavaDoc minimumSize = new java.awt.Dimension JavaDoc(150,80);
42   protected PanelPopupMenu popup;
43
44   //
45
// -- CONSTRUCTORS -----------------------------------------------
46
//
47

48   public HostPanel(AbstractDataObjectPanel parentDataObjectPanel, HostObject targetHostObject) {
49     super(parentDataObjectPanel, targetHostObject.getHostName(), "HostObject");
50     this.hostObject = targetHostObject;
51     // Component init
52
// if (hostObject.isGlobusEnabled())
53
// setBackground(new java.awt.Color(0xff, 0xd0, 0xd0));
54
//else
55
setBackground(new java.awt.Color JavaDoc(0xd0, 0xd0, 0xd0));
56     createBorder(hostObject.getOperatingSystem());
57     setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.CENTER, 9, 5));
58
59     // Popup menu
60
popup = new PanelPopupMenu("Host " + name+" OS "+hostObject.getOperatingSystem());
61     popup.add(new javax.swing.AbstractAction JavaDoc("Look for new nodes", null) {
62       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
63         hostObject.createAllNodes();
64       }
65     });
66     popup.addSeparator();
67     popup.add(new javax.swing.AbstractAction JavaDoc("Stop Monitoring this host", null) {
68       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
69         hostObject.destroyObject();
70       }
71     });
72   
73     //Monitoring Event
74
addMouseListener(popup.getMenuMouseListener());
75
76     addMouseMotionListener(new java.awt.event.MouseMotionAdapter JavaDoc() {
77       public void mouseDragged(java.awt.event.MouseEvent JavaDoc e) {
78         if (controller.isLayoutAutomatic()) return;
79         e.translatePoint(getX(), getY());
80         setLocation(e.getX(), e.getY());
81       }
82     });
83     addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
84       public void mouseReleased(java.awt.event.MouseEvent JavaDoc e) {
85         HostPanel.this.parentDataObjectPanel.revalidate();
86         HostPanel.this.parentDataObjectPanel.repaint();
87       }
88     });
89   }
90
91
92   //
93
// -- PUBLIC METHODS -----------------------------------------------
94
//
95

96   //
97
// -- implements HostObjectListener -----------------------------------------------
98
//
99

100   public void vmObjectAdded(VMObject vmObject) {
101     VMPanel panel = new VMPanel(this, vmObject);
102     addChild(vmObject, panel);
103     vmObject.registerListener(panel);
104   }
105   
106   public void vmObjectRemoved(VMObject vmObject) {
107     removeChild(vmObject);
108   }
109   
110   public void operatingSystemFound(String JavaDoc os) {
111     createBorder(os);
112     popup.setName("Host " + name+" OS "+os);
113     repaint();
114   }
115   
116
117   //
118
// -- PROTECTED METHODS -----------------------------------------------
119
//
120

121   protected AbstractDataObject getAbstractDataObject() {
122     return hostObject;
123   }
124   
125   
126   protected VMPanel getVMPanel(VMObject vmObject) {
127     return (VMPanel) getChild(vmObject);
128   }
129
130
131   protected Object JavaDoc[][] getDataObjectInfo() {
132     return new Object JavaDoc[][] {
133       {"Hostname", name}
134     };
135   }
136
137
138   protected java.awt.Dimension JavaDoc getMinimumSizeInternal() {
139     return minimumSize;
140   }
141   
142   
143   protected void setFontSize(java.awt.Font JavaDoc font) {
144     super.setFontSize(font);
145     createBorder(hostObject.getOperatingSystem());
146   }
147
148   //
149
// -- PRIVATE METHODS -----------------------------------------------
150
//
151

152   private String JavaDoc getNodeNameFromDialog() {
153     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(
154           parentFrame, // Component parentComponent,
155
"Enter the name of the node to create on host "+hostObject.getHostName(), // Object message,
156
"Creating a new remote JVM", // String title,
157
javax.swing.JOptionPane.PLAIN_MESSAGE // int messageType,
158
);
159     if (result == null || (! (result instanceof String JavaDoc))) return null;
160     return (String JavaDoc) result;
161   }
162   
163
164   private void createBorder(String JavaDoc os) {
165     if (os == null) os = "OS Undefined";
166     setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createMatteBorder(1,1,1,1, new java.awt.Color JavaDoc(0, 0, 128)), name+":"+os,
167      javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, defaultFont));
168   }
169
170 }
171
172
173
174
Popular Tags