KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > settings > PasswordPanel


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 package org.netbeans.modules.exceptions.settings;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Cursor JavaDoc;
24 import java.awt.event.MouseAdapter JavaDoc;
25 import java.awt.event.MouseEvent JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JCheckBox JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.JPasswordField JavaDoc;
32 import javax.swing.JTextField JavaDoc;
33 import org.openide.awt.HtmlBrowser;
34
35 /**
36  *
37  * @author jindra
38  */

39 public class PasswordPanel extends JPanel JavaDoc {
40
41     private JCheckBox JavaDoc savePasswdCheckBox;
42     private JLabel JavaDoc jLabel1;
43     private JLabel JavaDoc jLabel2;
44     private JLabel JavaDoc jLabel3;
45     private JLabel JavaDoc jLabel4;
46     private JLabel JavaDoc jLabel5;
47     private JLabel JavaDoc jLabel6;
48     private JPasswordField JavaDoc passwdField;
49     private JTextField JavaDoc userNameField;
50
51     private final ExceptionsSettings settings = new ExceptionsSettings();
52     private final java.util.ResourceBundle JavaDoc bundle = org.openide.util.NbBundle.getBundle(PasswordPanel.class);
53     /** Creates a new instance of PasswordPanel */
54     public PasswordPanel() {
55         super();
56         initComponents();
57     }
58
59     private void initComponents() {
60         jLabel1 = new JLabel JavaDoc(bundle.getString("User_name"));
61         jLabel1.setLabelFor(userNameField);
62         userNameField = new JTextField JavaDoc();
63         jLabel2 = new JLabel JavaDoc(bundle.getString("Password"));
64         jLabel2.setLabelFor(passwdField);
65         jLabel3 = new JLabel JavaDoc(bundle.getString("NoNbUser"));
66         jLabel4 = new JLabel JavaDoc(bundle.getString("Register"));
67         jLabel5 = new JLabel JavaDoc(bundle.getString("here"));
68         jLabel5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
69         jLabel5.setForeground(Color.BLUE);
70         jLabel6 = new JLabel JavaDoc("."); // NOI18N
71
savePasswdCheckBox = new JCheckBox JavaDoc(bundle.getString("Remember_password"));
72         savePasswdCheckBox.setMnemonic(bundle.getString("Remember_password").charAt(0));
73         passwdField = new JPasswordField JavaDoc();
74         jLabel5.addMouseListener(new MouseAdapter JavaDoc() {
75
76             public void mouseClicked(MouseEvent JavaDoc arg0) {
77                 try {
78                     HtmlBrowser.URLDisplayer.getDefault().showURL(new java.net.URL JavaDoc("http://www.netbeans.org/servlets/Join")); // NOI18N
79
}
80                 catch (MalformedURLException JavaDoc ex) {
81                     java.util.logging.Logger.getLogger(PasswordPanel.class.getName()).log(java.util.logging.Level.INFO, ex.getMessage(), ex);
82                 }
83             }
84         });
85         setBackground(getBackground());
86
87         savePasswdCheckBox.setBackground(getBackground());
88         savePasswdCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
89         savePasswdCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
90
91         org.jdesktop.layout.GroupLayout panelLayout = new org.jdesktop.layout.GroupLayout(this);
92         setLayout(panelLayout);
93         panelLayout.setHorizontalGroup(
94                 panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
95                 .add(panelLayout.createSequentialGroup()
96                 .addContainerGap()
97                 .add(panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
98                 .add(panelLayout.createSequentialGroup()
99                 .add(jLabel1)
100                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
101                 .add(userNameField, 80, 120, 150))
102                 .add(panelLayout.createSequentialGroup()
103                 .add(jLabel2)
104                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
105                 .add(passwdField))
106                 .add(savePasswdCheckBox)
107                 .add(jLabel3)
108                 .add(panelLayout.createSequentialGroup()
109                 .add(jLabel4)
110                 .add(jLabel5)
111                 .add(jLabel6)))
112                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
113                 );
114         panelLayout.setVerticalGroup(
115                 panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
116                 .add(panelLayout.createSequentialGroup()
117                 .addContainerGap()
118                 .add(panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
119                 .add(jLabel1)
120                 .add(userNameField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
121                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
122                 .add(panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
123                 .add(jLabel2)
124                 .add(passwdField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
125                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
126                 .add(savePasswdCheckBox)
127                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
128                 .add(jLabel3)
129                 .add(panelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
130                 .add(jLabel4)
131                 .add(jLabel5)
132                 .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
133                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
134                 );
135
136     }
137
138     public void load() {
139         String JavaDoc passwd = settings.getPassword();
140         boolean save = settings.getSavePassword();
141         if (save) passwdField.setText(passwd);
142         else passwdField.setText(""); // NOI18N
143
userNameField.setText(settings.getUserName());
144         savePasswdCheckBox.setSelected((passwd.length()!=0)&&save);
145     }
146
147
148     public void store() {
149         settings.setSavePassword(isSelected());
150         settings.setPassword(getPasswd());
151         settings.setUserName(getUserName());
152     }
153
154     public boolean valid() {
155         if ((getPasswd().length()!=0) && savePasswdCheckBox.isSelected()) return false;
156         return true;
157     }
158
159     public String JavaDoc getUserName() {
160         return userNameField.getText();
161     }
162
163     public String JavaDoc getPasswd() {
164         return new String JavaDoc(passwdField.getPassword());
165     }
166
167     public void cleanPasswd() {
168         passwdField.setText("");
169     }
170
171     public Boolean JavaDoc isSelected(){
172         return savePasswdCheckBox.isSelected();
173     }
174
175     public final void setBackground(Color JavaDoc col) {
176         super.setBackground(col);
177         if (savePasswdCheckBox !=null) savePasswdCheckBox.setBackground(col);
178     }
179
180 }
181
Popular Tags