1 31 package org.objectweb.proactive.ic2d.gui; 32 33 import java.awt.Color ; 34 import java.awt.Component ; 35 import java.awt.Dimension ; 36 import java.awt.FlowLayout ; 37 import java.awt.Graphics ; 38 import java.awt.GridBagConstraints ; 39 import java.awt.GridBagLayout ; 40 import java.awt.GridLayout ; 41 import java.awt.Insets ; 42 import java.awt.event.WindowAdapter ; 43 44 import javax.swing.Icon ; 45 import javax.swing.JComponent ; 46 import javax.swing.JFrame ; 47 import javax.swing.JLabel ; 48 import javax.swing.JPanel ; 49 import javax.swing.border.TitledBorder ; 50 51 import org.objectweb.proactive.ic2d.gui.data.ActiveObjectPanel; 52 53 public class Legend extends JFrame { 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 gridBagLayout; 66 getContentPane().setLayout(gridBagLayout = new GridBagLayout ()); 67 68 JPanel activeObjectsPanel = new JPanel (new GridLayout (-1, 2, 5, 5)); 69 getContentPane().add(activeObjectsPanel); 70 activeObjectsPanel.setBorder(new TitledBorder ("Active objects")); 71 gridBagLayout.setConstraints(activeObjectsPanel, 72 new GridBagConstraints (0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, 73 GridBagConstraints.BOTH, new Insets (0, 0, 0, 0), 0, 0)); 74 75 { 76 JComponent comp = new JPanel () { 77 78 public void paintComponent(Graphics g) { 79 Dimension 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 ("Active by itself")); 88 } 89 90 { 91 JComponent comp = new JPanel () { 92 93 public void paintComponent(Graphics g) { 94 Dimension 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 ("Serving request")); 104 } 105 106 { 107 JComponent comp = new JPanel () { 108 109 public void paintComponent(Graphics g) { 110 Dimension 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 ("Waiting for request")); 120 } 121 122 { 123 JComponent comp = new JPanel () { 124 125 public void paintComponent(Graphics g) { 126 Dimension 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 ("Waiting for result (wait by necessity)")); 135 } 136 137 { 138 JComponent comp = new JPanel () { 139 140 public void paintComponent(Graphics g) { 141 Dimension 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 ("Migrating")); 151 } 152 153 JPanel requestQueuePanel = new JPanel (new GridLayout (2, 2, 0, 0)); 154 getContentPane().add(requestQueuePanel); 155 requestQueuePanel.setBorder(new TitledBorder ("Pending Requests")); 156 gridBagLayout.setConstraints(requestQueuePanel, 157 new GridBagConstraints (0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, 158 GridBagConstraints.BOTH, new Insets (0, 0, 0, 0), 0, 0)); 159 160 { 161 JComponent comp = new JPanel () { 162 163 public void paintComponent(Graphics g) { 164 Dimension 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 ("Pending requests:")); 183 requestQueuePanel.add(new JLabel ()); 184 JPanel requestQueuePanel2 = new JPanel (new GridLayout (1, 3)); 185 requestQueuePanel.add(requestQueuePanel2); 186 requestQueuePanel2.add(new JLabel ("1 ", 187 new Icon () { 188 public int getIconHeight() { return 4; } 189 public int getIconWidth() { return 4; } 190 public void paintIcon(Component c, Graphics 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 (ActiveObjectPanel.NUMBER_OF_REQUESTS_FOR_SEVERAL+" ", 196 new Icon () { 197 public int getIconHeight() { return 4; } 198 public int getIconWidth() { return 4; } 199 public void paintIcon(Component c, Graphics 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 (ActiveObjectPanel.NUMBER_OF_REQUESTS_FOR_MANY+ 205 " ", 206 new Icon () { 207 public int getIconHeight() { return 4; } 208 public int getIconWidth() { return 4; } 209 public void paintIcon(Component c, Graphics 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 nodePanel = new JPanel (new GridLayout (-1, 2, 5, 5)); 217 getContentPane().add(nodePanel); 218 nodePanel.setBorder(new TitledBorder ("Nodes")); 219 gridBagLayout.setConstraints(nodePanel, 220 new GridBagConstraints (0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, 221 GridBagConstraints.BOTH, new Insets (0, 0, 0, 0), 0, 0)); 222 223 { 224 JComponent comp = new JPanel () { 225 226 public void paintComponent(Graphics g) { 227 Dimension dim = getSize(); 228 int w = dim.width; 229 int h = dim.height; 230 g.setColor(new Color (0xd0, 0xd0, 0xe0)); 231 g.fillRect(w/4, 0, w/2, h); 232 } 233 }; 234 nodePanel.add(comp); 235 nodePanel.add(new JLabel ("RMI Node")); 236 } 237 238 { 239 JComponent comp = new JPanel () { 240 241 public void paintComponent(Graphics g) { 242 Dimension 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 ("Jini Node")); 252 } 253 254 JPanel jvmPanel = new JPanel (new GridLayout (-1, 2, 5, 5)); 255 getContentPane().add(jvmPanel); 256 jvmPanel.setBorder(new TitledBorder ("JVMs")); 257 gridBagLayout.setConstraints(jvmPanel, 258 new GridBagConstraints (0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, 259 GridBagConstraints.BOTH, new Insets (0, 0, 0, 0), 0, 0)); 260 261 { 262 JComponent comp = new JPanel () { 263 264 private int w = 100; 265 private int h = 50; 266 267 public void paintComponent(Graphics g) { 268 Dimension dim = getSize(); 269 int w = dim.width; 270 int h = dim.height; 271 g.setColor(new Color (0xd0, 0xd0, 0xd0)); 272 g.fillRect(w/4, 0, w/2, h); 273 } 274 }; 275 jvmPanel.add(comp); 276 jvmPanel.add(new JLabel ("Standard Jvm")); 277 } 278 279 { 280 JComponent comp = new JPanel () { 281 282 private int w = 100; 283 private int h = 50; 284 285 public void paintComponent(Graphics g) { 286 Dimension dim = getSize(); 287 int w = dim.width; 288 int h = dim.height; 289 g.setColor(new Color (0xff, 0xd0, 0xd0)); 290 g.fillRect(w/4, 0, w/2, h); 291 } 292 }; 293 jvmPanel.add(comp); 294 jvmPanel.add(new JLabel ("Globus Jvm")); 295 } 296 297 JPanel hostPanel = new JPanel (new GridLayout (-1, 2, 5, 5)); 298 getContentPane().add(hostPanel); 299 hostPanel.setBorder(new TitledBorder ("Hosts")); 300 gridBagLayout.setConstraints(hostPanel, 301 new GridBagConstraints (0, 4, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, 302 GridBagConstraints.BOTH, new Insets (0, 0, 0, 0), 0, 0)); 303 304 { 305 JComponent comp = new JPanel () { 306 307 private int w = 100; 308 private int h = 50; 309 310 public void paintComponent(Graphics g) { 311 Dimension dim = getSize(); 312 int w = dim.width; 313 int h = dim.height; 314 g.setColor(new Color (0xd0, 0xd0, 0xd0)); 315 g.fillRect(w/4, 0, w/2, h); 316 } 317 }; 318 hostPanel.add(comp); 319 hostPanel.add(new JLabel ("Standard Host")); 320 } 321 322 323 324 getContentPane().validate(); 325 } 326 327 addWindowListener(new WindowAdapter () { 328 public void windowClosing() { 329 setVisible(false); 330 } 331 }); 332 } 333 334 private void add(String name, JComponent comp) { 335 JPanel pan = new JPanel (new FlowLayout ()); 336 pan.add(new JLabel (name)); 337 pan.add(comp); 338 getContentPane().add(pan); 339 } 340 341 public static void main(String [] argv) { 342 Legend.uniqueInstance().show(); 343 } 344 } | Popular Tags |