KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > editors > passwordEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * passwordEditor.java
21  *
22  * Created on February 36, 2004, 11:53 PM
23  */

24 package org.netbeans.modules.j2ee.sun.ide.editors;
25
26 import java.awt.Component JavaDoc;
27 import java.awt.event.KeyEvent JavaDoc;
28 import java.awt.event.KeyAdapter JavaDoc;
29 import java.beans.PropertyEditorSupport JavaDoc;
30
31 import javax.swing.JPasswordField JavaDoc;
32
33 import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor;
34
35 /**
36  *
37  * @author nityad
38  */

39
40 public class passwordEditor extends PropertyEditorSupport JavaDoc implements EnhancedPropertyEditor{
41
42     public static String JavaDoc prev = "null"; // NOI18N
43
private String JavaDoc curValue;
44         
45     public passwordEditor() {
46     curValue = null;
47     }
48
49     public String JavaDoc getAsText () {
50       if((curValue==null)||(curValue.trim().equals(""))) // NOI18N
51
return prev;
52       else
53          return curValue;
54     }
55
56     public void setAsText (String JavaDoc string) throws IllegalArgumentException JavaDoc {
57       /*if((string==null)||(string.equals(""))) // NOI18N
58            curValue = prev;
59        else
60            curValue = string;*/

61
62        if((string!=null)&&(!string.trim().equals(""))){ // NOI18N
63
curValue = string;
64             prev = curValue;
65        }
66        firePropertyChange();
67     }
68     
69     public void setValue (Object JavaDoc v) {
70         if(!(v.toString().trim().equals(""))) {// NOI18N
71
prev = (String JavaDoc)v;
72         }
73         curValue = (String JavaDoc)v;
74     }
75
76     public Object JavaDoc getValue () {
77        prev = curValue;
78        return curValue;
79     }
80
81     public Component JavaDoc getInPlaceCustomEditor () {
82        JPasswordField JavaDoc textfield = new JPasswordField JavaDoc(curValue);
83        textfield.setEchoChar('*');
84        textfield.selectAll();
85        textfield.addKeyListener(new KeyAdapter JavaDoc() {
86             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
87                 JPasswordField JavaDoc cb = (JPasswordField JavaDoc)evt.getSource();
88                 String JavaDoc enteredPwd = new String JavaDoc(cb.getPassword());
89                 curValue = enteredPwd;
90                 // CR 5055478/6199209 cb.setText(curValue);
91
firePropertyChange();
92                 if(evt.getKeyCode() == KeyEvent.VK_ENTER){
93                     KeyEvent JavaDoc esc = new KeyEvent JavaDoc(evt.getComponent(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ESCAPE, KeyEvent.CHAR_UNDEFINED);
94                     java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().dispatchKeyEvent(esc);
95                     //firePropertyChange();
96
}
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