1 19 20 package org.netbeans.modules.exceptions.settings; 21 22 import java.awt.Color ; 23 import java.awt.Cursor ; 24 import java.awt.event.MouseAdapter ; 25 import java.awt.event.MouseEvent ; 26 import java.net.MalformedURLException ; 27 import javax.swing.BorderFactory ; 28 import javax.swing.JCheckBox ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JPasswordField ; 32 import javax.swing.JTextField ; 33 import org.openide.awt.HtmlBrowser; 34 35 39 public class PasswordPanel extends JPanel { 40 41 private JCheckBox savePasswdCheckBox; 42 private JLabel jLabel1; 43 private JLabel jLabel2; 44 private JLabel jLabel3; 45 private JLabel jLabel4; 46 private JLabel jLabel5; 47 private JLabel jLabel6; 48 private JPasswordField passwdField; 49 private JTextField userNameField; 50 51 private final ExceptionsSettings settings = new ExceptionsSettings(); 52 private final java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(PasswordPanel.class); 53 54 public PasswordPanel() { 55 super(); 56 initComponents(); 57 } 58 59 private void initComponents() { 60 jLabel1 = new JLabel (bundle.getString("User_name")); 61 jLabel1.setLabelFor(userNameField); 62 userNameField = new JTextField (); 63 jLabel2 = new JLabel (bundle.getString("Password")); 64 jLabel2.setLabelFor(passwdField); 65 jLabel3 = new JLabel (bundle.getString("NoNbUser")); 66 jLabel4 = new JLabel (bundle.getString("Register")); 67 jLabel5 = new JLabel (bundle.getString("here")); 68 jLabel5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 69 jLabel5.setForeground(Color.BLUE); 70 jLabel6 = new JLabel ("."); savePasswdCheckBox = new JCheckBox (bundle.getString("Remember_password")); 72 savePasswdCheckBox.setMnemonic(bundle.getString("Remember_password").charAt(0)); 73 passwdField = new JPasswordField (); 74 jLabel5.addMouseListener(new MouseAdapter () { 75 76 public void mouseClicked(MouseEvent arg0) { 77 try { 78 HtmlBrowser.URLDisplayer.getDefault().showURL(new java.net.URL ("http://www.netbeans.org/servlets/Join")); } 80 catch (MalformedURLException 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 (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 passwd = settings.getPassword(); 140 boolean save = settings.getSavePassword(); 141 if (save) passwdField.setText(passwd); 142 else passwdField.setText(""); 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 getUserName() { 160 return userNameField.getText(); 161 } 162 163 public String getPasswd() { 164 return new String (passwdField.getPassword()); 165 } 166 167 public void cleanPasswd() { 168 passwdField.setText(""); 169 } 170 171 public Boolean isSelected(){ 172 return savePasswdCheckBox.isSelected(); 173 } 174 175 public final void setBackground(Color col) { 176 super.setBackground(col); 177 if (savePasswdCheckBox !=null) savePasswdCheckBox.setBackground(col); 178 } 179 180 } 181 | Popular Tags |