1 19 24 package org.netbeans.modules.j2ee.sun.ide.editors; 25 26 import java.awt.Component ; 27 import java.awt.event.KeyEvent ; 28 import java.awt.event.KeyAdapter ; 29 import java.beans.PropertyEditorSupport ; 30 31 import javax.swing.JPasswordField ; 32 33 import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor; 34 35 39 40 public class passwordEditor extends PropertyEditorSupport implements EnhancedPropertyEditor{ 41 42 public static String prev = "null"; private String curValue; 44 45 public passwordEditor() { 46 curValue = null; 47 } 48 49 public String getAsText () { 50 if((curValue==null)||(curValue.trim().equals(""))) return prev; 52 else 53 return curValue; 54 } 55 56 public void setAsText (String string) throws IllegalArgumentException { 57 61 62 if((string!=null)&&(!string.trim().equals(""))){ curValue = string; 64 prev = curValue; 65 } 66 firePropertyChange(); 67 } 68 69 public void setValue (Object v) { 70 if(!(v.toString().trim().equals(""))) { prev = (String )v; 72 } 73 curValue = (String )v; 74 } 75 76 public Object getValue () { 77 prev = curValue; 78 return curValue; 79 } 80 81 public Component getInPlaceCustomEditor () { 82 JPasswordField textfield = new JPasswordField (curValue); 83 textfield.setEchoChar('*'); 84 textfield.selectAll(); 85 textfield.addKeyListener(new KeyAdapter () { 86 public void keyReleased(java.awt.event.KeyEvent evt) { 87 JPasswordField cb = (JPasswordField )evt.getSource(); 88 String enteredPwd = new String (cb.getPassword()); 89 curValue = enteredPwd; 90 firePropertyChange(); 92 if(evt.getKeyCode() == KeyEvent.VK_ENTER){ 93 KeyEvent esc = new KeyEvent (evt.getComponent(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ESCAPE, KeyEvent.CHAR_UNDEFINED); 94 java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().dispatchKeyEvent(esc); 95 } 97 } 98 }); 99 return textfield; 100 } 101 102 public boolean hasInPlaceCustomEditor () { 103 return true; 104 } 105 106 public boolean supportsEditingTaggedValues () { 107 return false; 108 } 109 110 } 111 112 113 114 115 116 | Popular Tags |