1 17 package org.apache.jmeter.visualizers; 18 19 import java.awt.Dimension ; 20 import java.awt.FlowLayout ; 21 22 import javax.swing.ImageIcon ; 23 import javax.swing.JPanel ; 24 import javax.swing.JLabel ; 25 import org.apache.jmeter.util.JMeterUtils; 26 import org.apache.jmeter.monitor.util.Stats; 27 28 35 public class ServerPanel extends JPanel 36 implements MonitorGuiListener 37 { 38 39 private JLabel serverField; 40 private JLabel timestampField; 41 44 private Dimension prefsize = new Dimension (25,75); 45 private JLabel healthIcon; 46 private JLabel loadIcon; 47 48 51 public static final ImageIcon HEALTHY = 52 JMeterUtils.getImage("monitor-healthy.gif"); 53 public static final ImageIcon ACTIVE = 54 JMeterUtils.getImage("monitor-active.gif"); 55 public static final ImageIcon WARNING = 56 JMeterUtils.getImage("monitor-warning.gif"); 57 public static final ImageIcon DEAD = 58 JMeterUtils.getImage("monitor-dead.gif"); 59 62 public static final ImageIcon LOAD_1 = 63 JMeterUtils.getImage("monitor-load-1.gif"); 64 public static final ImageIcon LOAD_2 = 65 JMeterUtils.getImage("monitor-load-2.gif"); 66 public static final ImageIcon LOAD_3 = 67 JMeterUtils.getImage("monitor-load-3.gif"); 68 public static final ImageIcon LOAD_4 = 69 JMeterUtils.getImage("monitor-load-4.gif"); 70 public static final ImageIcon LOAD_5 = 71 JMeterUtils.getImage("monitor-load-5.gif"); 72 public static final ImageIcon LOAD_6 = 73 JMeterUtils.getImage("monitor-load-6.gif"); 74 public static final ImageIcon LOAD_7 = 75 JMeterUtils.getImage("monitor-load-7.gif"); 76 public static final ImageIcon LOAD_8 = 77 JMeterUtils.getImage("monitor-load-8.gif"); 78 public static final ImageIcon LOAD_9 = 79 JMeterUtils.getImage("monitor-load-9.gif"); 80 public static final ImageIcon LOAD_10 = 81 JMeterUtils.getImage("monitor-load-10.gif"); 82 83 85 88 public ServerPanel(MonitorModel model) 89 { 90 super(); 91 init(model); 93 } 94 95 99 public ServerPanel() 100 { 101 } 103 104 109 private void init(MonitorModel model) 110 { 111 this.setLayout(new FlowLayout ()); 112 serverField = new JLabel (model.getURL()); 113 this.add(serverField); 114 healthIcon = new JLabel (getHealthyImageIcon(model.getHealth())); 115 healthIcon.setPreferredSize(prefsize); 116 this.add(healthIcon); 117 loadIcon = new JLabel (getLoadImageIcon(model.getLoad())); 118 this.add(loadIcon); 119 timestampField = new JLabel (model.getTimestampString()); 120 this.add(timestampField); 121 } 122 123 129 public static ImageIcon getHealthyImageIcon(int health){ 130 ImageIcon i = null; 131 switch(health){ 132 case Stats.HEALTHY: 133 i = HEALTHY; 134 break; 135 case Stats.ACTIVE: 136 i = ACTIVE; 137 break; 138 case Stats.WARNING: 139 i = WARNING; 140 break; 141 case Stats.DEAD: 142 i = DEAD; 143 break; 144 } 145 return i; 146 } 147 148 154 public static ImageIcon getLoadImageIcon(int load){ 155 if (load <= 10){ 156 return LOAD_1; 157 } else if (load > 10 && load <= 20){ 158 return LOAD_2; 159 } else if (load > 20 && load <= 30){ 160 return LOAD_3; 161 } else if (load > 30 && load <= 40){ 162 return LOAD_4; 163 } else if (load > 40 && load <= 50){ 164 return LOAD_5; 165 } else if (load > 50 && load <= 60){ 166 return LOAD_6; 167 } else if (load > 60 && load <= 70){ 168 return LOAD_7; 169 } else if (load > 70 && load <= 80){ 170 return LOAD_8; 171 } else if (load > 80 && load <= 90){ 172 return LOAD_9; 173 } else { 174 return LOAD_10; 175 } 176 } 177 178 183 public void updateGui(MonitorModel stat){ 184 loadIcon.setIcon(getLoadImageIcon(stat.getLoad())); 187 healthIcon.setIcon(getHealthyImageIcon(stat.getHealth())); 188 timestampField.setText(stat.getTimestampString()); 189 this.updateGui(); 190 } 191 192 195 public void updateGui(){ 196 this.repaint(); 197 } 198 } 199 | Popular Tags |