1 17 package org.apache.jmeter.visualizers; 18 19 import java.awt.BorderLayout ; 20 import java.awt.Container ; 21 import java.awt.Graphics ; 22 import java.awt.event.ItemEvent ; 23 import java.awt.event.ItemListener ; 24 import java.awt.Image ; 25 26 import javax.swing.border.Border ; 27 import javax.swing.border.EmptyBorder ; 28 29 import org.apache.jmeter.gui.util.VerticalPanel; 30 import org.apache.jmeter.reporters.ResultCollector; 31 import org.apache.jmeter.testelement.TestElement; 32 33 import org.apache.jmeter.samplers.Clearable; 34 import org.apache.jmeter.samplers.SampleResult; 35 import org.apache.jmeter.util.JMeterUtils; 36 import org.apache.jmeter.visualizers.gui.AbstractVisualizer; 37 38 48 public class MonitorHealthVisualizer extends AbstractVisualizer 49 implements ImageVisualizer, ItemListener , GraphListener, Clearable 50 { 51 private MonitorTabPane TABPANE; 52 private MonitorHealthPanel HEALTHPANE; 53 private MonitorPerformancePanel PERFPANE; 54 private MonitorAccumModel MODEL; 55 private MonitorGraph GRAPH; 56 57 public static final String BUFFER = "monitor.buffer.size"; 58 59 62 public MonitorHealthVisualizer() 63 { 64 MODEL = new MonitorAccumModel(); 65 GRAPH = new MonitorGraph(MODEL); 66 init(); 67 MODEL.setBufferSize(JMeterUtils.getPropDefault(BUFFER,800)); 68 } 69 70 public String getLabelResource() 71 { 72 return "monitor_health_title"; 73 } 74 75 82 public void add(SampleResult res) 83 { 84 MODEL.addSample(res); 85 } 86 87 public Image getImage() 88 { 89 Image result = GRAPH.createImage(this.getWidth(),this.getHeight()); 90 Graphics image = result.getGraphics(); 91 GRAPH.paintComponent(image); 92 return result; 93 } 94 95 public void itemStateChanged(ItemEvent e) 96 { 97 } 98 99 public synchronized void updateGui() 100 { 101 this.repaint(); 102 } 103 104 public synchronized void updateGui(Sample s) 105 { 106 this.repaint(); 107 } 108 109 112 private void init() 113 { 114 this.setLayout(new BorderLayout ()); 115 116 Border margin = new EmptyBorder (10, 10, 5, 10); 118 this.setBorder(margin); 119 120 this.add(this.makeTitlePanel(), BorderLayout.NORTH); 122 this.createTabs(); 123 } 124 125 protected void createTabs(){ 126 TABPANE = new MonitorTabPane(); 127 createHealthPane(TABPANE); 128 createPerformancePane(TABPANE); 129 this.add(TABPANE, BorderLayout.CENTER); 130 } 131 132 136 public void createHealthPane(MonitorTabPane pane){ 137 HEALTHPANE = new MonitorHealthPanel(MODEL); 138 pane.addTab(JMeterUtils.getResString("monitor_health_tab_title"), 139 HEALTHPANE); 140 } 141 142 146 public void createPerformancePane(MonitorTabPane pane){ 147 PERFPANE = new MonitorPerformancePanel(MODEL,GRAPH); 148 pane.addTab(JMeterUtils.getResString("monitor_performance_tab_title"), 149 PERFPANE); 150 } 151 152 protected Container makeTitlePanel() 153 { 154 VerticalPanel titlePanel = new VerticalPanel(); 155 titlePanel.add(createTitleLabel()); 156 titlePanel.add(getNamePanel()); 157 return titlePanel; 158 } 159 160 164 public void clear(){ 165 this.MODEL.clear(); 166 this.HEALTHPANE.clear(); 167 this.PERFPANE.clear(); 168 } 169 170 public TestElement createTestElement() 171 { 172 if (collector == null) 173 { 174 collector = new ResultCollector(); 175 } 176 modifyTestElement(collector); 177 return (TestElement) collector.clone(); 178 } 179 } 180 | Popular Tags |