1 18 19 package org.apache.jmeter.control.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 25 import javax.swing.Box ; 26 import javax.swing.JLabel ; 27 import javax.swing.JPanel ; 28 import javax.swing.JTextField ; 29 30 import org.apache.jmeter.control.IfController; 31 import org.apache.jmeter.gui.util.FocusRequester; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.util.JMeterUtils; 34 35 43 44 public class IfControllerPanel extends AbstractControllerGui 45 implements ActionListener 46 { 47 48 private static final String CONDITION_LABEL = "if_controller_label"; 49 50 54 private JTextField theCondition; 55 56 61 private boolean displayName = true; 62 63 64 65 private static final String CONDITION = "JS_Condition"; 66 67 70 public IfControllerPanel() { 71 this(true); 72 } 73 74 83 public IfControllerPanel (boolean displayName) 84 { 85 this.displayName = displayName; 86 init(); 87 } 88 89 97 public void configure(TestElement element) { 98 super.configure(element); 99 if (element instanceof IfController) { 100 theCondition.setText(((IfController) element).getCondition()); 101 } 102 103 } 104 105 108 public TestElement createTestElement() { 109 IfController controller = new IfController(); 110 modifyTestElement(controller); 111 return controller; 112 } 113 114 117 public void modifyTestElement(TestElement controller) { 118 configureTestElement(controller); 119 if (controller instanceof IfController) 120 { 121 if (theCondition.getText().length() > 0) { 122 ((IfController) controller).setCondition(theCondition.getText()); 123 } else { 124 ((IfController) controller).setCondition(""); 125 } 126 } 127 } 128 129 135 public void actionPerformed(ActionEvent event) { 136 new FocusRequester(theCondition); 137 } 138 139 public String getLabelResource() { 140 return "if_controller_title"; 141 } 142 143 146 private void init() 147 { 148 if (displayName) { 150 setLayout(new BorderLayout (0, 5)); 151 setBorder(makeBorder()); 152 add(makeTitlePanel(), BorderLayout.NORTH); 153 154 JPanel mainPanel = new JPanel (new BorderLayout ()); 155 mainPanel.add(createConditionPanel(), BorderLayout.NORTH); 156 add(mainPanel, BorderLayout.CENTER); 157 158 } else { 159 setLayout(new BorderLayout ()); 161 add(createConditionPanel(), BorderLayout.NORTH); 162 } 163 } 164 165 166 171 private JPanel createConditionPanel() { 172 JPanel conditionPanel = new JPanel (new BorderLayout (5, 0)); 173 174 JLabel conditionLabel = 176 new JLabel (JMeterUtils.getResString( CONDITION_LABEL )); 177 conditionPanel.add(conditionLabel, BorderLayout.WEST); 178 179 theCondition = new JTextField (""); 181 theCondition.setName(CONDITION); 182 conditionLabel.setLabelFor(theCondition); 183 conditionPanel.add(theCondition, BorderLayout.CENTER); 184 theCondition.addActionListener(this); 185 186 conditionPanel.add( 187 Box.createHorizontalStrut( conditionLabel.getPreferredSize().width 188 + theCondition.getPreferredSize().width) 189 , BorderLayout.NORTH); 190 191 return conditionPanel; 192 } 193 } | Popular Tags |