1 19 20 package org.netbeans.modules.ruby.rubyproject; 21 22 import java.awt.event.ActionListener ; 23 import java.io.File ; 24 import java.io.File ; 25 import org.openide.filesystems.FileUtil; 26 27 import javax.swing.JFileChooser ; 28 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation; 29 import org.openide.util.NbBundle; 30 31 35 public class RubyHomeOptionsPanel extends javax.swing.JPanel implements ActionListener { 36 37 38 public RubyHomeOptionsPanel() { 39 initComponents(); 40 } 41 42 public void setRuby(String path) { 43 rubyField.setText(path); 44 } 45 46 public String getRuby() { 47 return rubyField.getText().trim(); 48 } 49 50 public void setRake(String path) { 51 rakeField.setText(path); 52 } 53 54 public String getRake() { 55 return rakeField.getText().trim(); 56 } 57 58 public void setRDoc(String path) { 59 rdocField.setText(path); 60 } 61 62 public String getRDoc() { 63 return rdocField.getText().trim(); 64 } 65 66 public void setRails(String path) { 67 railsField.setText(path); 68 } 69 70 public String getRails() { 71 return railsField.getText().trim(); 72 } 73 74 79 private void initComponents() { 81 82 jLabel1 = new javax.swing.JLabel (); 83 rubyField = new javax.swing.JTextField (); 84 jButton1 = new javax.swing.JButton (); 85 rakeLabel = new javax.swing.JLabel (); 86 rakeField = new javax.swing.JTextField (); 87 jButton2 = new javax.swing.JButton (); 88 railsLabel = new javax.swing.JLabel (); 89 rdocField = new javax.swing.JTextField (); 90 jButton3 = new javax.swing.JButton (); 91 rdocLabel = new javax.swing.JLabel (); 92 railsField = new javax.swing.JTextField (); 93 jButton4 = new javax.swing.JButton (); 94 jLabel2 = new javax.swing.JLabel (); 95 96 setPreferredSize(new java.awt.Dimension (600, 200)); 97 98 jLabel1.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyLabel")); 100 jButton1.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeBrowse")); jButton1.addActionListener(this); 102 103 rakeLabel.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RakeLabel")); 105 jButton2.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeBrowse")); jButton2.addActionListener(this); 107 108 railsLabel.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.railsLabel.text")); 110 jButton3.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.jButton3.text")); jButton3.addActionListener(this); 112 113 rdocLabel.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.rdocLabel.text")); 115 jButton4.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.jButton4.text")); jButton4.addActionListener(this); 117 118 jLabel2.setText(org.openide.util.NbBundle.getMessage(RubyHomeOptionsPanel.class, "RubyHomeOptionsPanel.jLabel2.text")); 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 178 public void actionPerformed(java.awt.event.ActionEvent 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 } 193 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { 195 JFileChooser chooser = new JFileChooser (); 196 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 197 chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); 198 chooser.setMultiSelectionEnabled(false); 199 200 String workDir = railsField.getText(); 201 if (workDir.equals("")) { 202 workDir = new File (RubyInstallation.getInstance().getRake()).getParent(); 203 } 204 chooser.setSelectedFile(new File (workDir)); 205 chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration")); 206 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); 208 railsField.setText(file.getAbsolutePath()); 209 } 210 211 } 213 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { 215 JFileChooser chooser = new JFileChooser (); 216 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 217 chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); 218 chooser.setMultiSelectionEnabled(false); 219 220 String workDir = rdocField.getText(); 221 if (workDir.equals("")) { 222 workDir = new File (RubyInstallation.getInstance().getRake()).getParent(); 223 } 224 chooser.setSelectedFile(new File (workDir)); 225 chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration")); 226 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); 228 rdocField.setText(file.getAbsolutePath()); 229 } 230 } 232 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 235 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 236 chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); 237 chooser.setMultiSelectionEnabled(false); 238 239 String workDir = rakeField.getText(); 240 if (workDir.equals("")) { 241 workDir = new File (RubyInstallation.getInstance().getRake()).getParent(); 242 } 243 chooser.setSelectedFile(new File (workDir)); 244 chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration")); 245 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); 247 rakeField.setText(file.getAbsolutePath()); 248 } 249 } 251 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 252 253 JFileChooser chooser = new JFileChooser (); 254 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 255 chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); 256 chooser.setMultiSelectionEnabled(false); 257 258 String workDir = rubyField.getText(); 259 if (workDir.equals("")) { 260 workDir = new File (RubyInstallation.getInstance().getRuby()).getParent(); 261 } 262 chooser.setSelectedFile(new File (workDir)); 263 chooser.setDialogTitle(NbBundle.getMessage(RubyHomeOptionsPanel.class, "LBL_BrowseConfiguration")); 264 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); 266 rubyField.setText(file.getAbsolutePath()); 267 } 268 } 269 270 271 private javax.swing.JButton jButton1; 273 private javax.swing.JButton jButton2; 274 private javax.swing.JButton jButton3; 275 private javax.swing.JButton jButton4; 276 private javax.swing.JLabel jLabel1; 277 private javax.swing.JLabel jLabel2; 278 private javax.swing.JTextField railsField; 279 private javax.swing.JLabel railsLabel; 280 private javax.swing.JTextField rakeField; 281 private javax.swing.JLabel rakeLabel; 282 private javax.swing.JTextField rdocField; 283 private javax.swing.JLabel rdocLabel; 284 private javax.swing.JTextField rubyField; 285 287 } 288 | Popular Tags |