khammond 01/10/02 06:00:40 Modified: src/org/apache/jmeter/assertions/gui AssertionGui.java Log: New GUI style. Revision Changes Path 1.4 +359 -330 jakarta-jmeter/src/org/apache/jmeter/assertions/gui/AssertionGui.java Index: AssertionGui.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/org/apache/jmeter/assertions/gui/AssertionGui.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AssertionGui.java 2001/08/31 00:46:43 1.3 +++ AssertionGui.java 2001/10/02 13:00:39 1.4 @@ -1,330 +1,359 @@ -/* - * ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache JMeter" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact [EMAIL PROTECTED] - * - * 5. Products derived from this software may not be called "Apache", - * "Apache JMeter", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * <http://www.apache.org/>. - */ -package org.apache.jmeter.assertions.gui; - -import java.awt.event.*; -import javax.swing.*; -import javax.swing.table.*; -import java.awt.*; -import java.util.*; - -import org.apache.jmeter.assertions.Assertion; -import org.apache.jmeter.gui.*; -import org.apache.jmeter.samplers.SampleResult; - -/************************************************************ - * Title: Jakarta-JMeter Description: Copyright: Copyright (c) 2001 Company: - * Apache - * - *@author Michael Stover - *@created $Date: 2001/08/31 00:46:43 $ - *@version 1.0 - ***********************************************************/ - -public class AssertionGui extends JPanel implements ModelSupported -{ - - private Assertion model; - private NamePanel namePanel; - private JRadioButton responseStringButton,labelButton,containsBox,matchesBox; - private JCheckBox notBox; - private JTextArea addPatternField; - private JList patternList; - private JButton addPattern,clearPatterns; - - /************************************************************ - * !ToDo (Constructor description) - ***********************************************************/ - public AssertionGui() - { - } - - public void setModel(Object model) - { - this.model = (Assertion)model; - init(); - } - - public void updateGui() - { - if(model.isContainsType()) - { - containsBox.setSelected(true); - matchesBox.setSelected(false); - } - else - { - containsBox.setSelected(false); - matchesBox.setSelected(true); - } - if(model.isNotType()) - { - notBox.setSelected(true); - } - else - { - notBox.setSelected(false); - } - if(SampleResult.TEXT_RESPONSE.equals(model.getTestField())) - { - responseStringButton.setSelected(true); - labelButton.setSelected(false); - } - else - { - responseStringButton.setSelected(false); - labelButton.setSelected(true); - } - } - - private void init() - { - this.setLayout(new VerticalLayout(2,VerticalLayout.LEFT)); - namePanel = new NamePanel(model); - this.add(namePanel); - add(createFieldPanel()); - add(createTypePanel()); - add(createStringPanel()); - } - - private JPanel createFieldPanel() - { - JPanel panel = new JPanel(); - panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), - "Response Field to Test")); - responseStringButton = new JRadioButton("Text Response"); - labelButton = new JRadioButton("URL Sampled"); - responseStringButton.addActionListener(new RSHandler()); - labelButton.addActionListener(new LabelHandler()); - ButtonGroup group = new ButtonGroup(); - group.add(responseStringButton); - group.add(labelButton); - panel.add(responseStringButton); - panel.add(labelButton); - return panel; - } - - private JPanel createTypePanel() - { - JPanel panel = new JPanel(); - panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), - "Pattern Matching Rules")); - containsBox = new JRadioButton("Contains"); - matchesBox = new JRadioButton("Matches"); - notBox = new JCheckBox("Not"); - containsBox.addActionListener(new ContainsHandler()); - matchesBox.addActionListener(new MatchesHandler()); - notBox.addActionListener(new NotHandler()); - ButtonGroup group = new ButtonGroup(); - group.add(matchesBox); - group.add(containsBox); - panel.add(containsBox); - panel.add(matchesBox); - panel.add(notBox); - return panel; - } - - private JPanel createStringPanel() - { - JPanel panel = new JPanel(); - panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), - "Patterns to Test")); - patternList = new JList(new PatternListModel(model)); - addPatternField = new JTextArea(3,25); - addPattern = new JButton("Add"); - addPattern.addActionListener(new AddPatternListener()); - patternList.setCellRenderer(new DefaultListCellRenderer()); - clearPatterns = new JButton(org.apache.jmeter.util.JMeterUtils.getResString("clear")); - clearPatterns.addActionListener(new ClearPatternsListener()); - panel.add(addPatternField); - panel.add(addPattern); - panel.add(patternList); - panel.add(clearPatterns); - return panel; - } - - private class ClearPatternsListener implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - ((PatternListModel)patternList.getModel()).clear(); - } - } - - private class AddPatternListener implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - String pattern = addPatternField.getText(); - addPatternField.setText(""); - ((PatternListModel)patternList.getModel()).addTestString(pattern); - } - } - - private class RSHandler implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - model.setTestField(SampleResult.TEXT_RESPONSE); - } - } - - private class LabelHandler implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - model.setTestField(SampleResult.SAMPLE_LABEL); - } - } - - private class ContainsHandler implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - model.setToContainsType(); - } - } - - private class MatchesHandler implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - model.setToMatchType(); - } - } - - private class NotHandler implements ActionListener - { - public void actionPerformed(ActionEvent e) - { - if(notBox.isSelected()) - { - model.setToNotType(); - } - else - { - model.unsetNotType(); - } - } - } - - private class PatternRenderer extends DefaultListCellRenderer - { - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) - { - String displayText = value.toString(); - if(displayText.length() > 10) - { - displayText = displayText.substring(0,10); - } - JLabel label = new JLabel(displayText); - if(isSelected) - { - label.setBackground(Color.blue); - label.setForeground(Color.white); - label.setOpaque(true); - } - else - { - label.setForeground(Color.black); - label.setBackground(Color.white); - } - if(cellHasFocus) - { - label.setBorder(BorderFactory.createEtchedBorder()); - } - label.setText(displayText); - return label; - } - } - - private class PatternListModel extends AbstractListModel - { - Assertion model; - - public PatternListModel(Assertion model) - { - super(); - this.model = model; - } - - public int getSize() - { - return model.getTestStringList().size(); - } - - public void addTestString(String pattern) - { - model.addTestString(pattern); - int size = model.getTestStringList().size(); - this.fireIntervalAdded(this,size-1,size); - } - - public Object getElementAt(int index) - { - return model.getTestStringList().get(index); - } - - public void clear() - { - model.clearTestStrings(); - this.fireContentsChanged(this,0,0); - } - } -} +/* + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache JMeter" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache", + * "Apache JMeter", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +package org.apache.jmeter.assertions.gui; + +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.table.*; +import java.awt.*; +import java.util.*; + +import org.apache.jmeter.assertions.Assertion; +import org.apache.jmeter.gui.*; +import org.apache.jmeter.util.JMeterUtils; +import org.apache.jmeter.samplers.SampleResult; + +/************************************************************ + * Title: Jakarta-JMeter Description: Copyright: Copyright (c) 2001 Company: + * Apache + * + *@author Michael Stover + *@created $Date: 2001/10/02 13:00:39 $ + *@version 1.0 + ***********************************************************/ + +public class AssertionGui extends JPanel implements ModelSupported +{ + private Assertion model; + private NamePanel namePanel; + private JRadioButton responseStringButton,labelButton,containsBox,matchesBox; + private JCheckBox notBox; + private JTextArea addPatternField; + private JList patternList; + private JButton addPattern,clearPatterns; + + /************************************************************ + * !ToDo (Constructor description) + ***********************************************************/ + public AssertionGui() + { + } + + public void setModel(Object model) + { + this.model = (Assertion)model; + init(); + } + + public void updateGui() + { + if(model.isContainsType()) + { + containsBox.setSelected(true); + matchesBox.setSelected(false); + } + + else + { + containsBox.setSelected(false); + matchesBox.setSelected(true); + } + + if(model.isNotType()) + { + notBox.setSelected(true); + } + else + { + notBox.setSelected(false); + } + + if(SampleResult.TEXT_RESPONSE.equals(model.getTestField())) + { + responseStringButton.setSelected(true); + labelButton.setSelected(false); + } + else + { + responseStringButton.setSelected(false); + labelButton.setSelected(true); + } + } + + private void init() + { + this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP)); + + // MAIN PANEL + JPanel mainPanel = new JPanel(); + Border margin = new EmptyBorder(10, 10, 5, 10); + mainPanel.setBorder(margin); + mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); + + // TITLE + JLabel panelTitleLabel = new JLabel(JMeterUtils.getResString("assertion_title")); + Font curFont = panelTitleLabel.getFont(); + int curFontSize = curFont.getSize(); + curFontSize += 4; + panelTitleLabel.setFont(new Font(curFont.getFontName(), curFont.getStyle(), curFontSize)); + mainPanel.add(panelTitleLabel); + + // NAME + namePanel = new NamePanel(model); + mainPanel.add(namePanel); + + mainPanel.add(createFieldPanel()); + mainPanel.add(createTypePanel()); + mainPanel.add(createStringPanel()); + + this.add(mainPanel); + } + + private JPanel createFieldPanel() + { + JPanel panel = new JPanel(); + panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), + JMeterUtils.getResString("assertion_resp_field"))); + responseStringButton = new JRadioButton(JMeterUtils.getResString("assertion_text_resp")); + labelButton = new JRadioButton(JMeterUtils.getResString("assertion_url_samp")); + responseStringButton.addActionListener(new RSHandler()); + labelButton.addActionListener(new LabelHandler()); + ButtonGroup group = new ButtonGroup(); + group.add(responseStringButton); + group.add(labelButton); + panel.add(responseStringButton); + panel.add(labelButton); + return panel; + } + + private JPanel createTypePanel() + { + JPanel panel = new JPanel(); + panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), + JMeterUtils.getResString("assertion_pattern_match_rules"))); + containsBox = new JRadioButton(JMeterUtils.getResString("assertion_contains")); + matchesBox = new JRadioButton(JMeterUtils.getResString("assertion_matches")); + notBox = new JCheckBox(JMeterUtils.getResString("assertion_not")); + containsBox.addActionListener(new ContainsHandler()); + matchesBox.addActionListener(new MatchesHandler()); + notBox.addActionListener(new NotHandler()); + ButtonGroup group = new ButtonGroup(); + group.add(matchesBox); + group.add(containsBox); + panel.add(containsBox); + panel.add(matchesBox); + panel.add(notBox); + return panel; + } + + private JPanel createStringPanel() + { + JPanel panel = new JPanel(); + panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), + JMeterUtils.getResString("assertion_patterns_to_test"))); + patternList = new JList(new PatternListModel(model)); + addPatternField = new JTextArea(3,25); + addPattern = new JButton(JMeterUtils.getResString("add")); + addPattern.addActionListener(new AddPatternListener()); + patternList.setCellRenderer(new DefaultListCellRenderer()); + clearPatterns = new JButton(org.apache.jmeter.util.JMeterUtils.getResString("clear")); + clearPatterns.addActionListener(new ClearPatternsListener()); + panel.add(addPatternField); + panel.add(addPattern); + panel.add(patternList); + panel.add(clearPatterns); + return panel; + } + + private class ClearPatternsListener implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + ((PatternListModel)patternList.getModel()).clear(); + } + } + + private class AddPatternListener implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + String pattern = addPatternField.getText(); + addPatternField.setText(""); + ((PatternListModel)patternList.getModel()).addTestString(pattern); + } + } + + private class RSHandler implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + model.setTestField(SampleResult.TEXT_RESPONSE); + } + } + + private class LabelHandler implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + model.setTestField(SampleResult.SAMPLE_LABEL); + } + } + + private class ContainsHandler implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + model.setToContainsType(); + } + } + + private class MatchesHandler implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + model.setToMatchType(); + } + } + + private class NotHandler implements ActionListener + { + public void actionPerformed(ActionEvent e) + { + if(notBox.isSelected()) + { + model.setToNotType(); + } + else + { + model.unsetNotType(); + } + } + } + + private class PatternRenderer extends DefaultListCellRenderer + { + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) + { + String displayText = value.toString(); + if(displayText.length() > 10) + { + displayText = displayText.substring(0,10); + } + + JLabel label = new JLabel(displayText); + + if(isSelected) + { + label.setBackground(Color.blue); + label.setForeground(Color.white); + label.setOpaque(true); + } + else + { + label.setForeground(Color.black); + label.setBackground(Color.white); + } + + if(cellHasFocus) + { + label.setBorder(BorderFactory.createEtchedBorder()); + } + + label.setText(displayText); + + return label; + } + } + + private class PatternListModel extends AbstractListModel + { + Assertion model; + + public PatternListModel(Assertion model) + { + super(); + this.model = model; + } + + public int getSize() + { + return model.getTestStringList().size(); + } + + public void addTestString(String pattern) + { + model.addTestString(pattern); + int size = model.getTestStringList().size(); + this.fireIntervalAdded(this,size-1,size); + } + + public Object getElementAt(int index) + { + return model.getTestStringList().get(index); + } + + public void clear() + { + model.clearTestStrings(); + this.fireContentsChanged(this,0,0); + } + } +}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
