1 31 package org.objectweb.proactive.ic2d.gui; 32 33 import java.rmi.RemoteException ; 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 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 eventListsFrame; 67 private javax.swing.JFrame processesFrame; 68 private javax.swing.JFrame globusProcessFrame; 69 private javax.swing.JFrame fileChooserFrame; 70 private ExternalProcess externalProcess; 71 private ProActiveRuntimeImpl proActiveRuntimeImpl; 72 private static final String HOME = System.getProperty("user.home"); 73 74 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 (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 c = getContentPane(); 100 c.setLayout(new java.awt.BorderLayout ()); 101 102 javax.swing.JSplitPane splitPanel = new javax.swing.JSplitPane (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 proActiveRuntimeImpl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime(); 111 112 proActiveRuntimeImpl.addRuntimeRegistrationEventListener(this); 113 addWindowListener(new java.awt.event.WindowAdapter () { 114 public void windowClosing(java.awt.event.WindowEvent e) { 115 System.exit(0); 124 } 125 }); 126 127 setVisible(true); 128 eventListsFrame = createEventListFrame(eventListsPanel); 129 processesFrame = createProcessesFrame(); 130 logger.log("IC2D ready !"); 132 } 133 134 public void activeObjectAdded(ActiveObject activeObject) { 141 } 142 143 public void activeObjectRemoved(ActiveObject activeObject) { 144 communicationRecorder.removeActiveObject(activeObject); 145 } 146 147 150 public void runtimeRegistered(RuntimeRegistrationEvent event) { 151 ProActiveRuntime proActiveRuntimeRegistered; 152 153 String protocol; 154 String 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 e) { 163 logger.log("Cannot create the RMI Host " + host, e); 165 } 166 } 167 168 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 private javax.swing.JFrame createEventListFrame(javax.swing.JPanel panel) { 218 final javax.swing.JFrame frame = new javax.swing.JFrame ("Events lists"); 220 frame.setLocation(new java.awt.Point (0, DEFAULT_HEIGHT)); 221 frame.setSize(new java.awt.Dimension (DEFAULT_WIDTH, DEFAULT_HEIGHT / 2)); 222 java.awt.Container c = frame.getContentPane(); 223 c.setLayout(new java.awt.GridLayout (1, 1)); 224 javax.swing.JScrollPane scrollingEventListsPanel = new javax.swing.JScrollPane (panel); 225 scrollingEventListsPanel.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER); 226 c.add(scrollingEventListsPanel); 227 frame.addWindowListener(new java.awt.event.WindowAdapter () { 228 public void windowClosing(java.awt.event.WindowEvent e) { 229 frame.setVisible(!frame.isVisible()); 230 } 231 }); 232 frame.setVisible(true); 233 return frame; 234 } 235 236 private javax.swing.JFrame createProcessesFrame() { 237 final javax.swing.JFrame frame = new ProcessControlFrame(); 238 frame.setLocation(new java.awt.Point (DEFAULT_WIDTH, 0)); 239 frame.addWindowListener(new java.awt.event.WindowAdapter () { 241 public void windowClosing(java.awt.event.WindowEvent e) { 242 frame.setVisible(!frame.isVisible()); 243 } 244 }); 245 return frame; 246 } 247 248 private javax.swing.JMenuBar createMenuBar() { 271 javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar (); 272 273 javax.swing.JMenu monitoringMenu = new javax.swing.JMenu ("Monitoring"); 277 278 { 280 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 281 "Monitor a new RMI host"); 282 b.addActionListener(new java.awt.event.ActionListener () { 283 public void actionPerformed(java.awt.event.ActionEvent e) { 284 DialogUtils.openNewRMIHostDialog(IC2DFrame.this, 285 ic2dObject.getWorldObject(), logger); 286 } 287 }); 288 monitoringMenu.add(b); 289 } 290 291 { 293 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 294 "Monitor a new RMI Node"); 295 b.addActionListener(new java.awt.event.ActionListener () { 296 public void actionPerformed(java.awt.event.ActionEvent e) { 297 DialogUtils.openNewNodeDialog(IC2DFrame.this, 298 ic2dObject.getWorldObject(), logger); 299 } 300 }); 301 monitoringMenu.add(b); 302 } 303 304 { 305 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 306 "Monitor a new Ibis host"); 307 b.addActionListener(new java.awt.event.ActionListener () { 308 public void actionPerformed(java.awt.event.ActionEvent e) { 309 DialogUtils.openNewIbisHostDialog(IC2DFrame.this, 310 ic2dObject.getWorldObject(), logger); 311 } 312 }); 313 monitoringMenu.add(b); 314 } 315 316 { 317 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 318 "Monitor all JINI Hosts"); 319 b.addActionListener(new java.awt.event.ActionListener () { 320 public void actionPerformed(java.awt.event.ActionEvent e) { 321 ic2dObject.getWorldObject().addHosts(); 322 } 323 }); 324 monitoringMenu.add(b); 325 } 326 327 { 328 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 329 "Monitor a new JINI Hosts"); 330 b.addActionListener(new java.awt.event.ActionListener () { 331 public void actionPerformed(java.awt.event.ActionEvent e) { 332 DialogUtils.openNewJINIHostDialog(IC2DFrame.this, 333 ic2dObject.getWorldObject(), logger); 334 } 335 }); 336 monitoringMenu.add(b); 337 } 338 339 monitoringMenu.addSeparator(); 340 341 { 357 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 358 "Show filtered classes"); 359 b.addActionListener(new java.awt.event.ActionListener () { 360 public void actionPerformed(java.awt.event.ActionEvent 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 { 372 javax.swing.JMenuItem b = new javax.swing.JMenuItem ("Legend"); 373 b.addActionListener(new java.awt.event.ActionListener () { 374 public void actionPerformed(java.awt.event.ActionEvent e) { 375 doLegend(); 376 } 377 }); 378 b.setToolTipText("Display the legend"); 379 monitoringMenu.add(b); 380 } 381 monitoringMenu.addSeparator(); 382 383 { 385 javax.swing.JMenuItem b = new javax.swing.JMenuItem ("Quit"); 386 b.addActionListener(new java.awt.event.ActionListener () { 387 public void actionPerformed(java.awt.event.ActionEvent e) { 388 System.exit(0); 397 } 398 }); 399 monitoringMenu.add(b); 400 } 401 menuBar.add(monitoringMenu); 402 403 { 421 javax.swing.JMenu lookMenu = new javax.swing.JMenu ("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 a = new javax.swing.AbstractAction (infos[i].getName(), 425 null) { 426 public void actionPerformed( 427 java.awt.event.ActionEvent e) { 428 try { 429 String classname = (String ) getValue("class"); 430 431 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 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 javax.swing.JMenu windowMenu = new javax.swing.JMenu ("Window"); 451 { 452 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 453 "Hide/Show EventsList windows"); 454 b.addActionListener(new java.awt.event.ActionListener () { 455 public void actionPerformed(java.awt.event.ActionEvent 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 b = new javax.swing.JMenuItem ( 468 "Hide/Show Processes windows"); 469 b.addActionListener(new java.awt.event.ActionListener () { 470 public void actionPerformed(java.awt.event.ActionEvent 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 javax.swing.JMenu globusMenu = new javax.swing.JMenu ("Globus"); 487 { 488 javax.swing.JMenuItem b = new javax.swing.JMenuItem ( 489 "Start a new Node with Globus"); 490 b.addActionListener(new java.awt.event.ActionListener () { 491 public void actionPerformed(java.awt.event.ActionEvent e) { 492 SubmitJobPanel.main(new String [0]); 493 } 499 }); 500 globusMenu.add(b); 501 } 502 503 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 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 message) { 547 logger.warn(message); 548 } 549 550 public void log(String message) { 551 logger.log(message); 552 } 553 554 public void log(String message, Throwable e) { 555 logger.log(message, e); 556 } 557 558 public void log(Throwable e) { 559 logger.log(e); 560 } 561 } 562 } 563 | Popular Tags |