1 18 19 package org.apache.jmeter.config.gui; 20 import java.awt.BorderLayout ; 21 22 import javax.swing.JLabel ; 23 import javax.swing.JPanel ; 24 import javax.swing.JPasswordField ; 25 import javax.swing.JTextField ; 26 27 import org.apache.jmeter.config.ConfigTestElement; 28 import org.apache.jmeter.gui.util.VerticalPanel; 29 import org.apache.jmeter.testelement.TestElement; 30 import org.apache.jmeter.testelement.property.StringProperty; 31 import org.apache.jmeter.util.JMeterUtils; 32 33 39 public class LoginConfigGui extends AbstractConfigGui 40 { 41 42 private JTextField username = new JTextField (15); 43 44 45 private JPasswordField password = new JPasswordField (15); 46 47 52 private boolean displayName = true; 53 54 57 public LoginConfigGui() 58 { 59 this(true); 60 } 61 62 71 public LoginConfigGui(boolean displayName) 72 { 73 this.displayName = displayName; 74 init(); 75 } 76 77 public String getLabelResource() 78 { 79 return "login_config_element"; 80 } 81 82 90 public void configure(TestElement element) 91 { 92 super.configure(element); 93 username.setText( 94 element.getPropertyAsString(ConfigTestElement.USERNAME)); 95 password.setText( 96 element.getPropertyAsString(ConfigTestElement.PASSWORD)); 97 } 98 99 100 public TestElement createTestElement() 101 { 102 ConfigTestElement element = new ConfigTestElement(); 103 modifyTestElement(element); 104 return element; 105 } 106 107 108 public void modifyTestElement(TestElement element) 109 { 110 configureTestElement(element); 111 element.setProperty( 112 new StringProperty(ConfigTestElement.USERNAME, username.getText())); 113 114 String passwordString = new String (password.getPassword()); 115 element.setProperty( 116 new StringProperty(ConfigTestElement.PASSWORD, passwordString)); 117 } 118 119 122 private void init() 123 { 124 setLayout(new BorderLayout (0, 5)); 125 126 if (displayName) 127 { 128 setBorder(makeBorder()); 129 add(makeTitlePanel(), BorderLayout.NORTH); 130 } 131 132 VerticalPanel mainPanel = new VerticalPanel(); 133 mainPanel.add(createUsernamePanel()); 134 mainPanel.add(createPasswordPanel()); 135 add(mainPanel, BorderLayout.CENTER); 136 } 137 138 143 private JPanel createUsernamePanel() 144 { 145 JPanel panel = new JPanel (new BorderLayout (5, 0)); 146 JLabel label = new JLabel (JMeterUtils.getResString("username")); 147 label.setLabelFor(username); 148 panel.add(label, BorderLayout.WEST); 149 panel.add(username, BorderLayout.CENTER); 150 return panel; 151 } 152 153 158 private JPanel createPasswordPanel() 159 { 160 JPanel panel = new JPanel (new BorderLayout (5, 0)); 161 JLabel label = new JLabel (JMeterUtils.getResString("password")); 162 label.setLabelFor(password); 163 panel.add(label, BorderLayout.WEST); 164 panel.add(password, BorderLayout.CENTER); 165 return panel; 166 } 167 } 168 | Popular Tags |