1 17 package org.apache.jmeter.visualizers; 18 19 import java.awt.BorderLayout ; 20 import java.awt.Component ; 21 import java.awt.Dimension ; 22 import java.awt.Font ; 23 import javax.swing.BoxLayout ; 24 import javax.swing.ImageIcon ; 25 import javax.swing.JLabel ; 26 import javax.swing.JPanel ; 27 28 import java.util.HashMap ; 29 30 import javax.swing.JScrollPane ; 31 32 import org.apache.jmeter.util.JMeterUtils; 33 import org.apache.jmeter.samplers.Clearable; 34 39 public class MonitorHealthPanel extends JPanel 40 implements MonitorListener, Clearable 41 { 42 private HashMap SERVERMAP = new HashMap (); 43 private JPanel SERVERS = null; 44 private MonitorAccumModel MODEL; 45 private JScrollPane SCROLL = null; 46 47 Font plainText = new Font ("plain", Font.PLAIN, 9); 48 public static final String INFO_H = 49 JMeterUtils.getResString("monitor_equation_healthy"); 50 public static final String INFO_A = 51 JMeterUtils.getResString("monitor_equation_active"); 52 public static final String INFO_W = 53 JMeterUtils.getResString("monitor_equation_warning"); 54 public static final String INFO_D = 55 JMeterUtils.getResString("monitor_equation_dead"); 56 public static final String INFO_LOAD = 57 JMeterUtils.getResString("monitor_equation_load"); 58 59 63 public MonitorHealthPanel() 64 { 65 } 67 68 71 public MonitorHealthPanel(MonitorAccumModel model) 72 { 73 this.MODEL = model; 74 this.MODEL.addListener(this); 75 init(); 76 } 77 78 82 protected void init(){ 83 this.setLayout(new BorderLayout ()); 84 ImageIcon legend = JMeterUtils.getImage("monitor-legend.gif"); 85 JLabel label = new JLabel (legend); 86 label.setPreferredSize(new Dimension (550,25)); 87 this.add(label,BorderLayout.NORTH); 88 89 this.SERVERS = new JPanel (); 90 this.SERVERS.setLayout(new BoxLayout (SERVERS, BoxLayout.Y_AXIS)); 91 this.SERVERS.setAlignmentX(Component.LEFT_ALIGNMENT); 92 93 SCROLL = new JScrollPane (this.SERVERS); 94 SCROLL.setPreferredSize(new Dimension (300,300)); 95 this.add(SCROLL,BorderLayout.CENTER); 96 97 String eqstring1 = " " + INFO_H + " | " + INFO_A; 99 String eqstring2 = " " + INFO_W + " | " + INFO_D; 100 String eqstring3 = " " + INFO_LOAD; 101 JLabel eqs = new JLabel (); 102 eqs.setLayout(new BorderLayout ()); 103 eqs.setPreferredSize(new Dimension (500,60)); 104 eqs.add(new JLabel (eqstring1),BorderLayout.NORTH); 105 eqs.add(new JLabel (eqstring2),BorderLayout.CENTER); 106 eqs.add(new JLabel (eqstring3),BorderLayout.SOUTH); 107 this.add(eqs,BorderLayout.SOUTH); 108 } 109 110 114 public void addSample(MonitorModel model){ 115 if (SERVERMAP.containsKey(model.getURL())){ 116 ServerPanel pane = null; 117 if(SERVERMAP.get(model.getURL()) != null){ 118 pane = (ServerPanel)SERVERMAP.get((model.getURL())); 119 } else { 120 pane = new ServerPanel(model); 121 SERVERMAP.put(model.getURL(),pane); 122 } 123 pane.updateGui(model); 124 } else { 125 ServerPanel newpane = new ServerPanel(model); 126 SERVERMAP.put(model.getURL(),newpane); 127 this.SERVERS.add(newpane); 128 newpane.updateGui(model); 129 } 130 this.SERVERS.updateUI(); 131 } 132 133 137 public void clear(){ 138 this.SERVERMAP.clear(); 139 this.SERVERS.removeAll(); 140 this.SERVERS.updateUI(); 141 } 142 } 143 | Popular Tags |