KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > options > BlueJPanel


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.options;
21
22 import java.io.File JavaDoc;
23 import java.io.File JavaDoc;
24 import javax.swing.JFileChooser JavaDoc;
25 import javax.swing.SwingUtilities JavaDoc;
26 import javax.swing.filechooser.FileFilter JavaDoc;
27 import org.netbeans.bluej.BluejProject;
28 import org.openide.DialogDisplayer;
29 import org.openide.NotifyDescriptor;
30 import org.openide.util.NbBundle;
31 import org.openide.util.Utilities;
32
33 /**
34  *
35  * @author mkleint
36  */

37 public class BlueJPanel extends javax.swing.JPanel JavaDoc {
38
39     private boolean changed = false;
40     /** Creates new form BlueJPanel */
41     public BlueJPanel() {
42         initComponents();
43     }
44     
45     /** This method is called from within the constructor to
46      * initialize the form.
47      * WARNING: Do NOT modify this code. The content of this method is
48      * always regenerated by the Form Editor.
49      */

50     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
51
private void initComponents() {
52         lblHome = new javax.swing.JLabel JavaDoc();
53         txtHome = new javax.swing.JTextField JavaDoc();
54         btnHome = new javax.swing.JButton JavaDoc();
55         lblHint = new javax.swing.JLabel JavaDoc();
56
57         lblHome.setLabelFor(txtHome);
58         lblHome.setText(org.openide.util.NbBundle.getBundle(BlueJPanel.class).getString("LBL_Home"));
59
60         btnHome.setText(org.openide.util.NbBundle.getBundle(BlueJPanel.class).getString("BTN_Home"));
61         btnHome.addActionListener(new java.awt.event.ActionListener JavaDoc() {
62             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
63                 btnHomeActionPerformed(evt);
64             }
65         });
66
67         lblHint.setText(org.openide.util.NbBundle.getBundle(BlueJPanel.class).getString("LBL_Hint"));
68         lblHint.setVerticalAlignment(javax.swing.SwingConstants.TOP);
69
70         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
71         this.setLayout(layout);
72         layout.setHorizontalGroup(
73             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
74             .add(layout.createSequentialGroup()
75                 .addContainerGap()
76                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
77                     .add(lblHint, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
78                     .add(layout.createSequentialGroup()
79                         .add(lblHome)
80                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
81                         .add(txtHome, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
82                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
83                         .add(btnHome)))
84                 .addContainerGap())
85         );
86         layout.setVerticalGroup(
87             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
88             .add(layout.createSequentialGroup()
89                 .addContainerGap()
90                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
91                     .add(lblHome)
92                     .add(txtHome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
93                     .add(btnHome))
94                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
95                 .add(lblHint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
96                 .add(136, 136, 136))
97         );
98     }// </editor-fold>//GEN-END:initComponents
99

100     private void btnHomeActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_btnHomeActionPerformed
101
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(txtHome.getText());
102         if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
103             chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
104             chooser.setFileFilter(new FileFilter JavaDoc() {
105                 public boolean accept(File JavaDoc f) {
106                     return f.isDirectory(); // || (f.isFile() && f.getName().endsWith(".app"));
107
}
108                 public String JavaDoc getDescription() {
109                     return NbBundle.getMessage(BlueJPanel.class, "Macosx_filter");
110                 }
111             });
112         } else {
113             chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
114         }
115         int r = chooser.showDialog(
116                 SwingUtilities.getWindowAncestor(this),
117                 NbBundle.getMessage(BlueJPanel.class, "Select_Directory"));
118         if (r == JFileChooser.APPROVE_OPTION) {
119             File JavaDoc file = chooser.getSelectedFile();
120             File JavaDoc bjLib = BluejProject.getUserLibPath(file);
121             System.out.println("bjhome=" + bjLib.getAbsolutePath());
122             if (!bjLib.exists()) {
123                 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
124                         NbBundle.getMessage(BlueJPanel.class, "Not_a_bluej_home", file),
125                         NotifyDescriptor.Message.WARNING_MESSAGE));
126                 return;
127             }
128             txtHome.setText(file.getAbsolutePath());
129             changed = true;
130         }
131         
132     }//GEN-LAST:event_btnHomeActionPerformed
133

134     boolean isChangedData() {
135         return changed;
136     }
137
138     boolean isValidData() {
139         return true;
140     }
141
142     String JavaDoc getBlueJHome() {
143         return txtHome.getText().trim();
144     }
145
146     void setBlueJHome(String JavaDoc home) {
147         txtHome.setText(home);
148     }
149     
150     
151     // Variables declaration - do not modify//GEN-BEGIN:variables
152
private javax.swing.JButton JavaDoc btnHome;
153     private javax.swing.JLabel JavaDoc lblHint;
154     private javax.swing.JLabel JavaDoc lblHome;
155     private javax.swing.JTextField JavaDoc txtHome;
156     // End of variables declaration//GEN-END:variables
157

158 }
159
Popular Tags