1 19 20 21 package org.netbeans.modules.ruby.rubyproject.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.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 42 public class PanelOptionsVisual extends SettingsPanel implements ActionListener , PropertyChangeListener { 43 44 private static boolean lastMainClassCheck = true; 46 private PanelConfigureProject panel; 47 private boolean valid; 48 49 50 public PanelOptionsVisual( PanelConfigureProject panel, int type ) { 51 initComponents(); 52 this.panel = panel; 53 54 switch (type) { 55 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 () { 73 74 public void insertUpdate(DocumentEvent e) { 75 mainClassChanged (); 76 } 77 78 public void removeUpdate(DocumentEvent e) { 79 mainClassChanged (); 80 } 81 82 public void changedUpdate(DocumentEvent e) { 83 mainClassChanged (); 84 } 85 86 }); 87 } 88 89 public void actionPerformed( ActionEvent 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 event) { 98 if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) { 99 String newProjectName = NewRubyProjectWizardIterator.getPackageName((String ) 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 [] {newProjectName} 105 )); 106 } 107 } 108 109 114 private void initComponents() { 116 java.awt.GridBagConstraints gridBagConstraints; 117 118 setAsMainCheckBox = new javax.swing.JCheckBox (); 119 createMainCheckBox = new javax.swing.JCheckBox (); 120 mainClassTextField = new javax.swing.JTextField (); 121 jPanel1 = new javax.swing.JPanel (); 122 123 setLayout(new java.awt.GridBagLayout ()); 124 125 setAsMainCheckBox.setSelected(true); 126 org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_setAsMainCheckBox")); setAsMainCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 128 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 0, 5, 0); 133 add(setAsMainCheckBox, gridBagConstraints); 134 setAsMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_setAsMainCheckBox")); setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_setAsMainCheckBox")); 137 createMainCheckBox.setSelected(true); 138 org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_createMainCheckBox")); createMainCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 140 gridBagConstraints = new java.awt.GridBagConstraints (); 141 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 142 gridBagConstraints.weighty = 1.0; 143 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 144 add(createMainCheckBox, gridBagConstraints); 145 createMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_createMainCheckBox")); createMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_createMainCheckBox")); 148 mainClassTextField.setText("com.myapp.Main"); 149 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 12, 12, 0); 156 add(mainClassTextField, gridBagConstraints); 157 mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled")); mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled")); 160 gridBagConstraints = new java.awt.GridBagConstraints (); 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")); jPanel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_jPanel1")); 171 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_PanelOptionsVisual")); getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_PanelOptionsVisual")); } 175 boolean valid(WizardDescriptor settings) { 176 if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) { 177 if (!valid) { 178 settings.putProperty( "WizardPanel_errorMessage", NbBundle.getMessage(PanelOptionsVisual.class,"ERROR_IllegalMainClassName")); } 181 return this.valid; 182 } 183 else { 184 return true; 185 } 186 } 187 188 void read (WizardDescriptor d) { 189 } 191 192 void validate (WizardDescriptor d) throws WizardValidationException { 193 } 195 196 void store( WizardDescriptor d ) { 197 d.putProperty( "setAsMain", setAsMainCheckBox.isSelected() && setAsMainCheckBox.isVisible() ? Boolean.TRUE : Boolean.FALSE ); d.putProperty( "mainClass", createMainCheckBox.isSelected() && createMainCheckBox.isVisible() ? mainClassTextField.getText() : null ); } 200 201 private javax.swing.JCheckBox createMainCheckBox; 203 private javax.swing.JPanel jPanel1; 204 private javax.swing.JTextField mainClassTextField; 205 private javax.swing.JCheckBox setAsMainCheckBox; 206 208 private void mainClassChanged () { 209 210 String mainClassName = this.mainClassTextField.getText (); 211 StringTokenizer tk = new StringTokenizer (mainClassName, "."); boolean valid = true; 213 while (tk.hasMoreTokens()) { 214 String token = tk.nextToken(); 215 if (token.length() == 0 || token.equals(" ")) { 216 valid = false; 217 break; 218 } 219 } 220 this.valid = valid; 221 this.panel.fireChangeEvent(); 222 } 223 } 224 225 | Popular Tags |