KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > NewObjectPanel


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.openide.loaders;
21
22 import java.awt.event.KeyEvent JavaDoc;
23 import javax.swing.KeyStroke JavaDoc;
24 import javax.swing.SwingUtilities JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import javax.swing.event.DocumentListener JavaDoc;
28 import org.openide.awt.Mnemonics;
29 import org.openide.util.Utilities;
30
31 /** Dialog that can be used in create from template.
32 *
33 * @author Jaroslav Tulach, David Strupl, Jiri Rechtacek
34 */

35 final class NewObjectPanel extends javax.swing.JPanel JavaDoc implements DocumentListener JavaDoc {
36
37     /** listener to changes in panel */
38     private ChangeListener JavaDoc listener;
39     
40     /** Creates new form NewObjectPanel */
41     public NewObjectPanel() {
42         initComponents ();
43
44         setName(getString("LAB_NewObjectPanelName")); // NOI18N
45

46         setBorder (new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(8, 8, 8, 8)));
47
48         // registers itself to listen to changes in the content of document
49
newObjectName.getDocument().addDocumentListener(this);
50         newObjectName.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
51
52         java.util.ResourceBundle JavaDoc bundle = org.openide.util.NbBundle.getBundle(NewObjectPanel.class);
53         
54         setNewObjectName(""); // NOI18N
55

56         putClientProperty("WizardPanel_contentData", new String JavaDoc[] { getName() }); //NOI18N
57
putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(0)); //NOI18N
58

59         newObjectName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_NewObjectName")); // NOI18N
60
getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_NewObjectPanel")); // NOI18N
61
}
62
63     /** Preffered size */
64     public java.awt.Dimension JavaDoc getPreferredSize() {
65         return TemplateWizard.PREF_DIM;
66     }
67
68     /** This method is called from within the constructor to
69      * initialize the form.
70      * WARNING: Do NOT modify this code. The content of this method is
71      * always regenerated by the FormEditor.
72      */

73     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
74
private void initComponents() {
75         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
76
77         namePanel = new javax.swing.JPanel JavaDoc();
78         jLabel1 = new javax.swing.JLabel JavaDoc();
79         newObjectName = new javax.swing.JTextField JavaDoc();
80
81         FormListener formListener = new FormListener();
82
83         setPreferredSize(new java.awt.Dimension JavaDoc(560, 520));
84         setLayout(new java.awt.BorderLayout JavaDoc(0, 8));
85
86         namePanel.setPreferredSize(new java.awt.Dimension JavaDoc(0, 0));
87         namePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
88
89         jLabel1.setLabelFor(newObjectName);
90         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/openide/loaders/Bundle"); // NOI18N
91
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("CTL_NewObjectName")); // NOI18N
92
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
93         gridBagConstraints.gridx = 0;
94         gridBagConstraints.gridy = 0;
95         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
96         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
97         namePanel.add(jLabel1, gridBagConstraints);
98
99         newObjectName.addFocusListener(formListener);
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridx = 1;
102         gridBagConstraints.gridy = 0;
103         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
104         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105         gridBagConstraints.weightx = 1.0;
106         gridBagConstraints.weighty = 1.0;
107         namePanel.add(newObjectName, gridBagConstraints);
108
109         add(namePanel, java.awt.BorderLayout.CENTER);
110     }
111
112     // Code for dispatching events from components to event handlers.
113

114     private class FormListener implements java.awt.event.FocusListener JavaDoc {
115         FormListener() {}
116         public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
117             if (evt.getSource() == newObjectName) {
118                 NewObjectPanel.this.newObjectNameFocusGained(evt);
119             }
120         }
121
122         public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
123         }
124     }// </editor-fold>//GEN-END:initComponents
125

126     private void packageNameFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_packageNameFocusGained
127

128     }//GEN-LAST:event_packageNameFocusGained
129

