1 17 18 package org.apache.jmeter.extractor.gui; 19 20 import java.awt.BorderLayout ; 21 import java.awt.Component ; 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.util.List ; 25 26 import javax.swing.BorderFactory ; 27 import javax.swing.Box ; 28 import javax.swing.ButtonGroup ; 29 import javax.swing.JPanel ; 30 import javax.swing.JRadioButton ; 31 32 import org.apache.jmeter.extractor.RegexExtractor; 33 import org.apache.jmeter.processor.gui.AbstractPostProcessorGui; 34 import org.apache.jmeter.testelement.TestElement; 35 import org.apache.jmeter.util.JMeterUtils; 36 import org.apache.jorphan.gui.JLabeledTextField; 37 import org.apache.jorphan.util.JOrphanUtils; 38 39 41 public class RegexExtractorGui extends AbstractPostProcessorGui 42 { 43 private JLabeledTextField regexField; 44 private JLabeledTextField templateField; 45 private JLabeledTextField defaultField; 46 private JLabeledTextField matchNumberField; 47 private JLabeledTextField refNameField; 48 49 private JRadioButton useBody; 51 private JRadioButton useHeaders; 52 53 public RegexExtractorGui() 54 { 55 super(); 56 init(); 57 } 58 59 public String getLabelResource() 60 { 61 return "regex_extractor_title"; 62 } 63 64 public void configure(TestElement el) 65 { 66 super.configure(el); 67 useHeaders.setSelected(el.getPropertyAsBoolean(RegexExtractor.USEHEADERS)); 68 useBody.setSelected(!el.getPropertyAsBoolean(RegexExtractor.USEHEADERS)); 69 regexField.setText(el.getPropertyAsString(RegexExtractor.REGEX)); 70 templateField.setText(el.getPropertyAsString(RegexExtractor.TEMPLATE)); 71 defaultField.setText(el.getPropertyAsString(RegexExtractor.DEFAULT)); 72 matchNumberField.setText( 73 el.getPropertyAsString(RegexExtractor.MATCH_NUMBER)); 74 refNameField.setText(el.getPropertyAsString(RegexExtractor.REFNAME)); 75 } 76 77 80 public TestElement createTestElement() 81 { 82 RegexExtractor extractor = new RegexExtractor(); 83 modifyTestElement(extractor); 84 return extractor; 85 } 86 87 91 public void modifyTestElement(TestElement extractor) 92 { 93 super.configureTestElement(extractor); 94 extractor.setProperty( 95 RegexExtractor.USEHEADERS, 96 JOrphanUtils.booleanToString(useHeaders.isSelected())); 97 extractor.setProperty( 98 RegexExtractor.MATCH_NUMBER, 99 matchNumberField.getText()); 100 if(extractor instanceof RegexExtractor) 101 { 102 RegexExtractor regex = (RegexExtractor)extractor; 103 regex.setRefName(refNameField.getText()); 104 regex.setRegex(regexField.getText()); 105 regex.setTemplate(templateField.getText()); 106 regex.setDefaultValue(defaultField.getText()); 107 } 108 } 109 110 private void init() 111 { 112 setLayout(new BorderLayout ()); 113 setBorder(makeBorder()); 114 115 Box box = Box.createVerticalBox(); 116 box.add(makeTitlePanel()); 117 box.add(makeSourcePanel()); 118 add(box,BorderLayout.NORTH); 119 add(makeParameterPanel(),BorderLayout.CENTER); 120 } 121 122 private JPanel makeSourcePanel() 123 { 124 JPanel panel = new JPanel (); 125 panel.setBorder( 126 BorderFactory.createTitledBorder( 127 JMeterUtils.getResString("regex_source"))); 128 129 useBody = 130 new JRadioButton (JMeterUtils.getResString("regex_src_body")); 131 useHeaders = 132 new JRadioButton (JMeterUtils.getResString("regex_src_hdrs")); 133 134 ButtonGroup group = new ButtonGroup (); 135 group.add(useBody); 136 group.add(useHeaders); 137 138 panel.add(useBody); 139 panel.add(useHeaders); 140 141 useBody.setSelected(true); 142 return panel; 143 } 144 145 private JPanel makeParameterPanel() 146 { 147 regexField = 148 new JLabeledTextField(JMeterUtils.getResString("regex_field")); 149 templateField = 150 new JLabeledTextField(JMeterUtils.getResString("template_field")); 151 defaultField = 152 new JLabeledTextField( 153 JMeterUtils.getResString("default_value_field")); 154 refNameField = 155 new JLabeledTextField(JMeterUtils.getResString("ref_name_field")); 156 matchNumberField = 157 new JLabeledTextField(JMeterUtils.getResString("match_num_field")); 158 159 JPanel panel = new JPanel (new GridBagLayout ()); 160 GridBagConstraints gbc = new GridBagConstraints (); 161 initConstraints(gbc); 162 addField(panel,refNameField,gbc); 163 resetContraints(gbc); 164 addField(panel,regexField,gbc); 165 resetContraints(gbc); 166 addField(panel,templateField,gbc); 167 resetContraints(gbc); 168 addField(panel,matchNumberField,gbc); 169 resetContraints(gbc); 170 gbc.weighty = 1; 171 addField(panel,defaultField,gbc); 172 return panel; 173 } 174 175 private void addField( 176 JPanel panel, 177 JLabeledTextField field, 178 GridBagConstraints gbc) 179 { 180 List item = field.getComponentList(); 181 panel.add((Component )item.get(0),gbc.clone()); 182 gbc.gridx++; 183 gbc.weightx = 1;; 184 panel.add((Component )item.get(1),gbc.clone()); 185 } 186 187 private void resetContraints(GridBagConstraints gbc) 188 { 189 gbc.gridx = 0; 190 gbc.gridy++; 191 gbc.weightx = 0; 192 } 193 194 private void initConstraints(GridBagConstraints gbc) 195 { 196 gbc.anchor = GridBagConstraints.NORTHWEST; 197 gbc.fill = GridBagConstraints.NONE; 198 gbc.gridheight = 1; 199 gbc.gridwidth = 1; 200 gbc.gridx = 0; 201 gbc.gridy = 0; 202 gbc.weightx = 0; 203 gbc.weighty = 0; 204 } 205 } 206 | Popular Tags |