/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. * * Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution License("CDDL") (collectively, the * "License"). You may not use this file except in compliance with the * License. You can obtain a copy of the License at * http://www.netbeans.org/cddl-gplv2.html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software, include this License Header * Notice in each file and include the License file at * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the GPL Version 2 section of the License file that * accompanied this code. If applicable, add the following below the * License Header, with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL * or only the GPL Version 2, indicate your decision by adding * "[Contributor] elects to include this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of license, a recipient has the option to distribute * your version of this file under either the CDDL, the GPL Version 2 or * to extend the choice of license to its licensees as provided above. * However, if you add GPL Version 2 code and therefore, elected the GPL * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ package org.netbeans.modules.ruby.rubyproject.ui.wizards; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.text.MessageFormat; import java.util.StringTokenizer; import javax.swing.event.DocumentListener; import javax.swing.event.DocumentEvent; import org.netbeans.modules.ruby.platform.PlatformComponentFactory; import org.netbeans.modules.ruby.platform.RubyPlatformCustomizer; import org.netbeans.modules.ruby.rubyproject.Util; import org.netbeans.modules.ruby.rubyproject.ui.wizards.NewRubyProjectWizardIterator.Type; import org.openide.WizardDescriptor; import org.openide.WizardValidationException; import org.openide.util.NbBundle; import org.openide.util.Utilities; public final class PanelOptionsVisual extends SettingsPanel implements ActionListener, PropertyChangeListener { private static boolean lastMainClassCheck = true; // XXX Store somewhere private final PanelConfigureProject panel; private boolean valid; PanelOptionsVisual(PanelConfigureProject panel, Type type) { initComponents(); Util.preselectWizardPlatform(platforms); this.panel = panel; fireChangeEvent(); PlatformComponentFactory.addPlatformChangeListener(platforms, new PlatformComponentFactory.PlatformChangeListener() { public void platformChanged() { fireChangeEvent(); } }); switch (type) { case APPLICATION: createMainCheckBox.addActionListener(this); createMainCheckBox.setSelected(lastMainClassCheck); mainClassTextField.setEnabled(lastMainClassCheck); break; case EXISTING: createMainCheckBox.setVisible(false); mainClassTextField.setVisible(false); break; default: throw new IllegalStateException("unknown type: " + type); } this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener () { public void insertUpdate(DocumentEvent e) { mainClassChanged (); } public void removeUpdate(DocumentEvent e) { mainClassChanged (); } public void changedUpdate(DocumentEvent e) { mainClassChanged (); } }); } public @Override void removeNotify() { Util.storeWizardPlatform(platforms); super.removeNotify(); } public void actionPerformed( ActionEvent e ) { if ( e.getSource() == createMainCheckBox ) { lastMainClassCheck = createMainCheckBox.isSelected(); mainClassTextField.setEnabled( lastMainClassCheck ); fireChangeEvent(); } } public void propertyChange (PropertyChangeEvent event) { if ("roots".equals(event.getPropertyName())) { fireChangeEvent(); } if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) { String newProjectName = NewRubyProjectWizardIterator.getPackageName((String) event.getNewValue()); if (!Utilities.isJavaIdentifier(newProjectName)) { newProjectName = NbBundle.getMessage (PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName); } this.mainClassTextField.setText (MessageFormat.format( NbBundle.getMessage (PanelOptionsVisual.class,"TXT_ClassName"), new Object[] {newProjectName} )); } } private void fireChangeEvent() { this.panel.fireChangeEvent(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { createMainCheckBox = new javax.swing.JCheckBox(); mainClassTextField = new javax.swing.JTextField(); rubyPlatformLabel = new javax.swing.JLabel(); platforms = org.netbeans.modules.ruby.platform.PlatformComponentFactory.getRubyPlatformsComboxBox(); manageButton = new javax.swing.JButton(); createMainCheckBox.setSelected(true); org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_createMainCheckBox")); // NOI18N rubyPlatformLabel.setLabelFor(platforms); org.openide.awt.Mnemonics.setLocalizedText(rubyPlatformLabel, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "RubyPlatformLabel")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(manageButton, org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "RubyHomeBrowse")); // NOI18N manageButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { manageButtonActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(createMainCheckBox) .add(rubyPlatformLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(platforms, 0, 319, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(manageButton)) .add(mainClassTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 416, Short.MAX_VALUE))) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(createMainCheckBox) .add(mainClassTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(rubyPlatformLabel) .add(manageButton) .add(platforms, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) ); createMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_createMainCheckBox")); // NOI18N createMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_createMainCheckBox")); // NOI18N mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled")); // NOI18N mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled")); // NOI18N rubyPlatformLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "PanelOptionsVisual.rubyPlatformLabel.AccessibleContext.accessibleDescription")); // NOI18N manageButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "PanelOptionsVisual.manageButton.AccessibleContext.accessibleDescription")); // NOI18N getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_PanelOptionsVisual")); // NOI18N getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_PanelOptionsVisual")); // NOI18N }// </editor-fold>//GEN-END:initComponents private void manageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageButtonActionPerformed RubyPlatformCustomizer.manage(platforms); }//GEN-LAST:event_manageButtonActionPerformed boolean valid(WizardDescriptor settings) { if (PlatformComponentFactory.getPlatform(platforms) == null) { return false; } if (mainClassTextField.isVisible() && mainClassTextField.isEnabled()) { if (!valid) { settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, // NOI18N NbBundle.getMessage(PanelOptionsVisual.class, "ERROR_IllegalMainClassName")); //NOI18N } return this.valid; } else { return true; } } void read(WizardDescriptor d) { } void validate (WizardDescriptor d) throws WizardValidationException { // nothing to validate } void store( WizardDescriptor d ) { d.putProperty( /*XXX Define somewhere */ "setAsMain", Boolean.FALSE); // NOI18N d.putProperty( /*XXX Define somewhere */ "mainClass", createMainCheckBox.isSelected() && createMainCheckBox.isVisible() ? mainClassTextField.getText() : null ); // NOI18N d.putProperty("platform", PlatformComponentFactory.getPlatform(platforms)); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox createMainCheckBox; private javax.swing.JTextField mainClassTextField; private javax.swing.JButton manageButton; private javax.swing.JComboBox platforms; private javax.swing.JLabel rubyPlatformLabel; // End of variables declaration//GEN-END:variables private void mainClassChanged () { String mainClassName = this.mainClassTextField.getText (); StringTokenizer tk = new StringTokenizer (mainClassName, "."); //NOI18N valid = true; while (tk.hasMoreTokens()) { String token = tk.nextToken(); if (token.length() == 0 || /* !Utilities.isJavaIdentifier(token)*/ token.equals(" ")) { valid = false; break; } } fireChangeEvent(); } }