KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > modifier > gui > UserParameterModifierGui


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/modifier/gui/UserParameterModifierGui.java,v 1.11 2004/03/05 01:38:17 sebb Exp $
2
/*
3  * Copyright 2001-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.protocol.http.modifier.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Dimension JavaDoc;
23
24 import javax.swing.BorderFactory JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.JScrollPane JavaDoc;
28 import javax.swing.JTextArea JavaDoc;
29 import javax.swing.JTextField JavaDoc;
30
31 import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
32 import org.apache.jmeter.protocol.http.modifier.UserParameterModifier;
33 import org.apache.jmeter.testelement.TestElement;
34 import org.apache.jmeter.util.JMeterUtils;
35
36 /**
37  * A swing panel to allow UI with the UserParameterModifier class.
38  *
39  * @version $Revision: 1.11 $ on $Date: 2004/03/05 01:38:17 $
40  */

41 public class UserParameterModifierGui extends AbstractPreProcessorGui
42 {
43     //-------------------------------------------
44
// Constants and Data Members
45
//-------------------------------------------
46
private JTextField JavaDoc fileNameField;
47  
48     //-------------------------------------------
49
// Constructors
50
//-------------------------------------------
51

52     public UserParameterModifierGui()
53     {
54         super();
55         init();
56     }
57     
58     public TestElement createTestElement()
59     {
60         UserParameterModifier mod = new UserParameterModifier();
61         modifyTestElement(mod);
62         return mod;
63     }
64
65     /**
66      * Modifies a given TestElement to mirror the data in the gui components.
67      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
68      */

69     public void modifyTestElement(TestElement mod)
70     {
71         this.configureTestElement(mod);
72         ((UserParameterModifier) mod).setXmlUri(fileNameField.getText());
73     }
74
75     public void updateGui()
76     {
77     }
78
79     public String JavaDoc getLabelResource()
80     {
81         return "http_user_parameter_modifier";
82     }
83
84     public void configure(TestElement el)
85     {
86         super.configure(el);
87         fileNameField.setText(((UserParameterModifier) el).getXmlUri());
88     }
89
90     /*-------------------------------------------------------------------------
91      * Methods Private
92      *------------------------------------------------------------------------*/

93     private void init()
94     {
95         setLayout(new BorderLayout JavaDoc(0, 5));
96         setBorder(makeBorder());
97         add(makeTitlePanel(), BorderLayout.NORTH);
98
99         JPanel JavaDoc mainPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(0, 5));
100         mainPanel.add(getFileLocator(), BorderLayout.NORTH);
101
102         // We want the help text to look like a label, but wrap like a text area
103
JTextArea JavaDoc helpText =
104             new JTextArea JavaDoc(JMeterUtils.getResString("user_param_mod_help_note"));
105         helpText.setLineWrap(true);
106         helpText.setWrapStyleWord(true);
107         helpText.setBackground(getBackground());
108         helpText.setEditable(false);
109         JLabel JavaDoc dummyLabel = new JLabel JavaDoc();
110         helpText.setFont(dummyLabel.getFont());
111         helpText.setForeground(dummyLabel.getForeground());
112         JScrollPane JavaDoc scroller = new JScrollPane JavaDoc(helpText);
113         scroller.setBorder(BorderFactory.createEmptyBorder());
114         mainPanel.add(scroller, BorderLayout.CENTER);
115
116         add(mainPanel, BorderLayout.CENTER);
117     }
118
119     private JPanel JavaDoc getFileLocator()
120     {
121         fileNameField = new JTextField JavaDoc("users.xml", 15);
122         JLabel JavaDoc label = new JLabel JavaDoc(JMeterUtils.getResString("filename"));
123         label.setLabelFor(fileNameField);
124
125         JPanel JavaDoc fileLocator = new JPanel JavaDoc(new BorderLayout JavaDoc());
126         fileLocator.add(label, BorderLayout.WEST);
127         fileLocator.add(fileNameField, BorderLayout.CENTER);
128         return fileLocator;
129     }
130
131     public Dimension JavaDoc getPreferredSize()
132     {
133         return getMinimumSize();
134     }
135 }
Popular Tags