KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > control > gui > WhileControllerGui


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/control/gui/WhileControllerGui.java,v 1.1.2.2 2005/03/05 11:14:28 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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 package org.apache.jmeter.control.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24
25 import javax.swing.Box JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JPanel JavaDoc;
28 import javax.swing.JTextField JavaDoc;
29
30 import org.apache.jmeter.control.WhileController;
31 import org.apache.jmeter.gui.util.FocusRequester;
32 import org.apache.jmeter.testelement.TestElement;
33 import org.apache.jmeter.util.JMeterUtils;
34
35 public class WhileControllerGui extends AbstractControllerGui
36     implements ActionListener JavaDoc
37 {
38
39       private static final String JavaDoc CONDITION_LABEL = "while_controller_label";
40
41     /**
42      * A field allowing the user to specify the condition (not yet used).
43      */

44     private JTextField JavaDoc theCondition;
45
46     /** The name of the condition field component. */
47     private static final String JavaDoc CONDITION = "While_Condition";
48
49     /**
50      * Create a new LoopControlPanel as a standalone component.
51      */

52     public WhileControllerGui() {
53         init();
54     }
55
56     /**
57      * A newly created component can be initialized with the contents of
58      * a Test Element object by calling this method. The component is
59      * responsible for querying the Test Element object for the
60      * relevant information to display in its GUI.
61      *
62      * @param element the TestElement to configure
63      */

64     public void configure(TestElement element) {
65         super.configure(element);
66         if (element instanceof WhileController) {
67             theCondition.setText(((WhileController) element).getCondition());
68         }
69
70     }
71
72     /**
73      * Implements JMeterGUIComponent.createTestElement()
74      */

75     public TestElement createTestElement() {
76         WhileController controller = new WhileController();
77         modifyTestElement(controller);
78         return controller;
79     }
80
81     /**
82      * Implements JMeterGUIComponent.modifyTestElement(TestElement)
83      */

84     public void modifyTestElement(TestElement controller) {
85         configureTestElement(controller);
86         if (controller instanceof WhileController)
87         {
88             if (theCondition.getText().length() > 0) {
89                 ((WhileController) controller).setCondition(theCondition.getText());
90             } else {
91                 ((WhileController) controller).setCondition("");
92             }
93         }
94     }
95
96     /**
97      * Invoked when an action occurs. This implementation assumes that the
98      * target component is the infinite loops checkbox.
99      *
100      * @param event the event that has occurred
101      */

102     public void actionPerformed(ActionEvent JavaDoc event) {
103         new FocusRequester(theCondition);
104     }
105
106     public String JavaDoc getLabelResource() {
107         return "while_controller_title";
108     }
109
110     /**
111      * Initialize the GUI components and layout for this component.
112      */

113     private void init()
114     {
115         setLayout(new BorderLayout JavaDoc(0, 5));
116         setBorder(makeBorder());
117         add(makeTitlePanel(), BorderLayout.NORTH);
118
119         JPanel JavaDoc mainPanel = new JPanel JavaDoc(new BorderLayout JavaDoc());
120         mainPanel.add(createConditionPanel(), BorderLayout.NORTH);
121         add(mainPanel, BorderLayout.CENTER);
122
123     }
124
125
126     /**
127      * Create a GUI panel containing the condition.
128      * TODO make use of the field
129      * @return a GUI panel containing the condition components
130      */

131     private JPanel JavaDoc createConditionPanel() {
132         JPanel JavaDoc conditionPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(5, 0));
133
134         // Condition LABEL
135
JLabel JavaDoc conditionLabel =
136         new JLabel JavaDoc(JMeterUtils.getResString( CONDITION_LABEL ));
137         conditionPanel.add(conditionLabel, BorderLayout.WEST);
138
139         // TEXT FIELD
140
theCondition = new JTextField JavaDoc(""); // This means exit if last sample failed
141
theCondition.setName(CONDITION);
142         conditionLabel.setLabelFor(theCondition);
143         conditionPanel.add(theCondition, BorderLayout.CENTER);
144         theCondition.addActionListener(this);
145
146         conditionPanel.add(
147             Box.createHorizontalStrut( conditionLabel.getPreferredSize().width
148             + theCondition.getPreferredSize().width)
149             , BorderLayout.NORTH);
150
151         return conditionPanel;
152     }
153 }
Popular Tags