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: /**
020: * GUI class supporting the MD5Hex assertion functionality.
021: *
022: */package org.apache.jmeter.assertions.gui;
023:
024: import java.awt.BorderLayout;
025:
026: import javax.swing.BorderFactory;
027: import javax.swing.JLabel;
028: import javax.swing.JPanel;
029: import javax.swing.JTextField;
030:
031: import org.apache.jmeter.assertions.MD5HexAssertion;
032: import org.apache.jmeter.gui.util.HorizontalPanel;
033: import org.apache.jmeter.testelement.TestElement;
034: import org.apache.jmeter.util.JMeterUtils;
035:
036: public class MD5HexAssertionGUI extends AbstractAssertionGui {
037:
038: private JTextField md5HexInput;
039:
040: public MD5HexAssertionGUI() {
041: init();
042: }
043:
044: private void init() {
045:
046: setLayout(new BorderLayout(0, 10));
047: setBorder(makeBorder());
048:
049: add(makeTitlePanel(), BorderLayout.NORTH);
050:
051: JPanel mainPanel = new JPanel(new BorderLayout());
052:
053: // USER_INPUT
054: HorizontalPanel md5HexPanel = new HorizontalPanel();
055: md5HexPanel.setBorder(BorderFactory.createTitledBorder(
056: BorderFactory.createEtchedBorder(), JMeterUtils
057: .getResString("md5hex_assertion_md5hex_test"))); // $NON-NLS-1$
058:
059: md5HexPanel.add(new JLabel(JMeterUtils
060: .getResString("md5hex_assertion_label"))); //$NON-NLS-1$
061:
062: md5HexInput = new JTextField(25);
063: // md5HexInput.addFocusListener(this);
064: md5HexPanel.add(md5HexInput);
065:
066: mainPanel.add(md5HexPanel, BorderLayout.NORTH);
067: add(mainPanel, BorderLayout.CENTER);
068:
069: }
070:
071: public void configure(TestElement el) {
072: super .configure(el);
073: MD5HexAssertion assertion = (MD5HexAssertion) el;
074: this .md5HexInput.setText(String.valueOf(assertion
075: .getAllowedMD5Hex()));
076: }
077:
078: public String getLabelResource() {
079: return "md5hex_assertion_title"; // $NON-NLS-1$
080: }
081:
082: /*
083: * @return
084: */
085: public TestElement createTestElement() {
086:
087: MD5HexAssertion el = new MD5HexAssertion();
088: modifyTestElement(el);
089: return el;
090:
091: }
092:
093: /*
094: * @param element
095: */
096: public void modifyTestElement(TestElement element) {
097: configureTestElement(element);
098: String md5HexString = this .md5HexInput.getText();
099: // initialize to empty string, this will fail the assertion
100: if (md5HexString == null || md5HexString.length() == 0) {
101: md5HexString = "";
102: }
103: ((MD5HexAssertion) element).setAllowedMD5Hex(md5HexString);
104: }
105:
106: /**
107: * Implements JMeterGUIComponent.clearGui
108: */
109: public void clearGui() {
110: super .clearGui();
111:
112: md5HexInput.setText(""); //$NON-NLS-1$
113: }
114: }
|