KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > EventListsPanel


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

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 JavaDoc implements CommunicationEventListener, ActiveObjectWatcher {
45
46   private static final String JavaDoc IMAGES_DIR = "org/objectweb/proactive/ic2d/gui/images/";
47   private static final String JavaDoc REPLY_RECEIVED_ICON = IMAGES_DIR+"ReplyReceived.gif";
48   private static final String JavaDoc REPLY_SENT_ICON = IMAGES_DIR+"ReplySent.gif";
49   private static final String JavaDoc REQUEST_RECEIVED_ICON = IMAGES_DIR+"RequestReceived.gif";
50   private static final String JavaDoc REQUEST_SENT_ICON = IMAGES_DIR+"RequestSent.gif";
51   private static final String JavaDoc WAITING_FOR_REQUEST_ICON = IMAGES_DIR+"WaitingForRequest.gif";
52   private static final String JavaDoc WAIT_BY_NECESSITY_ICON = IMAGES_DIR+"WaitByNecessity.gif";
53   private static final String JavaDoc 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 JavaDoc LIST_BG_COLOR = new java.awt.Color JavaDoc(0, 0, 80);
60   private static final java.awt.Font JavaDoc MFONT = new java.awt.Font JavaDoc("Dialog", 1, 10);
61   private static final java.awt.Color JavaDoc[] SHADES;
62   static {
63     // Create the SHADES!
64
SHADES = new java.awt.Color JavaDoc[21];
65     for (int i = 0; i < 10; i++) {
66       SHADES[i] = new java.awt.Color JavaDoc(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 JavaDoc(150 + (20-i) * 10, (20-i)*13+30, (20-i)*13+30);
71     }
72   }
73
74   private javax.swing.ImageIcon JavaDoc requestReceivedIcon;
75   private javax.swing.ImageIcon JavaDoc replySentIcon;
76   private javax.swing.ImageIcon JavaDoc requestSentIcon;
77   private javax.swing.ImageIcon JavaDoc replyReceivedIcon;
78   private javax.swing.ImageIcon JavaDoc waitingForRequestIcon;
79   private javax.swing.ImageIcon JavaDoc waitByNecessityIcon;
80   private javax.swing.ImageIcon JavaDoc voidRequestServedIcon;
81                      
82   /**
83    * KEY: id
84    * VAL: corresponding JList [model = default]
85    */

86   private java.util.HashMap JavaDoc objectTrackPanelMap;
87   private BoundedCircularArrayList events;
88   
89   /**
90    * The array of strings representing the state of a requestEvent
91    */

92   private int colorMode = RELATED_EVENT_COLOR_MODE;
93   public javax.swing.JPopupMenu JavaDoc popup;
94   private javax.swing.JPanel JavaDoc centerPanel;
95   private PlayerFrameTimeLine recorder;
96   /** last object in one of the lists that was selected */
97   private Object JavaDoc lastSelected;
98
99   protected IC2DGUIController controller;
100   protected IC2DObject ic2dObject;
101   
102   /** enables this component to be a dropTarget */
103   private java.awt.dnd.DropTarget JavaDoc dropTarget;
104
105
106   //
107
// -- CONSTRUCTORS -----------------------------------------------
108
//
109

110   public EventListsPanel(IC2DObject ic2dObject, IC2DGUIController controller) {
111     this.ic2dObject = ic2dObject;
112     this.controller = controller;
113         
114     // dnd stuff
115
dropTarget = new java.awt.dnd.DropTarget JavaDoc(this, java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE, new MyDropTargetListener(), true);
116
117     objectTrackPanelMap = new java.util.HashMap JavaDoc();
118     events = new BoundedCircularArrayList(1000);
119     recorder = new PlayerFrameTimeLine(this, ic2dObject.getController());
120
121     setLayout(new java.awt.BorderLayout JavaDoc());
122     {
123       javax.swing.JPanel JavaDoc tools = new javax.swing.JPanel JavaDoc();
124       final javax.swing.JComboBox JavaDoc colorCombo = new javax.swing.JComboBox JavaDoc(
125             new String JavaDoc [] {"Color related events", "Color chronological order", "No coloring"});
126       colorCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
127         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc b = new javax.swing.JButton JavaDoc("Messages recorder");
139       b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
140         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
141           recorder.setVisible(! recorder.isVisible());
142         }
143       });
144       tools.add(b);
145       }
146       {
147       javax.swing.JButton JavaDoc b = new javax.swing.JButton JavaDoc("Clear all events");
148       b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
149         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
150           clearAll();
151         }
152       });
153       tools.add(b);
154       }
155       {
156       javax.swing.JButton JavaDoc b = new javax.swing.JButton JavaDoc("Legend");
157       b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
158         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc();
168     add(centerPanel, java.awt.BorderLayout.CENTER);
169     
170     // main area
171
centerPanel.setBackground(java.awt.Color.white);
172
173     // Lists pane
174
java.awt.GridLayout JavaDoc grid = new java.awt.GridLayout JavaDoc(1, 0);
175     grid.setHgap(5);
176     centerPanel.setLayout(grid);
177     validate();
178     loadIcon();
179   }
180
181
182   
183   //
184
// -- PUBLIC METHODS -----------------------------------------------
185
//
186

