KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > platform > NbPlatformCustomizerHarness


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.apisupport.project.ui.platform;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.swing.JFileChooser JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import org.netbeans.modules.apisupport.project.Util;
27 import org.netbeans.modules.apisupport.project.ui.UIUtil;
28 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.util.NbBundle;
31
32 /**
33  * Permits selection of build harness associated with a NetBeans platform.
34  * @author Jesse Glick
35  * @see "#71628"
36  */

37 public class NbPlatformCustomizerHarness extends JPanel JavaDoc {
38     
39     private NbPlatform plaf;
40     
41     public NbPlatformCustomizerHarness() {
42         initComponents();
43     }
44     
45     void setPlatform(NbPlatform plaf) {
46         this.plaf = plaf;
47         if (plaf.isDefault()) {
48             ideButton.setSelected(true);
49         } else {
50             File JavaDoc harnessLocation = plaf.getHarnessLocation();
51             if (harnessLocation.equals(NbPlatform.getDefaultPlatform().getHarnessLocation())) {
52                 ideButton.setSelected(true);
53             } else if (harnessLocation.equals(plaf.getBundledHarnessLocation())) {
54                 platformButton.setSelected(true);
55             } else {
56                 otherButton.setSelected(true);
57             }
58         }
59         update();
60         UIUtil.setText(otherText, plaf.getHarnessLocation().getAbsolutePath());
61     }
62     
63     private void update() {
64         versionText.setText(NbPlatform.getHarnessVersionDisplayName(plaf.getHarnessVersion()));
65         if (plaf.isDefault()) {
66             platformButton.setEnabled(false);
67             otherButton.setEnabled(false);
68         } else {
69             platformButton.setEnabled(true);
70             otherButton.setEnabled(true);
71         }
72         browseButton.setEnabled(otherButton.isSelected());
73     }
74     
75     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
76
private void initComponents() {
77         buttonGroup = new javax.swing.ButtonGroup JavaDoc();
78         ideButton = new javax.swing.JRadioButton JavaDoc();
79         platformButton = new javax.swing.JRadioButton JavaDoc();
80         otherButton = new javax.swing.JRadioButton JavaDoc();
81         otherText = new javax.swing.JTextField JavaDoc();
82         browseButton = new javax.swing.JButton JavaDoc();
83         versionLabel = new javax.swing.JLabel JavaDoc();
84         versionText = new javax.swing.JTextField JavaDoc();
85
86         buttonGroup.add(ideButton);
87         org.openide.awt.Mnemonics.setLocalizedText(ideButton, NbBundle.getMessage(NbPlatformCustomizerHarness.class, "NbPCH.ideButton"));
88         ideButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
89         ideButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
90         ideButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
91             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
92                 ideButtonActionPerformed(evt);
93             }
94         });
95
96         buttonGroup.add(platformButton);
97         org.openide.awt.Mnemonics.setLocalizedText(platformButton, NbBundle.getMessage(NbPlatformCustomizerHarness.class, "NbPCH.platformButton"));
98         platformButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
99         platformButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
100         platformButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
101             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
102                 platformButtonActionPerformed(evt);
103             }
104         });
105
106         buttonGroup.add(otherButton);
107         org.openide.awt.Mnemonics.setLocalizedText(otherButton, NbBundle.getMessage(NbPlatformCustomizerHarness.class, "NbPCH.otherButton"));
108         otherButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
109         otherButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
110         otherButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
111             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
112                 otherButtonActionPerformed(evt);
113             }
114         });
115
116         otherText.setEditable(false);
117
118         org.openide.awt.Mnemonics.setLocalizedText(browseButton, NbBundle.getMessage(NbPlatformCustomizerHarness.class, "NbPCH.browseButton"));
119         browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
120             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
121                 browseButtonActionPerformed(evt);
122             }
123         });
124
125         versionLabel.setLabelFor(versionText);
126         org.openide.awt.Mnemonics.setLocalizedText(versionLabel, NbBundle.getMessage(NbPlatformCustomizerHarness.class, "NbPCH.versionLabel"));
127
128         versionText.setEditable(false);
129
130         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
131         this.setLayout(layout);
132         layout.setHorizontalGroup(
133             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
134             .add(layout.createSequentialGroup()
135                 .addContainerGap()
136                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
137                     .add(layout.createSequentialGroup()
138                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
139                             .add(ideButton)
140                             .add(platformButton)
141                             .add(layout.createSequentialGroup()
142                                 .add(otherButton)
143                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
144                                 .add(otherText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)))
145                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
146                         .add(browseButton))
147                     .add(layout.createSequentialGroup()
148                         .add(versionLabel)
149                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
150                         .add(versionText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)))
151                 .addContainerGap())
152         );
153         layout.setVerticalGroup(
154             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
155             .add(layout.createSequentialGroup()
156                 .addContainerGap()
157                 .add(ideButton)
158                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
159                 .add(platformButton)
160                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
161                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
162                     .add(otherButton)
163                     .add(browseButton)
164                     .add(otherText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
165                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
166                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
167                     .add(versionLabel)
168                     .add(versionText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
169                 .addContainerGap(196, Short.MAX_VALUE))
170         );
171     }// </editor-fold>//GEN-END:initComponents
172

173     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
174
JFileChooser JavaDoc jfc = new JFileChooser JavaDoc() {
175             // Trick stolen from ProjectChooserAccessory.ProjectFileChooser:
176
public void approveSelection() {
177                 File JavaDoc dir = FileUtil.normalizeFile(getSelectedFile());
178                 if (NbPlatform.isHarness(dir)) {
179                     super.approveSelection();
180                 } else {
181                     setCurrentDirectory(dir);
182                 }
183             }
184         };
185         FileUtil.preventFileChooserSymlinkTraversal(jfc, null);
186         jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
187         jfc.setSelectedFile(plaf.getHarnessLocation());
188         if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
189             try {
190                 plaf.setHarnessLocation(FileUtil.normalizeFile(jfc.getSelectedFile()));
191             } catch (IOException JavaDoc e) {
192                 Util.err.notify(e);
193             }
194         }
195         update();
196         UIUtil.setText(otherText, plaf.getHarnessLocation().getAbsolutePath());
197     }//GEN-LAST:event_browseButtonActionPerformed
198

