KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > util > DialogUtils


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.util;
32
33 import java.awt.Component JavaDoc;
34
35 import org.objectweb.proactive.ic2d.data.WorldObject;
36 import org.objectweb.proactive.ic2d.gui.data.IC2DPanel;
37 import org.objectweb.proactive.ic2d.gui.dialog.FilteredClassesPanel;
38 import org.objectweb.proactive.ic2d.util.ActiveObjectFilter;
39 import org.objectweb.proactive.ic2d.util.IC2DMessageLogger;
40
41 public class DialogUtils {
42
43   private DialogUtils() {
44   }
45
46   public static void openNewRMIHostDialog(
47     java.awt.Component JavaDoc parentComponent,
48     WorldObject worldObject,
49     IC2DMessageLogger logger) {
50     String JavaDoc initialHostValue = "localhost";
51     try {
52       initialHostValue = java.net.InetAddress.getLocalHost().getCanonicalHostName();
53     } catch (java.net.UnknownHostException JavaDoc e) {
54     }
55     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(parentComponent, // Component parentComponent,
56
"Please enter the name or the IP of the host to monitor :", // Object message,
57
"Adding a host to monitor", // String title,
58
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
59
null, // Icon icon,
60
null, // Object[] selectionValues,
61
initialHostValue // Object initialSelectionValue)
62
);
63     if (result == null || (!(result instanceof String JavaDoc)))
64       return;
65     String JavaDoc host = (String JavaDoc) result;
66     try {
67       worldObject.addHostObject(host, "rmi");
68     } catch (java.rmi.RemoteException JavaDoc e) {
69       logger.log("Cannot create the RMI Host " + host, e);
70     }
71   }
72
73
74   public static void openNewIbisHostDialog(
75     java.awt.Component JavaDoc parentComponent,
76     WorldObject worldObject,
77     IC2DMessageLogger logger) {
78     String JavaDoc initialHostValue = "localhost";
79     try {
80       initialHostValue = java.net.InetAddress.getLocalHost().getCanonicalHostName();
81     } catch (java.net.UnknownHostException JavaDoc e) {
82     }
83     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(parentComponent, // Component parentComponent,
84
"Please enter the name or the IP of the host to monitor :", // Object message,
85
"Adding a host to monitor", // String title,
86
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
87
null, // Icon icon,
88
null, // Object[] selectionValues,
89
initialHostValue // Object initialSelectionValue)
90
);
91     if (result == null || (!(result instanceof String JavaDoc)))
92       return;
93     String JavaDoc host = (String JavaDoc) result;
94     try {
95       worldObject.addHostObject(host, "ibis");
96     } catch (java.rmi.RemoteException JavaDoc e) {
97       logger.log("Cannot create the Ibis Host " + host, e);
98     }
99   }
100
101   /*
102     public static void openNewGlobusHostDialog(java.awt.Frame parent, WorldObject worldObject, IC2DMessageLogger logger) {
103       org.objectweb.proactive.ic2d.gui.dialog.NewGlobusHostDialog diag = new org.objectweb.proactive.ic2d.gui.dialog.NewGlobusHostDialog(parent, true);
104       diag.setVisible(true);
105       if (diag.success)
106         worldObject.createNewRemoteHostGlobus(diag.host, diag.port);
107       diag = null;
108     }
109   */

110
111   public static void openNewJINIHostDialog(
112     java.awt.Component JavaDoc parentComponent,
113     WorldObject worldObject,
114     IC2DMessageLogger logger) {
115     String JavaDoc initialHostValue = "localhost";
116     try {
117       initialHostValue = java.net.InetAddress.getLocalHost().getCanonicalHostName();
118     } catch (java.net.UnknownHostException JavaDoc e) {
119     }
120     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(parentComponent, // Component parentComponent,
121
"Please enter the name or the IP of the host to monitor :", // Object message,
122
"Adding a host to monitor", // String title,
123
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
124
null, // Icon icon,
125
null, // Object[] selectionValues,
126
initialHostValue // Object initialSelectionValue)
127
);
128     if (result == null || (!(result instanceof String JavaDoc)))
129       return;
130     String JavaDoc host = (String JavaDoc) result;
131     System.out.println("host "+host);
132     worldObject.addHosts(host);
133     
134   }
135
136   public static void openNewNodeDialog(
137     java.awt.Component JavaDoc parentComponent,
138     WorldObject worldObject,
139     IC2DMessageLogger logger) {
140     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(parentComponent, // Component parentComponent,
141
"Please enter the URL of the node in the form //hostname/nodename :", // Object message,
142
"Adding a JVM to monitor", // String title,
143
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
144
null, // Icon icon,
145
null, // Object[] selectionValues,
146
"//hostname/nodename" // Object initialSelectionValue)
147
);
148     if (result == null || (!(result instanceof String JavaDoc)))
149       return;
150     String JavaDoc url = (String JavaDoc) result;
151     int n1 = url.indexOf("//");
152     int n2 = url.lastIndexOf("/");
153     if (n1 == -1 || n2 == -1 || n2 <= n1 + 1) {
154       logger.warn(url + " isn't an proper node url !");
155       return;
156     }
157     String JavaDoc host = url.substring(n1 + 2, n2);
158     String JavaDoc nodeName = url.substring(n2 + 1);
159     try {
160       worldObject.addHostObject(host, nodeName);
161     } catch (java.rmi.RemoteException JavaDoc e) {
162       logger.log("Cannot create the RMI Host " + host, e);
163     }
164   }
165
166   public static void displayMessageDialog(java.awt.Component JavaDoc parentComponent, Object JavaDoc message) {
167     javax.swing.JOptionPane.showMessageDialog(parentComponent, // Component parentComponent,
168
message, // Object message,
169
"IC2D Message", // String title,
170
javax.swing.JOptionPane.INFORMATION_MESSAGE // int messageType,
171
);
172   }
173
174   public static void displayWarningDialog(java.awt.Component JavaDoc parentComponent, Object JavaDoc message) {
175     javax.swing.JOptionPane.showMessageDialog(parentComponent, // Component parentComponent,
176
message, // Object message,
177
"IC2D Message", // String title,
178
javax.swing.JOptionPane.WARNING_MESSAGE // int messageType,
179
);
180   }
181   
182   
183   public static void openFilteredClassesDialog(java.awt.Component JavaDoc parentComponent, IC2DPanel ic2dPanel, ActiveObjectFilter filter) {
184     FilteredClassesPanel panel = new FilteredClassesPanel(filter);
185     int result = javax.swing.JOptionPane.showOptionDialog(parentComponent, // Component parentComponent,
186
panel, // Object message,
187
"Filtered classes dialog", // String title,
188
javax.swing.JOptionPane.OK_CANCEL_OPTION, // option buttons
189
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
190
null, // Icon icon,
191
null, // Object[] selectionValues
192
null
193       );
194     if (result != javax.swing.JOptionPane.OK_OPTION) return;
195     if (panel.updateFilter(filter)) {
196       ic2dPanel.updateFilteredClasses();
197     }
198   }
199   
200 // public static void openNewGlobusHostDialog(java.awt.Component parentComponent, IC2DPanel ic2dPanel, ActiveObjectFilter filter) {
201
// }
202

203     /**
204      * Method openNewGlobusHostDialog.
205      * @param component
206      * @param worldObject
207      * @param logger
208      */

209     public static void openNewGlobusHostDialog(
210         Component JavaDoc parentComponent,
211         WorldObject worldObject,
212         IC2DMessageLogger logger)
213     {
214         String JavaDoc initialHostValue = "localhost";
215     try {
216       initialHostValue = java.net.InetAddress.getLocalHost().getCanonicalHostName();
217     } catch (java.net.UnknownHostException JavaDoc e) {
218         e.printStackTrace();
219     }
220     Object JavaDoc result = javax.swing.JOptionPane.showInputDialog(parentComponent, // Component parentComponent,
221
"Please enter the name or the IP of the Globus host to monitor :", // Object message,
222
"Adding a host to monitor", // String title,
223
javax.swing.JOptionPane.PLAIN_MESSAGE, // int messageType,
224
null, // Icon icon,
225
null, // Object[] selectionValues,
226
initialHostValue // Object initialSelectionValue)
227
);
228     if (result == null || (!(result instanceof String JavaDoc)))
229       return;
230     String JavaDoc host = (String JavaDoc) result;
231     try {
232       worldObject.addHostObject(host, "rmi");
233       worldObject.addHosts(host);
234     } catch (java.rmi.RemoteException JavaDoc e) {
235       logger.log("Cannot create the Globus Host " + host, e);
236     }
237     }
238
239 }
240
Popular Tags