KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > data > IC2DPanel


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.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   //
58
// -- CONSTRUCTORS -----------------------------------------------
59
//
60

61   public IC2DPanel(java.awt.Frame JavaDoc 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     //Create the worldPanel
72
worldPanel = new WorldPanel(this, ic2dObject.getWorldObject(), communicationRecorder);
73     putChild(ic2dObject.getWorldObject(),worldPanel);
74     ic2dObject.getWorldObject().registerListener(worldPanel);
75     setLayout(new java.awt.BorderLayout JavaDoc());
76     
77     // create panel to host WorldPanel
78
javax.swing.JScrollPane JavaDoc scrollableWorldPanel = new javax.swing.JScrollPane JavaDoc(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   //
87
// -- PUBLIC METHODS -----------------------------------------------
88
//
89

90   public void updateFilteredClasses() {
91     removeAllActiveObjectsFromWatcher();
92     worldPanel.filterChangeParentNotification(null);
93   }
94   
95   //
96
// -- implements CommunicationEventListener -----------------------------------------------
97
//
98

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    // recordCommunication(object, ((SpyMessageEvent) spyEvent).getDestinationBodyID(), true);
107
// already recorded in requestMessageReceived
108
}
109   
110   public void replyMessageSent(ActiveObject object, SpyEvent spyEvent) {
111    // recordCommunication(object, ((SpyMessageEvent) spyEvent).getDestinationBodyID(), true);
112
// not recording replies
113
}
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    // recordCommunication(object, ((SpyMessageEvent) spyEvent).getSourceBodyID(), false);
121
// not recording replies
122
}
123
124   public void voidRequestServed(ActiveObject object, SpyEvent spyEvent) {
125   }
126
127   public void allEventsProcessed() {
128     worldPanel.repaint();
129   }
130
131
132   //
133
// -- PROTECTED METHODS -----------------------------------------------
134
//
135

136   protected AbstractDataObject getAbstractDataObject() {
137     return ic2dObject;
138   }
139   
140   
141   protected Object JavaDoc[][] getDataObjectInfo() {
142     return new Object JavaDoc[][] {
143       };
144   }
145
146
147   //
148
// -- PRIVATE METHODS -----------------------------------------------
149
//
150

151   private javax.swing.JPanel JavaDoc createControlPanel() {
152     javax.swing.JPanel JavaDoc p = new javax.swing.JPanel JavaDoc(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.CENTER));
153
154     // Draw Topology
155
{
156     final javax.swing.JCheckBox JavaDoc topo = new javax.swing.JCheckBox JavaDoc("Display topology");
157     topo.setSelected(communicationRecorder.isEnabled());
158     topo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
159         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
160           communicationRecorder.setEnabled(topo.isSelected());
161           repaint();
162         }
163       });
164     p.add(topo);
165     }
166     
167     // Topology proportional / Ratio / filaire
168
javax.swing.ButtonGroup JavaDoc group = new javax.swing.ButtonGroup JavaDoc();
169     
170     final javax.swing.JRadioButton JavaDoc b1 = new javax.swing.JRadioButton JavaDoc("proportional");
171     b1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
172         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc b2 = new javax.swing.JRadioButton JavaDoc("ratio");
184     b2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
185         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc b3 = new javax.swing.JRadioButton JavaDoc("filaire");
197     b3.addActionListener(new java.awt.event.ActionListener JavaDoc() {
198         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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     // Reset topology
211
javax.swing.JButton JavaDoc b = new javax.swing.JButton JavaDoc("Reset Topology");
212     b.addActionListener(new java.awt.event.ActionListener JavaDoc() {
213         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
214           communicationRecorder.clear();
215           repaint();
216         }
217       });
218     b.setToolTipText("Reset the current topology");
219     p.add(b);
220
221
222     // Enable monitoring
223
{
224     final javax.swing.JCheckBox JavaDoc cb = new javax.swing.JCheckBox JavaDoc("Monitoring enable");
225     cb.setSelected(ic2dObject.getController().isMonitoring());
226     cb.addActionListener(new java.awt.event.ActionListener JavaDoc() {
227         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
228           ic2dObject.getController().setMonitoring(cb.isSelected());
229         }
230       });
231     p.add(cb);
232     }
233
234     return p;
235   }
236
237
238
239   // Record that two objects talked together
240
private void recordCommunication(ActiveObject activeObjectOriginator, UniqueID peerActiveObjectID, boolean isSend) {
241     ActiveObject peerActiveObject = ic2dObject.getWorldObject().findActiveObjectById(peerActiveObjectID);
242     if (peerActiveObject == null) return;
243     // now get the 2 panels associated with the two objects
244
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   //
268
// -- INNER CLASSES -----------------------------------------------
269
//
270

271 }
Popular Tags