KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > IC2DFrame


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;
32
33 import java.rmi.RemoteException JavaDoc;
34
35 import org.globus.ogce.gui.gram.gui.SubmitJobPanel;
36 import org.objectweb.proactive.core.event.RuntimeRegistrationEvent;
37 import org.objectweb.proactive.core.event.RuntimeRegistrationEventListener;
38 import org.objectweb.proactive.core.process.ExternalProcess;
39 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
40 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
41 import org.objectweb.proactive.ic2d.IC2D;
42 import org.objectweb.proactive.ic2d.data.ActiveObject;
43 import org.objectweb.proactive.ic2d.data.IC2DObject;
44 import org.objectweb.proactive.ic2d.event.IC2DObjectListener;
45 import org.objectweb.proactive.ic2d.gui.data.IC2DPanel;
46 import org.objectweb.proactive.ic2d.gui.process.ProcessControlFrame;
47 import org.objectweb.proactive.ic2d.gui.util.DialogUtils;
48 import org.objectweb.proactive.ic2d.gui.util.MessagePanel;
49 import org.objectweb.proactive.ic2d.spy.SpyEvent;
50 import org.objectweb.proactive.ic2d.util.ActiveObjectFilter;
51 import org.objectweb.proactive.ic2d.util.IC2DMessageLogger;
52
53
54 public class IC2DFrame extends javax.swing.JFrame JavaDoc implements IC2DObjectListener,
55     RuntimeRegistrationEventListener {
56     private static final int DEFAULT_WIDTH = 850;
57     private static final int DEFAULT_HEIGHT = 600;
58     private int options;
59     private IC2DPanel ic2dPanel;
60     private IC2DObject ic2dObject;
61     private IC2DMessageLogger logger;
62     private IC2DGUIController controller;
63     private ActiveObjectFilter activeObjectFilter;
64     private ActiveObjectCommunicationRecorder communicationRecorder;
65     private EventListsPanel eventListsPanel;
66     private javax.swing.JFrame JavaDoc eventListsFrame;
67     private javax.swing.JFrame JavaDoc processesFrame;
68     private javax.swing.JFrame JavaDoc globusProcessFrame;
69     private javax.swing.JFrame JavaDoc fileChooserFrame;
70     private ExternalProcess externalProcess;
71     private ProActiveRuntimeImpl proActiveRuntimeImpl;
72     private static final String JavaDoc HOME = System.getProperty("user.home");
73
74     //
75
// -- CONTRUCTORS -----------------------------------------------
76
//
77
public IC2DFrame(IC2DObject ic2dObject) {
78         this(ic2dObject, IC2D.NOTHING);
79     }
80
81     public IC2DFrame(IC2DObject object, int options) {
82         super("IC2D");
83         this.options = options;
84         this.setSize(new java.awt.Dimension JavaDoc(DEFAULT_WIDTH, DEFAULT_HEIGHT));
85         this.ic2dObject = object;
86         setJMenuBar(createMenuBar());
87
88         activeObjectFilter = new ActiveObjectFilter();
89         controller = new MyController();
90         communicationRecorder = new ActiveObjectCommunicationRecorder();
91         MessagePanel messagePanel = new MessagePanel("Messages");
92         logger = messagePanel.getMessageLogger();
93         ic2dObject.registerLogger(logger);
94         ic2dObject.registerListener(this);
95         eventListsPanel = new EventListsPanel(ic2dObject, controller);
96         ic2dPanel = new IC2DPanel(this, ic2dObject, controller,
97                 communicationRecorder, activeObjectFilter, eventListsPanel);
98
99         java.awt.Container JavaDoc c = getContentPane();
100         c.setLayout(new java.awt.BorderLayout JavaDoc());
101
102         //Create the split pane
103
javax.swing.JSplitPane JavaDoc splitPanel = new javax.swing.JSplitPane JavaDoc(javax.swing.JSplitPane.VERTICAL_SPLIT,
104                 false, ic2dPanel, messagePanel);
105         splitPanel.setDividerLocation(DEFAULT_HEIGHT - 200);
106         splitPanel.setOneTouchExpandable(true);
107         c.add(splitPanel, java.awt.BorderLayout.CENTER);
108
109         // Listeners
110
proActiveRuntimeImpl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
111
112         proActiveRuntimeImpl.addRuntimeRegistrationEventListener(this);
113         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
114                 public void windowClosing(java.awt.event.WindowEvent JavaDoc e) {
115                     // try {
116
// ProActiveRuntime part = RuntimeFactory.getDefaultRuntime();
117
// part.killRT(true);
118
// } catch (ProActiveException e1) {
119
// e1.printStackTrace();
120
// } catch (Exception ex) {
121
// ex.printStackTrace();
122
// }
123
System.exit(0);
124                 }
125             });
126
127         setVisible(true);
128         eventListsFrame = createEventListFrame(eventListsPanel);
129         processesFrame = createProcessesFrame();
130         //fileChooserFrame = createFileChooserFrame();
131
logger.log("IC2D ready !");
132     }
133
134     //
135
// -- PUBLIC METHODS -----------------------------------------------
136
//
137
//
138
// -- implements NodeObjectListener -----------------------------------------------
139
//
140
public void activeObjectAdded(ActiveObject activeObject) {
141     }
142
143     public void activeObjectRemoved(ActiveObject activeObject) {
144         communicationRecorder.removeActiveObject(activeObject);
145     }
146
147     /* (non-Javadoc)
148      * @see org.objectweb.proactive.core.event.RuntimeRegistrationEventListener#runtimeRegistered(org.objectweb.proactive.core.event.RuntimeRegistrationEvent)
149      */

