1 19 package org.netbeans.modules.j2ee.websphere6.ui.nodes.editors; 20 21 import java.beans.*; 22 import java.awt.*; 23 import java.awt.event.*; 24 import javax.swing.*; 25 import javax.swing.border.*; 26 27 import org.openide.explorer.propertysheet.editors.*; 28 import org.openide.explorer.propertysheet.*; 29 30 import org.netbeans.modules.j2ee.websphere6.util.*; 31 32 38 public class WSPasswordEditor extends PropertyEditorSupport 39 implements ExPropertyEditor { 40 41 45 private String value = ""; 46 47 52 public String getAsText() { 53 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getAsText()"); 56 return value.replaceAll(".", "*"); } 59 60 66 public void setAsText(String string) throws IllegalArgumentException { 67 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "setAsText(" + string + ")"); 70 if (string != null) { 73 value = string; 74 firePropertyChange(); 75 } 76 } 77 78 82 private PropertyEnv myPropertyEnv = null; 83 84 public void attachEnv(PropertyEnv env) { 85 myPropertyEnv = env; 86 } 87 88 93 public void setValue(Object object) { 94 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "setValue(" + object + ")"); 97 if (object != null) { 99 value = object.toString(); 100 } 101 } 102 103 108 public Object getValue() { 109 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getValue()"); 112 return value; 114 } 115 116 122 public Component getInPlaceCustomEditor() { 123 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getInPlaceCustomEditor()"); 126 JPasswordField textfield = new JPasswordField(value); 128 129 textfield.setEchoChar('*'); 131 textfield.setBorder(new EmptyBorder(0, 0, 0, 0)); 132 textfield.setMargin(new Insets(0, 0, 0, 0)); 133 134 textfield.selectAll(); 136 137 textfield.addKeyListener(new PasswordListener()); 139 140 return textfield; 142 } 143 144 149 public boolean hasInPlaceCustomEditor() { 150 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "hasInPlaceCustomEditor()"); 153 return true; 155 } 156 157 163 public boolean supportsEditingTaggedValues() { 164 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), 166 "supportsEditingTaggedValues()"); 168 return false; 170 } 171 172 178 private class PasswordListener extends KeyAdapter { 179 184 public void keyReleased(KeyEvent event) { 185 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "keyReleased(" + event + ")"); 189 JPasswordField field = (JPasswordField) event.getSource(); 191 192 value = new String (field.getPassword()); 194 195 firePropertyChange(); 197 198 if(event.getKeyCode() == KeyEvent.VK_ENTER){ 201 KeyEvent escapeEvent = new KeyEvent(event.getComponent(), 202 KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ESCAPE, 203 KeyEvent.CHAR_UNDEFINED); 204 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 205 dispatchKeyEvent(escapeEvent); 206 } 207 } 208 } 209 210 } | Popular Tags |