KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > RubyHomeOptionsPanel


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.ruby.rubyproject;
21
22 import java.awt.event.ActionListener JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.File JavaDoc;
25 import org.openide.filesystems.FileUtil;
26
27 import javax.swing.JFileChooser JavaDoc;
28 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author Tor Norbye
34  */

35 public class RubyHomeOptionsPanel extends javax.swing.JPanel JavaDoc implements ActionListener JavaDoc {
36     
37     /** Creates new form RubyHomeOptionsPanel */
38     public RubyHomeOptionsPanel() {
39         initComponents();
40     }
41     
42     public void setRuby(String JavaDoc path) {
43         rubyField.setText(path);
44     }
45     
46     public String JavaDoc getRuby() {
47         return rubyField.getText().trim();
48     }
49
50     public void setRake(String JavaDoc path) {
51         rakeField.setText(path);
52     }
53     
54     public String JavaDoc getRake() {
55         return rakeField.getText().trim();
56     }
57     
58     public void setRDoc(String JavaDoc path) {
59         rdocField.setText(path);
60     }
61     
62     public String JavaDoc getRDoc() {
63         return rdocField.getText().trim();
64     }
65     
66     public void setRails(String JavaDoc path) {
67         railsField.setText(path);
68     }
69     
70     public String JavaDoc getRails() {
71         return railsField.getText().trim();
72     }
73     
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81
82         jLabel1 = new javax.swing.JLabel JavaDoc();
83         rubyField = new javax.swing.JTextField JavaDoc();
84         jButton1 = new javax.swing.JButton JavaDoc();
85         rakeLabel = new javax.swing.JLabel JavaDoc();
86         rakeField = new javax.swing.JTextField JavaDoc();
87         jButton2 = new javax.swing.JButton JavaDoc();
88         railsLabel = new javax.swing.JLabel JavaDoc();
89         rdocField = new javax.swing.JTextField JavaDoc();
90         jButton3 = new javax.swing.JButton JavaDoc();
91         rdocLabel = new javax.swing.JLabel JavaDoc();
92         railsField = new javax.swing.JTextField JavaDoc();
93         jButton4 = new javax.swing.JButton JavaDoc();
94         jLabel2 = new javax.swing.JLabel JavaDoc();
95
96         setPreferredSize(new java.awt.Dimension JavaDoc(600, 200));
97
98         jLabel1.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyLabel")); // NOI18N
99

100         jButton1.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeBrowse")); // NOI18N
101
jButton1.addActionListener(this);
102
103         rakeLabel.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RakeLabel")); // NOI18N
104

105         jButton2.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeBrowse")); // NOI18N
106
jButton2.addActionListener(this);
107
108         railsLabel.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.railsLabel.text")); // NOI18N
109

110         jButton3.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.jButton3.text")); // NOI18N
111
jButton3.addActionListener(this);
112
113         rdocLabel.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.rdocLabel.text")); // NOI18N
114

115         jButton4.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.jButton4.text")); // NOI18N
116
jButton4.addActionListener(this);
117
118         jLabel2.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.jLabel2.text")); // NOI18N
119

120         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
121         this.setLayout(layout);
122         layout.setHorizontalGroup(
123             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
124             .add(layout.createSequentialGroup()
125                 .add(jLabel2)
126                 .add(127, 127, 127))
127             .add(layout.createSequentialGroup()
128                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
129                     .add(jLabel1)
130                     .add(rakeLabel)
131                     .add(rdocLabel)
132                     .add(railsLabel))
133                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
134                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
135                     .add(rdocField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
136                     .add(org.jdesktop.layout.GroupLayout.TRAILING, rakeField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
137                     .add(railsField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)
138                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
139                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
140                         .add(rubyField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 581, Short.MAX_VALUE)))
141                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
142                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
143                     .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
144                     .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
145                     .add(jButton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
146                     .add(jButton4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
147         );
148         layout.setVerticalGroup(
149             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150             .add(layout.createSequentialGroup()
151                 .add(jLabel2)
152                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
153                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
154                     .add(jLabel1)
155                     .add(jButton1)
156                     .add(rubyField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
157                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
158                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
159                     .add(rakeLabel)
160                     .add(rakeField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
161                     .add(jButton2))
162                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
163                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
164                     .add(rdocLabel)
165                     .add(rdocField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
166                     .add(jButton3))
167                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
168                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
169                     .add(railsLabel)
170                     .add(railsField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
171                     .add(jButton4))
172                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
173         );
174     }
175
176     // Code for dispatching events from components to event handlers.
177

178     public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
179         if (evt.getSource() == jButton1) {
180             RubyHomeOptionsPanel.this.jButton1ActionPerformed(evt);
181         }
182         else if (evt.getSource() == jButton2) {
183             RubyHomeOptionsPanel.this.jButton2ActionPerformed(evt);
184         }
185         else if (evt.getSource() == jButton3) {
186             RubyHomeOptionsPanel.this.jButton3ActionPerformed(evt);
187         }
188         else if (evt.getSource() == jButton4) {
189             RubyHomeOptionsPanel.this.jButton4ActionPerformed(evt);
190         }
191     }// </editor-fold>//GEN-END:initComponents
192

193     private void jButton4ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton4ActionPerformed
194

195         JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
196         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
197         chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
198         chooser.setMultiSelectionEnabled(false);
199
200         String JavaDoc workDir = railsField.getText();
201         if (workDir.equals("")) {
202             workDir = new File JavaDoc(RubyInstallation.getInstance().getRake()).getParent();
203         }
204         chooser.setSelectedFile(new File JavaDoc(workDir));
205         chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration"));
206         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
207
File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
208             railsField.setText(file.getAbsolutePath());
209         }
210         
211     }//GEN-LAST:event_jButton4ActionPerformed
212

213     private void jButton3ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton3ActionPerformed
214

215         JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
216         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
217         chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
218         chooser.setMultiSelectionEnabled(false);
219
220         String JavaDoc workDir = rdocField.getText();
221         if (workDir.equals("")) {
222             workDir = new File JavaDoc(RubyInstallation.getInstance().getRake()).getParent();
223         }
224         chooser.setSelectedFile(new File JavaDoc(workDir));
225         chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration"));
226         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
227
File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
228             rdocField.setText(file.getAbsolutePath());
229         }
230     }//GEN-LAST:event_jButton3ActionPerformed
231

