KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > export > OpenFilePanel


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.tasklist.core.export;
21
22 import java.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import org.netbeans.modules.tasklist.core.util.SimpleWizardPanel;
25 import org.openide.util.NbBundle;
26
27 /**
28  * Panel with a file chooser
29  */

30 public class OpenFilePanel extends javax.swing.JPanel JavaDoc {
31     private SimpleWizardPanel panel;
32
33     /** Creates new form ChooseFilePanel */
34     public OpenFilePanel() {
35         initComponents();
36     }
37
38     /**
39      * Associates a wizard panel with this Swing panel.
40      * This method should be called to initialize this panel.
41      *
42      * @param panel associated panel.
43      */

44     public void setWizardPanel(SimpleWizardPanel panel) {
45         this.panel = panel;
46     }
47     
48     /** This method is called from within the constructor to
49      * initialize the form.
50      * WARNING: Do NOT modify this code. The content of this method is
51      * always regenerated by the Form Editor.
52      */

53     private void initComponents() {//GEN-BEGIN:initComponents
54
jFileChooser = new javax.swing.JFileChooser JavaDoc();
55
56         setLayout(new java.awt.BorderLayout JavaDoc());
57
58         setName(org.openide.util.NbBundle.getBundle(OpenFilePanel.class).getString("ChooseSource"));
59         jFileChooser.setControlButtonsAreShown(false);
60         jFileChooser.addPropertyChangeListener(new java.beans.PropertyChangeListener JavaDoc() {
61             public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
62                 jFileChooserPropertyChange(evt);
63             }
64         });
65
66         add(jFileChooser, java.awt.BorderLayout.CENTER);
67
68     }//GEN-END:initComponents
69

70     private void jFileChooserPropertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {//GEN-FIRST:event_jFileChooserPropertyChange
71
if (evt.getPropertyName() == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) {
72             check();
73         }
74     }//GEN-LAST:event_jFileChooserPropertyChange
75

76     
77     // Variables declaration - do not modify//GEN-BEGIN:variables
78
private javax.swing.JFileChooser JavaDoc jFileChooser;
79     // End of variables declaration//GEN-END:variables
80

81     /**
82      * Returns the associated file chooser
83      *
84      * @return file chooser
85      */

86     public JFileChooser JavaDoc getFileChooser() {
87         return jFileChooser;
88     }
89
90     /**
91      * Sets choosed file
92      *
93      * @param f choosed file
94      */

95     public void setFile(File JavaDoc f) {
96         jFileChooser.setSelectedFile(f);
97         check();
98     }
99     
100     /**
101      * Returns selected file
102      *
103      * @return selected file or null
104      */

105     public File JavaDoc getFile() {
106         return jFileChooser.getSelectedFile();
107     }
108     
109     /**
110      * Sets the valid property
111      */

112     private void check() {
113         File JavaDoc f = jFileChooser.getSelectedFile();
114         if (f == null) {
115             panel.setErrorMessage(NbBundle.getMessage(
116                 OpenFilePanel.class, "EmptyFileName2")); // NOI18N
117
return;
118         }
119         
120         try {
121             System.getSecurityManager().checkRead(f.getAbsolutePath());
122             panel.setErrorMessage(null);
123         } catch (SecurityException JavaDoc e) {
124             panel.setErrorMessage(e.getLocalizedMessage());
125         }
126     }
127 }
128
Popular Tags