KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.Color JavaDoc;
34 import java.awt.Component JavaDoc;
35 import java.awt.Dimension JavaDoc;
36 import java.awt.FlowLayout JavaDoc;
37 import java.awt.Graphics JavaDoc;
38 import java.awt.GridBagConstraints JavaDoc;
39 import java.awt.GridBagLayout JavaDoc;
40 import java.awt.GridLayout JavaDoc;
41 import java.awt.Insets JavaDoc;
42 import java.awt.event.WindowAdapter JavaDoc;
43
44 import javax.swing.Icon JavaDoc;
45 import javax.swing.JComponent JavaDoc;
46 import javax.swing.JFrame JavaDoc;
47 import javax.swing.JLabel JavaDoc;
48 import javax.swing.JPanel JavaDoc;
49 import javax.swing.border.TitledBorder JavaDoc;
50
51 import org.objectweb.proactive.ic2d.gui.data.ActiveObjectPanel;
52
53 public class Legend extends JFrame JavaDoc {
54
55   private static Legend uniqueInstance;
56
57   public static Legend uniqueInstance() {
58     return uniqueInstance == null ? uniqueInstance = new Legend() : uniqueInstance;
59   }
60
61   private Legend() {
62     super("World Panel Legend");
63     setSize(500, 400);
64     {
65        GridBagLayout JavaDoc gridBagLayout;
66        getContentPane().setLayout(gridBagLayout = new GridBagLayout JavaDoc());
67        
68        JPanel JavaDoc activeObjectsPanel = new JPanel JavaDoc(new GridLayout JavaDoc(-1, 2, 5, 5));
69        getContentPane().add(activeObjectsPanel);
70        activeObjectsPanel.setBorder(new TitledBorder JavaDoc("Active objects"));
71        gridBagLayout.setConstraints(activeObjectsPanel,
72             new GridBagConstraints JavaDoc(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
73             GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
74
75       {
76         JComponent JavaDoc comp = new JPanel JavaDoc() {
77
78           public void paintComponent(Graphics JavaDoc g) {
79             Dimension JavaDoc dim = getSize();
80             int w = dim.width;
81             int h = dim.height;
82             g.setColor(ActiveObjectPanel.COLOR_WHEN_ACTIVE);
83             g.fillOval(w/4, 0, w/2, h);
84           }
85         };
86         activeObjectsPanel.add(comp);
87         activeObjectsPanel.add(new JLabel JavaDoc("Active by itself"));
88       }
89
90       {
91         JComponent JavaDoc comp = new JPanel JavaDoc() {
92
93           public void paintComponent(Graphics JavaDoc g) {
94             Dimension JavaDoc dim = getSize();
95             int w = dim.width;
96             int h = dim.height;
97
98             g.setColor(ActiveObjectPanel.COLOR_WHEN_SERVING_REQUEST);
99             g.fillOval(w/4, 0, w/2, h);
100           }
101         };
102         activeObjectsPanel.add(comp);
103         activeObjectsPanel.add(new JLabel JavaDoc("Serving request"));
104       }
105
106       {
107         JComponent JavaDoc comp = new JPanel JavaDoc() {
108
109           public void paintComponent(Graphics JavaDoc g) {
110             Dimension JavaDoc dim = getSize();
111             int w = dim.width;
112             int h = dim.height;
113
114             g.setColor(ActiveObjectPanel.COLOR_WHEN_WAITING_REQUEST);
115             g.fillOval(w/4, 0, w/2, h);
116           }
117         };
118         activeObjectsPanel.add(comp);
119         activeObjectsPanel.add(new JLabel JavaDoc("Waiting for request"));
120       }
121
122       {
123         JComponent JavaDoc comp = new JPanel JavaDoc() {
124
125           public void paintComponent(Graphics JavaDoc g) {
126             Dimension JavaDoc dim = getSize();
127             int w = dim.width;
128             int h = dim.height;
129             g.setColor(ActiveObjectPanel.COLOR_WHEN_WAITING_BY_NECESSITY);
130             g.fillOval(w/4, 0, w/2, h);
131           }
132         };
133         activeObjectsPanel.add(comp);
134         activeObjectsPanel.add(new JLabel JavaDoc("Waiting for result (wait by necessity)"));
135       }
136
137       {
138         JComponent JavaDoc comp = new JPanel JavaDoc() {
139
140           public void paintComponent(Graphics JavaDoc g) {
141             Dimension JavaDoc dim = getSize();
142             int w = dim.width;
143             int h = dim.height;
144
145             g.setColor(ActiveObjectPanel.COLOR_WHEN_MIGRATING);
146             g.fillOval(w/4, 0, w/2, h);
147           }
148         };
149         activeObjectsPanel.add(comp);
150         activeObjectsPanel.add(new JLabel JavaDoc("Migrating"));
151       }
152
153       JPanel JavaDoc requestQueuePanel = new JPanel JavaDoc(new GridLayout JavaDoc(2, 2, 0, 0));
154       getContentPane().add(requestQueuePanel);
155       requestQueuePanel.setBorder(new TitledBorder JavaDoc("Pending Requests"));
156        gridBagLayout.setConstraints(requestQueuePanel,
157             new GridBagConstraints JavaDoc(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
158             GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
159
160       {
161         JComponent JavaDoc comp = new JPanel JavaDoc() {
162
163           public void paintComponent(Graphics JavaDoc g) {
164             Dimension JavaDoc dim = getSize();
165             int w = dim.width;
166             int h = dim.height;
167
168             g.setColor(ActiveObjectPanel.COLOR_WHEN_SERVING_REQUEST);
169             g.fillOval(w/4, 0, w/2, h);
170
171             g.setColor(ActiveObjectPanel.COLOR_REQUEST_SINGLE);
172             for (int i = 0; i < 5; i ++)
173               g.fillRect(w / 2 - 15 + i*6, 2, 4, 4);
174
175             g.setColor(ActiveObjectPanel.COLOR_REQUEST_SEVERAL);
176             for (int i = 0; i < 3; i ++)
177               g.fillRect(w / 2 - 9 + i*6, h - 6, 4, 4);
178
179           }
180         };
181         requestQueuePanel.add(comp);
182         requestQueuePanel.add(new JLabel JavaDoc("Pending requests:"));
183         requestQueuePanel.add(new JLabel JavaDoc());
184         JPanel JavaDoc requestQueuePanel2 = new JPanel JavaDoc(new GridLayout JavaDoc(1, 3));
185         requestQueuePanel.add(requestQueuePanel2);
186         requestQueuePanel2.add(new JLabel JavaDoc("1 ",
187             new Icon JavaDoc() {
188                 public int getIconHeight() { return 4; }
189                 public int getIconWidth() { return 4; }
190                 public void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y) {
191                   g.setColor(ActiveObjectPanel.COLOR_REQUEST_SINGLE);
192                   g.fillRect(x, y, 4, 4);
193                 }
194             }, JLabel.LEFT));
195         requestQueuePanel2.add(new JLabel JavaDoc(ActiveObjectPanel.NUMBER_OF_REQUESTS_FOR_SEVERAL+" ",
196             new Icon JavaDoc() {
197                 public int getIconHeight() { return 4; }
198                 public int getIconWidth() { return 4; }
199                 public void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y) {
200                   g.setColor(ActiveObjectPanel.COLOR_REQUEST_SEVERAL);
201                   g.fillRect(x, y, 4, 4);
202                 }
203             }, JLabel.LEFT));
204         requestQueuePanel2.add(new JLabel JavaDoc(ActiveObjectPanel.NUMBER_OF_REQUESTS_FOR_MANY+
205                                         " ",
206             new Icon JavaDoc() {
207                 public int getIconHeight() { return 4; }
208                 public int getIconWidth() { return 4; }
209                 public void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y) {
210                   g.setColor(ActiveObjectPanel.COLOR_REQUEST_MANY);
211                   g.fillRect(x, y, 4, 4);
212                 }
213             }, JLabel.LEFT));
214       }
215
216       JPanel JavaDoc nodePanel = new JPanel JavaDoc(new GridLayout JavaDoc(-1, 2, 5, 5));
217       getContentPane().add(nodePanel);
218       nodePanel.setBorder(new TitledBorder JavaDoc("Nodes"));
219        gridBagLayout.setConstraints(nodePanel,
220             new GridBagConstraints JavaDoc(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
221             GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
222
223       {
224         JComponent JavaDoc comp = new JPanel JavaDoc() {
225
226           public void paintComponent(Graphics JavaDoc g) {
227             Dimension JavaDoc dim = getSize();
228             int w = dim.width;
229             int h = dim.height;
230             g.setColor(new Color JavaDoc(0xd0, 0xd0, 0xe0));
231             g.fillRect(w/4, 0, w/2, h);
232           }
233         };
234         nodePanel.add(comp);
235         nodePanel.add(new JLabel JavaDoc("RMI Node"));
236       }
237       
238       {
239         JComponent JavaDoc comp = new JPanel JavaDoc() {
240
241           public void paintComponent(Graphics JavaDoc g) {
242             Dimension JavaDoc dim = getSize();
243             int w = dim.width;
244             int h = dim.height;
245             
246             g.setColor(java.awt.Color.cyan);
247             g.fillRect(w/4, 0, w/2, h);
248           }
249         };
250         nodePanel.add(comp);
251         nodePanel.add(new JLabel JavaDoc("Jini Node"));
252       }
253       
254       JPanel JavaDoc jvmPanel = new JPanel JavaDoc(new GridLayout JavaDoc(-1, 2, 5, 5));
255       getContentPane().add(jvmPanel);
256       jvmPanel.setBorder(new TitledBorder JavaDoc("JVMs"));
257        gridBagLayout.setConstraints(jvmPanel,
258             new GridBagConstraints JavaDoc(0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
259             GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
260
261       {
262         JComponent JavaDoc comp = new JPanel JavaDoc() {
263
264           private int w = 100;
265           private int h = 50;
266
267           public void paintComponent(Graphics JavaDoc g) {
268             Dimension JavaDoc dim = getSize();
269             int w = dim.width;
270             int h = dim.height;
271             g.setColor(new Color JavaDoc(0xd0, 0xd0, 0xd0));
272             g.fillRect(w/4, 0, w/2, h);
273           }
274         };
275         jvmPanel.add(comp);
276         jvmPanel.add(new JLabel JavaDoc("Standard Jvm"));
277       }
278
279       {
280         JComponent JavaDoc comp = new JPanel JavaDoc() {
281
282           private int w = 100;
283           private int h = 50;
284
285           public void paintComponent(Graphics JavaDoc g) {
286             Dimension JavaDoc dim = getSize();
287             int w = dim.width;
288             int h = dim.height;
289             g.setColor(new Color JavaDoc(0xff, 0xd0, 0xd0));
290             g.fillRect(w/4, 0, w/2, h);
291           }
292         };
293         jvmPanel.add(comp);
294         jvmPanel.add(new JLabel JavaDoc("Globus Jvm"));
295       }
296
297       JPanel JavaDoc hostPanel = new JPanel JavaDoc(new GridLayout JavaDoc(-1, 2, 5, 5));
298       getContentPane().add(hostPanel);
299       hostPanel.setBorder(new TitledBorder JavaDoc("Hosts"));
300        gridBagLayout.setConstraints(hostPanel,
301             new GridBagConstraints JavaDoc(0, 4, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
302             GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
303
304       {
305         JComponent JavaDoc comp = new JPanel JavaDoc() {
306
307           private int w = 100;
308           private int h = 50;
309
310           public void paintComponent(Graphics JavaDoc g) {
311             Dimension JavaDoc dim = getSize();
312             int w = dim.width;
313             int h = dim.height;
314             g.setColor(new Color JavaDoc(0xd0, 0xd0, 0xd0));
315             g.fillRect(w/4, 0, w/2, h);
316           }
317         };
318         hostPanel.add(comp);
319         hostPanel.add(new JLabel JavaDoc("Standard Host"));
320       }
321
322       
323
324       getContentPane().validate();
325     }
326
327     addWindowListener(new WindowAdapter JavaDoc() {
328       public void windowClosing() {
329         setVisible(false);
330       }
331     });
332   }
333
334   private void add(String JavaDoc name, JComponent JavaDoc comp) {
335     JPanel JavaDoc pan = new JPanel JavaDoc(new FlowLayout JavaDoc());
336     pan.add(new JLabel JavaDoc(name));
337     pan.add(comp);
338     getContentPane().add(pan);
339   }
340
341   public static void main(String JavaDoc[] argv) {
342     Legend.uniqueInstance().show();
343   }
344 }
Popular Tags