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-2007 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: package org.netbeans.modules.visualweb.complib.ui;
042:
043: import java.io.File;
044: import java.util.prefs.Preferences;
045:
046: import javax.swing.JFileChooser;
047: import javax.swing.filechooser.FileFilter;
048:
049: import org.netbeans.modules.visualweb.complib.ComplibServiceProvider;
050: import org.netbeans.modules.visualweb.complib.IdeUtil;
051: import org.netbeans.modules.visualweb.extension.openide.awt.JFileChooser_RAVE;
052: import org.openide.util.NbBundle;
053:
054: final class ComplibOptionsPanel extends javax.swing.JPanel {
055:
056: private static final String IMPORT_START_DIR = "importStartDir";
057: private final ComplibOptionsPanelController controller;
058:
059: ComplibOptionsPanel(ComplibOptionsPanelController controller) {
060: this .controller = controller;
061: initComponents();
062: // TODO listen to changes in form fields and call controller.changed()
063: }
064:
065: /** This method is called from within the constructor to
066: * initialize the form.
067: * WARNING: Do NOT modify this code. The content of this method is
068: * always regenerated by the Form Editor.
069: */
070: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
071: private void initComponents() {
072: jPanel1 = new javax.swing.JPanel();
073: importStartDirLbl = new javax.swing.JLabel();
074: importStartDirField = new javax.swing.JTextField();
075: importResetBtn = new javax.swing.JButton();
076: importBrowseBtn = new javax.swing.JButton();
077: sharedComplibCheckBox = new javax.swing.JCheckBox();
078:
079: setBackground(java.awt.Color.white);
080: jPanel1.setBackground(java.awt.Color.white);
081: jPanel1.setBorder(javax.swing.BorderFactory
082: .createTitledBorder(org.openide.util.NbBundle
083: .getMessage(ComplibOptionsPanel.class,
084: "AdvancedOption_ImportPanelTitle")));
085: importStartDirLbl.setLabelFor(importStartDirField);
086: org.openide.awt.Mnemonics.setLocalizedText(importStartDirLbl,
087: org.openide.util.NbBundle.getMessage(
088: ComplibOptionsPanel.class,
089: "AdvancedOption_ImportStartDirLbl"));
090:
091: org.openide.awt.Mnemonics.setLocalizedText(importResetBtn,
092: org.openide.util.NbBundle.getMessage(
093: ComplibOptionsPanel.class,
094: "AdvancedOption_ImportResetBtn"));
095: importResetBtn
096: .addActionListener(new java.awt.event.ActionListener() {
097: public void actionPerformed(
098: java.awt.event.ActionEvent evt) {
099: importResetActionPerformed(evt);
100: }
101: });
102:
103: org.openide.awt.Mnemonics.setLocalizedText(importBrowseBtn,
104: org.openide.util.NbBundle.getMessage(
105: ComplibOptionsPanel.class,
106: "AdvancedOption_ImportBrowseBtn"));
107: importBrowseBtn
108: .addActionListener(new java.awt.event.ActionListener() {
109: public void actionPerformed(
110: java.awt.event.ActionEvent evt) {
111: browseActionPerformed(evt);
112: }
113: });
114:
115: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
116: jPanel1);
117: jPanel1.setLayout(jPanel1Layout);
118: jPanel1Layout
119: .setHorizontalGroup(jPanel1Layout
120: .createParallelGroup(
121: org.jdesktop.layout.GroupLayout.LEADING)
122: .add(
123: jPanel1Layout
124: .createSequentialGroup()
125: .addContainerGap()
126: .add(
127: jPanel1Layout
128: .createParallelGroup(
129: org.jdesktop.layout.GroupLayout.LEADING)
130: .add(
131: jPanel1Layout
132: .createSequentialGroup()
133: .add(
134: importStartDirLbl)
135: .addPreferredGap(
136: org.jdesktop.layout.LayoutStyle.RELATED)
137: .add(
138: importStartDirField,
139: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
140: 246,
141: Short.MAX_VALUE)
142: .addPreferredGap(
143: org.jdesktop.layout.LayoutStyle.RELATED)
144: .add(
145: importBrowseBtn))
146: .add(
147: org.jdesktop.layout.GroupLayout.TRAILING,
148: importResetBtn))
149: .addContainerGap()));
150: jPanel1Layout
151: .setVerticalGroup(jPanel1Layout
152: .createParallelGroup(
153: org.jdesktop.layout.GroupLayout.LEADING)
154: .add(
155: jPanel1Layout
156: .createSequentialGroup()
157: .addContainerGap()
158: .add(
159: jPanel1Layout
160: .createParallelGroup(
161: org.jdesktop.layout.GroupLayout.BASELINE)
162: .add(
163: importStartDirLbl)
164: .add(
165: importStartDirField,
166: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
167: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
168: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
169: .add(
170: importBrowseBtn))
171: .add(12, 12, 12).add(
172: importResetBtn)
173: .addContainerGap()));
174:
175: sharedComplibCheckBox.setBackground(java.awt.Color.white);
176: org.openide.awt.Mnemonics
177: .setLocalizedText(sharedComplibCheckBox,
178: org.openide.util.NbBundle.getMessage(
179: ComplibOptionsPanel.class,
180: "AdvancedOption_SharedComplibCheckBox"));
181: sharedComplibCheckBox.setBorder(javax.swing.BorderFactory
182: .createEmptyBorder(0, 0, 0, 0));
183: sharedComplibCheckBox
184: .setMargin(new java.awt.Insets(0, 0, 0, 0));
185:
186: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
187: this );
188: this .setLayout(layout);
189: layout
190: .setHorizontalGroup(layout
191: .createParallelGroup(
192: org.jdesktop.layout.GroupLayout.LEADING)
193: .add(
194: layout
195: .createSequentialGroup()
196: .addContainerGap()
197: .add(
198: layout
199: .createParallelGroup(
200: org.jdesktop.layout.GroupLayout.LEADING)
201: .add(
202: layout
203: .createSequentialGroup()
204: .add(
205: 10,
206: 10,
207: 10)
208: .add(
209: sharedComplibCheckBox))
210: .add(
211: jPanel1,
212: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
213: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
214: Short.MAX_VALUE))
215: .addContainerGap()));
216: layout
217: .setVerticalGroup(layout
218: .createParallelGroup(
219: org.jdesktop.layout.GroupLayout.LEADING)
220: .add(
221: layout
222: .createSequentialGroup()
223: .addContainerGap()
224: .add(
225: jPanel1,
226: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
227: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
228: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
229: .addPreferredGap(
230: org.jdesktop.layout.LayoutStyle.RELATED)
231: .add(sharedComplibCheckBox)
232: .addContainerGap(
233: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
234: Short.MAX_VALUE)));
235: }// </editor-fold>//GEN-END:initComponents
236:
237: private void browseActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseActionPerformed
238: JFileChooser fcd = JFileChooser_RAVE.getJFileChooser();
239: fcd.setFileFilter(new FileFilter() {
240: @Override
241: public boolean accept(File f) {
242: return f.isDirectory();
243: }
244:
245: @Override
246: public String getDescription() {
247: return NbBundle.getMessage(ComplibOptionsPanel.class,
248: "AdvancedOption_ImportFilterDesc"); // NOI18N
249: }
250: });
251:
252: File file = new File(importStartDirField.getText());
253: fcd.setCurrentDirectory(file);
254:
255: // FIXME This does not allow user to select a directory for some reason
256: if (fcd.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
257: File selectedFile = fcd.getSelectedFile();
258: importStartDirField.setText(selectedFile.getAbsolutePath());
259: }
260: }// GEN-LAST:event_browseActionPerformed
261:
262: private void importResetActionPerformed(
263: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importResetActionPerformed
264: String samplesDir = IdeUtil.getRaveSamplesDirectory()
265: .getAbsolutePath();
266: importStartDirField.setText(samplesDir);
267: }// GEN-LAST:event_importResetActionPerformed
268:
269: private static Preferences prefs = ComplibServiceProvider
270: .getInstance().getPreferences();
271:
272: static {
273: initImportStartDir();
274: }
275:
276: /**
277: * Set system property to overwrite the default file chooser start
278: * directory.
279: */
280: private static void initImportStartDir() {
281: // Current property name
282: String dir = System.getProperty("complib.importStartDir");
283: if (dir == null) {
284: // Deprecated property name
285: dir = System.getProperty("toolbox.importStartDir");
286: }
287:
288: if (dir != null) {
289: prefs.put(IMPORT_START_DIR, dir);
290: }
291: }
292:
293: /**
294: * Return the directory used initially by the FileChooser
295: * to import complib files. Order of precedence is: 1) current System
296: * property 2) deprecated System property 3) saved Preference 4) IDE samples
297: * directory. Note: #1 and #2 will overwrite #3.
298: *
299: * @return
300: */
301: static File getImportStartDir() {
302: // Initially point to the rave samples directory
303: String samplesDir = IdeUtil.getRaveSamplesDirectory()
304: .getAbsolutePath();
305: String importStartPath = prefs
306: .get(IMPORT_START_DIR, samplesDir);
307: return new File(importStartPath);
308: }
309:
310: void load() {
311: importStartDirField.setText(getImportStartDir()
312: .getAbsolutePath());
313:
314: // TODO Hook up the shared component library action
315: sharedComplibCheckBox.setEnabled(false);
316: sharedComplibCheckBox.setSelected(true);
317:
318: // TODO read settings and initialize GUI
319: // Example:
320: // someCheckBox.setSelected(Preferences.userNodeForPackage(ComplibPanel.class).getBoolean("someFlag", false));
321: // or:
322: // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
323: }
324:
325: void store() {
326: prefs.put(IMPORT_START_DIR, importStartDirField.getText());
327: // TODO store modified settings
328: // Example:
329: // Preferences.userNodeForPackage(ComplibPanel.class).putBoolean("someFlag", someCheckBox.isSelected());
330: // or:
331: // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
332: }
333:
334: boolean valid() {
335: // Check whether form is consistent and complete
336: File startDir = new File(importStartDirField.getText());
337: if (!startDir.isDirectory()) {
338: return false;
339: }
340: return true;
341: }
342:
343: // Variables declaration - do not modify//GEN-BEGIN:variables
344: private javax.swing.JButton importBrowseBtn;
345: private javax.swing.JButton importResetBtn;
346: private javax.swing.JTextField importStartDirField;
347: private javax.swing.JLabel importStartDirLbl;
348: private javax.swing.JPanel jPanel1;
349: private javax.swing.JCheckBox sharedComplibCheckBox;
350: // End of variables declaration//GEN-END:variables
351:
352: }
|