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.reporters.gui;
020:
021: import java.awt.BorderLayout;
022:
023: import javax.swing.Box;
024: import javax.swing.JCheckBox;
025: import javax.swing.JLabel;
026: import javax.swing.JPanel;
027: import javax.swing.JTextField;
028:
029: import org.apache.jmeter.reporters.ResultSaver;
030: import org.apache.jmeter.samplers.Clearable;
031: import org.apache.jmeter.processor.gui.AbstractPostProcessorGui;
032: import org.apache.jmeter.testelement.TestElement;
033: import org.apache.jmeter.util.JMeterUtils;
034:
035: /**
036: * Create a ResultSaver test element, which saves the sample information in set
037: * of files
038: *
039: */
040: public class ResultSaverGui extends AbstractPostProcessorGui implements
041: Clearable {
042:
043: private JTextField filename;
044:
045: private JCheckBox errorsOnly;
046:
047: public ResultSaverGui() {
048: super ();
049: init();
050: }
051:
052: /**
053: * @see org.apache.jmeter.gui.JMeterGUIComponent#getStaticLabel()
054: */
055: public String getLabelResource() {
056: return "resultsaver_title"; // $NON-NLS-1$
057: }
058:
059: /**
060: * @see org.apache.jmeter.gui.JMeterGUIComponent#configure(TestElement)
061: */
062: public void configure(TestElement el) {
063: super .configure(el);
064: filename.setText(el.getPropertyAsString(ResultSaver.FILENAME));
065: errorsOnly.setSelected(el
066: .getPropertyAsBoolean(ResultSaver.ERRORS_ONLY));
067: }
068:
069: /**
070: * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
071: */
072: public TestElement createTestElement() {
073: ResultSaver ResultSaver = new ResultSaver();
074: modifyTestElement(ResultSaver);
075: return ResultSaver;
076: }
077:
078: /**
079: * Modifies a given TestElement to mirror the data in the gui components.
080: *
081: * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
082: */
083: public void modifyTestElement(TestElement te) {
084: super .configureTestElement(te);
085: te.setProperty(ResultSaver.FILENAME, filename.getText());
086: te
087: .setProperty(ResultSaver.ERRORS_ONLY, errorsOnly
088: .isSelected());
089: }
090:
091: /**
092: * Implements JMeterGUIComponent.clearGui
093: */
094: public void clearGui() {
095: super .clearGui();
096:
097: filename.setText(""); //$NON-NLS-1$
098: errorsOnly.setSelected(false);
099: }
100:
101: private void init() {
102: setLayout(new BorderLayout());
103: setBorder(makeBorder());
104: Box box = Box.createVerticalBox();
105: box.add(makeTitlePanel());
106: box.add(createFilenamePanel());
107: errorsOnly = new JCheckBox(JMeterUtils
108: .getResString("resultsaver_errors")); // $NON-NLS-1$
109: box.add(errorsOnly);
110: add(box, BorderLayout.NORTH);
111:
112: // add(makeTitlePanel(),BorderLayout.NORTH);
113: }
114:
115: private JPanel createFilenamePanel()// TODO ought to be a FileChooser ...
116: {
117: JLabel label = new JLabel(JMeterUtils
118: .getResString("resultsaver_prefix")); // $NON-NLS-1$
119:
120: filename = new JTextField(10);
121: filename.setName(ResultSaver.FILENAME);
122: label.setLabelFor(filename);
123:
124: JPanel filenamePanel = new JPanel(new BorderLayout(5, 0));
125: filenamePanel.add(label, BorderLayout.WEST);
126: filenamePanel.add(filename, BorderLayout.CENTER);
127: return filenamePanel;
128: }
129:
130: // Needed to avoid Class cast error in Clear.java
131: public void clearData() {
132: }
133:
134: }
|