199     private void otherButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_otherButtonActionPerformed
200
try {
201             plaf.setHarnessLocation(FileUtil.normalizeFile(new File JavaDoc(otherText.getText())));
202         } catch (IOException JavaDoc e) {
203             Util.err.notify(e);
204         }
205         update();
206     }//GEN-LAST:event_otherButtonActionPerformed
207

208     private void platformButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_platformButtonActionPerformed
209
try {
210             plaf.setHarnessLocation(plaf.getBundledHarnessLocation());
211         } catch (IOException JavaDoc e) {
212             Util.err.notify(e);
213         }
214         update();
215     }//GEN-LAST:event_platformButtonActionPerformed
216

217     private void ideButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_ideButtonActionPerformed
218
try {
219             plaf.setHarnessLocation(NbPlatform.getDefaultPlatform().getHarnessLocation());
220         } catch (IOException JavaDoc e) {
221             Util.err.notify(e);
222         }
223         update();
224     }//GEN-LAST:event_ideButtonActionPerformed
225

226     
227     // Variables declaration - do not modify//GEN-BEGIN:variables
228
private javax.swing.JButton JavaDoc browseButton;
229     private javax.swing.ButtonGroup JavaDoc buttonGroup;
230     private javax.swing.JRadioButton JavaDoc ideButton;
231     private javax.swing.JRadioButton JavaDoc otherButton;
232     private javax.swing.JTextField JavaDoc otherText;
233     private javax.swing.JRadioButton JavaDoc platformButton;
234     private javax.swing.JLabel JavaDoc versionLabel;
235     private javax.swing.JTextField JavaDoc versionText;
236     // End of variables declaration//GEN-END:variables
237

238 }
239
Popular Tags