KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > export > ExportPanel


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.bluej.export;
21
22 import java.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import javax.swing.SwingUtilities JavaDoc;
25 import javax.swing.event.DocumentEvent JavaDoc;
26 import javax.swing.event.DocumentListener JavaDoc;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author mkleint
34  */

35 public class ExportPanel extends javax.swing.JPanel JavaDoc {
36
37     /** Creates new form ExportPanel */
38     public ExportPanel(FileObject dir, final ExportWizardPanel1 wizPanel) {
39         initComponents();
40         txtSource.setText(dir.getPath());
41         setName(NbBundle.getMessage(ExportPanel.class, "TIT_ExportPanel"));
42         txtFolder.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
43             public void changedUpdate(DocumentEvent JavaDoc e) {
44                 wizPanel.updateValue(txtFolder.getText());
45             }
46             public void insertUpdate(DocumentEvent JavaDoc e) {
47                 wizPanel.updateValue(txtFolder.getText());
48             }
49             public void removeUpdate(DocumentEvent JavaDoc e) {
50                 wizPanel.updateValue(txtFolder.getText());
51             }
52         });
53     }
54     
55     /** This method is called from within the constructor to
56      * initialize the form.
57      * WARNING: Do NOT modify this code. The content of this method is
58      * always regenerated by the Form Editor.
59      */

60     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
61
private void initComponents() {
62         lblWarning = new javax.swing.JLabel JavaDoc();
63         lblFolder = new javax.swing.JLabel JavaDoc();
64         txtFolder = new javax.swing.JTextField JavaDoc();
65         btnFolder = new javax.swing.JButton JavaDoc();
66         lblSource = new javax.swing.JLabel JavaDoc();
67         txtSource = new javax.swing.JTextField JavaDoc();
68         lblWarning2 = new javax.swing.JLabel JavaDoc();
69
70         lblWarning.setText(org.openide.util.NbBundle.getMessage(ExportPanel.class, "LBL_Warning"));
71         lblWarning.setVerticalAlignment(javax.swing.SwingConstants.TOP);
72
73         lblFolder.setLabelFor(lblFolder);
74         lblFolder.setText(org.openide.util.NbBundle.getMessage(ExportPanel.class, "LBL_Folder"));
75
76         btnFolder.setText(org.openide.util.NbBundle.getMessage(ExportPanel.class, "BTN_Folder"));
77         btnFolder.addActionListener(new java.awt.event.ActionListener JavaDoc() {
78             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
79                 btnFolderActionPerformed(evt);
80             }
81         });
82
83         lblSource.setLabelFor(txtSource);
84         lblSource.setText(org.openide.util.NbBundle.getMessage(ExportPanel.class, "LBL_Source"));
85
86         txtSource.setEditable(false);
87         txtSource.setEnabled(false);
88
89         lblWarning2.setText(org.openide.util.NbBundle.getMessage(ExportPanel.class, "LBL_Warning2"));
90
91         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
92         this.setLayout(layout);
93         layout.setHorizontalGroup(
94             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
95             .add(layout.createSequentialGroup()
96                 .addContainerGap()
97                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
98                     .add(lblWarning)
99                     .add(layout.createSequentialGroup()
100                         .add(lblSource)
101                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
102                         .add(txtSource, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE))
103                     .add(layout.createSequentialGroup()
104                         .add(lblFolder)
105                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
106                         .add(txtFolder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
107                         .add(12, 12, 12)
108                         .add(btnFolder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
109                     .add(lblWarning2))
110                 .addContainerGap())
111         );
112         layout.setVerticalGroup(
113             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
114             .add(layout.createSequentialGroup()
115                 .addContainerGap()
116                 .add(lblWarning)
117                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
118                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
119                     .add(lblSource)
120                     .add(txtSource, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
121                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
122                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
123                     .add(lblFolder)
124                     .add(txtFolder, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
125                     .add(btnFolder))
126                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
127                 .add(lblWarning2)
128                 .addContainerGap(178, Short.MAX_VALUE))
129         );
130     }// </editor-fold>//GEN-END:initComponents
131

132     private void btnFolderActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnFolderActionPerformed
133
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
134         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
135         chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
136         chooser.setMultiSelectionEnabled( false );
137         int option = chooser.showOpenDialog( SwingUtilities.getWindowAncestor( this ) ); // Sow the chooser
138
if (txtFolder.getText().length() > 0) {
139             chooser.setCurrentDirectory(new File JavaDoc(txtFolder.getText().trim()));
140         }
141         if ( option == JFileChooser.APPROVE_OPTION ) {
142             
143             File JavaDoc file = chooser.getSelectedFile();
144             txtFolder.setText(FileUtil.normalizeFile(file).getAbsolutePath());
145         }
146         
147     }//GEN-LAST:event_btnFolderActionPerformed
148

149     
150     // Variables declaration - do not modify//GEN-BEGIN:variables
151
private javax.swing.JButton JavaDoc btnFolder;
152     private javax.swing.JLabel JavaDoc lblFolder;
153     private javax.swing.JLabel JavaDoc lblSource;
154     private javax.swing.JLabel JavaDoc lblWarning;
155     private javax.swing.JLabel JavaDoc lblWarning2;
156     private javax.swing.JTextField JavaDoc txtFolder;
157     private javax.swing.JTextField JavaDoc txtSource;
158     // End of variables declaration//GEN-END:variables
159

160 }
161
Popular Tags