0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.modules.ruby.platform;
0042:
0043: import java.awt.Color;
0044: import java.awt.Dialog;
0045: import java.awt.EventQueue;
0046: import java.io.File;
0047: import java.util.Locale;
0048: import java.util.Set;
0049: import javax.swing.AbstractListModel;
0050: import javax.swing.JButton;
0051: import javax.swing.JComboBox;
0052: import javax.swing.JFileChooser;
0053: import javax.swing.JPanel;
0054: import javax.swing.ListModel;
0055: import javax.swing.UIManager;
0056: import javax.swing.event.ListSelectionEvent;
0057: import javax.swing.event.ListSelectionListener;
0058: import javax.swing.filechooser.FileFilter;
0059: import org.netbeans.api.ruby.platform.RubyPlatform;
0060: import org.netbeans.api.ruby.platform.RubyPlatformManager;
0061: import org.netbeans.modules.ruby.platform.PlatformComponentFactory.RubyPlatformListModel;
0062: import org.netbeans.modules.ruby.platform.gems.GemManager;
0063: import org.netbeans.modules.ruby.platform.gems.GemPanel;
0064: import org.openide.DialogDescriptor;
0065: import org.openide.DialogDisplayer;
0066: import org.openide.awt.Mnemonics;
0067: import org.openide.filesystems.FileUtil;
0068: import org.openide.util.HelpCtx;
0069: import org.openide.util.NbBundle;
0070: import org.openide.util.RequestProcessor;
0071:
0072: public class RubyPlatformCustomizer extends JPanel {
0073:
0074: private static final String LAST_PLATFORM_DIRECTORY = "lastPlatformDirectory"; // NOI18N
0075:
0076: private static String lastSelectedPlatformID;
0077:
0078: public static void showCustomizer() {
0079: RubyPlatformCustomizer customizer = new RubyPlatformCustomizer();
0080: JButton closeButton = new JButton();
0081: closeButton
0082: .getAccessibleContext()
0083: .setAccessibleDescription(
0084: getMessage("RubyPlatformCustomizer.closeButton.AccessibleContext.accessibleName"));
0085: Mnemonics.setLocalizedText(closeButton, NbBundle.getMessage(
0086: RubyPlatformCustomizer.class, "CTL_Close"));
0087: DialogDescriptor descriptor = new DialogDescriptor(
0088: customizer,
0089: getMessage("CTL_RubyPlatformManager_Title"), // NOI18N
0090: true, new Object[] { closeButton }, closeButton,
0091: DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(
0092: RubyPlatformCustomizer.class), null);
0093: Dialog dlg = DialogDisplayer.getDefault().createDialog(
0094: descriptor);
0095: dlg.setVisible(true);
0096: dlg.dispose();
0097: }
0098:
0099: public RubyPlatformCustomizer() {
0100: initComponents();
0101: getAccessibleContext()
0102: .setAccessibleName(
0103: getMessage("RubyPlatformCustomizer.AccessibleContext.accessibleName"));
0104: getAccessibleContext()
0105: .setAccessibleDescription(
0106: getMessage("RubyPlatformCustomizer.AccessibleContext.accessibleDescription"));
0107: refreshPlatformList();
0108: gemPathList
0109: .addListSelectionListener(new ListSelectionListener() {
0110: public void valueChanged(ListSelectionEvent e) {
0111: removeGemPath.setEnabled(gemPathList
0112: .getSelectedValue() != null);
0113: }
0114: });
0115: platformsList
0116: .addListSelectionListener(new ListSelectionListener() {
0117: public void valueChanged(ListSelectionEvent e) {
0118: refreshPlatform();
0119: }
0120: });
0121:
0122: // run platform detection is this is the first time
0123: if (Util.isFirstPlatformTouch()) {
0124: performPlatformDetection();
0125: } else {
0126: setAutoDetecting(false);
0127: }
0128: }
0129:
0130: public static void manage(JComboBox platforms) {
0131: RubyPlatformCustomizer.showCustomizer();
0132: RubyPlatform origPlatform = (RubyPlatform) platforms
0133: .getSelectedItem();
0134: platforms
0135: .setModel(new PlatformComponentFactory.RubyPlatformListModel()); // refresh
0136: platforms.setSelectedItem(origPlatform);
0137: platforms.requestFocus();
0138: }
0139:
0140: private RubyPlatform getSelectedPlatform() {
0141: return (RubyPlatform) platformsList.getSelectedValue();
0142: }
0143:
0144: private void refreshPlatformList() {
0145: if (platformsList.getModel().getSize() > 0) {
0146: platformsList.setSelectedIndex(0);
0147: if (lastSelectedPlatformID != null) {
0148: RubyPlatform lastPlaf = RubyPlatformManager
0149: .getPlatformByID(lastSelectedPlatformID);
0150: if (lastPlaf != null) {
0151: platformsList.setSelectedValue(lastPlaf, true);
0152: }
0153: }
0154: }
0155: refreshPlatform();
0156: }
0157:
0158: private static String getMessage(String key) {
0159: return NbBundle.getMessage(RubyPlatformCustomizer.class, key);
0160: }
0161:
0162: private void performPlatformDetection() {
0163: setAutoDetecting(true);
0164: RequestProcessor.getDefault().post(new Runnable() {
0165: public void run() {
0166: RubyPlatformManager.performPlatformDetection();
0167: EventQueue.invokeLater(new Runnable() {
0168: public void run() {
0169: platformsList
0170: .setModel(new RubyPlatformListModel());
0171: refreshPlatformList();
0172: setAutoDetecting(false);
0173: }
0174: });
0175: }
0176: });
0177: }
0178:
0179: private void setAutoDetecting(boolean autoDetecting) {
0180: autoDetectButton.setEnabled(!autoDetecting);
0181: addButton.setEnabled(!autoDetecting);
0182: autoDetectProgress.setVisible(autoDetecting);
0183: autoDetectLabel.setVisible(autoDetecting);
0184: }
0185:
0186: private void refreshPlatform() {
0187: RubyPlatform plaf = getSelectedPlatform();
0188:
0189: if (plaf == null) {
0190: removeButton.setEnabled(false);
0191: return;
0192: }
0193: lastSelectedPlatformID = plaf.getID();
0194: plfNameValue.setText(plaf.getInfo().getLongDescription());
0195: plfInterpreterValue.setText(plaf.getInterpreter());
0196: Color color;
0197: boolean gemsInstalled = plaf.hasRubyGemsInstalled();
0198: if (gemsInstalled) {
0199: gemHomeValue.setText(plaf.getGemManager().getGemHome());
0200: gemPathList.setModel(createGemPathsModel(plaf));
0201: gemToolValue.setText(plaf.getGemManager().getGemTool()
0202: + " (" + plaf.getInfo().getGemVersion() + ')'); // NOI18N
0203: color = UIManager.getColor("Label.foreground");
0204: } else {
0205: color = PlatformComponentFactory.INVALID_PLAF_COLOR;
0206: String notInstalledMsg = GemManager
0207: .getNotInstalledMessage();
0208: gemHomeValue.setText(notInstalledMsg);
0209: gemToolValue.setText(notInstalledMsg);
0210: }
0211: browseGemHome.setEnabled(gemsInstalled);
0212: gemHomeValue.setForeground(color);
0213: gemToolValue.setForeground(color);
0214: removeButton.setEnabled(!plaf.isDefault());
0215: removeGemPath
0216: .setEnabled(gemPathList.getSelectedValue() != null);
0217:
0218: refreshDebugger();
0219: }
0220:
0221: private ListModel createGemPathsModel(final RubyPlatform plaf) {
0222: return new GemPathsListModel(plaf);
0223: }
0224:
0225: private static final class GemPathsListModel extends
0226: AbstractListModel {
0227:
0228: private RubyPlatform platform;
0229:
0230: GemPathsListModel(final RubyPlatform platform) {
0231: this .platform = platform;
0232: }
0233:
0234: public Object getElementAt(int index) {
0235: return index >= getSize() ? null
0236: : getPaths().toArray()[index];
0237: }
0238:
0239: public int getSize() {
0240: return getPaths().size();
0241: }
0242:
0243: void addPath(File repo) {
0244: platform.getGemManager().addGemPath(repo);
0245: super .fireIntervalAdded(this , 0, getSize());
0246: }
0247:
0248: void removePath(File path) {
0249: platform.getGemManager().removeGemPath(path);
0250: super .fireIntervalRemoved(this , 0, getSize());
0251: }
0252:
0253: private Set<File> getPaths() {
0254: return platform.getGemManager().getGemPath();
0255: }
0256: }
0257:
0258: private GemPathsListModel getGemPathListModel() {
0259: return (GemPathsListModel) gemPathList.getModel();
0260: }
0261:
0262: /** This method is called from within the constructor to
0263: * initialize the form.
0264: * WARNING: Do NOT modify this code. The content of this method is
0265: * always regenerated by the Form Editor.
0266: */
0267: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
0268: private void initComponents() {
0269:
0270: platformsListSP = new javax.swing.JScrollPane();
0271: platformsList = PlatformComponentFactory.getRubyPlatformsList();
0272: addButton = new javax.swing.JButton();
0273: removeButton = new javax.swing.JButton();
0274: autoDetectButton = new javax.swing.JButton();
0275: configPanel = new javax.swing.JPanel();
0276: gemTool = new javax.swing.JLabel();
0277: gemToolValue = new javax.swing.JTextField();
0278: gemHome = new javax.swing.JLabel();
0279: gemHomeValue = new javax.swing.JTextField();
0280: browseGemHome = new javax.swing.JButton();
0281: gemPath = new javax.swing.JLabel();
0282: plfInterpreter = new javax.swing.JLabel();
0283: plfInterpreterValue = new javax.swing.JTextField();
0284: plfName = new javax.swing.JLabel();
0285: plfNameValue = new javax.swing.JTextField();
0286: gemPathSP = new javax.swing.JScrollPane();
0287: gemPathList = new javax.swing.JList();
0288: addGemPath = new javax.swing.JButton();
0289: removeGemPath = new javax.swing.JButton();
0290: progressPanel = new javax.swing.JPanel();
0291: autoDetectLabel = new javax.swing.JLabel();
0292: autoDetectProgress = new javax.swing.JProgressBar();
0293: debuggerPanel = new javax.swing.JPanel();
0294: rubyDebuggerLabel = new javax.swing.JLabel();
0295: upperSep = new javax.swing.JSeparator();
0296: engineLabel = new javax.swing.JLabel();
0297: engineType = new javax.swing.JLabel();
0298: installFastDebugger = new javax.swing.JButton();
0299:
0300: platformsList
0301: .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
0302: platformsListSP.setViewportView(platformsList);
0303: platformsList
0304: .getAccessibleContext()
0305: .setAccessibleName(
0306: org.openide.util.NbBundle
0307: .getMessage(
0308: RubyPlatformCustomizer.class,
0309: "RubyPlatformCustomizer.platformsList.AccessibleContext.accessibleName")); // NOI18N
0310: platformsList
0311: .getAccessibleContext()
0312: .setAccessibleDescription(
0313: org.openide.util.NbBundle
0314: .getMessage(
0315: RubyPlatformCustomizer.class,
0316: "RubyPlatformCustomizer.platformsList.AccessibleContext.accessibleDescription")); // NOI18N
0317:
0318: org.openide.awt.Mnemonics.setLocalizedText(addButton,
0319: org.openide.util.NbBundle.getMessage(
0320: RubyPlatformCustomizer.class,
0321: "RubyPlatformCustomizer.addButton.text")); // NOI18N
0322: addButton
0323: .addActionListener(new java.awt.event.ActionListener() {
0324: public void actionPerformed(
0325: java.awt.event.ActionEvent evt) {
0326: addButtonaddPlatform(evt);
0327: }
0328: });
0329:
0330: org.openide.awt.Mnemonics.setLocalizedText(removeButton,
0331: org.openide.util.NbBundle.getMessage(
0332: RubyPlatformCustomizer.class,
0333: "RubyPlatformCustomizer.removeButton.text")); // NOI18N
0334: removeButton
0335: .addActionListener(new java.awt.event.ActionListener() {
0336: public void actionPerformed(
0337: java.awt.event.ActionEvent evt) {
0338: removeButtonremovePlatform(evt);
0339: }
0340: });
0341:
0342: org.openide.awt.Mnemonics
0343: .setLocalizedText(
0344: autoDetectButton,
0345: org.openide.util.NbBundle
0346: .getMessage(
0347: RubyPlatformCustomizer.class,
0348: "RubyPlatformCustomizer.autoDetectButton.text")); // NOI18N
0349: autoDetectButton
0350: .addActionListener(new java.awt.event.ActionListener() {
0351: public void actionPerformed(
0352: java.awt.event.ActionEvent evt) {
0353: autoDetectButtonremovePlatform(evt);
0354: }
0355: });
0356:
0357: gemTool.setLabelFor(gemToolValue);
0358: org.openide.awt.Mnemonics.setLocalizedText(gemTool,
0359: org.openide.util.NbBundle.getMessage(
0360: RubyPlatformCustomizer.class,
0361: "RubyPlatformCustomizer.gemTool.text")); // NOI18N
0362:
0363: gemToolValue.setEditable(false);
0364:
0365: gemHome.setLabelFor(gemHomeValue);
0366: org.openide.awt.Mnemonics.setLocalizedText(gemHome,
0367: org.openide.util.NbBundle.getMessage(
0368: RubyPlatformCustomizer.class,
0369: "RubyPlatformCustomizer.gemHome.text")); // NOI18N
0370:
0371: gemHomeValue.setEditable(false);
0372:
0373: org.openide.awt.Mnemonics.setLocalizedText(browseGemHome,
0374: org.openide.util.NbBundle.getMessage(
0375: RubyPlatformCustomizer.class,
0376: "RubyPlatformCustomizer.browseGemHome.text")); // NOI18N
0377: browseGemHome
0378: .addActionListener(new java.awt.event.ActionListener() {
0379: public void actionPerformed(
0380: java.awt.event.ActionEvent evt) {
0381: browseGemHomeActionPerformed(evt);
0382: }
0383: });
0384:
0385: gemPath.setLabelFor(gemPathList);
0386: org.openide.awt.Mnemonics.setLocalizedText(gemPath,
0387: org.openide.util.NbBundle.getMessage(
0388: RubyPlatformCustomizer.class,
0389: "RubyPlatformCustomizer.gemPath.text")); // NOI18N
0390:
0391: plfInterpreter.setLabelFor(plfInterpreterValue);
0392: org.openide.awt.Mnemonics.setLocalizedText(plfInterpreter,
0393: org.openide.util.NbBundle.getMessage(
0394: RubyPlatformCustomizer.class,
0395: "RubyPlatformCustomizer.plfInterpreter.text")); // NOI18N
0396:
0397: plfInterpreterValue.setEditable(false);
0398:
0399: plfName.setLabelFor(plfNameValue);
0400: org.openide.awt.Mnemonics.setLocalizedText(plfName,
0401: org.openide.util.NbBundle.getMessage(
0402: RubyPlatformCustomizer.class,
0403: "RubyPlatformCustomizer.plfName.text")); // NOI18N
0404:
0405: plfNameValue.setEditable(false);
0406:
0407: gemPathSP.setViewportView(gemPathList);
0408: gemPathList
0409: .getAccessibleContext()
0410: .setAccessibleName(
0411: org.openide.util.NbBundle
0412: .getMessage(
0413: RubyPlatformCustomizer.class,
0414: "RubyPlatformCustomizer.gemPathList.AccessibleContext.accessibleName")); // NOI18N
0415: gemPathList
0416: .getAccessibleContext()
0417: .setAccessibleDescription(
0418: org.openide.util.NbBundle
0419: .getMessage(
0420: RubyPlatformCustomizer.class,
0421: "RubyPlatformCustomizer.gemPathList.AccessibleContext.accessibleDescription")); // NOI18N
0422:
0423: org.openide.awt.Mnemonics.setLocalizedText(addGemPath,
0424: org.openide.util.NbBundle.getMessage(
0425: RubyPlatformCustomizer.class,
0426: "RubyPlatformCustomizer.addGemPath.text")); // NOI18N
0427: addGemPath
0428: .addActionListener(new java.awt.event.ActionListener() {
0429: public void actionPerformed(
0430: java.awt.event.ActionEvent evt) {
0431: addGemPathActionPerformed(evt);
0432: }
0433: });
0434:
0435: org.openide.awt.Mnemonics.setLocalizedText(removeGemPath,
0436: org.openide.util.NbBundle.getMessage(
0437: RubyPlatformCustomizer.class,
0438: "RubyPlatformCustomizer.removeGemPath.text")); // NOI18N
0439: removeGemPath
0440: .addActionListener(new java.awt.event.ActionListener() {
0441: public void actionPerformed(
0442: java.awt.event.ActionEvent evt) {
0443: removeGemPathActionPerformed(evt);
0444: }
0445: });
0446:
0447: org.jdesktop.layout.GroupLayout configPanelLayout = new org.jdesktop.layout.GroupLayout(
0448: configPanel);
0449: configPanel.setLayout(configPanelLayout);
0450: configPanelLayout
0451: .setHorizontalGroup(configPanelLayout
0452: .createParallelGroup(
0453: org.jdesktop.layout.GroupLayout.LEADING)
0454: .add(
0455: configPanelLayout
0456: .createSequentialGroup()
0457: .add(
0458: configPanelLayout
0459: .createParallelGroup(
0460: org.jdesktop.layout.GroupLayout.LEADING)
0461: .add(
0462: plfInterpreter)
0463: .add(plfName)
0464: .add(gemHome)
0465: .add(gemPath)
0466: .add(gemTool))
0467: .addPreferredGap(
0468: org.jdesktop.layout.LayoutStyle.RELATED)
0469: .add(
0470: configPanelLayout
0471: .createParallelGroup(
0472: org.jdesktop.layout.GroupLayout.LEADING)
0473: .add(
0474: configPanelLayout
0475: .createSequentialGroup()
0476: .add(
0477: configPanelLayout
0478: .createParallelGroup(
0479: org.jdesktop.layout.GroupLayout.LEADING)
0480: .add(
0481: gemHomeValue,
0482: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0483: 416,
0484: Short.MAX_VALUE)
0485: .add(
0486: gemPathSP,
0487: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0488: 416,
0489: Short.MAX_VALUE))
0490: .addPreferredGap(
0491: org.jdesktop.layout.LayoutStyle.RELATED)
0492: .add(
0493: configPanelLayout
0494: .createParallelGroup(
0495: org.jdesktop.layout.GroupLayout.TRAILING)
0496: .add(
0497: removeGemPath)
0498: .add(
0499: addGemPath)
0500: .add(
0501: browseGemHome)))
0502: .add(
0503: plfInterpreterValue,
0504: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0505: 511,
0506: Short.MAX_VALUE)
0507: .add(
0508: plfNameValue,
0509: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0510: 511,
0511: Short.MAX_VALUE)
0512: .add(
0513: gemToolValue,
0514: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0515: 511,
0516: Short.MAX_VALUE))));
0517:
0518: configPanelLayout.linkSize(new java.awt.Component[] { gemHome,
0519: gemTool, plfInterpreter, plfName },
0520: org.jdesktop.layout.GroupLayout.HORIZONTAL);
0521:
0522: configPanelLayout.linkSize(new java.awt.Component[] {
0523: addGemPath, browseGemHome, removeGemPath },
0524: org.jdesktop.layout.GroupLayout.HORIZONTAL);
0525:
0526: configPanelLayout
0527: .setVerticalGroup(configPanelLayout
0528: .createParallelGroup(
0529: org.jdesktop.layout.GroupLayout.LEADING)
0530: .add(
0531: configPanelLayout
0532: .createSequentialGroup()
0533: .add(
0534: configPanelLayout
0535: .createParallelGroup(
0536: org.jdesktop.layout.GroupLayout.BASELINE)
0537: .add(plfName)
0538: .add(
0539: plfNameValue,
0540: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0541: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0542: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0543: .add(7, 7, 7)
0544: .add(
0545: configPanelLayout
0546: .createParallelGroup(
0547: org.jdesktop.layout.GroupLayout.BASELINE)
0548: .add(
0549: plfInterpreter)
0550: .add(
0551: plfInterpreterValue,
0552: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0553: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0554: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0555: .add(11, 11, 11)
0556: .add(
0557: configPanelLayout
0558: .createParallelGroup(
0559: org.jdesktop.layout.GroupLayout.BASELINE)
0560: .add(gemHome)
0561: .add(
0562: gemHomeValue,
0563: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0564: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0565: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0566: .add(
0567: browseGemHome))
0568: .addPreferredGap(
0569: org.jdesktop.layout.LayoutStyle.RELATED)
0570: .add(
0571: configPanelLayout
0572: .createParallelGroup(
0573: org.jdesktop.layout.GroupLayout.LEADING)
0574: .add(gemPath)
0575: .add(
0576: gemPathSP,
0577: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0578: 68,
0579: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0580: .add(
0581: configPanelLayout
0582: .createSequentialGroup()
0583: .add(
0584: addGemPath)
0585: .addPreferredGap(
0586: org.jdesktop.layout.LayoutStyle.RELATED)
0587: .add(
0588: removeGemPath)))
0589: .addPreferredGap(
0590: org.jdesktop.layout.LayoutStyle.RELATED)
0591: .add(
0592: configPanelLayout
0593: .createParallelGroup(
0594: org.jdesktop.layout.GroupLayout.BASELINE)
0595: .add(gemTool)
0596: .add(
0597: gemToolValue,
0598: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0599: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0600: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))));
0601:
0602: gemToolValue
0603: .getAccessibleContext()
0604: .setAccessibleDescription(
0605: org.openide.util.NbBundle
0606: .getMessage(
0607: RubyPlatformCustomizer.class,
0608: "RubyPlatformCustomizer.gemToolValue.AccessibleContext.accessibleDescription")); // NOI18N
0609: gemHomeValue
0610: .getAccessibleContext()
0611: .setAccessibleDescription(
0612: org.openide.util.NbBundle
0613: .getMessage(
0614: RubyPlatformCustomizer.class,
0615: "RubyPlatformCustomizer.gemHomeValue.AccessibleContext.accessibleDescription")); // NOI18N
0616: browseGemHome
0617: .getAccessibleContext()
0618: .setAccessibleDescription(
0619: org.openide.util.NbBundle
0620: .getMessage(
0621: RubyPlatformCustomizer.class,
0622: "RubyPlatformCustomizer.browseGemHome.AccessibleContext.accessibleDescription")); // NOI18N
0623: plfInterpreterValue
0624: .getAccessibleContext()
0625: .setAccessibleDescription(
0626: org.openide.util.NbBundle
0627: .getMessage(
0628: RubyPlatformCustomizer.class,
0629: "RubyPlatformCustomizer.plfInterpreterValue.AccessibleContext.accessibleDescription")); // NOI18N
0630: plfNameValue
0631: .getAccessibleContext()
0632: .setAccessibleDescription(
0633: org.openide.util.NbBundle
0634: .getMessage(
0635: RubyPlatformCustomizer.class,
0636: "RubyPlatformCustomizer.plfNameValue.AccessibleContext.accessibleDescription")); // NOI18N
0637: addGemPath
0638: .getAccessibleContext()
0639: .setAccessibleDescription(
0640: org.openide.util.NbBundle
0641: .getMessage(
0642: RubyPlatformCustomizer.class,
0643: "RubyPlatformCustomizer.addGemPath.AccessibleContext.accessibleDescription")); // NOI18N
0644: removeGemPath
0645: .getAccessibleContext()
0646: .setAccessibleDescription(
0647: org.openide.util.NbBundle
0648: .getMessage(
0649: RubyPlatformCustomizer.class,
0650: "RubyPlatformCustomizer.removeGemPath.AccessibleContext.accessibleDescription")); // NOI18N
0651:
0652: org.openide.awt.Mnemonics.setLocalizedText(autoDetectLabel,
0653: org.openide.util.NbBundle.getMessage(
0654: RubyPlatformCustomizer.class,
0655: "RubyPlatformCustomizer.autoDetectLabel.text")); // NOI18N
0656: progressPanel.add(autoDetectLabel);
0657:
0658: autoDetectProgress.setIndeterminate(true);
0659: progressPanel.add(autoDetectProgress);
0660:
0661: org.openide.awt.Mnemonics
0662: .setLocalizedText(
0663: rubyDebuggerLabel,
0664: org.openide.util.NbBundle
0665: .getMessage(
0666: RubyPlatformCustomizer.class,
0667: "RubyPlatformCustomizer.rubyDebuggerLabel.text")); // NOI18N
0668:
0669: org.openide.awt.Mnemonics.setLocalizedText(engineLabel,
0670: org.openide.util.NbBundle.getMessage(
0671: RubyPlatformCustomizer.class,
0672: "RubyPlatformCustomizer.engineLabel.text")); // NOI18N
0673:
0674: engineType.setFont(new java.awt.Font("Dialog", 2, 12));
0675: org.openide.awt.Mnemonics
0676: .setLocalizedText(
0677: engineType,
0678: org.openide.util.NbBundle
0679: .getMessage(
0680: RubyPlatformCustomizer.class,
0681: "RubyPlatformCustomizer.classicDebuggerEngine.text")); // NOI18N
0682:
0683: org.openide.awt.Mnemonics
0684: .setLocalizedText(
0685: installFastDebugger,
0686: org.openide.util.NbBundle
0687: .getMessage(
0688: RubyPlatformCustomizer.class,
0689: "RubyPlatformCustomizer.installFastDebugger.text")); // NOI18N
0690: installFastDebugger
0691: .addActionListener(new java.awt.event.ActionListener() {
0692: public void actionPerformed(
0693: java.awt.event.ActionEvent evt) {
0694: installFastDebuggerActionPerformed(evt);
0695: }
0696: });
0697:
0698: org.jdesktop.layout.GroupLayout debuggerPanelLayout = new org.jdesktop.layout.GroupLayout(
0699: debuggerPanel);
0700: debuggerPanel.setLayout(debuggerPanelLayout);
0701: debuggerPanelLayout
0702: .setHorizontalGroup(debuggerPanelLayout
0703: .createParallelGroup(
0704: org.jdesktop.layout.GroupLayout.LEADING)
0705: .add(
0706: debuggerPanelLayout
0707: .createSequentialGroup()
0708: .add(rubyDebuggerLabel)
0709: .addPreferredGap(
0710: org.jdesktop.layout.LayoutStyle.RELATED)
0711: .add(
0712: upperSep,
0713: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0714: 510, Short.MAX_VALUE))
0715: .add(
0716: debuggerPanelLayout
0717: .createSequentialGroup()
0718: .add(engineLabel)
0719: .addPreferredGap(
0720: org.jdesktop.layout.LayoutStyle.RELATED)
0721: .add(engineType)
0722: .addPreferredGap(
0723: org.jdesktop.layout.LayoutStyle.RELATED)
0724: .add(installFastDebugger).add(
0725: 178, 178, 178)));
0726: debuggerPanelLayout
0727: .setVerticalGroup(debuggerPanelLayout
0728: .createParallelGroup(
0729: org.jdesktop.layout.GroupLayout.LEADING)
0730: .add(
0731: debuggerPanelLayout
0732: .createSequentialGroup()
0733: .add(
0734: debuggerPanelLayout
0735: .createParallelGroup(
0736: org.jdesktop.layout.GroupLayout.CENTER)
0737: .add(
0738: rubyDebuggerLabel)
0739: .add(
0740: upperSep,
0741: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0742: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0743: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0744: .addPreferredGap(
0745: org.jdesktop.layout.LayoutStyle.RELATED)
0746: .add(
0747: debuggerPanelLayout
0748: .createParallelGroup(
0749: org.jdesktop.layout.GroupLayout.BASELINE)
0750: .add(
0751: engineLabel)
0752: .add(engineType)
0753: .add(
0754: installFastDebugger))
0755: .addContainerGap(
0756: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0757: Short.MAX_VALUE)));
0758:
0759: installFastDebugger
0760: .getAccessibleContext()
0761: .setAccessibleDescription(
0762: org.openide.util.NbBundle
0763: .getMessage(
0764: RubyPlatformCustomizer.class,
0765: "RubyPlatformCustomizer.installFastDebugger.AccessibleContext.accessibleDescription")); // NOI18N
0766:
0767: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
0768: this );
0769: this .setLayout(layout);
0770: layout
0771: .setHorizontalGroup(layout
0772: .createParallelGroup(
0773: org.jdesktop.layout.GroupLayout.LEADING)
0774: .add(
0775: layout
0776: .createSequentialGroup()
0777: .addContainerGap()
0778: .add(
0779: layout
0780: .createParallelGroup(
0781: org.jdesktop.layout.GroupLayout.LEADING)
0782: .add(
0783: layout
0784: .createSequentialGroup()
0785: .add(
0786: platformsListSP,
0787: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0788: 235,
0789: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0790: .addPreferredGap(
0791: org.jdesktop.layout.LayoutStyle.RELATED)
0792: .add(
0793: layout
0794: .createParallelGroup(
0795: org.jdesktop.layout.GroupLayout.LEADING)
0796: .add(
0797: debuggerPanel,
0798: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0799: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0800: Short.MAX_VALUE)
0801: .add(
0802: configPanel,
0803: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0804: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0805: Short.MAX_VALUE)))
0806: .add(
0807: layout
0808: .createSequentialGroup()
0809: .add(
0810: addButton)
0811: .addPreferredGap(
0812: org.jdesktop.layout.LayoutStyle.RELATED)
0813: .add(
0814: removeButton)
0815: .addPreferredGap(
0816: org.jdesktop.layout.LayoutStyle.RELATED)
0817: .add(
0818: autoDetectButton)
0819: .addPreferredGap(
0820: org.jdesktop.layout.LayoutStyle.RELATED,
0821: 151,
0822: Short.MAX_VALUE)
0823: .add(
0824: progressPanel,
0825: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0826: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0827: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
0828: .addContainerGap()));
0829: layout
0830: .setVerticalGroup(layout
0831: .createParallelGroup(
0832: org.jdesktop.layout.GroupLayout.LEADING)
0833: .add(
0834: layout
0835: .createSequentialGroup()
0836: .addContainerGap()
0837: .add(
0838: layout
0839: .createParallelGroup(
0840: org.jdesktop.layout.GroupLayout.LEADING)
0841: .add(
0842: layout
0843: .createSequentialGroup()
0844: .add(
0845: platformsListSP,
0846: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0847: 314,
0848: Short.MAX_VALUE)
0849: .addPreferredGap(
0850: org.jdesktop.layout.LayoutStyle.RELATED))
0851: .add(
0852: layout
0853: .createSequentialGroup()
0854: .add(
0855: configPanel,
0856: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0857: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0858: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
0859: .add(
0860: 18,
0861: 18,
0862: 18)
0863: .add(
0864: debuggerPanel,
0865: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0866: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
0867: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
0868: .addPreferredGap(
0869: org.jdesktop.layout.LayoutStyle.RELATED)
0870: .add(
0871: layout
0872: .createParallelGroup(
0873: org.jdesktop.layout.GroupLayout.TRAILING)
0874: .add(
0875: layout
0876: .createParallelGroup(
0877: org.jdesktop.layout.GroupLayout.BASELINE)
0878: .add(
0879: addButton)
0880: .add(
0881: removeButton)
0882: .add(
0883: autoDetectButton))
0884: .add(
0885: progressPanel,
0886: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
0887: 25,
0888: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
0889: .addContainerGap()));
0890:
0891: layout.linkSize(new java.awt.Component[] { addButton,
0892: autoDetectButton, progressPanel, removeButton },
0893: org.jdesktop.layout.GroupLayout.VERTICAL);
0894:
0895: addButton
0896: .getAccessibleContext()
0897: .setAccessibleDescription(
0898: org.openide.util.NbBundle
0899: .getMessage(
0900: RubyPlatformCustomizer.class,
0901: "RubyPlatformCustomizer.addButton.AccessibleContext.accessibleDescription")); // NOI18N
0902: removeButton
0903: .getAccessibleContext()
0904: .setAccessibleDescription(
0905: org.openide.util.NbBundle
0906: .getMessage(
0907: RubyPlatformCustomizer.class,
0908: "RubyPlatformCustomizer.removeButton.AccessibleContext.accessibleDescription")); // NOI18N
0909: autoDetectButton
0910: .getAccessibleContext()
0911: .setAccessibleDescription(
0912: org.openide.util.NbBundle
0913: .getMessage(
0914: RubyPlatformCustomizer.class,
0915: "RubyPlatformCustomizer.autoDetectButton.AccessibleContext.accessibleDescription")); // NOI18N
0916: }// </editor-fold>//GEN-END:initComponents
0917:
0918: private PlatformComponentFactory.RubyPlatformListModel getPlafListModel() {
0919: return (PlatformComponentFactory.RubyPlatformListModel) platformsList
0920: .getModel();
0921: }
0922:
0923: private void addButtonaddPlatform(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonaddPlatform
0924: JFileChooser chooser = new JFileChooser(Util.getPreferences()
0925: .get(LAST_PLATFORM_DIRECTORY, ""));
0926: chooser.setAcceptAllFileFilterUsed(false);
0927: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
0928: chooser.setFileFilter(new FileFilter() {
0929: public boolean accept(File f) {
0930: return f.isDirectory()
0931: || (f.isFile() && f.getName().toLowerCase(
0932: Locale.US).contains("ruby")); // NOI18N
0933: }
0934:
0935: public String getDescription() {
0936: return getMessage("RubyPlatformCustomizer.rubyPlatform");
0937: }
0938: });
0939: int ret = chooser.showOpenDialog(this );
0940: if (ret == JFileChooser.APPROVE_OPTION) {
0941: File intepreter = FileUtil.normalizeFile(chooser
0942: .getSelectedFile());
0943: Util.getPreferences().put(LAST_PLATFORM_DIRECTORY,
0944: intepreter.getParentFile().getAbsolutePath());
0945: RubyPlatform platform = getPlafListModel().addPlatform(
0946: intepreter);
0947: if (platform == null) {
0948: Util
0949: .notifyLocalized(
0950: RubyPlatformCustomizer.class,
0951: "RubyPlatformCustomizer.invalid.platform.added",
0952: intepreter.getAbsolutePath()); // NOI18N
0953: } else {
0954: refreshPlatform();
0955: }
0956: }
0957: }//GEN-LAST:event_addButtonaddPlatform
0958:
0959: private void removeButtonremovePlatform(
0960: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonremovePlatform
0961: RubyPlatform plaf = getSelectedPlatform();
0962: if (plaf != null) {
0963: getPlafListModel().removePlatform(plaf);
0964: platformsList.setSelectedValue(RubyPlatformManager
0965: .getDefaultPlatform(), true);
0966: refreshPlatform();
0967: }
0968: }//GEN-LAST:event_removeButtonremovePlatform
0969:
0970: private void autoDetectButtonremovePlatform(
0971: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoDetectButtonremovePlatform
0972: performPlatformDetection();
0973: }//GEN-LAST:event_autoDetectButtonremovePlatform
0974:
0975: private void installFastDebuggerActionPerformed(
0976: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installFastDebuggerActionPerformed
0977: if (getSelectedPlatform().installFastDebugger()) {
0978: refreshDebugger();
0979: }
0980: }//GEN-LAST:event_installFastDebuggerActionPerformed
0981:
0982: private void browseGemHomeActionPerformed(
0983: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseGemHomeActionPerformed
0984: boolean changed = GemPanel.chooseAndSetGemHome(this ,
0985: getSelectedPlatform());
0986: if (changed) {
0987: refreshPlatform();
0988: }
0989: }//GEN-LAST:event_browseGemHomeActionPerformed
0990:
0991: private void addGemPathActionPerformed(
0992: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGemPathActionPerformed
0993: File repo = GemPanel.chooseGemRepository(this );
0994: if (repo != null) {
0995: String absPath = repo.getAbsolutePath();
0996: if (!getGemPathListModel().getPaths().contains(absPath)) {
0997: getGemPathListModel().addPath(repo);
0998: refreshPlatform();
0999: gemPathList.requestFocus();
1000: gemPathList.setSelectedValue(absPath, true);
1001: }
1002: }
1003: }//GEN-LAST:event_addGemPathActionPerformed
1004:
1005: private void removeGemPathActionPerformed(
1006: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeGemPathActionPerformed
1007: getGemPathListModel().removePath(
1008: (File) gemPathList.getSelectedValue());
1009: refreshPlatform();
1010: if (getGemPathListModel().getSize() > 0) {
1011: gemPathList.setSelectedIndex(0);
1012: }
1013: gemPathList.requestFocus();
1014: }//GEN-LAST:event_removeGemPathActionPerformed
1015:
1016: private void refreshDebugger() {
1017: RubyPlatform platform = getSelectedPlatform();
1018: boolean isJRuby = platform.isJRuby();
1019: boolean fdInstalled = platform.hasFastDebuggerInstalled();
1020: installFastDebugger.setEnabled(!isJRuby
1021: && platform.hasRubyGemsInstalled());
1022: installFastDebugger.setVisible(!isJRuby && !fdInstalled);
1023: String key = platform.hasFastDebuggerInstalled() ? "RubyPlatformCustomizer.rubyDebugEngine.text" // NOI18N
1024: : "RubyPlatformCustomizer.classicDebuggerEngine.text"; // NOI18N
1025: engineType.setText(getMessage(key));
1026: }
1027:
1028: // Variables declaration - do not modify//GEN-BEGIN:variables
1029: private javax.swing.JButton addButton;
1030: private javax.swing.JButton addGemPath;
1031: private javax.swing.JButton autoDetectButton;
1032: private javax.swing.JLabel autoDetectLabel;
1033: private javax.swing.JProgressBar autoDetectProgress;
1034: private javax.swing.JButton browseGemHome;
1035: private javax.swing.JPanel configPanel;
1036: private javax.swing.JPanel debuggerPanel;
1037: private javax.swing.JLabel engineLabel;
1038: private javax.swing.JLabel engineType;
1039: private javax.swing.JLabel gemHome;
1040: private javax.swing.JTextField gemHomeValue;
1041: private javax.swing.JLabel gemPath;
1042: private javax.swing.JList gemPathList;
1043: private javax.swing.JScrollPane gemPathSP;
1044: private javax.swing.JLabel gemTool;
1045: private javax.swing.JTextField gemToolValue;
1046: private javax.swing.JButton installFastDebugger;
1047: private javax.swing.JList platformsList;
1048: private javax.swing.JScrollPane platformsListSP;
1049: private javax.swing.JLabel plfInterpreter;
1050: private javax.swing.JTextField plfInterpreterValue;
1051: private javax.swing.JLabel plfName;
1052: private javax.swing.JTextField plfNameValue;
1053: private javax.swing.JPanel progressPanel;
1054: private javax.swing.JButton removeButton;
1055: private javax.swing.JButton removeGemPath;
1056: private javax.swing.JLabel rubyDebuggerLabel;
1057: private javax.swing.JSeparator upperSep;
1058: // End of variables declaration//GEN-END:variables
1059: }
|