KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > logger > UserInput


1 /*
2  * NewJFrame2.java
3  *
4  * Created on June 13, 2005, 5:37 PM
5  */

6
7 package org.netbeans.modules.logger;
8
9 import java.lang.StringBuffer JavaDoc;
10 import org.netbeans.modules.logger.listeners.ListenerTools;
11
12 /**
13  * Dsiplays a form the user has to fill in. Blocks the IDE launching as long as
14  * these parameters are not entered. We need to know some username and the level
15  * of experience using NB IDE.
16  * @author loicsegapelli
17  */

18 public class UserInput extends javax.swing.JFrame JavaDoc {
19     
20     /**
21      * first level of experience using NB
22      */

23     public final static String JavaDoc LEVEL1 = "beginner";
24     /**
25      * second level of experience using NB
26      */

27     public final static String JavaDoc LEVEL2 = "frequent user";
28     /**
29      * third level of experience using NB
30      */

31     public final static String JavaDoc LEVEL3 = "experienced user";
32     static String JavaDoc nickname = "";
33     static String JavaDoc level = LEVEL2;
34     static boolean typed = false;
35     Main main;
36     
37     /**
38      * Creates the form.
39      * @param main A reference to Main is necessary to send the parameters entered into
40      * the form back to the module
41      */

42     public UserInput(Main main) {
43         this.main = main;
44         initComponents();
45     }
46     
47     private void initComponents() {
48         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
49
50         buttonGroup = new javax.swing.ButtonGroup JavaDoc();
51         jPanel3 = new javax.swing.JPanel JavaDoc();
52         jPanel1 = new javax.swing.JPanel JavaDoc();
53         titleLabel = new javax.swing.JLabel JavaDoc();
54         nicknameTextField = new javax.swing.JTextField JavaDoc();
55         levelLabel = new javax.swing.JLabel JavaDoc();
56         level1RadioButton = new javax.swing.JRadioButton JavaDoc();
57         level2RadioButton = new javax.swing.JRadioButton JavaDoc();
58         level3RadioButton = new javax.swing.JRadioButton JavaDoc();
59         nameLabel = new javax.swing.JLabel JavaDoc();
60         jPanel2 = new javax.swing.JPanel JavaDoc();
61         helpButton = new javax.swing.JButton JavaDoc();
62         okButton = new javax.swing.JButton JavaDoc();
63
64         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
65         setTitle("Logger Module");
66         setName("Logger Module");
67         setResizable(false);
68         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
69
70         jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(12, 12, 12, 12)));
71         jPanel1.setMaximumSize(null);
72         jPanel1.setMinimumSize(null);
73         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(300, 300));
74         titleLabel.setText("<html>Thank you for using xDesign Logger Module. Please provide your name and the level of your experience with NetBeans.</html>");
75         titleLabel.setBorder(new javax.swing.border.TitledBorder JavaDoc("Thank you!"));
76         titleLabel.setFocusable(false);
77         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
78         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
79         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
80         gridBagConstraints.weightx = 1.0;
81         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 10, 11, 9);
82         jPanel1.add(titleLabel, gridBagConstraints);
83
84         nicknameTextField.setInputVerifier(new NicknameNormalizer());
85         nicknameTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
86             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
87                 focus(evt);
88             }
89         });
90         nicknameTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
91             public void keyTyped(java.awt.event.KeyEvent JavaDoc evt) {
92                 UserInput.this.keyTyped(evt);
93             }
94         });
95
96         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
97         gridBagConstraints.gridx = 1;
98         gridBagConstraints.gridy = 1;
99         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
100         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
101         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
103         jPanel1.add(nicknameTextField, gridBagConstraints);
104
105         levelLabel.setFont(new java.awt.Font JavaDoc("Lucida Grande", 1, 13));
106         levelLabel.setText("Select your level as a NetBeans user:");
107         levelLabel.setFocusable(false);
108         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints.gridx = 0;
110         gridBagConstraints.gridy = 2;
111         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
112         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
113         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
114         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 11);
115         jPanel1.add(levelLabel, gridBagConstraints);
116
117         buttonGroup.add(level1RadioButton);
118         level1RadioButton.setText(LEVEL1);
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridx = 1;
121         gridBagConstraints.gridy = 3;
122         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 11);
125         jPanel1.add(level1RadioButton, gridBagConstraints);
126
127         buttonGroup.add(level2RadioButton);
128         level2RadioButton.setText(LEVEL2);
129
130         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridx = 1;
132         gridBagConstraints.gridy = 4;
133         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
134         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 11);
136         jPanel1.add(level2RadioButton, gridBagConstraints);
137
138         buttonGroup.add(level3RadioButton);
139         level3RadioButton.setText(LEVEL3);
140         level2RadioButton.setSelected(true);
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 1;
143         gridBagConstraints.gridy = 5;
144         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146         gridBagConstraints.weighty = 1.0;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 11);
148         jPanel1.add(level3RadioButton, gridBagConstraints);
149
150         nameLabel.setFont(new java.awt.Font JavaDoc("Lucida Grande", 1, 13));
151         nameLabel.setText("Name: ");
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 0;
154         gridBagConstraints.gridy = 1;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 0);
157         jPanel1.add(nameLabel, gridBagConstraints);
158
159         jPanel2.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.CENTER, 5, 0));
160
161         helpButton.setText("Help");
162         helpButton.setEnabled(false);
163         jPanel2.add(helpButton);
164
165         okButton.setText("OK");
166         okButton.setEnabled(false);
167         okButton.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
168             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
169                 okButtonClicked(evt);
170             }
171         });
172
173         jPanel2.add(okButton);
174
175         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridx = 1;
177         gridBagConstraints.gridy = 6;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
179         jPanel1.add(jPanel2, gridBagConstraints);
180
181         getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
182
183         pack();
184     }
185     
186     private void focus(java.awt.event.FocusEvent JavaDoc evt) {
187         nicknameTextField.setText("");
188     }
189     
190     private void keyTyped(java.awt.event.KeyEvent JavaDoc evt) {
191         if(!typed) {
192             typed = true;
193             okButton.setEnabled(true);
194         }
195     }
196     
197     private void okButtonClicked(java.awt.event.MouseEvent JavaDoc evt) {
198         if(nickname.length()!=0){
199             if(level1RadioButton.isSelected()){
200                 level = LEVEL1;
201             } else if (level2RadioButton.isSelected()){
202                 level = LEVEL2;
203             } else if (level3RadioButton.isSelected()){
204                 level = LEVEL3;
205             }
206             level = level.split("\\s+")[0];
207             ListenerTools.saveParameters(level, nickname);
208             main.wakeUp();
209             this.dispose();
210         } else {
211             typed = false;
212             okButton.setEnabled(false);
213         }
214     }
215     
216     /**
217      * Here just to test the form. Not used by the module.
218      * @param args the command line arguments
219      */

