1 31 package org.objectweb.proactive.examples.doctor; 32 33 import java.awt.Dialog ; 34 import java.awt.Dimension ; 35 import java.awt.FontMetrics ; 36 import java.awt.Frame ; 37 import java.awt.Graphics ; 38 import java.awt.Panel ; 39 import java.awt.Point ; 40 import java.awt.event.WindowAdapter ; 41 import java.awt.event.WindowEvent ; 42 43 public class Legend extends Dialog { 44 45 public class LegendPanel extends Panel { 46 47 DisplayPanel display; 48 49 50 public LegendPanel(DisplayPanel _display) { 51 display = _display; 52 } 53 54 55 public void update(Graphics g) { 56 FontMetrics fm = g.getFontMetrics(); 57 int h = fm.getAscent(); 58 59 g.setColor(display.wellOn); 60 g.fillOval(30, 30 - h, h, h); 61 g.setColor(display.patColor); 62 g.drawString("Healthy patient", 40 + h, 30); 63 64 g.setColor(display.sickOn); 65 g.fillOval(30, 40 + h - h, h, h); 66 g.setColor(display.patColor); 67 g.drawString("Sick patient", 40 + h, 40 + h); 68 69 g.setColor(display.cureOn); 70 g.fillOval(30, 50 + 2 * h - h, h, h); 71 g.setColor(display.patColor); 72 g.drawString("Patient with doctor", 40 + h, 50 + 2 * h); 73 } 74 75 76 public Dimension getPreferredSize() { 77 return new Dimension (200, 90); 78 } 79 80 81 public void paint(Graphics g) { 82 update(g); 83 } 84 } 85 86 87 public Legend(Frame dw, DisplayPanel display) { 88 super(dw, "Legend", false); 89 90 Point parLoc = dw.getLocation(); 91 setLocation(parLoc.x + (dw.getSize().width), parLoc.y); 92 93 LegendPanel pan = new LegendPanel(display); 94 add(pan); 95 96 pack(); 97 98 this.addWindowListener(new WindowAdapter () { 99 100 public void windowClosing(WindowEvent e) { 101 setVisible(false); 102 } 103 }); 104 } 105 } 106 | Popular Tags |