232     private void jButton2ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton2ActionPerformed
233
//GEN-HEADEREND:event_jButton2ActionPerformed
234
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
235         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
236         chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
237         chooser.setMultiSelectionEnabled(false);
238
239         String JavaDoc workDir = rakeField.getText();
240         if (workDir.equals("")) {
241             workDir = new File JavaDoc(RubyInstallation.getInstance().getRake()).getParent();
242         }
243         chooser.setSelectedFile(new File JavaDoc(workDir));
244         chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration"));
245         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
246
File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
247             rakeField.setText(file.getAbsolutePath());
248         }
249     }//GEN-LAST:event_jButton2ActionPerformed
250

251     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
252                                              
253         JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
254         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
255         chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
256         chooser.setMultiSelectionEnabled(false);
257
258         String JavaDoc workDir = rubyField.getText();
259         if (workDir.equals("")) {
260             workDir = new File JavaDoc(RubyInstallation.getInstance().getRuby()).getParent();
261         }
262         chooser.setSelectedFile(new File JavaDoc(workDir));
263         chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration"));
264         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
265
File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
266             rubyField.setText(file.getAbsolutePath());
267         }
268     }
269    
270     
271     // Variables declaration - do not modify//GEN-BEGIN:variables
272
private javax.swing.JButton JavaDoc jButton1;
273     private javax.swing.JButton JavaDoc jButton2;
274     private javax.swing.JButton JavaDoc jButton3;
275     private javax.swing.JButton JavaDoc jButton4;
276     private javax.swing.JLabel JavaDoc jLabel1;
277     private javax.swing.JLabel JavaDoc jLabel2;
278     private javax.swing.JTextField JavaDoc railsField;
279     private javax.swing.JLabel JavaDoc railsLabel;
280     private javax.swing.JTextField JavaDoc rakeField;
281     private javax.swing.JLabel JavaDoc rakeLabel;
282     private javax.swing.JTextField JavaDoc rdocField;
283     private javax.swing.JLabel JavaDoc rdocLabel;
284     private javax.swing.JTextField JavaDoc rubyField;
285     // End of variables declaration//GEN-END:variables
286

287 }
288
Popular Tags