1 19 20 package org.netbeans.modules.apisupport.project.ui.platform; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import javax.swing.JFileChooser ; 25 import javax.swing.JPanel ; 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 37 public class NbPlatformCustomizerHarness extends JPanel { 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 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 private void initComponents() { 77 buttonGroup = new javax.swing.ButtonGroup (); 78 ideButton = new javax.swing.JRadioButton (); 79 platformButton = new javax.swing.JRadioButton (); 80 otherButton = new javax.swing.JRadioButton (); 81 otherText = new javax.swing.JTextField (); 82 browseButton = new javax.swing.JButton (); 83 versionLabel = new javax.swing.JLabel (); 84 versionText = new javax.swing.JTextField (); 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 (0, 0, 0, 0)); 90 ideButton.addActionListener(new java.awt.event.ActionListener () { 91 public void actionPerformed(java.awt.event.ActionEvent 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 (0, 0, 0, 0)); 100 platformButton.addActionListener(new java.awt.event.ActionListener () { 101 public void actionPerformed(java.awt.event.ActionEvent 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 (0, 0, 0, 0)); 110 otherButton.addActionListener(new java.awt.event.ActionListener () { 111 public void actionPerformed(java.awt.event.ActionEvent 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 () { 120 public void actionPerformed(java.awt.event.ActionEvent 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 } 173 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser jfc = new JFileChooser () { 175 public void approveSelection() { 177 File 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 e) { 192 Util.err.notify(e); 193 } 194 } 195 update(); 196 UIUtil.setText(otherText, plaf.getHarnessLocation().getAbsolutePath()); 197 } 199 private void otherButtonActionPerformed(java.awt.event.ActionEvent evt) { try { 201 plaf.setHarnessLocation(FileUtil.normalizeFile(new File (otherText.getText()))); 202 } catch (IOException e) { 203 Util.err.notify(e); 204 } 205 update(); 206 } 208 private void platformButtonActionPerformed(java.awt.event.ActionEvent evt) { try { 210 plaf.setHarnessLocation(plaf.getBundledHarnessLocation()); 211 } catch (IOException e) { 212 Util.err.notify(e); 213 } 214 update(); 215 } 217 private void ideButtonActionPerformed(java.awt.event.ActionEvent evt) { try { 219 plaf.setHarnessLocation(NbPlatform.getDefaultPlatform().getHarnessLocation()); 220 } catch (IOException e) { 221 Util.err.notify(e); 222 } 223 update(); 224 } 226 227 private javax.swing.JButton browseButton; 229 private javax.swing.ButtonGroup buttonGroup; 230 private javax.swing.JRadioButton ideButton; 231 private javax.swing.JRadioButton otherButton; 232 private javax.swing.JTextField otherText; 233 private javax.swing.JRadioButton platformButton; 234 private javax.swing.JLabel versionLabel; 235 private javax.swing.JTextField versionText; 236 238 } 239 | Popular Tags |