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.WhileController; 31 import org.apache.jmeter.gui.util.FocusRequester; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.util.JMeterUtils; 34 35 public class WhileControllerGui extends AbstractControllerGui 36 implements ActionListener 37 { 38 39 private static final String CONDITION_LABEL = "while_controller_label"; 40 41 44 private JTextField theCondition; 45 46 47 private static final String CONDITION = "While_Condition"; 48 49 52 public WhileControllerGui() { 53 init(); 54 } 55 56 64 public void configure(TestElement element) { 65 super.configure(element); 66 if (element instanceof WhileController) { 67 theCondition.setText(((WhileController) element).getCondition()); 68 } 69 70 } 71 72 75 public TestElement createTestElement() { 76 WhileController controller = new WhileController(); 77 modifyTestElement(controller); 78 return controller; 79 } 80 81 84 public void modifyTestElement(TestElement controller) { 85 configureTestElement(controller); 86 if (controller instanceof WhileController) 87 { 88 if (theCondition.getText().length() > 0) { 89 ((WhileController) controller).setCondition(theCondition.getText()); 90 } else { 91 ((WhileController) controller).setCondition(""); 92 } 93 } 94 } 95 96 102 public void actionPerformed(ActionEvent event) { 103 new FocusRequester(theCondition); 104 } 105 106 public String getLabelResource() { 107 return "while_controller_title"; 108 } 109 110 113 private void init() 114 { 115 setLayout(new BorderLayout (0, 5)); 116 setBorder(makeBorder()); 117 add(makeTitlePanel(), BorderLayout.NORTH); 118 119 JPanel mainPanel = new JPanel (new BorderLayout ()); 120 mainPanel.add(createConditionPanel(), BorderLayout.NORTH); 121 add(mainPanel, BorderLayout.CENTER); 122 123 } 124 125 126 131 private JPanel createConditionPanel() { 132 JPanel conditionPanel = new JPanel (new BorderLayout (5, 0)); 133 134 JLabel conditionLabel = 136 new JLabel (JMeterUtils.getResString( CONDITION_LABEL )); 137 conditionPanel.add(conditionLabel, BorderLayout.WEST); 138 139 theCondition = new JTextField (""); theCondition.setName(CONDITION); 142 conditionLabel.setLabelFor(theCondition); 143 conditionPanel.add(theCondition, BorderLayout.CENTER); 144 theCondition.addActionListener(this); 145 146 conditionPanel.add( 147 Box.createHorizontalStrut( conditionLabel.getPreferredSize().width 148 + theCondition.getPreferredSize().width) 149 , BorderLayout.NORTH); 150 151 return conditionPanel; 152 } 153 } | Popular Tags |