1 18 19 package org.apache.jmeter.gui; 20 import java.awt.BorderLayout ; 21 import java.util.Collection ; 22 23 import javax.swing.JLabel ; 24 import javax.swing.JPanel ; 25 import javax.swing.JPopupMenu ; 26 import javax.swing.JTextField ; 27 import javax.swing.event.DocumentEvent ; 28 import javax.swing.event.DocumentListener ; 29 30 import org.apache.jmeter.gui.tree.JMeterTreeNode; 31 import org.apache.jmeter.testelement.TestElement; 32 import org.apache.jmeter.testelement.WorkBench; 33 import org.apache.jmeter.testelement.property.StringProperty; 34 import org.apache.jmeter.util.JMeterUtils; 35 import org.apache.jmeter.util.LocaleChangeEvent; 36 40 41 public class NamePanel extends JPanel implements JMeterGUIComponent 42 { 43 44 private JTextField nameField = new JTextField (15); 45 46 47 private JLabel nameLabel; 48 49 50 private JMeterTreeNode node; 51 52 55 public NamePanel() 56 { 57 setName(getStaticLabel()); 58 init(); 59 } 60 61 64 private void init() 65 { 66 setLayout(new BorderLayout (5, 0)); 67 68 nameLabel = new JLabel (JMeterUtils.getResString("name")); 69 nameLabel.setName("name"); 70 nameLabel.setLabelFor(nameField); 71 72 nameField.getDocument().addDocumentListener(new DocumentListener () 73 { 74 public void insertUpdate(DocumentEvent e) 75 { 76 updateName(nameField.getText()); 77 } 78 79 public void removeUpdate(DocumentEvent e) 80 { 81 updateName(nameField.getText()); 82 } 83 84 public void changedUpdate(DocumentEvent e) 85 { 86 } 88 }); 89 90 add(nameLabel, BorderLayout.WEST); 91 add(nameField, BorderLayout.CENTER); 92 } 93 94 public void clear() 95 { 96 setName(getStaticLabel()); 97 } 98 99 100 105 public String getName() 106 { 107 if (nameField != null) return nameField.getText(); 108 else return ""; 109 } 110 111 116 public void setName(String name) 117 { 118 super.setName(name); 119 nameField.setText(name); 120 } 121 122 127 protected JMeterTreeNode getNode() 128 { 129 return node; 130 } 131 132 137 public void setNode(JMeterTreeNode node) 138 { 139 this.node = node; 140 } 141 142 143 public void configure(TestElement testElement) 144 { 145 setName(testElement.getPropertyAsString(TestElement.NAME)); 146 } 147 148 149 public JPopupMenu createPopupMenu() 150 { 151 return null; 152 } 153 154 155 public String getStaticLabel() 156 { 157 return JMeterUtils.getResString(getLabelResource()); 158 } 159 160 163 public String getLabelResource() { 164 return "root"; 165 } 166 167 168 public Collection getMenuCategories() 169 { 170 return null; 171 } 172 173 174 public TestElement createTestElement() 175 { 176 WorkBench wb = new WorkBench(); 177 modifyTestElement(wb); 178 return wb; 179 } 180 181 182 public void modifyTestElement(TestElement wb) 183 { 184 wb.setProperty(new StringProperty(TestElement.NAME, getName())); 185 wb.setProperty( 186 new StringProperty( 187 TestElement.GUI_CLASS, 188 this.getClass().getName())); 189 wb.setProperty( 190 new StringProperty( 191 TestElement.TEST_CLASS, 192 WorkBench.class.getName())); 193 } 194 195 201 private void updateName(String newValue) 202 { 203 if (getNode() != null) 204 { 205 getNode().nameChanged(); 206 } 207 } 208 209 215 public void localeChanged(LocaleChangeEvent event) 216 { 217 nameLabel.setText(JMeterUtils.getResString(nameLabel.getName())); 218 } 219 220 223 public String getDocAnchor() { 224 return null; 226 } 227 } 228 | Popular Tags |