KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > platform > PlatformChooserVisualPanel


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 package org.netbeans.modules.apisupport.project.ui.platform;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import javax.swing.JFileChooser JavaDoc;
27 import javax.swing.filechooser.FileFilter JavaDoc;
28 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings;
29 import org.netbeans.modules.apisupport.project.ui.wizard.BasicVisualPanel;
30 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
31 import org.openide.WizardDescriptor;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.util.NbBundle;
34
35 /**
36  * First panel from <em>Adding New Platform</em> wizard panels. Allows user to
37  * choose platform directory.
38  *
39  * @author Martin Krauskopf
40  */

41 public class PlatformChooserVisualPanel extends BasicVisualPanel
42         implements PropertyChangeListener JavaDoc {
43     
44     /** Creates new form BasicInfoVisualPanel */
45     public PlatformChooserVisualPanel(WizardDescriptor setting) {
46         super(setting);
47         initComponents();
48         initAccessibility();
49         String JavaDoc location = ModuleUISettings.getDefault().getLastUsedNbPlatformLocation();
50         if (location != null) {
51             platformChooser.setCurrentDirectory(new File JavaDoc(location));
52         }
53         platformChooser.setAcceptAllFileFilterUsed(false);
54         platformChooser.setFileFilter(new FileFilter JavaDoc() {
55             public boolean accept(File JavaDoc f) {
56                 return f.isDirectory();
57             }
58             public String JavaDoc getDescription() {
59                 return getMessage("CTL_PlatformFolder");
60             }
61         });
62         platformChooser.addPropertyChangeListener(this);
63         setName(NbPlatformCustomizer.CHOOSER_STEP);
64         platformChooser.putClientProperty(
65                 "JFileChooser.appBundleIsTraversable", "always"); // NOI18N #73124
66
}
67
68     public void addNotify() {
69         super.addNotify();
70         checkForm();
71     }
72     
73     /** Stores collected data into model. */
74     void storeData() {
75         File JavaDoc file = platformChooser.getSelectedFile();
76         if (file != null) {
77             getSettings().putProperty(NbPlatformCustomizer.PLAF_DIR_PROPERTY,
78                     file.getAbsolutePath());
79             getSettings().putProperty(NbPlatformCustomizer.PLAF_LABEL_PROPERTY,
80                     plafLabelValue.getText());
81         } // when wizard is cancelled file is null
82
}
83     
84     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
85         String JavaDoc propName = evt.getPropertyName();
86         if (propName.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
87             checkForm();
88         }
89     }
90     
91     private void checkForm() {
92         File JavaDoc selFile = platformChooser.getSelectedFile();
93         boolean invalid = true;
94         if (selFile != null) { // #73123
95
File JavaDoc plafDir = FileUtil.normalizeFile(selFile);
96             if (/* #60133 */ plafDir != null && NbPlatform.isPlatformDirectory(plafDir)) {
97                 try {
98                     setPlafLabel(NbPlatform.computeDisplayName(plafDir));
99                 } catch (IOException JavaDoc e) {
100                     setPlafLabel(plafDir.getAbsolutePath());
101                 }
102                 if (!NbPlatform.isSupportedPlatform(plafDir)) {
103                     setError(getMessage("MSG_UnsupportedPlatform"));
104                 } else if (NbPlatform.contains(plafDir)) {
105                     setError(getMessage("MSG_AlreadyAddedPlatform"));
106                 } else if (!NbPlatform.isLabelValid(plafLabelValue.getText())) {
107                     setWarning(getMessage("MSG_NameIsAlreadyUsedGoToNext"));
108                 } else {
109                     markValid();
110                     ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(plafDir.getParentFile().getAbsolutePath());
111                 }
112                 invalid = false;
113             }
114         }
115         if (invalid) {
116             markInvalid();
117             setPlafLabel(null);
118             storeData();
119         }
120     }
121     
122     private void setPlafLabel(String JavaDoc label) {
123         plafLabelValue.setText(label);
124         plafLabelValue.setCaretPosition(0);
125         storeData();
126     }
127     
128     private static String JavaDoc getMessage(String JavaDoc key) {
129         return NbBundle.getMessage(PlatformChooserVisualPanel.class, key);
130     }
131     
132     /** This method is called from within the constructor to
133      * initialize the form.
134      * WARNING: Do NOT modify this code. The content of this method is
135      * always regenerated by the Form Editor.
136      */

137     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
138
private void initComponents() {
139         infoPanel = new javax.swing.JPanel JavaDoc();
140         inner = new javax.swing.JPanel JavaDoc();
141         plafLabel = new javax.swing.JLabel JavaDoc();
142         plafLabelValue = new javax.swing.JTextField JavaDoc();
143         platformChooser = new javax.swing.JFileChooser JavaDoc();
144
145         infoPanel.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT, 6, 0));
146
147         inner.setLayout(new java.awt.GridLayout JavaDoc(2, 1, 0, 6));
148
149         plafLabel.setLabelFor(plafLabelValue);
150         org.openide.awt.Mnemonics.setLocalizedText(plafLabel, org.openide.util.NbBundle.getMessage(PlatformChooserVisualPanel.class, "LBL_PlatformName_P"));
151         inner.add(plafLabel);
152
153         plafLabelValue.setColumns(15);
154         plafLabelValue.setEditable(false);
155         inner.add(plafLabelValue);
156
157         infoPanel.add(inner);
158
159         setLayout(new java.awt.BorderLayout JavaDoc());
160
161         platformChooser.setAccessory(infoPanel);
162         platformChooser.setControlButtonsAreShown(false);
163         platformChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
164         add(platformChooser, java.awt.BorderLayout.CENTER);
165
166     }
167     // </editor-fold>//GEN-END:initComponents
168

169     // Variables declaration - do not modify//GEN-BEGIN:variables
170
private javax.swing.JPanel JavaDoc infoPanel;
171     private javax.swing.JPanel JavaDoc inner;
172     private javax.swing.JLabel JavaDoc plafLabel;
173     private javax.swing.JTextField JavaDoc plafLabelValue;
174     private javax.swing.JFileChooser JavaDoc platformChooser;
175     // End of variables declaration//GEN-END:variables
176

177     private void initAccessibility() {
178         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_PlatformChooserVisualPanel"));
179         plafLabelValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_plafLabelValue"));
180     }
181     
182 }
183
Popular Tags