1 19 20 21 package org.netbeans.modules.java.j2seproject.ui.wizards; 22 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.text.MessageFormat ; 28 import java.util.StringTokenizer ; 29 import javax.swing.event.DocumentListener ; 30 import javax.swing.event.DocumentEvent ; 31 import org.openide.WizardDescriptor; 32 import org.openide.WizardValidationException; 33 import org.openide.util.NbBundle; 34 import org.openide.util.Utilities; 35 36 39 public class PanelOptionsVisual extends SettingsPanel implements ActionListener , PropertyChangeListener { 40 41 private static boolean lastMainClassCheck = true; 43 private PanelConfigureProject panel; 44 private boolean valid; 45 46 public PanelOptionsVisual(PanelConfigureProject panel, NewJ2SEProjectWizardIterator.WizardType type) { 47 initComponents(); 48 this.panel = panel; 49 50 switch (type) { 51 case LIB: 52 setAsMainCheckBox.setVisible( false ); 53 createMainCheckBox.setVisible( false ); 54 mainClassTextField.setVisible( false ); 55 break; 56 case APP: 57 createMainCheckBox.addActionListener( this ); 58 createMainCheckBox.setSelected( lastMainClassCheck ); 59 mainClassTextField.setEnabled( lastMainClassCheck ); 60 break; 61 case EXT: 62 setAsMainCheckBox.setVisible( true ); 63 createMainCheckBox.setVisible( false ); 64 mainClassTextField.setVisible( false ); 65 break; 66 } 67 68 this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener () { 69 70 public void insertUpdate(DocumentEvent e) { 71 mainClassChanged (); 72 } 73 74 public void removeUpdate(DocumentEvent e) { 75 mainClassChanged (); 76 } 77 78 public void changedUpdate(DocumentEvent e) { 79 mainClassChanged (); 80 } 81 82 }); 83 } 84 85 public void actionPerformed( ActionEvent e ) { 86 if ( e.getSource() == createMainCheckBox ) { 87 lastMainClassCheck = createMainCheckBox.isSelected(); 88 mainClassTextField.setEnabled( lastMainClassCheck ); 89 this.panel.fireChangeEvent(); 90 } 91 } 92 93 public void propertyChange (PropertyChangeEvent event) { 94 if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) { 95 String newProjectName = NewJ2SEProjectWizardIterator.getPackageName((String ) event.getNewValue()); 96 if (!Utilities.isJavaIdentifier(newProjectName)) { 97 newProjectName = NbBundle.getMessage (PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName); 98 } 99 this.mainClassTextField.setText (MessageFormat.format( 100 NbBundle.getMessage (PanelOptionsVisual.class,"TXT_ClassName"), new Object [] {newProjectName} 101 )); 102 } 103 } 104 105 110 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 112 113 setAsMainCheckBox = new javax.swing.JCheckBox (); 114 createMainCheckBox = new javax.swing.JCheckBox (); 115 mainClassTextField = new javax.swing.JTextField (); 116 jPanel1 = new javax.swing.JPanel (); 117 118 setLayout(new java.awt.GridBagLayout ()); 119 120 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_PanelOptionsVisual")); 121 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_PanelOptionsVisual")); 122 setAsMainCheckBox.setSelected(true); 123 org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_setAsMainCheckBox")); 124 setAsMainCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 125 gridBagConstraints = new java.awt.GridBagConstraints (); 126 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 127 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 128 gridBagConstraints.weightx = 1.0; 129 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 130 add(setAsMainCheckBox, gridBagConstraints); 131 setAsMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_setAsMainCheckBox")); 132 setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_setAsMainCheckBox")); 133 134 createMainCheckBox.setSelected(true); 135 org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_createMainCheckBox")); 136 createMainCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 137 gridBagConstraints = new java.awt.GridBagConstraints (); 138 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 139 gridBagConstraints.weighty = 1.0; 140 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 141 add(createMainCheckBox, gridBagConstraints); 142 createMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_createMainCheckBox")); 143 createMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_createMainCheckBox")); 144 145 mainClassTextField.setText("com.myapp.Main"); 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 148 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 149 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 150 gridBagConstraints.weightx = 1.0; 151 gridBagConstraints.weighty = 1.0; 152 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 0); 153 add(mainClassTextField, gridBagConstraints); 154 mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled")); 155 mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled")); 156 157 gridBagConstraints = new java.awt.GridBagConstraints (); 158 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 159 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 160 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 161 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 162 gridBagConstraints.weightx = 1.0; 163 gridBagConstraints.weighty = 1.0; 164 add(jPanel1, gridBagConstraints); 165 jPanel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_jPanel1")); 166 jPanel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_jPanel1")); 167 168 } 170 boolean valid(WizardDescriptor settings) { 171 if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) { 172 if (!valid) { 173 settings.putProperty( "WizardPanel_errorMessage", NbBundle.getMessage(PanelOptionsVisual.class,"ERROR_IllegalMainClassName")); } 176 return this.valid; 177 } 178 else { 179 return true; 180 } 181 } 182 183 void read (WizardDescriptor d) { 184 } 186 187 void validate (WizardDescriptor d) throws WizardValidationException { 188 } 190 191 void store( WizardDescriptor d ) { 192 d.putProperty( "setAsMain", setAsMainCheckBox.isSelected() && setAsMainCheckBox.isVisible() ? Boolean.TRUE : Boolean.FALSE ); d.putProperty( "mainClass", createMainCheckBox.isSelected() && createMainCheckBox.isVisible() ? mainClassTextField.getText() : null ); } 195 196 private javax.swing.JCheckBox createMainCheckBox; 198 private javax.swing.JPanel jPanel1; 199 private javax.swing.JTextField mainClassTextField; 200 private javax.swing.JCheckBox setAsMainCheckBox; 201 203 private void mainClassChanged () { 204 String mainClassName = this.mainClassTextField.getText (); 205 StringTokenizer tk = new StringTokenizer (mainClassName, "."); boolean valid = true; 207 while (tk.hasMoreTokens()) { 208 String token = tk.nextToken(); 209 if (token.length() == 0 || !Utilities.isJavaIdentifier(token)) { 210 valid = false; 211 break; 212 } 213 } 214 this.valid = valid; 215 this.panel.fireChangeEvent(); 216 } 217 } 218 219 | Popular Tags |