1 31 package org.objectweb.proactive.ic2d.gui; 32 33 import org.objectweb.proactive.core.UniqueID; 34 import org.objectweb.proactive.ic2d.data.ActiveObject; 35 import org.objectweb.proactive.ic2d.data.IC2DObject; 36 import org.objectweb.proactive.ic2d.event.CommunicationEventListener; 37 import org.objectweb.proactive.ic2d.gui.data.UniqueIDDropTargetListener; 38 import org.objectweb.proactive.ic2d.gui.recording.PlayerFrameTimeLine; 39 import org.objectweb.proactive.ic2d.spy.SpyEvent; 40 import org.objectweb.proactive.ic2d.spy.SpyFutureEvent; 41 import org.objectweb.proactive.ic2d.spy.SpyMessageEvent; 42 43 44 public class EventListsPanel extends javax.swing.JPanel implements CommunicationEventListener, ActiveObjectWatcher { 45 46 private static final String IMAGES_DIR = "org/objectweb/proactive/ic2d/gui/images/"; 47 private static final String REPLY_RECEIVED_ICON = IMAGES_DIR+"ReplyReceived.gif"; 48 private static final String REPLY_SENT_ICON = IMAGES_DIR+"ReplySent.gif"; 49 private static final String REQUEST_RECEIVED_ICON = IMAGES_DIR+"RequestReceived.gif"; 50 private static final String REQUEST_SENT_ICON = IMAGES_DIR+"RequestSent.gif"; 51 private static final String WAITING_FOR_REQUEST_ICON = IMAGES_DIR+"WaitingForRequest.gif"; 52 private static final String WAIT_BY_NECESSITY_ICON = IMAGES_DIR+"WaitByNecessity.gif"; 53 private static final String VOID_REQUEST_SERVED_ICON = IMAGES_DIR+"VoidRequestServed.gif"; 54 55 private static final int RELATED_EVENT_COLOR_MODE = 0; 56 private static final int ABSOLUTE_EVENT_COLOR_MODE = 1; 57 private static final int NO_COLOR_MODE = 2; 58 59 private static final java.awt.Color LIST_BG_COLOR = new java.awt.Color (0, 0, 80); 60 private static final java.awt.Font MFONT = new java.awt.Font ("Dialog", 1, 10); 61 private static final java.awt.Color [] SHADES; 62 static { 63 SHADES = new java.awt.Color [21]; 65 for (int i = 0; i < 10; i++) { 66 SHADES[i] = new java.awt.Color (i*13+30, i*13+30, 150 + i * 10); 67 } 68 SHADES[10] = java.awt.Color.orange; 69 for (int i = 11; i < 21; i++) { 70 SHADES[i] = new java.awt.Color (150 + (20-i) * 10, (20-i)*13+30, (20-i)*13+30); 71 } 72 } 73 74 private javax.swing.ImageIcon requestReceivedIcon; 75 private javax.swing.ImageIcon replySentIcon; 76 private javax.swing.ImageIcon requestSentIcon; 77 private javax.swing.ImageIcon replyReceivedIcon; 78 private javax.swing.ImageIcon waitingForRequestIcon; 79 private javax.swing.ImageIcon waitByNecessityIcon; 80 private javax.swing.ImageIcon voidRequestServedIcon; 81 82 86 private java.util.HashMap objectTrackPanelMap; 87 private BoundedCircularArrayList events; 88 89 92 private int colorMode = RELATED_EVENT_COLOR_MODE; 93 public javax.swing.JPopupMenu popup; 94 private javax.swing.JPanel centerPanel; 95 private PlayerFrameTimeLine recorder; 96 97 private Object lastSelected; 98 99 protected IC2DGUIController controller; 100 protected IC2DObject ic2dObject; 101 102 103 private java.awt.dnd.DropTarget dropTarget; 104 105 106 110 public EventListsPanel(IC2DObject ic2dObject, IC2DGUIController controller) { 111 this.ic2dObject = ic2dObject; 112 this.controller = controller; 113 114 dropTarget = new java.awt.dnd.DropTarget (this, java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE, new MyDropTargetListener(), true); 116 117 objectTrackPanelMap = new java.util.HashMap (); 118 events = new BoundedCircularArrayList(1000); 119 recorder = new PlayerFrameTimeLine(this, ic2dObject.getController()); 120 121 setLayout(new java.awt.BorderLayout ()); 122 { 123 javax.swing.JPanel tools = new javax.swing.JPanel (); 124 final javax.swing.JComboBox colorCombo = new javax.swing.JComboBox ( 125 new String [] {"Color related events", "Color chronological order", "No coloring"}); 126 colorCombo.addActionListener(new java.awt.event.ActionListener () { 127 public void actionPerformed(java.awt.event.ActionEvent e) { 128 switch (colorCombo.getSelectedIndex()) { 129 case 0 : colorMode = RELATED_EVENT_COLOR_MODE; break; 130 case 1 : colorMode = ABSOLUTE_EVENT_COLOR_MODE; break; 131 case 2 : colorMode = NO_COLOR_MODE; break; 132 } 133 colorEvents(); 134 } 135 }); 136 tools.add(colorCombo); 137 { 138 javax.swing.JButton b = new javax.swing.JButton ("Messages recorder"); 139 b.addActionListener(new java.awt.event.ActionListener () { 140 public void actionPerformed(java.awt.event.ActionEvent e) { 141 recorder.setVisible(! recorder.isVisible()); 142 } 143 }); 144 tools.add(b); 145 } 146 { 147 javax.swing.JButton b = new javax.swing.JButton ("Clear all events"); 148 b.addActionListener(new java.awt.event.ActionListener () { 149 public void actionPerformed(java.awt.event.ActionEvent e) { 150 clearAll(); 151 } 152 }); 153 tools.add(b); 154 } 155 { 156 javax.swing.JButton b = new javax.swing.JButton ("Legend"); 157 b.addActionListener(new java.awt.event.ActionListener () { 158 public void actionPerformed(java.awt.event.ActionEvent e) { 159 showLegend(); 160 } 161 }); 162 tools.add(b); 163 } 164 add(tools, java.awt.BorderLayout.SOUTH); 165 } 166 167 centerPanel = new javax.swing.JPanel (); 168 add(centerPanel, java.awt.BorderLayout.CENTER); 169 170 centerPanel.setBackground(java.awt.Color.white); 172 173 java.awt.GridLayout grid = new java.awt.GridLayout (1, 0); 175 grid.setHgap(5); 176 centerPanel.setLayout(grid); 177 validate(); 178 loadIcon(); 179 } 180 181 182 183 187 public void clearAll() { 188 synchronized (objectTrackPanelMap) { 189 java.util.Iterator i = objectTrackPanelMap.values().iterator(); 190 while (i.hasNext()) { 191 ObjTrackPanel otp = (ObjTrackPanel) i.next(); 193 otp.getListModel().clear(); 194 } 195 } 196 events.clear(); 198 } 199 200 201 205 public void addActiveObject(ActiveObject activeObject) { 206 if (objectTrackPanelMap.containsKey(activeObject.getID())) return; 207 ObjTrackPanel otp = new ObjTrackPanel(activeObject); 208 synchronized (objectTrackPanelMap) { 209 objectTrackPanelMap.put(activeObject.getID(), otp); 210 } 211 centerPanel.add(otp); 212 revalidate(); 213 repaint(); 214 } 215 216 public void removeActiveObject(ActiveObject activeObject) { 217 ObjTrackPanel o; 218 synchronized (objectTrackPanelMap) { 219 o = (ObjTrackPanel) objectTrackPanelMap.remove(activeObject.getID()); 220 } 221 if (o == null) return; 222 centerPanel.remove(o); 223 revalidate(); 224 repaint(); 225 } 226 227 228 232 public void objectWaitingForRequest(ActiveObject object, SpyEvent spyEvent) { 233 recordEvent(object, spyEvent, true); 234 } 235 236 237 public void objectWaitingByNecessity(ActiveObject object, SpyEvent spyEvent) { 238 recordEvent(object, spyEvent, true); 239 } 240 241 242 public void requestMessageSent(ActiveObject object, SpyEvent spyEvent) { 243 recordEvent(object, spyEvent, false); 244 } 245 246 247 public void replyMessageSent(ActiveObject object, SpyEvent spyEvent) { 248 recordEvent(object, spyEvent, false); 249 } 250 251 252 public void requestMessageReceived(ActiveObject object, SpyEvent spyEvent) { 253 recordEvent(object, spyEvent, false); 254 } 255 256 257 public void replyMessageReceived(ActiveObject object, SpyEvent spyEvent) { 258 recordEvent(object, spyEvent, false); 259 } 260 261 public void voidRequestServed(ActiveObject object, SpyEvent spyEvent) { 262 recordEvent(object, spyEvent, false); 263 } 264 265 public void allEventsProcessed() { 266 synchronized (objectTrackPanelMap) { 268 java.util.Iterator i = objectTrackPanelMap.values().iterator(); 269 while (i.hasNext()) { 270 ObjTrackPanel otp = (ObjTrackPanel) i.next(); 272 otp.scrollDown(); 273 } 274 } 275 revalidate(); 276 repaint(); 277 } 278 279 280 281 285 private void loadIcon() { 286 ClassLoader c = this.getClass().getClassLoader(); 288 replyReceivedIcon = new javax.swing.ImageIcon (c.getResource(REPLY_RECEIVED_ICON)); 289 if (replyReceivedIcon == null) 290 controller.log("Can't load image "+REPLY_RECEIVED_ICON); 291 replySentIcon = new javax.swing.ImageIcon (c.getResource(REPLY_SENT_ICON)); 292 if (replySentIcon == null) 293 controller.log("Can't load image "+REPLY_SENT_ICON); 294 requestReceivedIcon = new javax.swing.ImageIcon (c.getResource(REQUEST_RECEIVED_ICON)); 295 if (requestReceivedIcon == null) 296 controller.log("Can't load image "+REQUEST_RECEIVED_ICON); 297 requestSentIcon = new javax.swing.ImageIcon (c.getResource(REQUEST_SENT_ICON)); 298 if (requestSentIcon == null) 299 controller.log("Can't load image "+REQUEST_SENT_ICON); 300 waitingForRequestIcon = new javax.swing.ImageIcon (c.getResource(WAITING_FOR_REQUEST_ICON)); 301 if (waitingForRequestIcon == null) 302 controller.log("Can't load image "+WAITING_FOR_REQUEST_ICON); 303 waitByNecessityIcon = new javax.swing.ImageIcon (c.getResource(WAIT_BY_NECESSITY_ICON)); 304 if (waitingForRequestIcon == null) 305 controller.log("Can't load image "+WAITING_FOR_REQUEST_ICON); 306 voidRequestServedIcon = new javax.swing.ImageIcon (c.getResource(VOID_REQUEST_SERVED_ICON)); 307 if (voidRequestServedIcon == null) 308 controller.log("Can't load image "+VOID_REQUEST_SERVED_ICON); 309 } 310 311 312 private ObjTrackPanel getObjTrackPanel(UniqueID id) { 313 synchronized (objectTrackPanelMap) { 314 return (ObjTrackPanel) objectTrackPanelMap.get(id); 315 } 316 } 317 318 319 322 private void recordEvent(final ActiveObject obj, final SpyEvent evt, final boolean dontRepeatSameType) { 323 javax.swing.SwingUtilities.invokeLater(new Runnable () { 325 public void run() { 326 ObjTrackPanel o = getObjTrackPanel(obj.getID()); 327 if (o == null) return; 328 if (dontRepeatSameType && ! o.getListModel().isEmpty()) { 329 SpyEvent lastElt = (SpyEvent) o.getListModel().lastElement(); 330 if (lastElt.getType() == evt.getType()) return; 331 } 332 o.getListModel().addEvent(evt); 333 events.add(evt); 334 recorder.recordEvent(obj, evt); 335 } 336 }); 337 } 339 340 341 private void showLegend() { 342 javax.swing.JFrame legendFrame = new javax.swing.JFrame ("Eventslist Legend"); 343 legendFrame.getContentPane().add(new LegendPanel()); 344 legendFrame.setSize(400, 600); 345 legendFrame.show(); 346 } 347 348 359 private void colorEvents() { 360 for (int i = 0; i < events.size(); i++) { 361 SpyEvent tmp = (SpyEvent)events.get(i); 362 tmp.setPos(-1); 363 } 364 if (lastSelected != null && lastSelected instanceof SpyMessageEvent) { 365 SpyMessageEvent m = (SpyMessageEvent) lastSelected; 366 switch (colorMode) { 367 case ABSOLUTE_EVENT_COLOR_MODE: 368 UniqueID id = m.getBodyID(); 369 if (id == null) return; 370 java.util.LinkedList bef = getMsgBefore(m, id); 371 java.util.LinkedList aft = getMsgAfter(m, id); 372 computeColor(m, 10); 373 for (int i = 0; i < bef.size(); i++) 374 computeColor((SpyEvent)bef.get(i), 9 - i); 375 for (int i = 0; i < aft.size(); i++) { 376 computeColor((SpyEvent)aft.get(i), 11 + i); 377 } 378 break; 379 380 case RELATED_EVENT_COLOR_MODE: 381 if (m.getSequenceNumber() == 0) { 382 m.setPos(11); 383 } else { 384 for (int i = 0; i < events.size(); i++) { 385 SpyEvent tmp = (SpyEvent)events.get(i); 386 if (tmp instanceof SpyMessageEvent) { 387 SpyMessageEvent myEvent = (SpyMessageEvent) tmp; 388 if (m.matches(myEvent)) tmp.setPos(getPosFromType(myEvent.getType())); 389 } 390 } 391 } 392 break; 393 } 394 } 395 repaint(); 396 397 } 398 399 400 private int getPosFromType(int type) { 401 switch (type) { 402 case SpyEvent.REQUEST_SENT_MESSAGE_TYPE : 403 return 11; 404 case SpyEvent.REQUEST_RECEIVED_MESSAGE_TYPE : 405 return 11; 406 case SpyEvent.REPLY_SENT_MESSAGE_TYPE : 407 case SpyEvent.VOID_REQUEST_SERVED_TYPE : 408 return 9; 409 case SpyEvent.REPLY_RECEIVED_MESSAGE_TYPE : 410 return 9; 411 } 412 return -1; 413 } 414 415 419 private void computeColor(SpyEvent m, int pos) { 420 m.setPos(pos); 421 if (! (m instanceof SpyMessageEvent)) return; 422 SpyMessageEvent myEvent = (SpyMessageEvent) m; 423 if (myEvent.getSequenceNumber() == 0) return; 424 for (int i = 0; i < events.size(); i++) { 425 Object o = events.get(i); 426 if (o instanceof SpyMessageEvent) { 427 SpyMessageEvent myEvent2 = (SpyMessageEvent) o; 428 if (myEvent.matches(myEvent2)) myEvent2.setPos(pos); 429 } 430 } 431 } 432 433 435 private java.util.LinkedList getMsgBefore(SpyMessageEvent target, UniqueID id) { 436 java.util.LinkedList result = new java.util.LinkedList (); 437 int index = events.indexOf(target); 438 if (index == -1) return result; 439 boolean isRequest; 440 if (target.isRequestMessage()) isRequest = true; 441 else if (target.isReplyMessage()) isRequest = false; 442 else return result; 443 444 for (int i = index-1; i >= 0; i--) { 445 Object o = events.get(i); 446 if (o instanceof SpyMessageEvent) { 447 SpyMessageEvent myEvent = (SpyMessageEvent) o; 448 if ((isRequest && myEvent.isRequestMessage()) || (!isRequest && myEvent.isReplyMessage())) { 449 if (myEvent.wasSent()) { 450 if (id.equals(myEvent.getSourceBodyID())) result.add(o); 451 } else { 452 if (id.equals(myEvent.getDestinationBodyID())) result.add(o); 453 } 454 } 455 } 456 } 457 return result; 459 } 460 461 462 464 private java.util.LinkedList getMsgAfter(SpyMessageEvent target, UniqueID id) { 465 java.util.LinkedList result = new java.util.LinkedList (); 466 int index = events.indexOf(target); 467 if (index == -1) return result; 468 boolean isRequest; 469 if (target.isRequestMessage()) isRequest = true; 470 else if (target.isReplyMessage()) isRequest = false; 471 else return result; 472 473 for (int i = index+1; i < events.size(); i++) { 474 Object o = events.get(i); 475 if (o instanceof SpyMessageEvent) { 476 SpyMessageEvent myEvent = (SpyMessageEvent) o; 477 if ((isRequest && myEvent.isRequestMessage()) || (!isRequest && myEvent.isReplyMessage())) { 478 if (myEvent.wasSent()) { 479 if (id.equals(myEvent.getSourceBodyID())) result.add(o); 480 } else { 481 if (id.equals(myEvent.getDestinationBodyID())) result.add(o); 482 } 483 } 484 } 485 } 486 return result; 488 } 489 490 491 495 private class MyListSelectionListener implements javax.swing.event.ListSelectionListener { 496 497 501 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 502 if (e.getValueIsAdjusting()) return; 503 lastSelected = ((javax.swing.JList )e.getSource()).getSelectedValue(); 504 colorEvents(); 505 } 506 507 508 } 509 510 511 512 513 514 515 518 private class TimeCellRenderer extends javax.swing.DefaultListCellRenderer { 519 520 public TimeCellRenderer() { 521 setOpaque(true); 522 setHorizontalAlignment(LEFT); 523 setVerticalAlignment(CENTER); 524 setFont(MFONT); 525 } 526 527 530 public java.awt.Component getListCellRendererComponent(javax.swing.JList list, Object val, int index, boolean isSelected, boolean cellHasFocus) { 531 if (! (val instanceof SpyEvent)) return this; 532 SpyEvent event = (SpyEvent) val; 533 switch (event.getType()) { 534 case SpyEvent.REQUEST_SENT_MESSAGE_TYPE: 535 { 536 SpyMessageEvent rq = (SpyMessageEvent)val; 537 UniqueID id = rq.getDestinationBodyID(); 538 setToolTipText("Request sent to " + id); 539 if (requestSentIcon != null) setIcon(requestSentIcon); 540 formatItem(rq, id); 541 } 542 break; 543 case SpyEvent.REQUEST_RECEIVED_MESSAGE_TYPE: 544 { 545 SpyMessageEvent rq = (SpyMessageEvent)val; 546 UniqueID id = rq.getSourceBodyID(); 547 setToolTipText("Request received from " + id); 548 if (requestReceivedIcon != null) setIcon(requestReceivedIcon); 549 formatItem(rq, id); 550 } 551 break; 552 553 554 case SpyEvent.REPLY_SENT_MESSAGE_TYPE: 555 { 556 SpyMessageEvent rp = (SpyMessageEvent)val; 557 UniqueID id = rp.getDestinationBodyID(); 558 setToolTipText("Reply sent to " + id); 559 if (replySentIcon != null) setIcon(replySentIcon); 560 formatItem(rp, id); 561 } 562 break; 563 case SpyEvent.REPLY_RECEIVED_MESSAGE_TYPE: 564 { 565 SpyMessageEvent rp = (SpyMessageEvent)val; 566 UniqueID id = rp.getSourceBodyID(); 567 setToolTipText("Reply received from " + id); 568 if (replyReceivedIcon != null) setIcon(replyReceivedIcon); 569 formatItem(rp, id); 570 } 571 break; 572 573 case SpyEvent.VOID_REQUEST_SERVED_TYPE: 574 { 575 SpyMessageEvent rp = (SpyMessageEvent)val; 576 UniqueID id = rp.getSourceBodyID(); 577 setToolTipText("Void request from "+id+" served"); 578 if (voidRequestServedIcon != null) setIcon(voidRequestServedIcon); 579 formatItem(rp, id); 580 } 581 break; 582 583 case SpyEvent.OBJECT_WAIT_BY_NECESSITY_TYPE: 584 SpyFutureEvent fe = (SpyFutureEvent)val; 585 setToolTipText("Waiting for a future created by "+fe.getCreatorID()); 586 setText("Waiting by necessity"); 587 setBackground(java.awt.Color.white); 588 if (waitByNecessityIcon != null) setIcon(waitByNecessityIcon); 589 break; 590 591 592 case SpyEvent.OBJECT_WAIT_FOR_REQUEST_TYPE: 593 setToolTipText(""); 594 setText("Waiting for request"); 595 setBackground(java.awt.Color.white); 596 if (waitingForRequestIcon != null) setIcon(waitingForRequestIcon); 597 break; 598 } 599 return this; 600 } 601 602 private void formatItem(SpyMessageEvent msg, UniqueID peerID) { 603 ActiveObject peer = null; 605 if (peerID != null) 606 peer = ic2dObject.findActiveObjectById(peerID); 607 if (peer != null) 608 setText("[" + peer.getName() + "]" + msg.getMethodName()); 609 else 610 setText("[?]" + msg.getMethodName()); 611 if (msg.getPos() <= -1 || msg.getPos() >= SHADES.length) 613 setBackground(java.awt.Color.white); 614 else setBackground(SHADES[msg.getPos()]); 615 } 616 } 617 618 619 620 621 622 623 624 625 626 631 private class ObjTrackPanel extends javax.swing.JPanel { 632 633 private javax.swing.JList list; 634 private EventListModel listModel; 635 private javax.swing.JScrollBar verticalScrollBar; 636 637 638 public ObjTrackPanel(ActiveObject activeObject) { 639 setToolTipText(activeObject.getID().toString()); 640 setSize(150,200); 641 javax.swing.JLabel lTitle = new javax.swing.JLabel (activeObject.getName(), javax.swing.JLabel.CENTER); 643 lTitle.setForeground(java.awt.Color.white); 644 lTitle.setBackground(LIST_BG_COLOR); 645 lTitle.setOpaque(true); 646 647 setLayout(new java.awt.BorderLayout ()); 648 add(lTitle, java.awt.BorderLayout.NORTH); 649 650 listModel = new EventListModel(); 651 list = new javax.swing.JList (listModel); 652 list.addListSelectionListener(new MyListSelectionListener()); 653 javax.swing.JScrollPane scList = new javax.swing.JScrollPane (list, javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 654 verticalScrollBar = scList.getVerticalScrollBar(); 655 list.setCellRenderer(new TimeCellRenderer()); 656 list.setBackground(java.awt.Color.white); 657 add(scList, java.awt.BorderLayout.CENTER); 658 setBorder(javax.swing.BorderFactory.createEtchedBorder(java.awt.Color.white, java.awt.Color.gray)); 659 660 EventListPopupMenu popup = new EventListPopupMenu(activeObject); 661 addMouseListener(popup.getMenuMouseListener()); 662 } 663 664 public EventListModel getListModel() { 665 return listModel; 666 } 667 668 public void scrollDown() { 669 verticalScrollBar.setValue(verticalScrollBar.getMaximum() + 50); 670 } 671 672 673 public java.awt.Dimension getPreferredSize() { 674 java.awt.Dimension d = super.getPreferredSize(); 675 d.width = 150; 676 return d; 677 } 678 } 679 680 681 682 683 684 private class EventListPopupMenu extends javax.swing.JPopupMenu { 685 public EventListPopupMenu(final ActiveObject activeObject) { 689 super("EventList Menu"); 690 add(new javax.swing.AbstractAction ("Remove this ActiveObject from the EventList", null) { 691 public void actionPerformed(java.awt.event.ActionEvent e) { 692 removeActiveObject(activeObject); 693 } 694 }); 695 } 696 697 public java.awt.event.MouseListener getMenuMouseListener() { 698 return new MyMouseListener(); 699 } 700 701 private class MyMouseListener extends java.awt.event.MouseAdapter { 705 public void mousePressed(java.awt.event.MouseEvent e) { 706 if (e.isPopupTrigger()) { 707 show(e.getComponent(), e.getX(), e.getY()); 708 } 709 } 710 public void mouseReleased(java.awt.event.MouseEvent e) { 711 if (e.isPopupTrigger()) { 712 show(e.getComponent(), e.getX(), e.getY()); 713 } 714 } 715 } 717 } 719 720 721 722 723 724 727 private class LegendPanel extends javax.swing.JPanel { 728 public LegendPanel() { 729 setLayout(new java.awt.GridLayout (0, 1, 0, 0)); 730 add(new javax.swing.JLabel ("Object waiting for request", waitingForRequestIcon, javax.swing.JLabel.LEFT)); 731 add(new javax.swing.JLabel ("Object waiting for result (wait by necessity)", waitByNecessityIcon, javax.swing.JLabel.LEFT)); 732 add(new javax.swing.JLabel ("Object sent a request", requestSentIcon, javax.swing.JLabel.LEFT)); 733 add(new javax.swing.JLabel ("Object received a request", requestReceivedIcon, javax.swing.JLabel.LEFT)); 734 add(new javax.swing.JLabel ("Object finished serving a request (void return type)", voidRequestServedIcon, javax.swing.JLabel.LEFT)); 735 add(new javax.swing.JLabel ("Object finished serving a request and sent a reply", replySentIcon, javax.swing.JLabel.LEFT)); 736 add(new javax.swing.JLabel ("Object received a reply", replyReceivedIcon, javax.swing.JLabel.LEFT)); 737 add(new javax.swing.JLabel ()); 738 for (int i = SHADES.length - 1; i >= 0; i--) { 740 javax.swing.JLabel l = new javax.swing.JLabel ( 741 i == 10 ? "Event you clicked on" : i == SHADES.length-5 ? "Older events" 742 : i == 5 ? "Newer events" : "", javax.swing.JLabel.CENTER); 743 l.setBackground(SHADES[i]); 744 l.setOpaque(true); 745 l.setVerticalAlignment(javax.swing.SwingConstants.CENTER); 746 add(l); 747 } 748 } 749 } 750 751 752 753 754 755 761 private class MyDropTargetListener extends UniqueIDDropTargetListener { 762 763 769 protected boolean processDrop(java.awt.dnd.DropTargetDropEvent event, UniqueID uniqueID) { 770 ActiveObject activeObject = ic2dObject.findActiveObjectById(uniqueID); 771 if (activeObject == null) return false; 772 if (event.getDropAction() == java.awt.dnd.DnDConstants.ACTION_MOVE) { 773 event.acceptDrop(java.awt.dnd.DnDConstants.ACTION_MOVE); 774 } else if (event.getDropAction() == java.awt.dnd.DnDConstants.ACTION_COPY) { 775 event.acceptDrop(java.awt.dnd.DnDConstants.ACTION_COPY); 776 } 777 event.dropComplete(false); 778 addActiveObject(activeObject); 779 return true; 780 } 781 782 783 786 protected void showDragFeedBack() { 787 } 788 789 790 793 protected void showDropFeedBack() { 794 } 795 796 797 800 protected void hideDnDFeedBack() { 801 } 802 803 } 805 806 807 808 809 810 811 private class EventListModel extends javax.swing.AbstractListModel { 812 813 private BoundedCircularArrayList eventList; 814 815 public EventListModel() { 819 eventList = new BoundedCircularArrayList(80); 820 } 821 822 826 public boolean isEmpty() { 830 return eventList.isEmpty(); 831 } 832 833 public int getSize() { 834 return eventList.size(); 835 } 836 837 public Object lastElement() { 838 return eventList.get(eventList.size()-1); 839 } 840 841 public Object getElementAt(int index) { 842 return eventList.get(index); 843 } 844 845 public void addEvent(SpyEvent evt) { 846 int n = eventList.size(); 847 eventList.add(evt); 848 fireIntervalAdded(this, n, n); 849 } 850 851 public void clear() { 852 int n = eventList.size(); 853 if (n>0) { 854 eventList.clear(); 855 fireIntervalRemoved(this, 0, n-1); 856 } 857 } 858 } 860 861 862 863 864 public class BoundedCircularArrayList extends org.objectweb.proactive.core.util.CircularArrayList { 865 866 private int fixedSize; 867 868 public BoundedCircularArrayList(int size) { 869 super(size); 870 fixedSize = size; 871 } 872 873 public void ensureCapacity(int minCapacity) { 874 } 876 877 public boolean add(Object o) { 878 modCount++; 879 array[tail] = o; 880 tail = (tail+1)%fixedSize; 881 if (tail == head) 882 head = (head+1)%fixedSize; 883 else size++; 884 return true; 885 } 886 887 888 public boolean addAll(java.util.Collection c) { 889 modCount++; 890 int numNew = Math.min(c.size(), fixedSize); 891 java.util.Iterator e = c.iterator(); 892 for (int i=0; i < numNew; i++) { 893 array[tail] = e.next(); 894 tail = (tail+1)%array.length; 895 if (tail == head) 896 head = (head+1)%fixedSize; 897 else size++; 898 } 899 return numNew != 0; 900 } 901 } } | Popular Tags |