1 19 20 package org.apache.tools.ant.module; 21 22 import java.awt.Component ; 23 import java.awt.Dialog ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.beans.PropertyEditor ; 27 import java.beans.PropertyEditorManager ; 28 import java.io.File ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.Properties ; 33 import java.util.regex.Pattern ; 34 import javax.swing.DefaultComboBoxModel ; 35 import javax.swing.JFileChooser ; 36 import javax.swing.JPanel ; 37 import javax.swing.SwingUtilities ; 38 import org.openide.DialogDescriptor; 39 import org.openide.DialogDisplayer; 40 import org.openide.NotifyDescriptor; 41 import org.openide.execution.NbClassPath; 42 import org.openide.util.NbBundle; 43 import org.openide.util.NbCollections; 44 45 49 public class AntCustomizer extends JPanel implements ActionListener { 50 51 private List <File > classpath; 52 private Map <String ,String > properties; 53 private boolean changed = false; 54 private boolean listen = false; 55 private File originalAntHome; 56 57 public AntCustomizer() { 58 initComponents(); 59 bAntHome.addActionListener (this); 60 ((DefaultComboBoxModel ) cbVerbosity.getModel()).removeAllElements(); cbVerbosity.addItem(NbBundle.getMessage(AntCustomizer.class, "LBL_verbosity_warn")); 62 cbVerbosity.addItem(NbBundle.getMessage(AntCustomizer.class, "LBL_verbosity_info")); 63 cbVerbosity.addItem(NbBundle.getMessage(AntCustomizer.class, "LBL_verbosity_verbose")); 64 cbVerbosity.addItem(NbBundle.getMessage(AntCustomizer.class, "LBL_verbosity_debug")); 65 bProperties.addActionListener (this); 66 bClasspath.addActionListener (this); 67 cbSaveFiles.addActionListener (this); 68 cbReuseOutput.addActionListener (this); 69 cbAlwaysShowOutput.addActionListener (this); 70 cbVerbosity.addActionListener (this); 71 } 72 73 void update () { 74 listen = false; 75 classpath = AntSettings.getExtraClasspath(); 76 properties = AntSettings.getProperties(); 77 originalAntHome = AntSettings.getAntHome(); 78 79 tfAntHome.setText(originalAntHome != null ? originalAntHome.toString() : null); 80 cbSaveFiles.setSelected(AntSettings.getSaveAll()); 81 cbReuseOutput.setSelected(AntSettings.getAutoCloseTabs()); 82 cbAlwaysShowOutput.setSelected(AntSettings.getAlwaysShowOutput()); 83 cbVerbosity.setSelectedIndex(AntSettings.getVerbosity() - 1); 84 lAntVersion.setText("(" + AntSettings.getAntVersion() + ")"); 85 changed = false; 86 initialized = true; 87 listen = true; 88 } 89 90 private boolean initialized = false; 91 92 void applyChanges () { 93 if (!initialized) return; 94 String antHome = tfAntHome.getText ().trim (); 95 AntSettings.setAntHome(new File (antHome)); 96 if (AntSettings.getAutoCloseTabs() != cbReuseOutput.isSelected()) { 97 AntSettings.setAutoCloseTabs(cbReuseOutput.isSelected()); 98 } 99 if (AntSettings.getSaveAll() != cbSaveFiles.isSelected()) { 100 AntSettings.setSaveAll(cbSaveFiles.isSelected()); 101 } 102 if (AntSettings.getAlwaysShowOutput() != cbAlwaysShowOutput.isSelected()) { 103 AntSettings.setAlwaysShowOutput(cbAlwaysShowOutput.isSelected()); 104 } 105 if (AntSettings.getVerbosity() != cbVerbosity.getSelectedIndex() + 1) { 106 AntSettings.setVerbosity(cbVerbosity.getSelectedIndex() + 1); 107 } 108 if (!AntSettings.getProperties().equals(properties)) { 109 AntSettings.setProperties(properties); 110 } 111 if (!AntSettings.getExtraClasspath().equals(classpath)) { 112 AntSettings.setExtraClasspath(classpath); 113 } 114 changed = false; 115 } 116 117 void cancel () { 118 if (AntSettings.getAntHome() != originalAntHome) { 119 AntSettings.setAntHome(originalAntHome); 120 } 121 changed = false; 122 } 123 124 boolean dataValid () { 125 return true; 126 } 127 128 boolean isChanged () { 129 return changed; 130 } 131 132 public void actionPerformed (ActionEvent e) { 133 if (!listen) return; 134 Object o = e.getSource (); 135 if (o == cbAlwaysShowOutput) { 136 changed = true; 137 } else 138 if (o == cbReuseOutput) { 139 changed = true; 140 } else 141 if (o == cbSaveFiles) { 142 changed = true; 143 } else 144 if (o == cbVerbosity) { 145 changed = true; 146 } else 147 if (o == bAntHome) { 148 JFileChooser chooser = new JFileChooser (tfAntHome.getText ()); 149 chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); 150 int r = chooser.showDialog ( 151 SwingUtilities.getWindowAncestor (this), 152 NbBundle.getMessage(AntCustomizer.class, "Select_Directory") 153 ); 154 if (r == JFileChooser.APPROVE_OPTION) { 155 File file = chooser.getSelectedFile (); 156 if (!new File (new File (file, "lib"), "ant.jar").isFile ()) { 157 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 158 NbBundle.getMessage(AntCustomizer.class, "Not_a_ant_home", file), 159 NotifyDescriptor.Message.WARNING_MESSAGE 160 )); 161 return; 162 } 163 tfAntHome.setText (file.getAbsolutePath ()); 164 AntSettings.setAntHome(file); 165 lAntVersion.setText("(" + AntSettings.getAntVersion() + ")"); 166 changed = true; 167 } 168 } else 169 if (o == bClasspath) { 170 PropertyEditor editor = PropertyEditorManager.findEditor(NbClassPath.class); 171 editor.setValue(new NbClassPath(classpath.toArray(new File [classpath.size()]))); 172 Component customEditor = editor.getCustomEditor (); 173 DialogDescriptor dd = new DialogDescriptor ( 174 customEditor, 175 NbBundle.getMessage(AntCustomizer.class, "Classpath_Editor_Title") 176 ); 177 Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd); 178 dialog.setVisible (true); 179 if (dd.getValue () == NotifyDescriptor.OK_OPTION) { 180 String cp = ((NbClassPath) editor.getValue()).getClassPath(); 181 if (cp.startsWith("\"") && cp.endsWith("\"")) { 182 cp = cp.substring(1, cp.length() - 1); 184 } 185 classpath = new ArrayList <File >(); 186 for (String f : cp.split(Pattern.quote(File.pathSeparator))) { 187 classpath.add(new File (f)); 188 } 189 changed = true; 190 } 191 } else 192 if (o == bProperties) { 193 PropertyEditor editor = PropertyEditorManager.findEditor(Properties .class); 194 Properties p = new Properties (); 195 p.putAll(properties); 196 editor.setValue(p); 197 Component customEditor = editor.getCustomEditor (); 198 DialogDescriptor dd = new DialogDescriptor ( 199 customEditor, 200 NbBundle.getMessage(AntCustomizer.class, "Properties_Editor_Title") 201 ); 202 Dialog dialog = DialogDisplayer.getDefault ().createDialog (dd); 203 dialog.setVisible (true); 204 if (dd.getValue () == NotifyDescriptor.OK_OPTION) { 205 properties = NbCollections.checkedMapByCopy((Properties ) editor.getValue(), String .class, String .class, true); 206 changed = true; 207 } 208 } 209 } 210 211 private void initComponents() { 213 javax.swing.JLabel antHomeLabel; 214 javax.swing.JLabel classpathLabel; 215 javax.swing.JPanel classpathPanel; 216 javax.swing.JLabel propertiesLabel; 217 javax.swing.JPanel propertiesPanel; 218 javax.swing.JLabel verbosityLabel; 219 220 antHomeLabel = new javax.swing.JLabel (); 221 tfAntHome = new javax.swing.JTextField (); 222 bAntHome = new javax.swing.JButton (); 223 bAntHomeDefault = new javax.swing.JButton (); 224 lAntVersion = new javax.swing.JLabel (); 225 cbSaveFiles = new javax.swing.JCheckBox (); 226 cbReuseOutput = new javax.swing.JCheckBox (); 227 cbAlwaysShowOutput = new javax.swing.JCheckBox (); 228 cbVerbosity = new javax.swing.JComboBox (); 229 verbosityLabel = new javax.swing.JLabel (); 230 propertiesPanel = new javax.swing.JPanel (); 231 propertiesLabel = new javax.swing.JLabel (); 232 bProperties = new javax.swing.JButton (); 233 classpathPanel = new javax.swing.JPanel (); 234 classpathLabel = new javax.swing.JLabel (); 235 bClasspath = new javax.swing.JButton (); 236 237 setBackground(java.awt.Color.white); 238 antHomeLabel.setLabelFor(tfAntHome); 239 org.openide.awt.Mnemonics.setLocalizedText(antHomeLabel, NbBundle.getMessage(AntCustomizer.class, "Ant_Home")); 240 241 org.openide.awt.Mnemonics.setLocalizedText(bAntHome, NbBundle.getMessage(AntCustomizer.class, "Ant_Home_Button")); 242 243 org.openide.awt.Mnemonics.setLocalizedText(bAntHomeDefault, NbBundle.getMessage(AntCustomizer.class, "Ant_Home_Default_Button")); 244 bAntHomeDefault.addActionListener(new java.awt.event.ActionListener () { 245 public void actionPerformed(java.awt.event.ActionEvent evt) { 246 bAntHomeDefaultActionPerformed(evt); 247 } 248 }); 249 250 lAntVersion.setBackground(java.awt.Color.white); 251 org.openide.awt.Mnemonics.setLocalizedText(lAntVersion, "<Ant version here...>"); 252 253 cbSaveFiles.setBackground(java.awt.Color.white); 254 org.openide.awt.Mnemonics.setLocalizedText(cbSaveFiles, NbBundle.getMessage(AntCustomizer.class, "Save_Files")); 255 cbSaveFiles.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 256 cbSaveFiles.setMargin(new java.awt.Insets (0, 0, 0, 0)); 257 258 cbReuseOutput.setBackground(java.awt.Color.white); 259 org.openide.awt.Mnemonics.setLocalizedText(cbReuseOutput, NbBundle.getMessage(AntCustomizer.class, "Reuse_Output")); 260 cbReuseOutput.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 261 cbReuseOutput.setMargin(new java.awt.Insets (0, 0, 0, 0)); 262 263 cbAlwaysShowOutput.setBackground(java.awt.Color.white); 264 org.openide.awt.Mnemonics.setLocalizedText(cbAlwaysShowOutput, NbBundle.getMessage(AntCustomizer.class, "Always_Show_Output")); 265 cbAlwaysShowOutput.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 266 cbAlwaysShowOutput.setMargin(new java.awt.Insets (0, 0, 0, 0)); 267 268 cbVerbosity.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "Normal" })); 269 270 verbosityLabel.setLabelFor(cbVerbosity); 271 org.openide.awt.Mnemonics.setLocalizedText(verbosityLabel, NbBundle.getMessage(AntCustomizer.class, "Verbosity")); 272 273 propertiesPanel.setBackground(java.awt.Color.white); 274 propertiesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(NbBundle.getMessage(AntCustomizer.class, "Properties_Panel"))); 275 org.openide.awt.Mnemonics.setLocalizedText(propertiesLabel, NbBundle.getMessage(AntCustomizer.class, "Properties_Text_Area")); 276 277 org.openide.awt.Mnemonics.setLocalizedText(bProperties, NbBundle.getMessage(AntCustomizer.class, "Properties_Button")); 278 279 org.jdesktop.layout.GroupLayout propertiesPanelLayout = new org.jdesktop.layout.GroupLayout(propertiesPanel); 280 propertiesPanel.setLayout(propertiesPanelLayout); 281 propertiesPanelLayout.setHorizontalGroup( 282 propertiesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 283 .add(propertiesPanelLayout.createSequentialGroup() 284 .addContainerGap() 285 .add(propertiesLabel) 286 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE) 287 .add(bProperties) 288 .addContainerGap()) 289 ); 290 propertiesPanelLayout.setVerticalGroup( 291 propertiesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 292 .add(propertiesPanelLayout.createSequentialGroup() 293 .add(propertiesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 294 .add(propertiesLabel) 295 .add(bProperties)) 296 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 297 ); 298 299 classpathPanel.setBackground(java.awt.Color.white); 300 classpathPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(NbBundle.getMessage(AntCustomizer.class, "Classpath_Panel"))); 301 org.openide.awt.Mnemonics.setLocalizedText(classpathLabel, NbBundle.getMessage(AntCustomizer.class, "Classpath_Text_Area")); 302 303 org.openide.awt.Mnemonics.setLocalizedText(bClasspath, NbBundle.getMessage(AntCustomizer.class, "Classpath_Button")); 304 305 org.jdesktop.layout.GroupLayout classpathPanelLayout = new org.jdesktop.layout.GroupLayout(classpathPanel); 306 classpathPanel.setLayout(classpathPanelLayout); 307 classpathPanelLayout.setHorizontalGroup( 308 classpathPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 309 .add(classpathPanelLayout.createSequentialGroup() 310 .addContainerGap() 311 .add(classpathLabel) 312 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 313 .add(bClasspath) 314 .addContainerGap()) 315 ); 316 classpathPanelLayout.setVerticalGroup( 317 classpathPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 318 .add(classpathLabel) 319 .add(bClasspath) 320 ); 321 322 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 323 this.setLayout(layout); 324 layout.setHorizontalGroup( 325 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 326 .add(propertiesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 327 .add(layout.createSequentialGroup() 328 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 329 .add(antHomeLabel) 330 .add(verbosityLabel)) 331 .add(16, 16, 16) 332 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 333 .add(layout.createSequentialGroup() 334 .add(cbAlwaysShowOutput) 335 .addContainerGap()) 336 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 337 .add(lAntVersion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE) 338 .add(layout.createSequentialGroup() 339 .add(cbVerbosity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 340 .addContainerGap()) 341 .add(layout.createSequentialGroup() 342 .add(cbReuseOutput) 343 .addContainerGap()) 344 .add(layout.createSequentialGroup() 345 .add(cbSaveFiles) 346 .addContainerGap()) 347 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 348 .add(tfAntHome, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE) 349 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 350 .add(bAntHome) 351 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 352 .add(bAntHomeDefault))))) 353 .add(classpathPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 354 ); 355 layout.setVerticalGroup( 356 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 357 .add(layout.createSequentialGroup() 358 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false) 359 .add(antHomeLabel) 360 .add(bAntHomeDefault) 361 .add(bAntHome) 362 .add(tfAntHome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 363 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 364 .add(lAntVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 365 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 366 .add(cbSaveFiles) 367 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 368 .add(cbReuseOutput) 369 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 370 .add(cbAlwaysShowOutput) 371 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 372 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 373 .add(cbVerbosity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 374 .add(verbosityLabel)) 375 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 376 .add(propertiesPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 377 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 378 .add(classpathPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 379 .addContainerGap()) 380 ); 381 } 383 private void bAntHomeDefaultActionPerformed(java.awt.event.ActionEvent evt) { AntSettings.setAntHome(null); 385 File antHome = AntSettings.getAntHome(); 386 if (antHome != null) { 387 tfAntHome.setText(antHome.getAbsolutePath()); 388 } else { 389 tfAntHome.setText(null); 390 } 391 lAntVersion.setText("(" + AntSettings.getAntVersion() + ")"); 392 changed = true; 393 } 395 private javax.swing.JButton bAntHome; 397 private javax.swing.JButton bAntHomeDefault; 398 private javax.swing.JButton bClasspath; 399 private javax.swing.JButton bProperties; 400 private javax.swing.JCheckBox cbAlwaysShowOutput; 401 private javax.swing.JCheckBox cbReuseOutput; 402 private javax.swing.JCheckBox cbSaveFiles; 403 private javax.swing.JComboBox cbVerbosity; 404 private javax.swing.JLabel lAntVersion; 405 private javax.swing.JTextField tfAntHome; 406 408 } 409 | Popular Tags |