KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.exceptions.settings;
20
21 import java.awt.GraphicsEnvironment JavaDoc;
22 import java.awt.Point JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JButton JavaDoc;
26 import javax.swing.JDialog JavaDoc;
27 import org.jdesktop.layout.GroupLayout;
28 import org.jdesktop.layout.LayoutStyle;
29 import org.openide.DialogDisplayer;
30 import org.openide.NotifyDescriptor;
31
32 /**
33  *
34  * @author jindra
35  */

36 public class SettingsSetter extends JDialog JavaDoc {
37     
38     private JButton JavaDoc oK;
39     private JButton JavaDoc cancel;
40     private final PasswordPanel panel = new PasswordPanel();
41     private java.util.ResourceBundle JavaDoc bundle = org.openide.util.NbBundle.getBundle(PasswordPanel.class);
42     
43     /** Creates new form NewJFrame */
44     public SettingsSetter(java.awt.Frame JavaDoc 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 JavaDoc(bundle.getString("OK"));
54         oK.setMnemonic(bundle.getString("OK").charAt(0));
55         cancel = new JButton JavaDoc(bundle.getString("Cancel"));
56         oK.setMnemonic(bundle.getString("Cancel").charAt(0));
57         panel.load();
58         cancel.addActionListener(new ActionListener JavaDoc() {
59             public void actionPerformed(ActionEvent JavaDoc event) {
60                 panel.cleanPasswd();
61                 panel.store();
62                 dispose();
63             }
64         });
65         
66         oK.addActionListener(new ActionListener JavaDoc() {
67             public void actionPerformed(ActionEvent JavaDoc event) {
68                 if ((panel.getPasswd().length()==0)||(panel.getUserName().length()==0)) {
69                     String JavaDoc 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 JavaDoc center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
105         setLocation(center.x - getWidth()/2, center.y - getHeight()/2);
106     }
107     
108     /**
109      * @param args the command line arguments
110      */

111     public static void main(String JavaDoc args[]) {
112         java.awt.EventQueue.invokeLater(new Runnable JavaDoc() {
113             public void run() {
114                 SettingsSetter dialog = new SettingsSetter(new javax.swing.JFrame JavaDoc(), true);
115                 dialog.addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
116                     public void windowClosing(java.awt.event.WindowEvent JavaDoc event) {
117                         System.exit(0);
118                     }
119                 });
120                 dialog.setVisible(true);
121             }
122         });
123     }
124     
125 }
126
Popular Tags