001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui.platform;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.logging.Logger;
047: import javax.swing.JFileChooser;
048: import javax.swing.JPanel;
049: import org.netbeans.modules.apisupport.project.ui.UIUtil;
050: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
051: import org.openide.filesystems.FileUtil;
052: import org.openide.util.Exceptions;
053: import org.openide.util.NbBundle;
054:
055: /**
056: * Permits selection of build harness associated with a NetBeans platform.
057: * @author Jesse Glick
058: * @see "#71628"
059: */
060: public class NbPlatformCustomizerHarness extends JPanel {
061:
062: private NbPlatform plaf;
063:
064: public NbPlatformCustomizerHarness() {
065: initComponents();
066: }
067:
068: void setPlatform(NbPlatform plaf) {
069: this .plaf = plaf;
070: if (plaf.isDefault()) {
071: ideButton.setSelected(true);
072: } else {
073: File harnessLocation = plaf.getHarnessLocation();
074: NbPlatform dflt = NbPlatform.getDefaultPlatform();
075: if (dflt != null
076: && harnessLocation
077: .equals(dflt.getHarnessLocation())) {
078: ideButton.setSelected(true);
079: } else if (harnessLocation.equals(plaf
080: .getBundledHarnessLocation())) {
081: platformButton.setSelected(true);
082: } else {
083: otherButton.setSelected(true);
084: }
085: }
086: update();
087: UIUtil.setText(otherText, plaf.getHarnessLocation()
088: .getAbsolutePath());
089: }
090:
091: private void update() {
092: versionText
093: .setText(NbPlatform.getHarnessVersionDisplayName(plaf
094: .getHarnessVersion()));
095: if (plaf.isDefault()) {
096: platformButton.setEnabled(false);
097: otherButton.setEnabled(false);
098: } else {
099: platformButton.setEnabled(true);
100: otherButton.setEnabled(true);
101: }
102: browseButton.setEnabled(otherButton.isSelected());
103: }
104:
105: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
106: private void initComponents() {
107:
108: buttonGroup = new javax.swing.ButtonGroup();
109: ideButton = new javax.swing.JRadioButton();
110: platformButton = new javax.swing.JRadioButton();
111: otherButton = new javax.swing.JRadioButton();
112: otherText = new javax.swing.JTextField();
113: browseButton = new javax.swing.JButton();
114: versionLabel = new javax.swing.JLabel();
115: versionText = new javax.swing.JTextField();
116:
117: buttonGroup.add(ideButton);
118: org.openide.awt.Mnemonics.setLocalizedText(ideButton, NbBundle
119: .getMessage(NbPlatformCustomizerHarness.class,
120: "NbPCH.ideButton")); // NOI18N
121: ideButton.setBorder(javax.swing.BorderFactory
122: .createEmptyBorder(0, 0, 0, 0));
123: ideButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
124: ideButton
125: .addActionListener(new java.awt.event.ActionListener() {
126: public void actionPerformed(
127: java.awt.event.ActionEvent evt) {
128: ideButtonActionPerformed(evt);
129: }
130: });
131:
132: buttonGroup.add(platformButton);
133: org.openide.awt.Mnemonics.setLocalizedText(platformButton,
134: NbBundle.getMessage(NbPlatformCustomizerHarness.class,
135: "NbPCH.platformButton")); // NOI18N
136: platformButton.setBorder(javax.swing.BorderFactory
137: .createEmptyBorder(0, 0, 0, 0));
138: platformButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
139: platformButton
140: .addActionListener(new java.awt.event.ActionListener() {
141: public void actionPerformed(
142: java.awt.event.ActionEvent evt) {
143: platformButtonActionPerformed(evt);
144: }
145: });
146:
147: buttonGroup.add(otherButton);
148: org.openide.awt.Mnemonics.setLocalizedText(otherButton,
149: NbBundle.getMessage(NbPlatformCustomizerHarness.class,
150: "NbPCH.otherButton")); // NOI18N
151: otherButton.setBorder(javax.swing.BorderFactory
152: .createEmptyBorder(0, 0, 0, 0));
153: otherButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
154: otherButton
155: .addActionListener(new java.awt.event.ActionListener() {
156: public void actionPerformed(
157: java.awt.event.ActionEvent evt) {
158: otherButtonActionPerformed(evt);
159: }
160: });
161:
162: otherText.setEditable(false);
163:
164: org.openide.awt.Mnemonics.setLocalizedText(browseButton,
165: NbBundle.getMessage(NbPlatformCustomizerHarness.class,
166: "NbPCH.browseButton")); // NOI18N
167: browseButton
168: .addActionListener(new java.awt.event.ActionListener() {
169: public void actionPerformed(
170: java.awt.event.ActionEvent evt) {
171: browseButtonActionPerformed(evt);
172: }
173: });
174:
175: versionLabel.setLabelFor(versionText);
176: org.openide.awt.Mnemonics.setLocalizedText(versionLabel,
177: NbBundle.getMessage(NbPlatformCustomizerHarness.class,
178: "NbPCH.versionLabel")); // NOI18N
179:
180: versionText.setEditable(false);
181:
182: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
183: this );
184: this .setLayout(layout);
185: layout
186: .setHorizontalGroup(layout
187: .createParallelGroup(
188: org.jdesktop.layout.GroupLayout.LEADING)
189: .add(
190: layout
191: .createSequentialGroup()
192: .addContainerGap()
193: .add(
194: layout
195: .createParallelGroup(
196: org.jdesktop.layout.GroupLayout.LEADING)
197: .add(
198: layout
199: .createSequentialGroup()
200: .add(
201: layout
202: .createParallelGroup(
203: org.jdesktop.layout.GroupLayout.LEADING)
204: .add(
205: ideButton)
206: .add(
207: platformButton)
208: .add(
209: layout
210: .createSequentialGroup()
211: .add(
212: otherButton)
213: .addPreferredGap(
214: org.jdesktop.layout.LayoutStyle.RELATED)
215: .add(
216: otherText,
217: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
218: 220,
219: Short.MAX_VALUE)))
220: .addPreferredGap(
221: org.jdesktop.layout.LayoutStyle.RELATED)
222: .add(
223: browseButton))
224: .add(
225: layout
226: .createSequentialGroup()
227: .add(
228: versionLabel)
229: .addPreferredGap(
230: org.jdesktop.layout.LayoutStyle.RELATED)
231: .add(
232: versionText,
233: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
234: 231,
235: Short.MAX_VALUE)))
236: .addContainerGap()));
237: layout
238: .setVerticalGroup(layout
239: .createParallelGroup(
240: org.jdesktop.layout.GroupLayout.LEADING)
241: .add(
242: layout
243: .createSequentialGroup()
244: .addContainerGap()
245: .add(ideButton)
246: .addPreferredGap(
247: org.jdesktop.layout.LayoutStyle.RELATED)
248: .add(platformButton)
249: .addPreferredGap(
250: org.jdesktop.layout.LayoutStyle.RELATED)
251: .add(
252: layout
253: .createParallelGroup(
254: org.jdesktop.layout.GroupLayout.BASELINE)
255: .add(
256: otherButton)
257: .add(
258: browseButton)
259: .add(
260: otherText,
261: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
262: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
263: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
264: .addPreferredGap(
265: org.jdesktop.layout.LayoutStyle.RELATED)
266: .add(
267: layout
268: .createParallelGroup(
269: org.jdesktop.layout.GroupLayout.BASELINE)
270: .add(
271: versionLabel)
272: .add(
273: versionText,
274: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
275: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
276: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
277: .addContainerGap(196,
278: Short.MAX_VALUE)));
279:
280: ideButton.getAccessibleContext().setAccessibleDescription(
281: org.openide.util.NbBundle.getMessage(
282: NbPlatformCustomizerHarness.class,
283: "ACS_HarnessSuppliedIDE")); // NOI18N
284: platformButton.getAccessibleContext().setAccessibleDescription(
285: org.openide.util.NbBundle.getMessage(
286: NbPlatformCustomizerHarness.class,
287: "ACS_HarnessSuppliedPlatform")); // NOI18N
288: otherButton.getAccessibleContext().setAccessibleDescription(
289: org.openide.util.NbBundle.getMessage(
290: NbPlatformCustomizerHarness.class,
291: "ACS_HarnessOther")); // NOI18N
292: versionLabel.getAccessibleContext().setAccessibleDescription(
293: org.openide.util.NbBundle.getMessage(
294: NbPlatformCustomizerHarness.class,
295: "ACS_HarnessVersion")); // NOI18N
296: }// </editor-fold>//GEN-END:initComponents
297:
298: private void browseButtonActionPerformed(
299: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
300: JFileChooser jfc = new JFileChooser() {
301: // Trick stolen from ProjectChooserAccessory.ProjectFileChooser:
302: public void approveSelection() {
303: File dir = FileUtil.normalizeFile(getSelectedFile());
304: if (NbPlatform.isHarness(dir)) {
305: super .approveSelection();
306: } else {
307: setCurrentDirectory(dir);
308: }
309: }
310: };
311: FileUtil.preventFileChooserSymlinkTraversal(jfc, null);
312: jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
313: jfc.setSelectedFile(plaf.getHarnessLocation());
314: if (jfc.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
315: try {
316: plaf.setHarnessLocation(FileUtil.normalizeFile(jfc
317: .getSelectedFile()));
318: } catch (IOException e) {
319: Exceptions.printStackTrace(e);
320: }
321: }
322: update();
323: UIUtil.setText(otherText, plaf.getHarnessLocation()
324: .getAbsolutePath());
325: }//GEN-LAST:event_browseButtonActionPerformed
326:
327: private void otherButtonActionPerformed(
328: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_otherButtonActionPerformed
329: try {
330: plaf.setHarnessLocation(FileUtil.normalizeFile(new File(
331: otherText.getText())));
332: } catch (IOException e) {
333: Exceptions.printStackTrace(e);
334: }
335: update();
336: }//GEN-LAST:event_otherButtonActionPerformed
337:
338: private void platformButtonActionPerformed(
339: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_platformButtonActionPerformed
340: try {
341: plaf.setHarnessLocation(plaf.getBundledHarnessLocation());
342: } catch (IOException e) {
343: Exceptions.printStackTrace(e);
344: }
345: update();
346: }//GEN-LAST:event_platformButtonActionPerformed
347:
348: private void ideButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ideButtonActionPerformed
349: try {
350: assert plaf != null;
351: NbPlatform dflt = NbPlatform.getDefaultPlatform();
352: if (dflt != null) {
353: plaf.setHarnessLocation(dflt.getHarnessLocation());
354: } else {
355: Logger.getLogger(
356: NbPlatformCustomizerHarness.class.getName())
357: .warning("No default platform found"); // #113233
358: }
359: } catch (IOException e) {
360: Exceptions.printStackTrace(e);
361: }
362: update();
363: }//GEN-LAST:event_ideButtonActionPerformed
364:
365: // Variables declaration - do not modify//GEN-BEGIN:variables
366: private javax.swing.JButton browseButton;
367: private javax.swing.ButtonGroup buttonGroup;
368: private javax.swing.JRadioButton ideButton;
369: private javax.swing.JRadioButton otherButton;
370: private javax.swing.JTextField otherText;
371: private javax.swing.JRadioButton platformButton;
372: private javax.swing.JLabel versionLabel;
373: private javax.swing.JTextField versionText;
374: // End of variables declaration//GEN-END:variables
375:
376: }
|