187   public void clearAll() {
188     synchronized (objectTrackPanelMap) {
189       java.util.Iterator JavaDoc i = objectTrackPanelMap.values().iterator();
190       while (i.hasNext()) {
191         // clean the ui
192
ObjTrackPanel otp = (ObjTrackPanel) i.next();
193         otp.getListModel().clear();
194       }
195     }
196     // clean the event vector
197
events.clear();
198   }
199   
200
201   //
202
// -- implements ActiveObjectWatcher -----------------------------------------------
203
//
204

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   //
229
// -- implements CommunicationEventListener -----------------------------------------------
230
//
231

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     //Code for downScrolling should be there...
267
synchronized (objectTrackPanelMap) {
268       java.util.Iterator JavaDoc i = objectTrackPanelMap.values().iterator();
269       while (i.hasNext()) {
270         // clean the ui
271
ObjTrackPanel otp = (ObjTrackPanel) i.next();
272         otp.scrollDown();
273       }
274     }
275     revalidate();
276     repaint();
277   }
278
279
280
281   //
282
// -- PRIVATE METHODS -----------------------------------------------
283
//
284

285   private void loadIcon() {
286     // images
287
ClassLoader JavaDoc c = this.getClass().getClassLoader();
288     replyReceivedIcon = new javax.swing.ImageIcon JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(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   /**
320    * Adds the event to the lists and to the event vec
321    */

322   private void recordEvent(final ActiveObject obj, final SpyEvent evt, final boolean dontRepeatSameType) {
323     //System.out.println("Record event evt="+evt);
324
javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
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   } // end recordEvent
338

339
340
341   private void showLegend() {
342     javax.swing.JFrame JavaDoc legendFrame = new javax.swing.JFrame JavaDoc("Eventslist Legend");
343     legendFrame.getContentPane().add(new LegendPanel());
344     legendFrame.setSize(400, 600);
345     legendFrame.show();
346   }
347
348   /** Colors the events correctly. <br>Possible modes:<br><ul>
349    * <li>NO_COLOR_MODE: No coloring</li>
350    * <li>RELATED_EVENT_COLOR_MODE: The four Qsent/Qrecv, Rsent/Rrecv (or Vserved) messages
351    * belonging to the one the user clicked on are colored. Requests in blue, replies in red.
352    * All others remain white.</li>
353    * <li>ABSOLUTE_EVENT_COLOR_MODE: The message the user clicked on and its corresponding
354    * four messages are colored yellow. If the user clicked on a request, older request
355    * messages in the same list with their corresponding messages are colored blue and newer ones red.
356    * If the user clicked on a reply, older reply
357    * messages in the same list with their corresponding messages are colored blue and newer ones red.</li>
358    */

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 JavaDoc bef = getMsgBefore(m, id);
371           java.util.LinkedList JavaDoc 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     /** calculates the corresponding SHADES index for related events */
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     /**
416      * Compute the color given the position
417      * and set the one of the message and its peers for absolute events
418      */

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 JavaDoc 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     /** returns all SpyMessageEvents that belong to the same body,
434      * the same type (request or reply) and occured before target */

435     private java.util.LinkedList JavaDoc getMsgBefore(SpyMessageEvent target, UniqueID id) {
436       java.util.LinkedList JavaDoc result = new java.util.LinkedList JavaDoc();
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 JavaDoc 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       //System.out.println(result.size()+" size");
458
return result;
459         }
460       
461       
462     /** returns all SpyMessageEvents that belong to the same body,
463      * the same type (request or reply) and occured after target */

464     private java.util.LinkedList JavaDoc getMsgAfter(SpyMessageEvent target, UniqueID id) {
465       java.util.LinkedList JavaDoc result = new java.util.LinkedList JavaDoc();
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 JavaDoc 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           // System.out.println(result.size()+" size");
487
return result;
488     }
489
490
491   //
492
// -- INNER CLASSES -----------------------------------------------
493
//
494

495   private class MyListSelectionListener implements javax.swing.event.ListSelectionListener JavaDoc {
496   
497     /**
498      * When an item is selected,
499      * this method is fired and changes the colors of the other items
500      */

501     public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc e) {
502       if (e.getValueIsAdjusting()) return;
503       lastSelected = ((javax.swing.JList JavaDoc)e.getSource()).getSelectedValue();
504       colorEvents();
505     }
506     
507
508   }
509   
510   
511   
512   
513   
514
515   /**
516    * CELL RENDERER
517    */

518   private class TimeCellRenderer extends javax.swing.DefaultListCellRenderer JavaDoc {
519
520     public TimeCellRenderer() {
521       setOpaque(true);
522       setHorizontalAlignment(LEFT);
523       setVerticalAlignment(CENTER);
524       setFont(MFONT);
525     }
526
527     /**
528      * This method sorts the events
529      */

530     public java.awt.Component JavaDoc getListCellRendererComponent(javax.swing.JList JavaDoc list, Object JavaDoc 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       // The sender or receiver is..
604
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       // Background
612
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   /**
627    * ObjectTracker
628    * Contains the name of the object
629    * and the list
630    */

631   private class ObjTrackPanel extends javax.swing.JPanel JavaDoc {
632
633     private javax.swing.JList JavaDoc list;
634     private EventListModel listModel;
635     private javax.swing.JScrollBar JavaDoc verticalScrollBar;
636
637
638     public ObjTrackPanel(ActiveObject activeObject) {
639       setToolTipText(activeObject.getID().toString());
640         setSize(150,200);
641       // Title
642
javax.swing.JLabel JavaDoc lTitle = new javax.swing.JLabel JavaDoc(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 JavaDoc());
648       add(lTitle, java.awt.BorderLayout.NORTH);
649
650       listModel = new EventListModel();
651       list = new javax.swing.JList JavaDoc(listModel);
652       list.addListSelectionListener(new MyListSelectionListener());
653       javax.swing.JScrollPane JavaDoc scList = new javax.swing.JScrollPane JavaDoc(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 JavaDoc getPreferredSize() {
674       java.awt.Dimension JavaDoc 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 JavaDoc {
685     //
686
// -- CONSTRUCTORS -----------------------------------------------
687
//
688
public EventListPopupMenu(final ActiveObject activeObject) {
689       super("EventList Menu");
690       add(new javax.swing.AbstractAction JavaDoc("Remove this ActiveObject from the EventList", null) {
691         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
692           removeActiveObject(activeObject);
693         }
694       });
695     }
696   
697     public java.awt.event.MouseListener JavaDoc getMenuMouseListener() {
698       return new MyMouseListener();
699     }
700
701     //
702
// -- INNER CLASSES -------------------------------------------------
703
//
704
private class MyMouseListener extends java.awt.event.MouseAdapter JavaDoc {
705       public void mousePressed(java.awt.event.MouseEvent JavaDoc e) {
706         if (e.isPopupTrigger()) {
707           show(e.getComponent(), e.getX(), e.getY());
708         }
709       }
710       public void mouseReleased(java.awt.event.MouseEvent JavaDoc e) {
711         if (e.isPopupTrigger()) {
712           show(e.getComponent(), e.getX(), e.getY());
713         }
714       }
715     } // end inner class MyMouseListener
716

717   } // end inner class PanelPopupMenu
718

719
720
721
722
723
724   /**
725    * Legend Panel
726    */

727   private class LegendPanel extends javax.swing.JPanel JavaDoc {
728     public LegendPanel() {
729       setLayout(new java.awt.GridLayout JavaDoc(0, 1, 0, 0));
730       add(new javax.swing.JLabel JavaDoc("Object waiting for request", waitingForRequestIcon, javax.swing.JLabel.LEFT));
731       add(new javax.swing.JLabel JavaDoc("Object waiting for result (wait by necessity)", waitByNecessityIcon, javax.swing.JLabel.LEFT));
732       add(new javax.swing.JLabel JavaDoc("Object sent a request", requestSentIcon, javax.swing.JLabel.LEFT));
733       add(new javax.swing.JLabel JavaDoc("Object received a request", requestReceivedIcon, javax.swing.JLabel.LEFT));
734       add(new javax.swing.JLabel JavaDoc("Object finished serving a request (void return type)", voidRequestServedIcon, javax.swing.JLabel.LEFT));
735       add(new javax.swing.JLabel JavaDoc("Object finished serving a request and sent a reply", replySentIcon, javax.swing.JLabel.LEFT));
736       add(new javax.swing.JLabel JavaDoc("Object received a reply", replyReceivedIcon, javax.swing.JLabel.LEFT));
737       add(new javax.swing.JLabel JavaDoc());
738       // populate panels
739
for (int i = SHADES.length - 1; i >= 0; i--) {
740         javax.swing.JLabel JavaDoc l = new javax.swing.JLabel JavaDoc(
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   /**
756    * MyDropTargetListener
757    * a listener that tracks the state of the operation
758    * @see java.awt.dnd.DropTargetListener
759    * @see java.awt.dnd.DropTarget
760    */

761   private class MyDropTargetListener extends UniqueIDDropTargetListener {
762     
763    /**
764     * processes the drop and return false if the drop is rejected or true if the drop is accepted.
765     * The method must not call the rejectDrop as returning false signel that the drop is rejected.
766     * On the other hand it is the responsability of this method to call the acceptDrop and dropComplete
767     * when accepting the drop and returning true
768     */

769     protected boolean processDrop(java.awt.dnd.DropTargetDropEvent JavaDoc 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    /**
784     * Displays a user feed back to show that the drag is going on
785     */

786     protected void showDragFeedBack() {
787     }
788    
789  
790    /**
791     * Displays a user feed back to show that the drop is going on
792     */

793     protected void showDropFeedBack() {
794     }
795    
796  
797    /**
798     * Removes the user feed back that shows the drag
799     */

800     protected void hideDnDFeedBack() {
801     }
802
803   } // end inner class MyDropTargetListener
804

805
806
807
808
809
810
811   private class EventListModel extends javax.swing.AbstractListModel JavaDoc {
812   
813     private BoundedCircularArrayList eventList;
814   
815     //
816
// -- CONSTRUCTORS -----------------------------------------------
817
//
818
public EventListModel() {
819       eventList = new BoundedCircularArrayList(80);
820     }
821
822     //
823
// -- Public methods -----------------------------------------------
824
//
825

826     //
827
// -- implements ListModel -----------------------------------------------
828
//
829
public boolean isEmpty() {
830       return eventList.isEmpty();
831     }
832     
833     public int getSize() {
834       return eventList.size();
835     }
836
837     public Object JavaDoc lastElement() {
838       return eventList.get(eventList.size()-1);
839     }
840     
841     public Object JavaDoc 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   } // end inner class EventListModel
859

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       // size is fixed
875
}
876
877     public boolean add(Object JavaDoc 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 JavaDoc c) {
889       modCount++;
890       int numNew = Math.min(c.size(), fixedSize);
891       java.util.Iterator JavaDoc 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   } // end inner class BoundedCircularArrayList
902
}
Popular Tags