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.timers.gui;
020:
021: import javax.swing.Box;
022: import javax.swing.JComponent;
023: import javax.swing.JLabel;
024: import javax.swing.JOptionPane;
025: import javax.swing.JTextField;
026:
027: import org.apache.jmeter.testelement.TestElement;
028: import org.apache.jmeter.timers.ConstantTimer;
029: import org.apache.jmeter.util.JMeterUtils;
030: import org.apache.jorphan.gui.layout.VerticalLayout;
031:
032: /**
033: * The GUI for ConstantTimer.
034: *
035: */
036: public class ConstantTimerGui extends AbstractTimerGui {
037: /**
038: * The default value for the delay.
039: */
040: private static final String DEFAULT_DELAY = "300";
041:
042: private static final String DELAY_FIELD = "Delay Field";
043:
044: private JTextField delayField;
045:
046: /**
047: * No-arg constructor.
048: */
049: public ConstantTimerGui() {
050: init();
051: }
052:
053: /**
054: * Handle an error.
055: *
056: * @param e
057: * the Exception that was thrown.
058: * @param thrower
059: * the JComponent that threw the Exception.
060: */
061: public static void error(Exception e, JComponent thrower) {
062: JOptionPane.showMessageDialog(thrower, e, "Error",
063: JOptionPane.ERROR_MESSAGE);
064: }
065:
066: public String getLabelResource() {
067: return "constant_timer_title"; // $NON-NLS-1$
068: }
069:
070: /**
071: * Create the test element underlying this GUI component.
072: *
073: * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
074: */
075: public TestElement createTestElement() {
076: ConstantTimer timer = new ConstantTimer();
077: modifyTestElement(timer);
078: return timer;
079: }
080:
081: /**
082: * Modifies a given TestElement to mirror the data in the gui components.
083: *
084: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
085: */
086: public void modifyTestElement(TestElement timer) {
087: this .configureTestElement(timer);
088: ((ConstantTimer) timer).setDelay(delayField.getText());
089: }
090:
091: /**
092: * Configure this GUI component from the underlying TestElement.
093: *
094: * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
095: */
096: public void configure(TestElement el) {
097: super .configure(el);
098: delayField.setText(((ConstantTimer) el).getDelay());
099: }
100:
101: /**
102: * Initialize this component.
103: */
104: private void init() {
105: setLayout(new VerticalLayout(5, VerticalLayout.BOTH,
106: VerticalLayout.TOP));
107:
108: setBorder(makeBorder());
109: add(makeTitlePanel());
110:
111: Box delayPanel = Box.createHorizontalBox();
112: JLabel delayLabel = new JLabel(JMeterUtils
113: .getResString("constant_timer_delay"));//$NON-NLS-1$
114: delayPanel.add(delayLabel);
115:
116: delayField = new JTextField(6);
117: delayField.setText(DEFAULT_DELAY);
118: delayField.setName(DELAY_FIELD);
119: delayPanel.add(delayField);
120: add(delayPanel);
121: }
122:
123: /*
124: * (non-Javadoc)
125: *
126: * @see org.apache.jmeter.gui.JMeterGUIComponent#clearGui()
127: */
128: public void clearGui() {
129: delayField.setText(DEFAULT_DELAY);
130: super.clearGui();
131: }
132: }
|