01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.jmeter.control.gui;
20:
21: import java.awt.BorderLayout;
22:
23: import javax.swing.JLabel;
24: import javax.swing.JPanel;
25: import javax.swing.JTextField;
26:
27: import org.apache.jmeter.control.SwitchController;
28: import org.apache.jmeter.testelement.TestElement;
29: import org.apache.jmeter.util.JMeterUtils;
30:
31: public class SwitchControllerGui extends AbstractControllerGui {
32: private static final String SWITCH_LABEL = "switch_controller_label"; // $NON-NLS-1$
33:
34: private JTextField switchValue;
35:
36: public SwitchControllerGui() {
37: init();
38: }
39:
40: public TestElement createTestElement() {
41: SwitchController ic = new SwitchController();
42: modifyTestElement(ic);
43: return ic;
44: }
45:
46: /**
47: * Modifies a given TestElement to mirror the data in the gui components.
48: *
49: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
50: */
51: public void modifyTestElement(TestElement ic) {
52: configureTestElement(ic);
53: ((SwitchController) ic).setSelection(switchValue.getText());
54: }
55:
56: /**
57: * Implements JMeterGUIComponent.clearGui
58: */
59: public void clearGui() {
60: super .clearGui();
61: switchValue.setText(""); // $NON-NLS-1$
62: }
63:
64: public void configure(TestElement el) {
65: super .configure(el);
66: switchValue.setText(((SwitchController) el).getSelection());
67: }
68:
69: public String getLabelResource() {
70: return "switch_controller_title"; // $NON-NLS-1$
71: }
72:
73: private void init() {
74: setLayout(new BorderLayout(0, 5));
75: setBorder(makeBorder());
76: add(makeTitlePanel(), BorderLayout.NORTH);
77:
78: JPanel mainPanel = new JPanel(new BorderLayout());
79: mainPanel.add(createSwitchPanel(), BorderLayout.NORTH);
80: add(mainPanel, BorderLayout.CENTER);
81: }
82:
83: private JPanel createSwitchPanel() {
84: JPanel switchPanel = new JPanel(new BorderLayout(5, 0));
85: JLabel selectionLabel = new JLabel(JMeterUtils
86: .getResString(SWITCH_LABEL));
87: switchValue = new JTextField(""); // $NON-NLS-1$
88: selectionLabel.setLabelFor(switchValue);
89: switchPanel.add(selectionLabel, BorderLayout.WEST);
90: switchPanel.add(switchValue, BorderLayout.CENTER);
91: return switchPanel;
92: }
93: }
|