Changeset 4110 in josm
- Timestamp:
- 2011-06-01T21:15:09+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java
r3770 r4110 15 15 import java.awt.event.FocusEvent; 16 16 import java.awt.event.KeyEvent; 17 import java.awt.event.KeyListener; 17 18 import java.awt.event.WindowAdapter; 18 19 import java.awt.event.WindowEvent; … … 104 105 public void prepareForOsmApiCredentials(String username, String password) { 105 106 setTitle(tr("Enter credentials for OSM API")); 106 getContentPane().add(pnlCredentials = new OsmApiCredentialsPanel( ), BorderLayout.CENTER);107 getContentPane().add(pnlCredentials = new OsmApiCredentialsPanel(this), BorderLayout.CENTER); 107 108 pnlCredentials.init(username, password); 108 109 validate(); … … 111 112 public void prepareForProxyCredentials(String username, String password) { 112 113 setTitle(tr("Enter credentials for HTTP proxy")); 113 getContentPane().add(pnlCredentials = new HttpProxyCredentialsPanel( ), BorderLayout.CENTER);114 getContentPane().add(pnlCredentials = new HttpProxyCredentialsPanel(this), BorderLayout.CENTER); 114 115 pnlCredentials.init(username, password); 115 116 validate(); … … 137 138 protected JMultilineLabel lblHeading; 138 139 protected JMultilineLabel lblWarning; 140 protected CredentialDialog owner; // owner Dependency Injection to use Key listeners for username and password text fields 139 141 140 142 protected void build() { … … 143 145 tfUserName.addFocusListener(new SelectAllOnFocusHandler()); 144 146 tfPassword.addFocusListener(new SelectAllOnFocusHandler()); 147 tfUserName.addKeyListener(new TFKeyListener(owner, tfUserName, tfPassword)); 148 tfPassword.addKeyListener(new TFKeyListener(owner, tfPassword, tfUserName)); 145 149 cbSaveCredentials = new JCheckBox(tr("Save user and password (unencrypted)")); 146 150 … … 202 206 } 203 207 204 public CredentialPanel() { 208 public CredentialPanel(CredentialDialog owner) { 209 this.owner = owner; 205 210 } 206 211 … … 243 248 } 244 249 245 public OsmApiCredentialsPanel() { 250 public OsmApiCredentialsPanel(CredentialDialog owner) { 251 super(owner); 246 252 build(); 247 253 } … … 260 266 } 261 267 262 public HttpProxyCredentialsPanel() { 268 public HttpProxyCredentialsPanel(CredentialDialog owner) { 269 super(owner); 263 270 build(); 264 271 } … … 275 282 } 276 283 284 /** 285 * Listener for username and password text fields key events. 286 * When user presses Enter: 287 * If current text field is empty (or just contains a sequence of spaces), nothing happens (or all spaces become selected). 288 * If current text field is not empty, but the next one is (or just contains a sequence of spaces), focuses the next text field. 289 * If both text fields contain characters, submits the form by calling owner's {@link OKAction}. 290 */ 291 static private class TFKeyListener implements KeyListener{ 292 protected CredentialDialog owner; // owner Dependency Injection to call OKAction 293 protected JTextField currentTF; 294 protected JTextField nextTF; 295 296 public TFKeyListener (CredentialDialog owner, JTextField currentTF, JTextField nextTF) 297 { 298 this.owner = owner; 299 this.currentTF = currentTF; 300 this.nextTF = nextTF; 301 } 302 303 public void keyPressed(KeyEvent e) { 304 if(e.getKeyChar() == KeyEvent.VK_ENTER) { 305 if (currentTF.getText().trim().isEmpty()) { 306 currentTF.selectAll(); 307 return; 308 } else if (nextTF.getText().trim().isEmpty()) { 309 nextTF.requestFocusInWindow(); 310 nextTF.selectAll(); 311 return; 312 } else { 313 OKAction okAction = owner.new OKAction(); 314 okAction.actionPerformed(null); 315 } 316 } 317 } 318 319 public void keyReleased ( KeyEvent e ){ 320 } 321 322 public void keyTyped ( KeyEvent e ){ 323 } 324 } 325 277 326 class OKAction extends AbstractAction { 278 327 public OKAction() {
Note:
See TracChangeset
for help on using the changeset viewer.