150     public void runtimeRegistered(RuntimeRegistrationEvent event) {
151         ProActiveRuntime proActiveRuntimeRegistered;
152
153         String JavaDoc protocol;
154         String JavaDoc host;
155
156         protocol = event.getProtocol();
157         proActiveRuntimeRegistered = proActiveRuntimeImpl.getProActiveRuntime(event.getRegisteredRuntimeName());
158         host = proActiveRuntimeRegistered.getVMInformation().getInetAddress()
159                                          .getCanonicalHostName();
160         try {
161             ic2dObject.getWorldObject().addHostObject(host, protocol);
162         } catch (RemoteException JavaDoc e) {
163             // TODO Auto-generated catch block
164
logger.log("Cannot create the RMI Host " + host, e);
165         }
166     }
167
168     //
169
// -- implements CommunicationEventListener -----------------------------------------------
170
//
171
public void objectWaitingForRequest(ActiveObject object, SpyEvent spyEvent) {
172         ic2dPanel.objectWaitingForRequest(object, spyEvent);
173         eventListsPanel.objectWaitingForRequest(object, spyEvent);
174     }
175
176     public void objectWaitingByNecessity(ActiveObject object, SpyEvent spyEvent) {
177         ic2dPanel.objectWaitingByNecessity(object, spyEvent);
178         eventListsPanel.objectWaitingByNecessity(object, spyEvent);
179     }
180
181     public void requestMessageSent(ActiveObject object, SpyEvent spyEvent) {
182         ic2dPanel.requestMessageSent(object, spyEvent);
183         eventListsPanel.requestMessageSent(object, spyEvent);
184     }
185
186     public void replyMessageSent(ActiveObject object, SpyEvent spyEvent) {
187         ic2dPanel.replyMessageSent(object, spyEvent);
188         eventListsPanel.replyMessageSent(object, spyEvent);
189     }
190
191     public void requestMessageReceived(ActiveObject object, SpyEvent spyEvent) {
192         ic2dPanel.requestMessageReceived(object, spyEvent);
193         eventListsPanel.requestMessageReceived(object, spyEvent);
194     }
195
196     public void replyMessageReceived(ActiveObject object, SpyEvent spyEvent) {
197         ic2dPanel.replyMessageReceived(object, spyEvent);
198         eventListsPanel.replyMessageReceived(object, spyEvent);
199     }
200
201     public void voidRequestServed(ActiveObject object, SpyEvent spyEvent) {
202         ic2dPanel.voidRequestServed(object, spyEvent);
203         eventListsPanel.voidRequestServed(object, spyEvent);
204     }
205
206     public void allEventsProcessed() {
207         ic2dPanel.allEventsProcessed();
208         eventListsPanel.allEventsProcessed();
209     }
210
211     //
212
// -- PROTECTED METHODS -----------------------------------------------
213
//
214
//
215
// -- PRIVATE METHODS -----------------------------------------------
216
//
217
private javax.swing.JFrame JavaDoc createEventListFrame(javax.swing.JPanel JavaDoc panel) {
218         // Create the timeLine panel
219
final javax.swing.JFrame JavaDoc frame = new javax.swing.JFrame JavaDoc("Events lists");
220         frame.setLocation(new java.awt.Point JavaDoc(0, DEFAULT_HEIGHT));
221         frame.setSize(new java.awt.Dimension JavaDoc(DEFAULT_WIDTH, DEFAULT_HEIGHT / 2));
222         java.awt.Container JavaDoc c = frame.getContentPane();
223         c.setLayout(new java.awt.GridLayout JavaDoc(1, 1));
224         javax.swing.JScrollPane JavaDoc scrollingEventListsPanel = new javax.swing.JScrollPane JavaDoc(panel);
225         scrollingEventListsPanel.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
226         c.add(scrollingEventListsPanel);
227         frame.addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
228                 public void windowClosing(java.awt.event.WindowEvent JavaDoc e) {
229                     frame.setVisible(!frame.isVisible());
230                 }
231             });
232         frame.setVisible(true);
233         return frame;
234     }
235
236     private javax.swing.JFrame JavaDoc createProcessesFrame() {
237         final javax.swing.JFrame JavaDoc frame = new ProcessControlFrame();
238         frame.setLocation(new java.awt.Point JavaDoc(DEFAULT_WIDTH, 0));
239         // Listeners
240
frame.addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
241                 public void windowClosing(java.awt.event.WindowEvent JavaDoc e) {
242                     frame.setVisible(!frame.isVisible());
243                 }
244             });
245         return frame;
246     }
247
248     // private javax.swing.JFrame createFileChooserFrame() {
249
// final javax.swing.JFrame frame = new DeployFileChooserFrame();
250
// //frame.setLocation(new java.awt.Point(DEFAULT_WIDTH, 0));
251
// // Listeners
252
// frame.addWindowListener(new java.awt.event.WindowAdapter() {
253
// public void windowClosing(java.awt.event.WindowEvent e) {
254
// frame.setVisible(! frame.isVisible());
255
// }
256
// });
257
// return frame;
258
// }
259
// private javax.swing.JFrame createGlobusProcessFrame() {
260
// final javax.swing.JFrame frame = new GlobusProcessControlFrame(externalProcess);
261
// //frame.setLocation(new java.awt.Point(DEFAULT_WIDTH, 0));
262
// // Listeners
263
// frame.addWindowListener(new java.awt.event.WindowAdapter() {
264
// public void windowClosing(java.awt.event.WindowEvent e) {
265
// frame.setVisible(! frame.isVisible());
266
// }
267
// });
268
// return frame;
269
// }
270
private javax.swing.JMenuBar JavaDoc createMenuBar() {
271         javax.swing.JMenuBar JavaDoc menuBar = new javax.swing.JMenuBar JavaDoc();
272
273         //
274
// monitoring menu
275
//
276
javax.swing.JMenu JavaDoc monitoringMenu = new javax.swing.JMenu JavaDoc("Monitoring");
277
278         // Add new RMI host
279
{
280             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
281                     "Monitor a new RMI host");
282             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
283                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
284                         DialogUtils.openNewRMIHostDialog(IC2DFrame.this,
285                             ic2dObject.getWorldObject(), logger);
286                     }
287                 });
288             monitoringMenu.add(b);
289         }
290
291         // Add new RMI Node
292
{
293             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
294                     "Monitor a new RMI Node");
295             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
296                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
297                         DialogUtils.openNewNodeDialog(IC2DFrame.this,
298                             ic2dObject.getWorldObject(), logger);
299                     }
300                 });
301             monitoringMenu.add(b);
302         }
303
304         {
305             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
306                     "Monitor a new Ibis host");
307             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
308                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
309                         DialogUtils.openNewIbisHostDialog(IC2DFrame.this,
310                             ic2dObject.getWorldObject(), logger);
311                     }
312                 });
313             monitoringMenu.add(b);
314         }
315
316         {
317             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
318                     "Monitor all JINI Hosts");
319             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
320                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
321                         ic2dObject.getWorldObject().addHosts();
322                     }
323                 });
324             monitoringMenu.add(b);
325         }
326
327         {
328             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
329                     "Monitor a new JINI Hosts");
330             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
331                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
332                         DialogUtils.openNewJINIHostDialog(IC2DFrame.this,
333                             ic2dObject.getWorldObject(), logger);
334                     }
335                 });
336             monitoringMenu.add(b);
337         }
338
339         monitoringMenu.addSeparator();
340
341         // Add new GLOBUS host
342
//deprecated
343
// {
344
// javax.swing.JMenuItem b = new javax.swing.JMenuItem("Monitor new GLOBUS host");
345
// b.addActionListener(new java.awt.event.ActionListener() {
346
// public void actionPerformed(java.awt.event.ActionEvent e) {
347
// DialogUtils.openNewGlobusHostDialog((java.awt.Component) IC2DFrame.this, ic2dObject.getWorldObject(), logger);
348
// }
349
// });
350
// //b.setEnabled((options & IC2D.GLOBUS) != 0);
351
// monitoringMenu.add(b);
352
// }
353
//
354
// monitoringMenu.addSeparator();
355
// Edit the filter list
356
{
357             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
358                     "Show filtered classes");
359             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
360                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
361                         DialogUtils.openFilteredClassesDialog(IC2DFrame.this,
362                             ic2dPanel, activeObjectFilter);
363                     }
364                 });
365             b.setToolTipText("Filter active objects");
366             monitoringMenu.add(b);
367         }
368         monitoringMenu.addSeparator();
369
370         // Display the legend
371
{
372             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc("Legend");
373             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
374                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
375                         doLegend();
376                     }
377                 });
378             b.setToolTipText("Display the legend");
379             monitoringMenu.add(b);
380         }
381         monitoringMenu.addSeparator();
382
383         // exit
384
{
385             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc("Quit");
386             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
387                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
388                         // try {
389
// ProActiveRuntime part = RuntimeFactory.getDefaultRuntime();
390
// part.killRT(true);
391
// } catch (ProActiveException e1) {
392
// e1.printStackTrace();
393
// } catch (Exception ex) {
394
// ex.printStackTrace();
395
// }
396
System.exit(0);
397                     }
398                 });
399             monitoringMenu.add(b);
400         }
401         menuBar.add(monitoringMenu);
402
403         // //Deploy
404
// javax.swing.JMenu DeployMenu = new javax.swing.JMenu("Deploy");
405
// {
406
// javax.swing.JMenuItem b = new javax.swing.JMenuItem("Deploy with descriptors");
407
// b.addActionListener(new java.awt.event.ActionListener() {
408
// public void actionPerformed(java.awt.event.ActionEvent e) {
409
// JFrame frame = createFileChooserFrame();
410
// frame.setVisible(true);
411
// }
412
// });
413
//
414
// DeployMenu.add(b);
415
// }
416
// menuBar.add(DeployMenu);
417
//
418
// look and feel
419
//
420
{
421             javax.swing.JMenu JavaDoc lookMenu = new javax.swing.JMenu JavaDoc("Look & feel");
422             javax.swing.UIManager.LookAndFeelInfo[] infos = javax.swing.UIManager.getInstalledLookAndFeels();
423             for (int i = 0; i < infos.length; i++) {
424                 javax.swing.AbstractAction JavaDoc a = new javax.swing.AbstractAction JavaDoc(infos[i].getName(),
425                         null) {
426                         public void actionPerformed(
427                             java.awt.event.ActionEvent JavaDoc e) {
428                             try {
429                                 String JavaDoc classname = (String JavaDoc) getValue("class");
430
431                                 //javax.swing.JFrame frame = (javax.swing.JFrame)getValue("frame");
432
javax.swing.UIManager.setLookAndFeel(classname);
433                                 javax.swing.SwingUtilities.updateComponentTreeUI(IC2DFrame.this);
434                                 javax.swing.SwingUtilities.updateComponentTreeUI(eventListsFrame);
435                                 javax.swing.SwingUtilities.updateComponentTreeUI(processesFrame);
436                             } catch (Exception JavaDoc ex) {
437                             }
438                         }
439                     };
440                 a.putValue("frame", this);
441                 a.putValue("class", infos[i].getClassName());
442                 lookMenu.add(a);
443             }
444             menuBar.add(lookMenu);
445         }
446
447         //
448
// Window
449
//
450
javax.swing.JMenu JavaDoc windowMenu = new javax.swing.JMenu JavaDoc("Window");
451         {
452             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
453                     "Hide/Show EventsList windows");
454             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
455                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
456                         if (eventListsFrame.isVisible()) {
457                             eventListsFrame.hide();
458                         } else {
459                             eventListsFrame.show();
460                         }
461                     }
462                 });
463             windowMenu.add(b);
464         }
465
466         {
467             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
468                     "Hide/Show Processes windows");
469             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
470                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
471                         if (processesFrame.isVisible()) {
472                             processesFrame.hide();
473                         } else {
474                             processesFrame.show();
475                         }
476                     }
477                 });
478             windowMenu.add(b);
479         }
480
481         menuBar.add(windowMenu);
482
483         //
484
// Globus
485
//
486
javax.swing.JMenu JavaDoc globusMenu = new javax.swing.JMenu JavaDoc("Globus");
487         {
488             javax.swing.JMenuItem JavaDoc b = new javax.swing.JMenuItem JavaDoc(
489                     "Start a new Node with Globus");
490             b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
491                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
492                         SubmitJobPanel.main(new String JavaDoc[0]);
493                         // if (fileChooserFrame.isVisible()) {
494
// fileChooserFrame.hide();
495
// } else {
496
// fileChooserFrame.show();
497
// }
498
}
499                 });
500             globusMenu.add(b);
501         }
502
503         // {
504
// javax.swing.JMenuItem b = new javax.swing.JMenuItem("Initialize proxy");
505
// b.addActionListener(new java.awt.event.ActionListener() {
506
// public void actionPerformed(java.awt.event.ActionEvent e) {
507
// GridProxyInit.main(new String[0]);
508
//// if (((FileChooser)fileChooserFrame).ready()){
509
//// ((FileChooser)fileChooserFrame).changeVisibilityGlobusProcessFrame();
510
//// }
511
//// else {
512
//// logger.log("Please select the deployment file with the file chooser in the window menu!");
513
//// }
514
//
515
// }
516
// });
517
// globusMenu.add(b);
518
// }
519
menuBar.add(globusMenu);
520
521         return menuBar;
522     }
523
524     private void doLegend() {
525         Legend legend = Legend.uniqueInstance();
526         legend.setVisible(!legend.isVisible());
527     }
528
529     //
530
// -- INNER CLASSES -----------------------------------------------
531
//
532
private class MyController implements IC2DGUIController {
533         private boolean isLayoutAutomatic = true;
534
535         public MyController() {
536         }
537
538         public boolean isLayoutAutomatic() {
539             return isLayoutAutomatic;
540         }
541
542         public void setAutomaticLayout(boolean b) {
543             isLayoutAutomatic = b;
544         }
545
546         public void warn(String JavaDoc message) {
547             logger.warn(message);
548         }
549
550         public void log(String JavaDoc message) {
551             logger.log(message);
552         }
553
554         public void log(String JavaDoc message, Throwable JavaDoc e) {
555             logger.log(message, e);
556         }
557
558         public void log(Throwable JavaDoc e) {
559             logger.log(e);
560         }
561     }
562 }
563
Popular Tags