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.protocol.http.modifier.gui;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Dimension;
023:
024: import javax.swing.BorderFactory;
025: import javax.swing.JLabel;
026: import javax.swing.JPanel;
027: import javax.swing.JScrollPane;
028: import javax.swing.JTextArea;
029: import javax.swing.JTextField;
030:
031: import org.apache.jmeter.processor.gui.AbstractPreProcessorGui;
032: import org.apache.jmeter.protocol.http.modifier.UserParameterModifier;
033: import org.apache.jmeter.testelement.TestElement;
034: import org.apache.jmeter.util.JMeterUtils;
035:
036: /**
037: * A swing panel to allow UI with the UserParameterModifier class.
038: *
039: */
040: public class UserParameterModifierGui extends AbstractPreProcessorGui {
041: // -------------------------------------------
042: // Constants and Data Members
043: // -------------------------------------------
044: private JTextField fileNameField;
045:
046: // -------------------------------------------
047: // Constructors
048: // -------------------------------------------
049:
050: public UserParameterModifierGui() {
051: super ();
052: init();
053: }
054:
055: public TestElement createTestElement() {
056: UserParameterModifier mod = new UserParameterModifier();
057: modifyTestElement(mod);
058: return mod;
059: }
060:
061: /**
062: * Modifies a given TestElement to mirror the data in the gui components.
063: *
064: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
065: */
066: public void modifyTestElement(TestElement mod) {
067: this .configureTestElement(mod);
068: ((UserParameterModifier) mod)
069: .setXmlUri(fileNameField.getText());
070: }
071:
072: /**
073: * Implements JMeterGUIComponent.clearGui
074: */
075: public void clearGui() {
076: super .clearGui();
077:
078: fileNameField.setText("users.xml"); //$NON-NLS-1$
079: }
080:
081: public void updateGui() {
082: }
083:
084: public String getLabelResource() {
085: return "http_user_parameter_modifier"; // $NON-NLS-1$
086: }
087:
088: public void configure(TestElement el) {
089: super .configure(el);
090: fileNameField.setText(((UserParameterModifier) el).getXmlUri());
091: }
092:
093: /*-------------------------------------------------------------------------
094: * Methods Private
095: *------------------------------------------------------------------------*/
096: private void init() {
097: setLayout(new BorderLayout(0, 5));
098: setBorder(makeBorder());
099: add(makeTitlePanel(), BorderLayout.NORTH);
100:
101: JPanel mainPanel = new JPanel(new BorderLayout(0, 5));
102: mainPanel.add(getFileLocator(), BorderLayout.NORTH);
103:
104: // We want the help text to look like a label, but wrap like a text area
105: JTextArea helpText = new JTextArea(JMeterUtils
106: .getResString("user_param_mod_help_note")); // $NON-NLS-1$
107: helpText.setLineWrap(true);
108: helpText.setWrapStyleWord(true);
109: helpText.setBackground(getBackground());
110: helpText.setEditable(false);
111: JLabel dummyLabel = new JLabel();
112: helpText.setFont(dummyLabel.getFont());
113: helpText.setForeground(dummyLabel.getForeground());
114: JScrollPane scroller = new JScrollPane(helpText);
115: scroller.setBorder(BorderFactory.createEmptyBorder());
116: mainPanel.add(scroller, BorderLayout.CENTER);
117:
118: add(mainPanel, BorderLayout.CENTER);
119: }
120:
121: private JPanel getFileLocator() {
122: fileNameField = new JTextField("users.xml", 15);
123: JLabel label = new JLabel(JMeterUtils.getResString("filename")); // $NON-NLS-1$
124: label.setLabelFor(fileNameField);
125:
126: JPanel fileLocator = new JPanel(new BorderLayout());
127: fileLocator.add(label, BorderLayout.WEST);
128: fileLocator.add(fileNameField, BorderLayout.CENTER);
129: return fileLocator;
130: }
131:
132: public Dimension getPreferredSize() {
133: return getMinimumSize();
134: }
135: }
|