KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > winsys > BasicSettingsPanel


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.wizard.winsys;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import javax.swing.DefaultComboBoxModel JavaDoc;
26 import org.netbeans.modules.apisupport.project.layers.LayerUtils;
27 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
28 import org.openide.WizardDescriptor;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.FileSystem;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33
34 /**
35  * the first panel in TopComponent wizard
36  *
37  * @author Milos Kleint
38  */

39 final class BasicSettingsPanel extends BasicWizardIterator.Panel {
40     
41     private NewTCIterator.DataModel data;
42     private static final String JavaDoc[] DEFAULT_MODES =
43             new String JavaDoc[] {
44                 "editor" //NOI18N
45
};
46     /**
47      * Creates new form BasicSettingsPanel
48      */

49     public BasicSettingsPanel(WizardDescriptor setting, NewTCIterator.DataModel data) {
50         super(setting);
51         this.data = data;
52         initComponents();
53         initAccessibility();
54         setupCombo();
55         putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle"));
56     }
57     
58     private void checkValidity() {
59         //TODO: probably nothing...
60
markValid();
61     }
62     
63 // public void addNotify() {
64
// super.addNotify();
65
// attachDocumentListeners();
66
// checkValidity();
67
// }
68
//
69
// public void removeNotify() {
70
// // prevent checking when the panel is not "active"
71
// removeDocumentListeners();
72
// super.removeNotify();
73
// }
74
//
75
// private void attachDocumentListeners() {
76
// if (!listenersAttached) {
77
// listenersAttached = true;
78
// }
79
// }
80
//
81
// private void removeDocumentListeners() {
82
// if (listenersAttached) {
83
// listenersAttached = false;
84
// }
85
// }
86

87     private void setupCombo() {
88         //TODO get dynamically from layers??
89
String JavaDoc[] modes = null;
90         try {
91             FileSystem fs = LayerUtils.getEffectiveSystemFilesystem(data.getProject());
92             FileObject foRoot = fs.getRoot().getFileObject("Windows2/Modes"); //NOI18N
93
if (foRoot != null) {
94                 FileObject[] fos = foRoot.getChildren();
95                 Collection JavaDoc col = new ArrayList JavaDoc();
96                 for (int i=0; i < fos.length; i++) {
97                     if (fos[i].isData() && "wsmode".equals(fos[i].getExt())) { //NOI18N
98
col.add(fos[i].getName());
99                     }
100                 }
101                 modes = (String JavaDoc[])col.toArray(new String JavaDoc[col.size()]);
102             } else {
103                 modes = DEFAULT_MODES;
104             }
105         } catch (IOException JavaDoc exc) {
106             modes = DEFAULT_MODES;
107
108         }
109         
110         comMode.setModel(new DefaultComboBoxModel JavaDoc(modes));
111     }
112     
113     protected void storeToDataModel() {
114         data.setOpened(cbOpenedOnStart.isSelected());
115         data.setMode((String JavaDoc)comMode.getSelectedItem());
116     }
117     
118     protected void readFromDataModel() {
119         cbOpenedOnStart.setSelected(data.isOpened());
120         if (data.getMode() != null) {
121             comMode.setSelectedItem(data.getMode());
122         } else {
123             comMode.setSelectedItem("output");//NOI18N
124
}
125         checkValidity();
126     }
127     
128     protected String JavaDoc getPanelName() {
129         return getMessage("LBL_BasicSettings_Title");
130     }
131     
132     protected HelpCtx getHelp() {
133         return new HelpCtx(BasicSettingsPanel.class);
134     }
135     
136     private static String JavaDoc getMessage(String JavaDoc key) {
137         return NbBundle.getMessage(BasicSettingsPanel.class, key);
138     }
139     
140     /** This method is called from within the constructor to
141      * initialize the form.
142      * WARNING: Do NOT modify this code. The content of this method is
143      * always regenerated by the Form Editor.
144      */

145     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
146
private void initComponents() {
147         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
148
149         lblMode = new javax.swing.JLabel JavaDoc();
150         comMode = new javax.swing.JComboBox JavaDoc();
151         cbOpenedOnStart = new javax.swing.JCheckBox JavaDoc();
152
153         setLayout(new java.awt.GridBagLayout JavaDoc());
154
155         lblMode.setLabelFor(comMode);
156         org.openide.awt.Mnemonics.setLocalizedText(lblMode, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "LBL_Mode"));
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
160         add(lblMode, gridBagConstraints);
161
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
164         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
165         gridBagConstraints.weightx = 0.1;
166         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 6);
167         add(comMode, gridBagConstraints);
168
169         org.openide.awt.Mnemonics.setLocalizedText(cbOpenedOnStart, org.openide.util.NbBundle.getMessage(BasicSettingsPanel.class, "LBL_OpenOnStart"));
170         cbOpenedOnStart.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 0, 0, 0)));
171         cbOpenedOnStart.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 0;
174         gridBagConstraints.gridy = 1;
175         gridBagConstraints.gridwidth = 2;
176         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
177         gridBagConstraints.weighty = 0.1;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
179         add(cbOpenedOnStart, gridBagConstraints);
180
181     }
182     // </editor-fold>//GEN-END:initComponents
183

184     // Variables declaration - do not modify//GEN-BEGIN:variables
185
private javax.swing.JCheckBox JavaDoc cbOpenedOnStart;
186     private javax.swing.JComboBox JavaDoc comMode;
187     private javax.swing.JLabel JavaDoc lblMode;
188     // End of variables declaration//GEN-END:variables
189

190     private void initAccessibility() {
191         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_BasicSettingsPanel"));
192         cbOpenedOnStart.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_OpenOnStart"));
193         comMode.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Mode"));
194     }
195     
196 }
197
Popular Tags