1 19 package org.netbeans.modules.exceptions.settings; 20 21 import java.awt.GraphicsEnvironment ; 22 import java.awt.Point ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import javax.swing.JButton ; 26 import javax.swing.JDialog ; 27 import org.jdesktop.layout.GroupLayout; 28 import org.jdesktop.layout.LayoutStyle; 29 import org.openide.DialogDisplayer; 30 import org.openide.NotifyDescriptor; 31 32 36 public class SettingsSetter extends JDialog { 37 38 private JButton oK; 39 private JButton cancel; 40 private final PasswordPanel panel = new PasswordPanel(); 41 private java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(PasswordPanel.class); 42 43 44 public SettingsSetter(java.awt.Frame parent, boolean modal) { 45 super(parent, modal); 46 initComponents(); 47 } 48 49 private void initComponents() { 50 setTitle(bundle.getString("Set_user_name")); 51 getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SettingSetter")); 52 panel.setBackground(getBackground()); 53 oK = new JButton (bundle.getString("OK")); 54 oK.setMnemonic(bundle.getString("OK").charAt(0)); 55 cancel = new JButton (bundle.getString("Cancel")); 56 oK.setMnemonic(bundle.getString("Cancel").charAt(0)); 57 panel.load(); 58 cancel.addActionListener(new ActionListener () { 59 public void actionPerformed(ActionEvent event) { 60 panel.cleanPasswd(); 61 panel.store(); 62 dispose(); 63 } 64 }); 65 66 oK.addActionListener(new ActionListener () { 67 public void actionPerformed(ActionEvent event) { 68 if ((panel.getPasswd().length()==0)||(panel.getUserName().length()==0)) { 69 String message = org.openide.util.NbBundle.getMessage(SettingsSetter.class, "SET_PASSWORD"); 70 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE)); } else { 71 panel.store(); 72 dispose(); 73 } 74 } 75 }); 76 GroupLayout layout = new GroupLayout(getContentPane()); 77 getContentPane().setLayout(layout); 78 layout.setHorizontalGroup( 79 layout.createParallelGroup(GroupLayout.LEADING) 80 .add(layout.createSequentialGroup() 81 .addContainerGap() 82 .add(layout.createParallelGroup(GroupLayout.LEADING) 83 .add(panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 84 .add(layout.createSequentialGroup() 85 .add(13, 13, 13) 86 .add(oK, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE) 87 .add(18, 18, 18) 88 .add(cancel))) 89 .addContainerGap()) 90 ); 91 layout.setVerticalGroup( 92 layout.createParallelGroup(GroupLayout.LEADING) 93 .add(layout.createSequentialGroup() 94 .addContainerGap() 95 .add(panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) 96 .addPreferredGap(LayoutStyle.RELATED, 17, Short.MAX_VALUE) 97 .add(layout.createParallelGroup(GroupLayout.BASELINE) 98 .add(oK) 99 .add(cancel)) 100 .addContainerGap()) 101 ); 102 103 pack(); 104 Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); 105 setLocation(center.x - getWidth()/2, center.y - getHeight()/2); 106 } 107 108 111 public static void main(String args[]) { 112 java.awt.EventQueue.invokeLater(new Runnable () { 113 public void run() { 114 SettingsSetter dialog = new SettingsSetter(new javax.swing.JFrame (), true); 115 dialog.addWindowListener(new java.awt.event.WindowAdapter () { 116 public void windowClosing(java.awt.event.WindowEvent event) { 117 System.exit(0); 118 } 119 }); 120 dialog.setVisible(true); 121 } 122 }); 123 } 124 125 } 126 | Popular Tags |