130     private void packageModelChanged (javax.swing.event.ListDataEvent JavaDoc evt) {//GEN-FIRST:event_packageModelChanged
131
}//GEN-LAST:event_packageModelChanged
132

133     private void newObjectNameFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_newObjectNameFocusGained
134
if (
135             Utilities.getOperatingSystem() == Utilities.OS_SOLARIS ||
136             Utilities.getOperatingSystem() == Utilities.OS_SUNOS
137         ) {
138             // does not work on CDE window manager, so better do nothin
139
return;
140         }
141
142         newObjectName.selectAll ();
143     }//GEN-LAST:event_newObjectNameFocusGained
144

145     private void templatesTreeValueChanged (javax.swing.event.TreeSelectionEvent JavaDoc evt) {//GEN-FIRST:event_templatesTreeValueChanged
146
}//GEN-LAST:event_templatesTreeValueChanged
147

148
149     // Variables declaration - do not modify//GEN-BEGIN:variables
150
private javax.swing.JLabel JavaDoc jLabel1;
151     private javax.swing.JPanel JavaDoc namePanel;
152     private javax.swing.JTextField JavaDoc newObjectName;
153     // End of variables declaration//GEN-END:variables
154

155     /** */
156     public void changedUpdate(final javax.swing.event.DocumentEvent JavaDoc p1) {
157         if (p1.getDocument () == newObjectName.getDocument ()) {
158             SwingUtilities.invokeLater (new Runnable JavaDoc () {
159                 public void run () {
160                     if (newObjectName.getText().equals ("")) { // NOI18N
161
setNewObjectName (""); // NOI18N
162
}
163                     fireStateChanged();
164                 }
165             });
166         }
167     }
168
169     public void removeUpdate(final javax.swing.event.DocumentEvent JavaDoc p1) {
170         changedUpdate (p1);
171     }
172     
173     public void insertUpdate(final javax.swing.event.DocumentEvent JavaDoc p1) {
174         changedUpdate (p1);
175     }
176
177     public void addNotify () {
178         super.addNotify ();
179         newObjectName.requestFocus ();
180     }
181
182     /** Add a listener to changes of the panel's validity.
183     * @param l the listener to add
184     * @see #isValid
185     */

186     void addChangeListener (ChangeListener JavaDoc l) {
187         if (listener != null) {
188             throw new IllegalStateException JavaDoc ();
189         }
190         listener = l;
191     }
192
193     /** Remove a listener to changes of the panel's validity.
194     * @param l the listener to remove
195     */

196     void removeChangeListener (ChangeListener JavaDoc l) {
197         listener = null;
198     }
199
200     /** Fires info to listener.
201     */

202     private void fireStateChanged () {
203         if (listener != null) {
204             listener.stateChanged (new ChangeEvent JavaDoc (this));
205         }
206     }
207   
208     /** Sets the class name to some reasonable value.
209     * @param name the name to set the name to
210     */

211     private void setNewObjectName (String JavaDoc name) {
212         String JavaDoc n = name;
213         if (name == null || name.length () == 0) {
214             n = defaultNewObjectName ();
215         }
216
217         newObjectName.getDocument().removeDocumentListener(this);
218         newObjectName.setText (n);
219         newObjectName.getDocument().addDocumentListener(this);
220
221         if (name == null || name.length () == 0) {
222             newObjectName.selectAll ();
223         }
224     }
225
226     /** */
227     public String JavaDoc getNewObjectName() {
228         return newObjectName.getText();
229     }
230     
231     /** Getter for default name of a class.
232     * @return the default name.
233     */

234     static String JavaDoc defaultNewObjectName () {
235         return getString("FMT_DefaultNewObjectName"); // NOI18N
236
}
237     
238     private static String JavaDoc getString(String JavaDoc key) {
239         return org.openide.util.NbBundle.getBundle(NewObjectPanel.class).getString(key);
240     }
241 }
242
Popular Tags