001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui.platform;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import javax.swing.event.DocumentEvent;
047: import org.netbeans.modules.apisupport.project.ui.UIUtil;
048: import org.netbeans.modules.apisupport.project.ui.wizard.BasicVisualPanel;
049: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
050: import org.openide.WizardDescriptor;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * Second panel from <em>Adding New Platform</em> wizard panels. Allows user to
055: * add additional info about a selected platform.
056: *
057: * @author Martin Krauskopf
058: */
059: public class PlatformInfoVisualPanel extends BasicVisualPanel {
060:
061: private boolean attached;
062:
063: /** Creates new form BasicInfoVisualPanel */
064: public PlatformInfoVisualPanel(WizardDescriptor setting) {
065: super (setting);
066: initComponents();
067: initAccessibility();
068: setName(NbPlatformCustomizer.INFO_STEP);
069: }
070:
071: void refreshData() {
072: String destDir = (String) getSettings().getProperty(
073: NbPlatformCustomizer.PLAF_DIR_PROPERTY);
074: try {
075: plafNameValue.setText(NbPlatform
076: .computeDisplayName(new File(destDir)));
077: } catch (IOException e) {
078: plafNameValue.setText(destDir);
079: }
080: checkForm();
081: }
082:
083: private void checkForm() {
084: String name = plafNameValue.getText().trim();
085: if (name.equals("")) {
086: setError(getMessage("MSG_BlankPlatformName"));
087: } else if (!NbPlatform.isLabelValid(name)
088: || /* #115909 */NbPlatform.getPlatformByID(name
089: .replace(' ', '_')) != null) {
090: setError(getMessage("MSG_NameIsAlreadyUsed"));
091: } else {
092: markValid();
093: }
094: }
095:
096: void storeData() {
097: getSettings().putProperty(
098: NbPlatformCustomizer.PLAF_LABEL_PROPERTY,
099: plafNameValue.getText().trim());
100: }
101:
102: public @Override
103: void addNotify() {
104: super .addNotify();
105: if (!attached) {
106: plafNameValue.getDocument().addDocumentListener(
107: new UIUtil.DocumentAdapter() {
108: public void insertUpdate(DocumentEvent e) {
109: checkForm();
110: }
111: });
112: attached = true;
113: }
114: }
115:
116: private static String getMessage(String key) {
117: return NbBundle.getMessage(PlatformInfoVisualPanel.class, key);
118: }
119:
120: /** This method is called from within the constructor to
121: * initialize the form.
122: * WARNING: Do NOT modify this code. The content of this method is
123: * always regenerated by the Form Editor.
124: */
125: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
126: private void initComponents() {
127: java.awt.GridBagConstraints gridBagConstraints;
128:
129: plafName = new javax.swing.JLabel();
130: plafNameValue = new javax.swing.JTextField();
131: filler = new javax.swing.JLabel();
132:
133: setLayout(new java.awt.GridBagLayout());
134:
135: org.openide.awt.Mnemonics.setLocalizedText(plafName,
136: org.openide.util.NbBundle.getMessage(
137: PlatformInfoVisualPanel.class,
138: "LBL_PlatformName_P"));
139: gridBagConstraints = new java.awt.GridBagConstraints();
140: gridBagConstraints.gridx = 0;
141: gridBagConstraints.gridy = 0;
142: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
143: add(plafName, gridBagConstraints);
144:
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridx = 1;
147: gridBagConstraints.gridy = 0;
148: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149: gridBagConstraints.weightx = 1.0;
150: add(plafNameValue, gridBagConstraints);
151:
152: gridBagConstraints = new java.awt.GridBagConstraints();
153: gridBagConstraints.gridx = 0;
154: gridBagConstraints.gridy = 1;
155: gridBagConstraints.weighty = 1.0;
156: add(filler, gridBagConstraints);
157:
158: }
159:
160: // </editor-fold>//GEN-END:initComponents
161:
162: // Variables declaration - do not modify//GEN-BEGIN:variables
163: private javax.swing.JLabel filler;
164: private javax.swing.JLabel plafName;
165: private javax.swing.JTextField plafNameValue;
166:
167: // End of variables declaration//GEN-END:variables
168:
169: private void initAccessibility() {
170: this .getAccessibleContext().setAccessibleDescription(
171: getMessage("ACS_PlatformInfoVisualPanel"));
172: plafNameValue.getAccessibleContext().setAccessibleDescription(
173: getMessage("ACS_CTL_plafNameValue"));
174: }
175: }
|