Class AbstractVisualizer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ChangeListener, ClearGui, JMeterGUIComponent, UnsharedComponent, Clearable, Printable, Visualizer
Direct Known Subclasses:
AssertionVisualizer, ComparisonVisualizer, GraphVisualizer, MailerVisualizer, RespTimeGraphVisualizer, SimpleDataWriter, StatGraphVisualizer, StatVisualizer, SummaryReport, TableVisualizer, ViewResultsFullVisualizer

public abstract class AbstractVisualizer extends AbstractListenerGui implements Visualizer, ChangeListener, UnsharedComponent, Clearable
This is the base class for JMeter GUI components which can display test results in some way. It provides the following conveniences to developers: For most developers, making a new visualizer is primarily for the purpose of either calculating new statistics on the sample results that other visualizers don't calculate, or displaying the results visually in a new and interesting way. Making a new visualizer for either of these purposes is easy - just extend this class and implement the add(SampleResult) method and display the results as you see fit. This AbstractVisualizer and the default ResultCollector handle logging and registering to receive SampleEvents for you - all you need to do is include the JPanel created by makeTitlePanel somewhere in your gui to allow users set the log file.

If you are doing more than that, you may need to extend ResultCollector as well and modify the configure(TestElement), modifyTestElement(TestElement), and createTestElement() methods to create and modify your alternate ResultCollector.

