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.ActiveObject; 35 import org.objectweb.proactive.ic2d.event.MessageMonitoringListener; 36 import org.objectweb.proactive.ic2d.gui.ActiveObjectWatcher; 37 import org.objectweb.proactive.ic2d.gui.IC2DGUIController; 38 import org.objectweb.proactive.ic2d.gui.menu.MessageMonitoringMenu; 39 import org.objectweb.proactive.ic2d.util.ActiveObjectFilter; 40 41 44 public abstract class AbstractDataObjectPanel extends javax.swing.JPanel implements MessageMonitoringListener { 45 46 private static final String [] COLUMN_NAMES = { "Property", "Value" }; 47 private static final java.awt.Color INFO_PANEL_BG_COLOR = new java.awt.Color (0xd0, 0xd0, 0xd0); 48 49 protected static final java.awt.Font REGULAR_FONT = new java.awt.Font ("SansSerif", java.awt.Font.BOLD, 12); 50 protected static final java.awt.Font BIG_FONT = new java.awt.Font ("SansSerif", java.awt.Font.BOLD, 14); 51 protected static final java.awt.Font VERY_BIG_FONT = new java.awt.Font ("SansSerif", java.awt.Font.BOLD, 16); 52 protected static final java.awt.Font SMALL_FONT = new java.awt.Font ("SansSerif", java.awt.Font.BOLD, 10); 53 protected static final java.awt.Font VERY_SMALL_FONT = new java.awt.Font ("SansSerif", java.awt.Font.BOLD, 8); 54 55 protected static final int REGULAR_FONT_SIZE = 10; 56 protected static final int BIG_FONT_SIZE = 20; 57 protected static final int VERY_BIG_FONT_SIZE = 30; 58 protected static final int SMALL_FONT_SIZE = 50; 59 protected static final int VERY_SMALL_FONT_SIZE = 70; 60 61 protected static final int MINIMUM_WIDTH = 100; 62 protected static final int MINIMUM_HEIGHT = 40; 63 64 protected java.awt.Dimension minimumSize = new java.awt.Dimension (MINIMUM_WIDTH, MINIMUM_HEIGHT); 65 66 protected String name; 67 protected String type; 68 protected java.awt.Frame parentFrame; 69 protected ActiveObjectFilter activeObjectFilter; 70 protected ActiveObjectWatcher activeObjectWatcher; 71 protected AbstractDataObjectPanel parentDataObjectPanel; 72 protected IC2DGUIController controller; 73 74 protected MessageMonitoringMenu monitoringMenu; 75 76 protected java.awt.Font defaultFont; 77 78 private java.util.HashMap childs; 80 81 protected boolean isDestroyed; 82 83 87 public AbstractDataObjectPanel( 88 java.awt.Frame parentFrame, 89 ActiveObjectFilter activeObjectFilter, 90 IC2DGUIController controller, 91 ActiveObjectWatcher activeObjectWatcher, 92 String name, 93 String type) { 94 this(name, type); 95 this.activeObjectFilter = activeObjectFilter; 96 this.activeObjectWatcher = activeObjectWatcher; 97 this.controller = controller; 98 this.parentFrame = parentFrame; 99 this.defaultFont = REGULAR_FONT; 100 } 101 102 public AbstractDataObjectPanel(AbstractDataObjectPanel parentDataObjectPanel, String name, String type) { 103 this(name, type); 104 this.parentDataObjectPanel = parentDataObjectPanel; 105 this.activeObjectFilter = parentDataObjectPanel.activeObjectFilter; 106 this.activeObjectWatcher = parentDataObjectPanel.activeObjectWatcher; 107 this.controller = parentDataObjectPanel.controller; 108 this.parentFrame = parentDataObjectPanel.parentFrame; 109 this.defaultFont = parentDataObjectPanel.defaultFont; 110 } 112 113 private AbstractDataObjectPanel(String name, String type) { 114 this.name = name; 115 this.type = type; 116 this.childs = new java.util.HashMap (); 117 setSize(minimumSize); 118 setToolTipText(name); 119 } 120 121 125 public java.awt.Dimension getMinimumSize() { 126 if (childs.isEmpty()) { 127 java.awt.Dimension d = getMinimumSizeInternal(); 128 if (d == null) 129 return super.getMinimumSize(); 130 else 131 return d; 132 } else { 133 return super.getMinimumSize(); 134 } 135 } 136 137 public java.awt.Dimension getPreferredSize() { 138 if (childs.isEmpty()) { 139 java.awt.Dimension d = getMinimumSizeInternal(); 140 if (d == null) 141 return super.getPreferredSize(); 142 else 143 return d; 144 } else { 145 return super.getPreferredSize(); 146 } 147 } 148 149 public boolean isDestroyed() { 150 return isDestroyed; 151 } 152 153 157 public void viewingInEventListChanged(boolean b) { 158 monitoringMenu.viewingInEventListChanged(b); 159 if (b) { 160 addAllActiveObjectsToWatcher(); 161 } else { 162 removeAllActiveObjectsFromWatcher(); 163 } 164 } 165 166 public void monitoringRequestReceiverChanged(boolean b) { 167 monitoringMenu.monitoringRequestReceiverChanged(b); 168 } 169 170 public void monitoringRequestSenderChanged(boolean b) { 171 monitoringMenu.monitoringRequestSenderChanged(b); 172 } 173 174 public void monitoringReplyReceiverChanged(boolean b) { 175 monitoringMenu.monitoringReplyReceiverChanged(b); 176 } 177 178 public void monitoringReplySenderChanged(boolean b) { 179 monitoringMenu.monitoringReplySenderChanged(b); 180 } 181 182 186 protected java.awt.Dimension getMinimumSizeInternal() { 187 return minimumSize; 188 } 189 190 protected AbstractDataObjectPanel getParentDataObjectPanel() { 191 return parentDataObjectPanel; 192 } 193 194 protected abstract Object [][] getDataObjectInfo(); 195 196 protected abstract AbstractDataObject getAbstractDataObject(); 197 198 protected void displayDataObjectInfo() { 199 javax.swing.JOptionPane.showMessageDialog(parentFrame, new DataObjectInfoPanel(), type + " info :" + name, javax.swing.JOptionPane.INFORMATION_MESSAGE ); 204 } 205 206 protected void filterChangeParentNotification(String qname) { 207 if (parentDataObjectPanel != null) 208 parentDataObjectPanel.filterChangeParentNotification(qname); 209 } 210 211 protected synchronized ActiveObjectPanel findActiveObjectPanelByActiveObject(ActiveObject activeObject) { 212 java.util.Iterator iterator = childsIterator(); 213 while (iterator.hasNext()) { 214 AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next(); 215 ActiveObjectPanel activeObjectPanel = o.findActiveObjectPanelByActiveObject(activeObject); 216 if (activeObjectPanel != null) 217 return activeObjectPanel; 218 } 219 return null; 220 } 221 222 225 protected AbstractDataObjectPanel getTopLevelParent() { 226 if (parentDataObjectPanel == null) { 227 return this; 228 } else { 229 return parentDataObjectPanel.getTopLevelParent(); 230 } 231 } 232 233 236 protected void destroy() { 237 if (isDestroyed) 238 return; 239 isDestroyed = true; 240 clearChilds(); 241 parentFrame = null; 242 activeObjectFilter = null; 243 parentDataObjectPanel = null; 244 controller = null; 245 } 246 247 250 protected synchronized void clearChilds() { 251 childs.clear(); 252 } 253 254 257 protected synchronized void putChild(AbstractDataObject key, AbstractDataObjectPanel child) { 258 childs.put(key, child); 259 } 260 261 264 protected synchronized void addChild(AbstractDataObject key, AbstractDataObjectPanel child) { 265 putChild(key, child); 267 add(child); 268 revalidate(); 269 repaint(); 270 } 271 272 275 protected synchronized AbstractDataObjectPanel removeChild(AbstractDataObject key) { 276 AbstractDataObjectPanel panel = (AbstractDataObjectPanel) childs.remove(key); 277 if (panel != null) { 278 panel.destroy(); 280 remove(panel); 281 revalidate(); 282 repaint(); 283 } 284 return panel; 285 } 286 287 290 protected synchronized AbstractDataObjectPanel getChild(AbstractDataObject key) { 291 return (AbstractDataObjectPanel) childs.get(key); 292 } 293 294 protected java.util.Iterator childsIterator() { 295 return childs.values().iterator(); 296 } 297 298 protected void setFontSize(int size) { 299 switch (size) { 300 case REGULAR_FONT_SIZE : 301 setFontSize(REGULAR_FONT); 302 break; 303 case BIG_FONT_SIZE : 304 setFontSize(BIG_FONT); 305 break; 306 case VERY_BIG_FONT_SIZE : 307 setFontSize(VERY_BIG_FONT); 308 break; 309 case SMALL_FONT_SIZE : 310 setFontSize(SMALL_FONT); 311 break; 312 case VERY_SMALL_FONT_SIZE : 313 setFontSize(VERY_SMALL_FONT); 314 break; 315 } 316 revalidate(); 317 repaint(); 318 } 319 320 protected synchronized void setFontSize(java.awt.Font font) { 321 defaultFont = font; 322 java.util.Iterator iterator = childsIterator(); 323 while (iterator.hasNext()) { 324 AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next(); 325 o.setFontSize(font); 326 } 327 } 328 329 protected synchronized void addAllActiveObjectsToWatcher() { 330 java.util.Iterator iterator = childsIterator(); 331 while (iterator.hasNext()) { 332 AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next(); 333 o.addAllActiveObjectsToWatcher(); 334 } 335 } 336 337 protected synchronized void removeAllActiveObjectsFromWatcher() { 338 java.util.Iterator iterator = childsIterator(); 339 while (iterator.hasNext()) { 340 AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next(); 341 o.removeAllActiveObjectsFromWatcher(); 342 } 343 } 344 345 protected synchronized void activeObjectAddedToFilter() { 346 java.util.Iterator iterator = childsIterator(); 347 while (iterator.hasNext()) { 348 AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next(); 349 o.activeObjectAddedToFilter(); 350 } 351 } 352 353 protected synchronized void activeObjectRemovedFromFilter() { 354 java.util.Iterator iterator = childsIterator(); 355 while (iterator.hasNext()) { 356 AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next(); 357 o.activeObjectRemovedFromFilter(); 358 } 359 } 360 361 365 369 protected class DataObjectInfoPanel extends javax.swing.JPanel { 370 public DataObjectInfoPanel() { 371 super(new java.awt.GridLayout (1, 1)); 372 javax.swing.JTable table = new javax.swing.JTable (getDataObjectInfo(), COLUMN_NAMES); 373 javax.swing.JScrollPane sp = new javax.swing.JScrollPane (table); 374 setSize(table.getPreferredSize()); 375 sp.setBackground(INFO_PANEL_BG_COLOR); 376 add(sp); 377 } 378 } 379 380 protected class PanelPopupMenu extends javax.swing.JPopupMenu { 381 382 javax.swing.JMenuItem titleItem; 383 384 public PanelPopupMenu(String name) { 388 super(name); 389 titleItem = add(name + " Menu"); 390 titleItem.setEnabled(false); 391 addSeparator(); 392 add(new FontSizeMenu()); 393 monitoringMenu = new MessageMonitoringMenu("Monitor events", getAbstractDataObject()); 394 add(monitoringMenu); 395 add(new javax.swing.AbstractAction ("Informations", null) { 396 public void actionPerformed(java.awt.event.ActionEvent e) { 397 displayDataObjectInfo(); 398 } 399 }); 400 addSeparator(); 401 } 402 403 public java.awt.event.MouseListener getMenuMouseListener() { 404 return new MyMouseListener(); 405 } 406 407 public void setName(String name) { 408 super.setName(name); 409 titleItem.setText(name); 410 } 411 412 public void addRefreshDisplayItem() { 413 add(new javax.swing.AbstractAction ("Refresh display") { 414 public void actionPerformed(java.awt.event.ActionEvent e) { 415 AbstractDataObjectPanel.this.revalidate(); 416 AbstractDataObjectPanel.this.repaint(); 417 } 418 }); 419 } 420 421 private class MyMouseListener extends java.awt.event.MouseAdapter { 425 public void mousePressed(java.awt.event.MouseEvent e) { 426 if (e.isPopupTrigger()) { 427 show(e.getComponent(), e.getX(), e.getY()); 428 } 429 } 430 public void mouseReleased(java.awt.event.MouseEvent e) { 431 if (e.isPopupTrigger()) { 432 show(e.getComponent(), e.getX(), e.getY()); 433 } 434 } 435 } 437 private class FontSizeMenu extends javax.swing.JMenu { 438 public FontSizeMenu() { 439 super("Change font size"); 440 add(createItem("Very large font size", VERY_BIG_FONT_SIZE)); 441 add(createItem("Large font size", BIG_FONT_SIZE)); 442 add(createItem("Regular font size", REGULAR_FONT_SIZE)); 443 add(createItem("Small font size", SMALL_FONT_SIZE)); 444 add(createItem("Very small font size", VERY_SMALL_FONT_SIZE)); 445 } 446 447 private javax.swing.JMenuItem createItem(String text, final int size) { 448 javax.swing.JMenuItem menuItem = new javax.swing.JMenuItem (text); 449 menuItem.addActionListener(new java.awt.event.ActionListener () { 450 public void actionPerformed(java.awt.event.ActionEvent event) { 451 setFontSize(size); 452 } 453 }); 454 return menuItem; 455 } 456 } } 459 } | Popular Tags |