1 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.WorldObject; 36 import org.objectweb.proactive.ic2d.event.WorldObjectListener; 37 import org.objectweb.proactive.ic2d.gui.ActiveObjectCommunicationRecorder; 38 import org.objectweb.proactive.ic2d.gui.util.DialogUtils; 39 40 public class WorldPanel extends AbstractDataObjectPanel implements WorldObjectListener, javax.swing.Scrollable { 41 42 private WorldObject worldObject; 43 private ActiveObjectCommunicationRecorder communicationRecorder; 44 45 49 public WorldPanel(AbstractDataObjectPanel dataObjectPanel, WorldObject targetWorldObject, ActiveObjectCommunicationRecorder communicationRecorder) { 50 super(dataObjectPanel, "IC2D", "WorldObject"); 51 this.worldObject = targetWorldObject; 52 this.communicationRecorder = communicationRecorder; 53 setBackground(java.awt.Color.white); 54 55 setLayout(new MyFlowLayout(java.awt.FlowLayout.CENTER, 25, 15)); 56 57 PanelPopupMenu popup = new PanelPopupMenu("World Panel"); 61 popup.add(new javax.swing.AbstractAction ("Monitor a new RMI Host", null) { 62 public void actionPerformed(java.awt.event.ActionEvent e) { 63 DialogUtils.openNewRMIHostDialog(parentFrame, worldObject, controller); 64 } 65 }); 66 popup.add(new javax.swing.AbstractAction ("Monitor a new RMI Node", null) { 67 public void actionPerformed(java.awt.event.ActionEvent e) { 68 DialogUtils.openNewNodeDialog(parentFrame, worldObject, controller); 69 } 70 }); 71 popup.add(new javax.swing.AbstractAction ("Monitor all JINI Hosts", null) { 72 public void actionPerformed(java.awt.event.ActionEvent e) { 73 worldObject.addHosts(); 74 } 75 }); 76 77 popup.add(new javax.swing.AbstractAction ("Monitor a new JINI Hosts", null) { 78 public void actionPerformed(java.awt.event.ActionEvent e) { 79 DialogUtils.openNewJINIHostDialog(parentFrame, worldObject, controller); 80 } 81 }); 82 popup.addSeparator(); 83 javax.swing.JCheckBoxMenuItem check = new javax.swing.JCheckBoxMenuItem ("Manual Layout", false); 84 check.addActionListener(new java.awt.event.ActionListener () { 85 public void actionPerformed(java.awt.event.ActionEvent e) { 86 controller.setAutomaticLayout(! controller.isLayoutAutomatic()); 87 revalidate(); 88 repaint(); 89 } 90 }); 91 popup.add(check); 92 addMouseListener(popup.getMenuMouseListener()); 93 } 94 95 96 100 public void paint(java.awt.Graphics g) { 101 super.paint(g); 102 if (communicationRecorder.isEnabled()) communicationRecorder.drawAllLinks(g, this.getLocationOnScreen()); 103 } 104 105 106 110 111 public void hostObjectAdded(HostObject hostObject) { 112 HostPanel panel = new HostPanel(this, hostObject); 113 addChild(hostObject, panel); 114 hostObject.registerListener(panel); 115 } 116 117 118 public void hostObjectRemoved(HostObject hostObject) { 119 removeChild(hostObject); 120 } 121 122 123 127 public java.awt.Dimension getPreferredScrollableViewportSize() { 128 return getPreferredSize(); 129 } 130 131 public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction) { 132 return (orientation == javax.swing.SwingConstants.VERTICAL) ? Math.max(4, visibleRect.height / 20) : Math.max(4, visibleRect.width / 20); 133 } 134 135 public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction) { 136 return (orientation == javax.swing.SwingConstants.VERTICAL) ? visibleRect.height : visibleRect.width; 137 } 138 139 public boolean getScrollableTracksViewportWidth() { 140 if (getParent() instanceof javax.swing.JViewport ) { 141 return (((javax.swing.JViewport )getParent()).getWidth() > getPreferredSize().width); 142 } 143 return false; 144 } 145 146 public boolean getScrollableTracksViewportHeight() { 147 if (getParent() instanceof javax.swing.JViewport ) { 148 return (((javax.swing.JViewport )getParent()).getHeight() > getPreferredSize().height); 149 } 150 return false; 151 } 152 153 157 protected AbstractDataObject getAbstractDataObject() { 158 return worldObject; 159 } 160 161 162 protected HostPanel getHostPanel(HostObject hostObject) { 163 return (HostPanel) getChild(hostObject); 164 } 165 166 167 protected Object [][] getDataObjectInfo() { 168 return new Object [][] { 169 }; 170 } 171 172 173 protected void filterChangeParentNotification(String qname) { 174 activeObjectAddedToFilter(); 175 revalidate(); 176 repaint(); 177 } 178 179 180 184 185 189 public class MyFlowLayout extends java.awt.FlowLayout { 190 194 public MyFlowLayout() { 195 super(); 196 } 197 198 206 public MyFlowLayout(int align) { 207 super(align); 208 } 209 210 221 public MyFlowLayout(int align, int hgap, int vgap) { 222 super(align, hgap, vgap); 223 } 224 225 234 public void layoutContainer(java.awt.Container target) { 235 if (controller.isLayoutAutomatic()) { 236 super.layoutContainer(target); 237 } else { 238 synchronized (target.getTreeLock()) { 239 int nmembers = target.getComponentCount(); 240 for (int i = 0 ; i < nmembers ; i++) { 241 java.awt.Component m = target.getComponent(i); 242 if (m.isVisible()) { 243 java.awt.Dimension d = m.getPreferredSize(); 244 m.setSize(d.width, d.height); 245 } 246 } 247 } 248 } 249 } 250 251 252 262 public java.awt.Dimension preferredLayoutSize(java.awt.Container target) { 263 synchronized (target.getTreeLock()) { 264 int maxX = 0; 265 int maxY = 0; 266 int nmembers = target.getComponentCount(); 267 for (int i = 0 ; i < nmembers ; i++) { 268 java.awt.Component m = target.getComponent(i); 269 if (m.isVisible()) { 270 int x = m.getX(); 271 int y = m.getY(); 272 x += m.getWidth(); 275 y += m.getHeight(); 276 if (x > maxX) maxX = x; 277 if (y > maxY) maxY = y; 278 } 279 } 280 return new java.awt.Dimension (maxX, maxY); 281 } 282 } 283 284 294 public java.awt.Dimension minimumLayoutSize(java.awt.Container target) { 295 return preferredLayoutSize(target); 296 } 297 } 298 299 300 301 } 302 | Popular Tags |