1 31 package org.objectweb.proactive.ic2d.gui.data; 32 33 import org.objectweb.proactive.core.UniqueID; 34 import org.objectweb.proactive.ic2d.data.AbstractDataObject; 35 import org.objectweb.proactive.ic2d.data.ActiveObject; 36 import org.objectweb.proactive.ic2d.data.HostObject; 37 import org.objectweb.proactive.ic2d.data.IC2DObject; 38 import org.objectweb.proactive.ic2d.data.NodeObject; 39 import org.objectweb.proactive.ic2d.data.VMObject; 40 import org.objectweb.proactive.ic2d.event.CommunicationEventListener; 41 import org.objectweb.proactive.ic2d.gui.ActiveObjectCommunicationRecorder; 42 import org.objectweb.proactive.ic2d.gui.ActiveObjectWatcher; 43 import org.objectweb.proactive.ic2d.gui.IC2DGUIController; 44 import org.objectweb.proactive.ic2d.spy.SpyEvent; 45 import org.objectweb.proactive.ic2d.spy.SpyMessageEvent; 46 import org.objectweb.proactive.ic2d.util.ActiveObjectFilter; 47 48 public class IC2DPanel extends AbstractDataObjectPanel implements CommunicationEventListener { 49 50 private IC2DObject ic2dObject; 51 private ActiveObjectCommunicationRecorder communicationRecorder; 52 private ActiveObjectWatcher activeObjectWatcher; 53 54 private WorldPanel worldPanel; 55 56 57 61 public IC2DPanel(java.awt.Frame parentFrame, IC2DObject ic2dObject, IC2DGUIController controller, 62 ActiveObjectCommunicationRecorder communicationRecorder, 63 ActiveObjectFilter filter, 64 ActiveObjectWatcher activeObjectWatcher) { 65 super(parentFrame, filter, controller, activeObjectWatcher, "IC2D", "IC2D"); 66 this.ic2dObject = ic2dObject; 67 this.communicationRecorder = communicationRecorder; 68 this.activeObjectWatcher = activeObjectWatcher; 69 setBackground(java.awt.Color.white); 70 71 worldPanel = new WorldPanel(this, ic2dObject.getWorldObject(), communicationRecorder); 73 putChild(ic2dObject.getWorldObject(),worldPanel); 74 ic2dObject.getWorldObject().registerListener(worldPanel); 75 setLayout(new java.awt.BorderLayout ()); 76 77 javax.swing.JScrollPane scrollableWorldPanel = new javax.swing.JScrollPane (worldPanel, javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 79 scrollableWorldPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("World Panel")); 80 scrollableWorldPanel.setBackground(java.awt.Color.white); 81 add(scrollableWorldPanel, java.awt.BorderLayout.CENTER); 82 add(createControlPanel(), java.awt.BorderLayout.SOUTH); 83 } 84 85 86 90 public void updateFilteredClasses() { 91 removeAllActiveObjectsFromWatcher(); 92 worldPanel.filterChangeParentNotification(null); 93 } 94 95 99 public void objectWaitingForRequest(ActiveObject object, SpyEvent spyEvent) { 100 } 101 102 public void objectWaitingByNecessity(ActiveObject object, SpyEvent spyEvent) { 103 } 104 105 public void requestMessageSent(ActiveObject object, SpyEvent spyEvent) { 106 } 109 110 public void replyMessageSent(ActiveObject object, SpyEvent spyEvent) { 111 } 114 115 public void requestMessageReceived(ActiveObject object, SpyEvent spyEvent) { 116 recordCommunication(object, ((SpyMessageEvent) spyEvent).getSourceBodyID(), false); 117 } 118 119 public void replyMessageReceived(ActiveObject object, SpyEvent spyEvent) { 120 } 123 124 public void voidRequestServed(ActiveObject object, SpyEvent spyEvent) { 125 } 126 127 public void allEventsProcessed() { 128 worldPanel.repaint(); 129 } 130 131 132 136 protected AbstractDataObject getAbstractDataObject() { 137 return ic2dObject; 138 } 139 140 141 protected Object [][] getDataObjectInfo() { 142 return new Object [][] { 143 }; 144 } 145 146 147 151 private javax.swing.JPanel createControlPanel() { 152 javax.swing.JPanel p = new javax.swing.JPanel (new java.awt.FlowLayout (java.awt.FlowLayout.CENTER)); 153 154 { 156 final javax.swing.JCheckBox topo = new javax.swing.JCheckBox ("Display topology"); 157 topo.setSelected(communicationRecorder.isEnabled()); 158 topo.addActionListener(new java.awt.event.ActionListener () { 159 public void actionPerformed(java.awt.event.ActionEvent e) { 160 communicationRecorder.setEnabled(topo.isSelected()); 161 repaint(); 162 } 163 }); 164 p.add(topo); 165 } 166 167 javax.swing.ButtonGroup group = new javax.swing.ButtonGroup (); 169 170 final javax.swing.JRadioButton b1 = new javax.swing.JRadioButton ("proportional"); 171 b1.addActionListener(new java.awt.event.ActionListener () { 172 public void actionPerformed(java.awt.event.ActionEvent e) { 173 if (b1.isSelected()) { 174 communicationRecorder.setDrawingStyle(ActiveObjectCommunicationRecorder.PROPORTIONAL_DRAWING_STYLE); 175 repaint(); 176 } 177 } 178 }); 179 b1.setSelected(communicationRecorder.getDrawingStyle() == ActiveObjectCommunicationRecorder.PROPORTIONAL_DRAWING_STYLE); 180 group.add(b1); 181 p.add(b1); 182 183 final javax.swing.JRadioButton b2 = new javax.swing.JRadioButton ("ratio"); 184 b2.addActionListener(new java.awt.event.ActionListener () { 185 public void actionPerformed(java.awt.event.ActionEvent e) { 186 if (b2.isSelected()) { 187 communicationRecorder.setDrawingStyle(ActiveObjectCommunicationRecorder.RATIO_DRAWING_STYLE); 188 repaint(); 189 } 190 } 191 }); 192 b2.setSelected(communicationRecorder.getDrawingStyle() == ActiveObjectCommunicationRecorder.RATIO_DRAWING_STYLE); 193 group.add(b2); 194 p.add(b2); 195 196 final javax.swing.JRadioButton b3 = new javax.swing.JRadioButton ("filaire"); 197 b3.addActionListener(new java.awt.event.ActionListener () { 198 public void actionPerformed(java.awt.event.ActionEvent e) { 199 if (b3.isSelected()) { 200 communicationRecorder.setDrawingStyle(ActiveObjectCommunicationRecorder.FILAIRE_DRAWING_STYLE); 201 repaint(); 202 } 203 } 204 }); 205 b3.setSelected(communicationRecorder.getDrawingStyle() == ActiveObjectCommunicationRecorder.FILAIRE_DRAWING_STYLE); 206 group.add(b3); 207 p.add(b3); 208 209 210 javax.swing.JButton b = new javax.swing.JButton ("Reset Topology"); 212 b.addActionListener(new java.awt.event.ActionListener () { 213 public void actionPerformed(java.awt.event.ActionEvent e) { 214 communicationRecorder.clear(); 215 repaint(); 216 } 217 }); 218 b.setToolTipText("Reset the current topology"); 219 p.add(b); 220 221 222 { 224 final javax.swing.JCheckBox cb = new javax.swing.JCheckBox ("Monitoring enable"); 225 cb.setSelected(ic2dObject.getController().isMonitoring()); 226 cb.addActionListener(new java.awt.event.ActionListener () { 227 public void actionPerformed(java.awt.event.ActionEvent e) { 228 ic2dObject.getController().setMonitoring(cb.isSelected()); 229 } 230 }); 231 p.add(cb); 232 } 233 234 return p; 235 } 236 237 238 239 private void recordCommunication(ActiveObject activeObjectOriginator, UniqueID peerActiveObjectID, boolean isSend) { 241 ActiveObject peerActiveObject = ic2dObject.getWorldObject().findActiveObjectById(peerActiveObjectID); 242 if (peerActiveObject == null) return; 243 ActiveObjectPanel originatorPanel = getActiveObjectPanel(activeObjectOriginator); 245 if (originatorPanel == null) return; 246 ActiveObjectPanel peerPanel = getActiveObjectPanel(peerActiveObject); 247 if (peerPanel == null) return; 248 if (isSend) communicationRecorder.recordCommunication(originatorPanel,peerPanel); 249 else communicationRecorder.recordCommunication(peerPanel,originatorPanel); 250 } 251 252 253 private ActiveObjectPanel getActiveObjectPanel(ActiveObject activeObject) { 254 NodeObject nodeObject = (NodeObject) activeObject.getParent(); 255 VMObject vmObject = (VMObject) nodeObject.getParent(); 256 HostObject hostObject = (HostObject) vmObject.getParent(); 257 HostPanel hostPanel = worldPanel.getHostPanel(hostObject); 258 if (hostPanel == null) return null; 259 VMPanel vmPanel = hostPanel.getVMPanel(vmObject); 260 if (vmPanel == null) return null; 261 NodePanel nodePanel = vmPanel.getNodePanel(nodeObject); 262 if (nodePanel == null) return null; 263 return nodePanel.getActiveObjectPanel(activeObject); 264 } 265 266 267 271 } | Popular Tags |