220     public static void main(String JavaDoc args[]) {
221         java.awt.EventQueue.invokeLater(new Runnable JavaDoc() {
222             public void run() {
223                 new UserInput(null).setVisible(true);
224             }
225         });
226     }
227     
228     private class NicknameNormalizer extends javax.swing.InputVerifier JavaDoc {
229         public boolean verify(javax.swing.JComponent JavaDoc input) {
230             javax.swing.JTextField JavaDoc tf = (javax.swing.JTextField JavaDoc) input;
231             nickname = tf.getText();
232             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
233             for(int i=0; i<nickname.length(); i++){
234                 char c = nickname.charAt(i);
235                 if(Character.isLetterOrDigit(c)) buffer.append(c);
236             }
237             nickname = buffer.toString();
238             tf.setText(nickname);
239             return nickname.length() != 0;
240         }
241     }
242
243     private javax.swing.ButtonGroup JavaDoc buttonGroup;
244     private javax.swing.JButton JavaDoc helpButton;
245     private javax.swing.JLabel JavaDoc levelLabel;
246     private javax.swing.JPanel JavaDoc jPanel1;
247     private javax.swing.JPanel JavaDoc jPanel2;
248     private javax.swing.JPanel JavaDoc jPanel3;
249     private javax.swing.JRadioButton JavaDoc level1RadioButton;
250     private javax.swing.JRadioButton JavaDoc level2RadioButton;
251     private javax.swing.JRadioButton JavaDoc level3RadioButton;
252     private javax.swing.JLabel JavaDoc nameLabel;
253     private javax.swing.JTextField JavaDoc nicknameTextField;
254     private javax.swing.JButton JavaDoc okButton;
255     private javax.swing.JLabel JavaDoc titleLabel;
256     
257 }
258
Popular Tags