KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
42  * A panel for the representation of a DataObject
43  */

44 public abstract class AbstractDataObjectPanel extends javax.swing.JPanel JavaDoc implements MessageMonitoringListener {
45
46   private static final String JavaDoc[] COLUMN_NAMES = { "Property", "Value" };
47   private static final java.awt.Color JavaDoc INFO_PANEL_BG_COLOR = new java.awt.Color JavaDoc(0xd0, 0xd0, 0xd0);
48
49   protected static final java.awt.Font JavaDoc REGULAR_FONT = new java.awt.Font JavaDoc("SansSerif", java.awt.Font.BOLD, 12);
50   protected static final java.awt.Font JavaDoc BIG_FONT = new java.awt.Font JavaDoc("SansSerif", java.awt.Font.BOLD, 14);
51   protected static final java.awt.Font JavaDoc VERY_BIG_FONT = new java.awt.Font JavaDoc("SansSerif", java.awt.Font.BOLD, 16);
52   protected static final java.awt.Font JavaDoc SMALL_FONT = new java.awt.Font JavaDoc("SansSerif", java.awt.Font.BOLD, 10);
53   protected static final java.awt.Font JavaDoc VERY_SMALL_FONT = new java.awt.Font JavaDoc("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 JavaDoc minimumSize = new java.awt.Dimension JavaDoc(MINIMUM_WIDTH, MINIMUM_HEIGHT);
65
66   protected String JavaDoc name;
67   protected String JavaDoc type;
68   protected java.awt.Frame JavaDoc 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 JavaDoc defaultFont;
77
78   // Data representation
79
private java.util.HashMap JavaDoc childs;
80
81   protected boolean isDestroyed;
82
83   //
84
// -- CONSTRUCTORS -----------------------------------------------
85
//
86

87   public AbstractDataObjectPanel(
88     java.awt.Frame JavaDoc parentFrame,
89     ActiveObjectFilter activeObjectFilter,
90     IC2DGUIController controller,
91     ActiveObjectWatcher activeObjectWatcher,
92     String JavaDoc name,
93     String JavaDoc 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 JavaDoc name, String JavaDoc 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     //controller.log("AbstractDataObjectPanel "+name+":"+type+" created");
111
}
112
113   private AbstractDataObjectPanel(String JavaDoc name, String JavaDoc type) {
114     this.name = name;
115     this.type = type;
116     this.childs = new java.util.HashMap JavaDoc();
117     setSize(minimumSize);
118     setToolTipText(name);
119   }
120
121   //
122
// -- PUBLICS METHODS -----------------------------------------------
123
//
124

125   public java.awt.Dimension JavaDoc getMinimumSize() {
126     if (childs.isEmpty()) {
127       java.awt.Dimension JavaDoc 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 JavaDoc getPreferredSize() {
138     if (childs.isEmpty()) {
139       java.awt.Dimension JavaDoc 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   //
154
// -- implements MessageMonitoringListener -----------------------------------------------
155
//
156

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   //
183
// -- PROTECTED METHODS -----------------------------------------------
184
//
185

186   protected java.awt.Dimension JavaDoc getMinimumSizeInternal() {
187     return minimumSize;
188   }
189
190   protected AbstractDataObjectPanel getParentDataObjectPanel() {
191     return parentDataObjectPanel;
192   }
193
194   protected abstract Object JavaDoc[][] getDataObjectInfo();
195
196   protected abstract AbstractDataObject getAbstractDataObject();
197
198   protected void displayDataObjectInfo() {
199     javax.swing.JOptionPane.showMessageDialog(parentFrame, // Component parentComponent,
200
new DataObjectInfoPanel(), // Object message,
201
type + " info :" + name, // String title,
202
javax.swing.JOptionPane.INFORMATION_MESSAGE // int messageType,
203
);
204   }
205
206   protected void filterChangeParentNotification(String JavaDoc qname) {
207     if (parentDataObjectPanel != null)
208       parentDataObjectPanel.filterChangeParentNotification(qname);
209   }
210
211   protected synchronized ActiveObjectPanel findActiveObjectPanelByActiveObject(ActiveObject activeObject) {
212     java.util.Iterator JavaDoc 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   /**
223    * return the top level parent
224    */

225   protected AbstractDataObjectPanel getTopLevelParent() {
226     if (parentDataObjectPanel == null) {
227       return this;
228     } else {
229       return parentDataObjectPanel.getTopLevelParent();
230     }
231   }
232
233   /**
234    * destroy
235    */

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   /**
248    * clear Child
249    */

250   protected synchronized void clearChilds() {
251     childs.clear();
252   }
253
254   /**
255    * put Child
256    */

257   protected synchronized void putChild(AbstractDataObject key, AbstractDataObjectPanel child) {
258     childs.put(key, child);
259   }
260
261   /**
262    * add Child
263    */

264   protected synchronized void addChild(AbstractDataObject key, AbstractDataObjectPanel child) {
265     //System.out.println("AbstractDataObjectPanel addChild name="+child.name+" type="+child.type);
266
putChild(key, child);
267     add(child);
268     revalidate();
269     repaint();
270   }
271
272   /**
273    * remove Child
274    */

275   protected synchronized AbstractDataObjectPanel removeChild(AbstractDataObject key) {
276     AbstractDataObjectPanel panel = (AbstractDataObjectPanel) childs.remove(key);
277     if (panel != null) {
278       //System.out.println("AbstractDataObjectPanel removeChild name="+panel.name+" type="+panel.type);
279
panel.destroy();
280       remove(panel);
281       revalidate();
282       repaint();
283     }
284     return panel;
285   }
286
287   /**
288    * get Child
289    */

290   protected synchronized AbstractDataObjectPanel getChild(AbstractDataObject key) {
291     return (AbstractDataObjectPanel) childs.get(key);
292   }
293
294   protected java.util.Iterator JavaDoc 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 JavaDoc font) {
321     defaultFont = font;
322     java.util.Iterator JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc iterator = childsIterator();
355     while (iterator.hasNext()) {
356       AbstractDataObjectPanel o = (AbstractDataObjectPanel) iterator.next();
357       o.activeObjectRemovedFromFilter();
358     }
359   }
360
361   //
362
// -- PRIVATE METHODS -----------------------------------------------
363
//
364

365   //
366
// -- INNER CLASSES -----------------------------------------------
367
//
368

369   protected class DataObjectInfoPanel extends javax.swing.JPanel JavaDoc {
370     public DataObjectInfoPanel() {
371       super(new java.awt.GridLayout JavaDoc(1, 1));
372       javax.swing.JTable JavaDoc table = new javax.swing.JTable JavaDoc(getDataObjectInfo(), COLUMN_NAMES);
373       javax.swing.JScrollPane JavaDoc sp = new javax.swing.JScrollPane JavaDoc(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 JavaDoc {
381
382     javax.swing.JMenuItem JavaDoc titleItem;
383
384     //
385
// -- CONSTRUCTORS -----------------------------------------------
386
//
387
public PanelPopupMenu(String JavaDoc 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 JavaDoc("Informations", null) {
396         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
397           displayDataObjectInfo();
398         }
399       });
400       addSeparator();
401     }
402
403     public java.awt.event.MouseListener JavaDoc getMenuMouseListener() {
404       return new MyMouseListener();
405     }
406
407     public void setName(String JavaDoc name) {
408       super.setName(name);
409       titleItem.setText(name);
410     }
411
412     public void addRefreshDisplayItem() {
413       add(new javax.swing.AbstractAction JavaDoc("Refresh display") {
414         public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
415           AbstractDataObjectPanel.this.revalidate();
416           AbstractDataObjectPanel.this.repaint();
417         }
418       });
419     }
420
421     //
422
// -- INNER CLASSES -------------------------------------------------
423
//
424
private class MyMouseListener extends java.awt.event.MouseAdapter JavaDoc {
425       public void mousePressed(java.awt.event.MouseEvent JavaDoc e) {
426         if (e.isPopupTrigger()) {
427           show(e.getComponent(), e.getX(), e.getY());
428         }
429       }
430       public void mouseReleased(java.awt.event.MouseEvent JavaDoc e) {
431         if (e.isPopupTrigger()) {
432           show(e.getComponent(), e.getX(), e.getY());
433         }
434       }
435     } // end inner class MyMouseListener
436

437     private class FontSizeMenu extends javax.swing.JMenu JavaDoc {
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 JavaDoc createItem(String JavaDoc text, final int size) {
448         javax.swing.JMenuItem JavaDoc menuItem = new javax.swing.JMenuItem JavaDoc(text);
449         menuItem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
450           public void actionPerformed(java.awt.event.ActionEvent JavaDoc event) {
451             setFontSize(size);
452           }
453         });
454         return menuItem;
455       }
456     } // end inner class FontSizeMenu
457
} // end inner class PanelPopupMenu
458

459 } // end class AbstractDataObjectPanelDataObjectPanel
Popular Tags