001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /*
020: * Example Sampler GUI (non-beans version)
021: */
022:
023: package org.apache.jmeter.examples.sampler.gui;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Component;
027:
028: import javax.swing.JLabel;
029: import javax.swing.JPanel;
030: import javax.swing.JTextArea;
031: import org.apache.jmeter.examples.sampler.ExampleSampler;
032: import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
033: import org.apache.jmeter.testelement.TestElement;
034: import org.apache.jmeter.util.JMeterUtils;
035:
036: /**
037: * Example Sampler (non-Bean version)
038: *
039: * This class is responsible for ensuring that the Sampler data is kept in step
040: * with the GUI.
041: *
042: * The GUI class is not invoked in non-GUI mode, so it should not perform any
043: * additional setup that a test would need at run-time
044: *
045: */
046: public class ExampleSamplerGui extends AbstractSamplerGui {
047:
048: private JTextArea data;
049:
050: public ExampleSamplerGui() {
051: init();
052: }
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
058: */
059: public String getLabelResource() {
060: return "example_title"; // $NON-NLS-1$
061: }
062:
063: /*
064: * (non-Javadoc) Copy the data from the test element to the GUI
065: *
066: * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(org.apache.jmeter.testelement.TestElement)
067: */
068: public void configure(TestElement element) {
069: data.setText(element.getPropertyAsString(ExampleSampler.DATA));
070: super .configure(element);
071: }
072:
073: /*
074: * (non-Javadoc) Create the corresponding Test Element and set up its data
075: *
076: * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
077: */
078: public TestElement createTestElement() {
079: ExampleSampler sampler = new ExampleSampler();
080: modifyTestElement(sampler);
081: return sampler;
082: }
083:
084: /*
085: * (non-Javadoc) Modifies a given TestElement to mirror the data in the gui
086: * components.
087: *
088: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
089: */
090: public void modifyTestElement(TestElement te) {
091: te.clear();
092: configureTestElement(te);
093: te.setProperty(ExampleSampler.DATA, data.getText());
094: }
095:
096: /*
097: * Helper method to set up the GUI screen
098: */
099: 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
116: .getResString("example_data")); //$NON-NLS-1$
117:
118: data = new JTextArea();
119: data.setName(ExampleSampler.DATA);
120: label.setLabelFor(data);
121:
122: JPanel dataPanel = new JPanel(new BorderLayout(5, 0));
123: dataPanel.add(label, BorderLayout.WEST);
124: dataPanel.add(data, BorderLayout.CENTER);
125:
126: return dataPanel;
127: }
128:
129: public void clearGui() {
130: super .clearGui();
131: data.setText(""); // $NON-NLS-1$
132:
133: }
134: }
|