Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.examples.sampler.gui » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *   http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    *
   17    */
   18   
   19   /*
   20    * Example Sampler GUI (non-beans version)
   21    */
   22   
   23   package org.apache.jmeter.examples.sampler.gui;
   24   
   25   import java.awt.BorderLayout;
   26   import java.awt.Component;
   27   
   28   import javax.swing.JLabel;
   29   import javax.swing.JPanel;
   30   import javax.swing.JTextArea;
   31   import org.apache.jmeter.examples.sampler.ExampleSampler;
   32   import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
   33   import org.apache.jmeter.testelement.TestElement;
   34   import org.apache.jmeter.util.JMeterUtils;
   35   
   36   /**
   37    * Example Sampler (non-Bean version)
   38    *
   39    * This class is responsible for ensuring that the Sampler data is kept in step
   40    * with the GUI.
   41    *
   42    * The GUI class is not invoked in non-GUI mode, so it should not perform any
   43    * additional setup that a test would need at run-time
   44    *
   45    */
   46   public class ExampleSamplerGui extends AbstractSamplerGui {
   47   
   48       private JTextArea data;
   49   
   50       public ExampleSamplerGui() {
   51           init();
   52       }
   53   
   54       /*
   55        * (non-Javadoc)
   56        *
   57        * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
   58        */
   59       public String getLabelResource() {
   60           return "example_title"; // $NON-NLS-1$
   61       }
   62   
   63       /*
   64        * (non-Javadoc) Copy the data from the test element to the GUI
   65        *
   66        * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(org.apache.jmeter.testelement.TestElement)
   67        */
   68       public void configure(TestElement element) {
   69           data.setText(element.getPropertyAsString(ExampleSampler.DATA));
   70           super.configure(element);
   71       }
   72   
   73       /*
   74        * (non-Javadoc) Create the corresponding Test Element and set up its data
   75        *
   76        * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
   77        */
   78       public TestElement createTestElement() {
   79           ExampleSampler sampler = new ExampleSampler();
   80           modifyTestElement(sampler);
   81           return sampler;
   82       }
   83   
   84       /*
   85        * (non-Javadoc) Modifies a given TestElement to mirror the data in the gui
   86        * components.
   87        *
   88        * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
   89        */
   90       public void modifyTestElement(TestElement te) {
   91           te.clear();
   92           configureTestElement(te);
   93           te.setProperty(ExampleSampler.DATA, data.getText());
   94       }
   95   
   96       /*
   97        * Helper method to set up the GUI screen
   98        */
   99       private void init() {
  100           // Standard setup
  101           setLayout(new BorderLayout(0, 5));
  102           setBorder(makeBorder());
  103           add(makeTitlePanel(), BorderLayout.NORTH); // Add the standard title
  104   
  105           // Specific setup
  106           add(createDataPanel(), BorderLayout.CENTER);
  107       }
  108   
  109       /*
  110        * Create a data input text field
  111        *
  112        * @return the panel for entering the data
  113        */
  114       private Component createDataPanel() {
  115           JLabel label = new JLabel(JMeterUtils.getResString("example_data")); //$NON-NLS-1$
  116   
  117           data = new JTextArea();
  118           data.setName(ExampleSampler.DATA);
  119           label.setLabelFor(data);
  120   
  121           JPanel dataPanel = new JPanel(new BorderLayout(5, 0));
  122           dataPanel.add(label, BorderLayout.WEST);
  123           dataPanel.add(data, BorderLayout.CENTER);
  124   
  125           return dataPanel;
  126       }
  127   
  128       public void clearGui() {
  129           super.clearGui();
  130           data.setText(""); // $NON-NLS-1$
  131   
  132       }
  133   }

Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.examples.sampler.gui » [javadoc | source]