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: package org.apache.jmeter.modifiers.gui;
020:
021: import javax.swing.JCheckBox;
022:
023: import org.apache.jmeter.modifiers.CounterConfig;
024: import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
025: import org.apache.jmeter.testelement.TestElement;
026: import org.apache.jmeter.util.JMeterUtils;
027: import org.apache.jorphan.gui.JLabeledTextField;
028: import org.apache.jorphan.gui.layout.VerticalLayout;
029:
030: public class CounterConfigGui extends AbstractPreProcessorGui {
031: private JLabeledTextField startField, incrField, endField,
032: varNameField, formatField;
033:
034: private JCheckBox perUserField;
035:
036: public CounterConfigGui() {
037: super ();
038: init();
039: }
040:
041: public String getLabelResource() {
042: return "counter_config_title";//$NON-NLS-1$
043: }
044:
045: /**
046: * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
047: */
048: public TestElement createTestElement() {
049: CounterConfig config = new CounterConfig();
050: modifyTestElement(config);
051: return config;
052: }
053:
054: /**
055: * Modifies a given TestElement to mirror the data in the gui components.
056: *
057: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
058: */
059: public void modifyTestElement(TestElement c) {
060: if (c instanceof CounterConfig) {
061: CounterConfig config = (CounterConfig) c;
062: config.setStart(startField.getText());
063: // Bug 22820 if (endField.getText().length() > 0)
064: {
065: config.setEnd(endField.getText());
066: }
067: config.setIncrement(incrField.getText());
068: config.setVarName(varNameField.getText());
069: config.setFormat(formatField.getText());
070: config.setIsPerUser(perUserField.isSelected());
071: }
072: super .configureTestElement(c);
073: }
074:
075: /**
076: * Implements JMeterGUIComponent.clearGui
077: */
078: public void clearGui() {
079: super .clearGui();
080:
081: startField.setText(""); //$NON-NLS-1$
082: incrField.setText(""); //$NON-NLS-1$
083: endField.setText(""); //$NON-NLS-1$
084: varNameField.setText(""); //$NON-NLS-1$
085: formatField.setText(""); //$NON-NLS-1$
086: perUserField.setSelected(false);
087: }
088:
089: public void configure(TestElement element) {
090: super .configure(element);
091: CounterConfig config = (CounterConfig) element;
092: startField.setText(config.getStartAsString());
093: endField.setText(config.getEndAsString());
094: incrField.setText(config.getIncrementAsString());
095: formatField.setText(config.getFormat());
096: varNameField.setText(config.getVarName());
097: perUserField.setSelected(config.isPerUser());
098: }
099:
100: private void init() {
101: setBorder(makeBorder());
102: setLayout(new VerticalLayout(5, VerticalLayout.BOTH));
103:
104: startField = new JLabeledTextField(JMeterUtils
105: .getResString("start"));//$NON-NLS-1$
106: incrField = new JLabeledTextField(JMeterUtils
107: .getResString("increment"));//$NON-NLS-1$
108: endField = new JLabeledTextField(JMeterUtils
109: .getResString("max"));//$NON-NLS-1$
110: varNameField = new JLabeledTextField(JMeterUtils
111: .getResString("var_name"));//$NON-NLS-1$
112: formatField = new JLabeledTextField(JMeterUtils
113: .getResString("format"));//$NON-NLS-1$
114: perUserField = new JCheckBox(JMeterUtils
115: .getResString("counter_per_user"));//$NON-NLS-1$
116:
117: add(makeTitlePanel());
118: add(startField);
119: add(incrField);
120: add(endField);
121: add(formatField);
122: add(varNameField);
123: add(perUserField);
124: }
125: }
|