KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > ui > wizards > PanelOptionsVisual


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
21 package org.netbeans.modules.ruby.rubyproject.ui.wizards;
22
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30 import javax.swing.event.DocumentEvent JavaDoc;
31 import org.openide.DialogDisplayer;
32 import org.openide.NotifyDescriptor;
33 import org.openide.WizardDescriptor;
34 import org.openide.WizardValidationException;
35 import org.openide.util.NbBundle;
36 import org.openide.util.Utilities;
37
38 /**
39  *
40  * @author phrebejk
41  */

42 public class PanelOptionsVisual extends SettingsPanel implements ActionListener JavaDoc, PropertyChangeListener JavaDoc {
43     
44     private static boolean lastMainClassCheck = true; // XXX Store somewhere
45

46     private PanelConfigureProject panel;
47     private boolean valid;
48     
49     /** Creates new form PanelOptionsVisual */
50     public PanelOptionsVisual( PanelConfigureProject panel, int type ) {
51         initComponents();
52         this.panel = panel;
53
54         switch (type) {
55 // case NewRubyProjectWizardIterator.TYPE_LIB:
56
// setAsMainCheckBox.setVisible( false );
57
// createMainCheckBox.setVisible( false );
58
// mainClassTextField.setVisible( false );
59
// break;
60
case NewRubyProjectWizardIterator.TYPE_APP:
61                 createMainCheckBox.addActionListener( this );
62                 createMainCheckBox.setSelected( lastMainClassCheck );
63                 mainClassTextField.setEnabled( lastMainClassCheck );
64                 break;
65             case NewRubyProjectWizardIterator.TYPE_EXT:
66                 setAsMainCheckBox.setVisible( true );
67                 createMainCheckBox.setVisible( false );
68                 mainClassTextField.setVisible( false );
69                 break;
70         }
71         
72         this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener JavaDoc () {
73             
74             public void insertUpdate(DocumentEvent JavaDoc e) {
75                 mainClassChanged ();
76             }
77             
78             public void removeUpdate(DocumentEvent JavaDoc e) {
79                 mainClassChanged ();
80             }
81             
82             public void changedUpdate(DocumentEvent JavaDoc e) {
83                 mainClassChanged ();
84             }
85             
86         });
87     }
88
89     public void actionPerformed( ActionEvent JavaDoc e ) {
90         if ( e.getSource() == createMainCheckBox ) {
91             lastMainClassCheck = createMainCheckBox.isSelected();
92             mainClassTextField.setEnabled( lastMainClassCheck );
93             this.panel.fireChangeEvent();
94         }
95     }
96     
97     public void propertyChange (PropertyChangeEvent JavaDoc event) {
98         if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) {
99             String JavaDoc newProjectName = NewRubyProjectWizardIterator.getPackageName((String JavaDoc) event.getNewValue());
100             if (!Utilities.isJavaIdentifier(newProjectName)) {
101                 newProjectName = NbBundle.getMessage (PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName);
102             }
103             this.mainClassTextField.setText (MessageFormat.format(
104                 NbBundle.getMessage (PanelOptionsVisual.class,"TXT_ClassName"), new Object JavaDoc[] {newProjectName}
105             ));
106         }
107     }
108     
109     /** This method is called from within the constructor to
110      * initialize the form.
111      * WARNING: Do NOT modify this code. The content of this method is
112      * always regenerated by the Form Editor.
113      */

114     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
115
private void initComponents() {
116         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
117
118         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
119         createMainCheckBox = new javax.swing.JCheckBox JavaDoc();
120         mainClassTextField = new javax.swing.JTextField JavaDoc();
121         jPanel1 = new javax.swing.JPanel JavaDoc();
122
123         setLayout(new java.awt.GridBagLayout JavaDoc());
124
125         setAsMainCheckBox.setSelected(true);
126         org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_setAsMainCheckBox")); // NOI18N
127
setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
130         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
131         gridBagConstraints.weightx = 1.0;
132         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
133         add(setAsMainCheckBox, gridBagConstraints);
134         setAsMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_setAsMainCheckBox")); // NOI18N
135
setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_setAsMainCheckBox")); // NOI18N
136

137         createMainCheckBox.setSelected(true);
138         org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_createMainCheckBox")); // NOI18N
139
createMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
140         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
141         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
142         gridBagConstraints.weighty = 1.0;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
144         add(createMainCheckBox, gridBagConstraints);
145         createMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_createMainCheckBox")); // NOI18N
146
createMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_createMainCheckBox")); // NOI18N
147

148         mainClassTextField.setText("com.myapp.Main");
149         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
150         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
151         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
152         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
153         gridBagConstraints.weightx = 1.0;
154         gridBagConstraints.weighty = 1.0;
155         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 0);
156         add(mainClassTextField, gridBagConstraints);
157         mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled")); // NOI18N
158
mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled")); // NOI18N
159

160         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
161         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
162         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
163         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
164         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
165         gridBagConstraints.weightx = 1.0;
166         gridBagConstraints.weighty = 1.0;
167         add(jPanel1, gridBagConstraints);
168         jPanel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_jPanel1")); // NOI18N
169
jPanel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_jPanel1")); // NOI18N
170

171         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_PanelOptionsVisual")); // NOI18N
172
getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_PanelOptionsVisual")); // NOI18N
173
}// </editor-fold>//GEN-END:initComponents
174

175     boolean valid(WizardDescriptor settings) {
176         if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) {
177             if (!valid) {
178                 settings.putProperty( "WizardPanel_errorMessage", // NOI18N
179
NbBundle.getMessage(PanelOptionsVisual.class,"ERROR_IllegalMainClassName")); //NOI18N
180
}
181             return this.valid;
182         }
183         else {
184             return true;
185         }
186     }
187     
188     void read (WizardDescriptor d) {
189         //TODO:
190
}
191     
192     void validate (WizardDescriptor d) throws WizardValidationException {
193         // nothing to validate
194
}
195
196     void store( WizardDescriptor d ) {
197         d.putProperty( /*XXX Define somewhere */ "setAsMain", setAsMainCheckBox.isSelected() && setAsMainCheckBox.isVisible() ? Boolean.TRUE : Boolean.FALSE ); // NOI18N
198
d.putProperty( /*XXX Define somewhere */ "mainClass", createMainCheckBox.isSelected() && createMainCheckBox.isVisible() ? mainClassTextField.getText() : null ); // NOI18N
199
}
200     
201     // Variables declaration - do not modify//GEN-BEGIN:variables
202
private javax.swing.JCheckBox JavaDoc createMainCheckBox;
203     private javax.swing.JPanel JavaDoc jPanel1;
204     private javax.swing.JTextField JavaDoc mainClassTextField;
205     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
206     // End of variables declaration//GEN-END:variables
207

208     private void mainClassChanged () {
209         
210         String JavaDoc mainClassName = this.mainClassTextField.getText ();
211         StringTokenizer JavaDoc tk = new StringTokenizer JavaDoc (mainClassName, "."); //NOI18N
212
boolean valid = true;
213         while (tk.hasMoreTokens()) {
214             String JavaDoc token = tk.nextToken();
215             if (token.length() == 0 || /* !Utilities.isJavaIdentifier(token)*/ token.equals(" ")) {
216                 valid = false;
217                 break;
218             }
219         }
220         this.valid = valid;
221         this.panel.fireChangeEvent();
222     }
223 }
224
225
Popular Tags