See Also:
  • Field Details

    • collector

      protected ResultCollector collector
    • isStats

      protected boolean isStats
  • Constructor Details

    • AbstractVisualizer

      protected AbstractVisualizer()
  • Method Details

    • isStats

      public boolean isStats()
      Description copied from interface: Visualizer
      This method is used to indicate a visualizer generates statistics.
      Specified by:
      isStats in interface Visualizer
      true if visualiser generates statistics
    • getErrorLoggingCheckbox

      protected JCheckBox getErrorLoggingCheckbox()
      Gets the checkbox which selects whether or not only errors should be logged. Subclasses don't normally need to worry about this checkbox, because it is automatically added to the GUI in makeTitlePanel(), and the behavior is handled in this base class.
      the error logging checkbox
    • getModel

      protected ResultCollector getModel()
      Provides access to the ResultCollector model class for extending implementations. Using this method and setModel(ResultCollector) is only necessary if your visualizer requires a differently behaving ResultCollector. Using these methods will allow maximum reuse of the methods provided by AbstractVisualizer in this event.
      the associated collector
    • getFilePanel

      protected Component getFilePanel()
      Gets the file panel which allows the user to save results to a file. Subclasses don't normally need to worry about this panel, because it is automatically added to the GUI in makeTitlePanel(), and the behavior is handled in this base class.
      the file panel allowing users to save results
    • setFile

      public void setFile(String filename)
      Sets the filename which results will be saved to. This will set the filename in the FilePanel. Subclasses don't normally need to call this method, because configuration of the FilePanel is handled in this base class.
      filename - the new filename
      See Also:
    • getFile

      public String getFile()
      Gets the filename which has been entered in the FilePanel. Subclasses don't normally need to call this method, because configuration of the FilePanel is handled in this base class.
      the current filename
      See Also:
    • stateChanged

      public void stateChanged(ChangeEvent e)
      Invoked when the target of the listener has changed its state. This implementation assumes that the target is the FilePanel, and will update the result collector for the new filename.
      Specified by:
      stateChanged in interface ChangeListener
      e - the event that has occurred
    • createTestElement

      public org.apache.jmeter.testelement.TestElement createTestElement()
      Description copied from interface: JMeterGUIComponent
      JMeter test components are separated into a model and a GUI representation. The model holds the data and the GUI displays it. The GUI class is responsible for knowing how to create and initialize with data the model class that it knows how to display, and this method is called when new test elements are created.

      Since 5.6.3, the default implementation is as follows, and subclasses should override JMeterGUIComponent.makeTestElement()

       public TestElement createTestElement() {
           TestElement element = makeTestElement();
           return el;

      Before 5.6.3 the canonical implementation was as follows, however, it is recommended to avoid overriding JMeterGUIComponent.createTestElement() and override JMeterGUIComponent.makeTestElement() instead.

       public TestElement createTestElement() {
           TestElementXYZ el = new TestElementXYZ();
           return el;
      Specified by:
      createTestElement in interface JMeterGUIComponent
      the Test Element object that the GUI component represents.
    • modifyTestElement

      public void modifyTestElement(org.apache.jmeter.testelement.TestElement c)
      Description copied from interface: JMeterGUIComponent
      GUI components are responsible for populating TestElements they create with the data currently held in the GUI components. This method should overwrite whatever data is currently in the TestElement as it is called after a user has filled out the form elements in the gui with new information.

      If you override AbstractJMeterGuiComponent, you might want using AbstractJMeterGuiComponent.bindingGroup instead of overriding modifyTestElement.

      The canonical implementation looks like this:

       public void modifyTestElement(TestElement element) {
           super.modifyTestElement(element); // clear the element and assign basic fields like name, gui class, test class
           // Using the element setters (preferred):
           // If the field is empty, you probably want to remove the property instead of storing an empty string
           // See Streamline binding of UI elements to TestElement properties
           // for more details
           TestElementXYZ xyz = (TestElementXYZ) element;
           xyz.setState(StringUtils.defaultIfEmpty(guiState.getText(), null));
           xyz.setCode(StringUtils.defaultIfEmpty(guiCode.getText(), null));
           ... other GUI fields ...
           // or directly (do not use unless there is no setter for the field):
           element.setProperty(TestElementXYZ.STATE, StringUtils.defaultIfEmpty(guiState.getText(), null))
           element.setProperty(TestElementXYZ.CODE, StringUtils.defaultIfEmpty(guiCode.getText(), null))
           ... other GUI fields ...
      Specified by:
      modifyTestElement in interface JMeterGUIComponent
      modifyTestElement in class AbstractJMeterGuiComponent
      c - the TestElement to modify
    • configure

      public void configure(org.apache.jmeter.testelement.TestElement el)
      Description copied from class: AbstractJMeterGuiComponent
      A newly created gui component can be initialized with the contents of a Test Element object by calling this method. The component is responsible for querying the Test Element object for the relevant information to display in its GUI.

      AbstractJMeterGuiComponent provides a partial implementation of this method, setting the name of the component and its enabled status. Subclasses should override this method, performing their own configuration as needed, but also calling this super-implementation.

      Specified by:
      configure in interface JMeterGUIComponent
      configure in class AbstractJMeterGuiComponent
      el - the TestElement to configure
    • configureTestElement

      protected void configureTestElement(AbstractListenerElement mc)
      This provides a convenience for extenders when they implement the JMeterGUIComponent.createTestElement() method. This method will set the name, gui class, and test class for the created Test Element. It should be called by every extending class when creating Test Elements, as that will best assure consistent behavior.
      mc - the TestElement being created.
    • makeTitlePanel

      protected Container makeTitlePanel()
      Create a standard title section for JMeter components. This includes the title for the component and the Name Panel allowing the user to change the name for the component. The AbstractVisualizer also adds the FilePanel allowing the user to save the results, and the error logging checkbox, allowing the user to choose whether or not only errors should be logged.

      This method is typically added to the top of the component at the beginning of the component's init method.

      makeTitlePanel in class AbstractJMeterGuiComponent
      a panel containing the component title, name panel, file panel, and error logging checkbox
    • setModel

      protected void setModel(ResultCollector collector)
      Provides extending classes the opportunity to set the ResultCollector model for the Visualizer. This is useful to allow maximum reuse of the methods from AbstractVisualizer.
      collector - ResultCollector for the visualizer
    • clearGui

      public void clearGui()
      Description copied from class: AbstractJMeterGuiComponent
      Provides a default implementation that resets the name field to the value of getStaticLabel(), reset comment and sets enabled to true. Your GUI may need more things cleared, in which case you should override, clear the extra fields, and still call super.clearGui().
      Specified by:
      clearGui in interface ClearGui
      clearGui in class AbstractJMeterGuiComponent