1 18 19 package org.apache.jmeter.visualizers.gui; 20 21 import java.awt.Component ; 22 import java.awt.Container ; 23 import java.util.Arrays ; 24 import java.util.Collection ; 25 26 import javax.swing.JCheckBox ; 27 import javax.swing.JPopupMenu ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 31 import org.apache.jmeter.gui.AbstractJMeterGuiComponent; 32 import org.apache.jmeter.gui.UnsharedComponent; 33 import org.apache.jmeter.gui.util.FilePanel; 34 import org.apache.jmeter.gui.util.MenuFactory; 35 import org.apache.jmeter.reporters.AbstractListenerElement; 36 import org.apache.jmeter.reporters.ResultCollector; 37 import org.apache.jmeter.testelement.TestElement; 38 import org.apache.jmeter.util.JMeterUtils; 39 import org.apache.jmeter.visualizers.Visualizer; 40 import org.apache.jorphan.logging.LoggingManager; 41 import org.apache.log.Logger; 42 43 99 public abstract class AbstractVisualizer 100 extends AbstractJMeterGuiComponent 101 implements Visualizer, ChangeListener , UnsharedComponent 102 { 103 104 private static transient Logger log =LoggingManager.getLoggerForClass(); 105 106 107 private FilePanel filePanel; 108 109 110 private JCheckBox errorLogging; 111 112 protected ResultCollector collector; 113 114 public AbstractVisualizer() 115 { 116 super(); 117 118 errorLogging = 119 new JCheckBox (JMeterUtils.getResString("log_errors_only")); 120 121 filePanel = new FilePanel( 122 JMeterUtils.getResString("file_visualizer_output_file"),".jtl"); 123 filePanel.addChangeListener(this); 124 filePanel.add(errorLogging); 125 126 } 127 128 137 protected JCheckBox getErrorLoggingCheckbox() 138 { 139 return errorLogging; 140 } 141 142 149 protected ResultCollector getModel() 150 { 151 return collector; 152 } 153 154 162 protected Component getFilePanel() 163 { 164 return filePanel; 165 } 166 167 177 public void setFile(String filename) 178 { 179 filePanel.setFilename(filename); 182 } 183 184 193 public String getFile() 194 { 195 return filePanel.getFilename(); 198 } 199 200 201 202 213 public JPopupMenu createPopupMenu() 214 { 215 return MenuFactory.getDefaultVisualizerMenu(); 216 } 217 218 225 public void stateChanged(ChangeEvent e) 226 { 227 log.info("getting new collector"); 228 collector = (ResultCollector) createTestElement(); 229 try 230 { 231 collector.loadExistingFile(); 232 } 233 catch (Exception err) 234 { 235 log.debug("Error occurred while loading file", err); 236 } 237 } 238 239 248 public Collection getMenuCategories() 249 { 250 return Arrays.asList(new String [] { MenuFactory.LISTENERS }); 251 } 252 253 254 public TestElement createTestElement() 255 { 256 if (collector == null) 257 { 258 collector = new ResultCollector(); 259 } 260 modifyTestElement(collector); 261 return (TestElement) collector.clone(); 262 } 263 264 265 public void modifyTestElement(TestElement c) 266 { 267 configureTestElement((AbstractListenerElement) c); 268 if (c instanceof ResultCollector) 269 { 270 ResultCollector rc = (ResultCollector) c; 271 rc.setErrorLogging(errorLogging.isSelected()); 272 rc.setFilename(getFile()); 273 collector = rc; 274 } 275 } 276 277 278 public void configure(TestElement el) 279 { 280 super.configure(el); 281 setFile(el.getPropertyAsString(ResultCollector.FILENAME)); 282 ResultCollector rc = (ResultCollector) el; 283 errorLogging.setSelected(rc.isErrorLogging()); 284 } 285 286 295 protected void configureTestElement(AbstractListenerElement mc) 296 { 297 super.configureTestElement(mc); 306 mc.setListener(this); 307 } 308 309 323 protected Container makeTitlePanel() 324 { 325 Container panel = super.makeTitlePanel(); 326 panel.add(getFilePanel()); 329 return panel; 330 } 331 332 338 protected void setModel(ResultCollector collector) 339 { 340 this.collector = collector; 341 } 342 } | Popular Tags |