1 19 20 package org.netbeans.modules.java.j2seplatform.wizard; 21 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.io.File ; 25 import java.net.MalformedURLException ; 26 import java.net.URI ; 27 import java.net.URL ; 28 import java.util.*; 29 import javax.swing.event.*; 30 import javax.swing.*; 31 import javax.swing.filechooser.FileFilter ; 32 import org.netbeans.api.java.classpath.ClassPath; 33 import org.netbeans.api.progress.ProgressHandle; 34 import org.netbeans.api.progress.ProgressHandleFactory; 35 import org.netbeans.spi.project.support.ant.PropertyUtils; 36 37 import org.openide.filesystems.*; 38 import org.openide.util.NbBundle; 39 import org.openide.util.RequestProcessor; 40 import org.openide.util.Task; 41 import org.openide.util.TaskListener; 42 import org.openide.util.HelpCtx; 43 44 import org.netbeans.api.java.platform.JavaPlatform; 45 import org.netbeans.api.java.platform.JavaPlatformManager; 46 import org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl; 47 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 48 import org.openide.ErrorManager; 49 import org.openide.WizardDescriptor; 50 51 61 public class DetectPanel extends javax.swing.JPanel { 62 63 private NewJ2SEPlatform primaryPlatform; 64 private ArrayList listeners; 65 66 71 public DetectPanel(NewJ2SEPlatform primaryPlatform) { 72 initComponents(); 73 postInitComponents (); 74 putClientProperty("WizardPanel_contentData", 75 new String [] { 76 NbBundle.getMessage(DetectPanel.class,"TITLE_PlatformName"), 77 }); 78 this.primaryPlatform = primaryPlatform; 79 this.setName (NbBundle.getMessage(DetectPanel.class,"TITLE_PlatformName")); 80 } 81 82 public void addNotify() { 83 super.addNotify(); 84 } 85 86 private void postInitComponents () { 87 this.jdkName.getDocument().addDocumentListener (new DocumentListener () { 88 89 public void insertUpdate(DocumentEvent e) { 90 handleNameChange (); 91 } 92 93 public void removeUpdate(DocumentEvent e) { 94 handleNameChange (); 95 } 96 97 public void changedUpdate(DocumentEvent e) { 98 handleNameChange (); 99 } 100 }); 101 this.progressLabel.setVisible(false); 102 this.progressPanel.setVisible(false); 103 } 104 105 private void handleNameChange () { 106 this.fireChange(); 107 } 108 109 114 private void initComponents() { 116 java.awt.GridBagConstraints gridBagConstraints; 117 118 jLabel3 = new javax.swing.JLabel (); 119 jdkName = new javax.swing.JTextField (); 120 jPanel1 = new javax.swing.JPanel (); 121 jLabel1 = new javax.swing.JLabel (); 122 jLabel4 = new javax.swing.JLabel (); 123 javadoc = new javax.swing.JTextField (); 124 sources = new javax.swing.JTextField (); 125 jButton1 = new javax.swing.JButton (); 126 jButton2 = new javax.swing.JButton (); 127 jPanel2 = new javax.swing.JPanel (); 128 progressLabel = new javax.swing.JLabel (); 129 progressPanel = new javax.swing.JPanel (); 130 131 setLayout(new java.awt.GridBagLayout ()); 132 133 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_DetectPanel")); 134 jLabel3.setLabelFor(jdkName); 135 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, NbBundle.getBundle(DetectPanel.class).getString("LBL_DetailsPanel_Name")); 136 gridBagConstraints = new java.awt.GridBagConstraints (); 137 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 138 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 139 add(jLabel3, gridBagConstraints); 140 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 143 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 144 gridBagConstraints.weightx = 1.0; 145 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 146 add(jdkName, gridBagConstraints); 147 jdkName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_PlatformName")); 148 149 jPanel1.setLayout(new java.awt.GridBagLayout ()); 150 151 jLabel1.setLabelFor(sources); 152 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("TXT_Sources")); 153 gridBagConstraints = new java.awt.GridBagConstraints (); 154 gridBagConstraints.gridx = 0; 155 gridBagConstraints.gridy = 0; 156 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 157 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 158 jPanel1.add(jLabel1, gridBagConstraints); 159 160 jLabel4.setLabelFor(javadoc); 161 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, NbBundle.getBundle(DetectPanel.class).getString("TXT_JavaDoc")); 162 gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 0; 164 gridBagConstraints.gridy = 1; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 166 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 167 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 168 jPanel1.add(jLabel4, gridBagConstraints); 169 170 gridBagConstraints = new java.awt.GridBagConstraints (); 171 gridBagConstraints.gridx = 1; 172 gridBagConstraints.gridy = 1; 173 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 174 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 175 gridBagConstraints.weightx = 1.0; 176 gridBagConstraints.insets = new java.awt.Insets (12, 6, 0, 0); 177 jPanel1.add(javadoc, gridBagConstraints); 178 javadoc.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_PlatformJavadoc")); 179 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 1; 182 gridBagConstraints.gridy = 0; 183 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 184 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 185 gridBagConstraints.weightx = 1.0; 186 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 187 jPanel1.add(sources, gridBagConstraints); 188 sources.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_PlatformSources")); 189 190 org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("LBL_BrowseSources")); 191 jButton1.addActionListener(new java.awt.event.ActionListener () { 192 public void actionPerformed(java.awt.event.ActionEvent evt) { 193 selectSources(evt); 194 } 195 }); 196 197 gridBagConstraints = new java.awt.GridBagConstraints (); 198 gridBagConstraints.gridx = 2; 199 gridBagConstraints.gridy = 0; 200 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 201 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 202 jPanel1.add(jButton1, gridBagConstraints); 203 jButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_SelectSources")); 204 205 org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("LBL_BrowseJavadoc")); 206 jButton2.addActionListener(new java.awt.event.ActionListener () { 207 public void actionPerformed(java.awt.event.ActionEvent evt) { 208 selectJavadoc(evt); 209 } 210 }); 211 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 2; 214 gridBagConstraints.gridy = 1; 215 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 216 gridBagConstraints.insets = new java.awt.Insets (12, 6, 0, 0); 217 jPanel1.add(jButton2, gridBagConstraints); 218 jButton2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(DetectPanel.class).getString("AD_SelectJavadoc")); 219 220 gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.gridx = 0; 222 gridBagConstraints.gridy = 1; 223 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 224 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 225 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 226 gridBagConstraints.weightx = 1.0; 227 gridBagConstraints.insets = new java.awt.Insets (24, 0, 0, 0); 228 add(jPanel1, gridBagConstraints); 229 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 0; 232 gridBagConstraints.gridy = 2; 233 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 234 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 235 gridBagConstraints.weightx = 1.0; 236 gridBagConstraints.weighty = 1.0; 237 add(jPanel2, gridBagConstraints); 238 239 progressLabel.setLabelFor(progressPanel); 240 org.openide.awt.Mnemonics.setLocalizedText(progressLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seplatform/wizard/Bundle").getString("TXT_PlatfromDetectProgress")); 241 gridBagConstraints = new java.awt.GridBagConstraints (); 242 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 243 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 244 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 245 gridBagConstraints.insets = new java.awt.Insets (12, 0, 6, 0); 246 add(progressLabel, gridBagConstraints); 247 248 gridBagConstraints = new java.awt.GridBagConstraints (); 249 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 250 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 251 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 252 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 253 add(progressPanel, gridBagConstraints); 254 255 } 256 258 private void selectJavadoc(java.awt.event.ActionEvent evt) { String newValue = this.browse(this.javadoc.getText(),NbBundle.getMessage(DetectPanel.class,"TXT_SelectJavadoc")); 260 if (newValue != null) { 261 this.javadoc.setText(newValue); 262 } 263 264 } 266 private void selectSources(java.awt.event.ActionEvent evt) { String newValue = this.browse(this.sources.getText(),NbBundle.getMessage(DetectPanel.class,"TXT_SelectSources")); 268 if (newValue != null) { 269 this.sources.setText(newValue); 270 } 271 } 273 public final synchronized void addChangeListener (ChangeListener listener) { 274 if (this.listeners == null) 275 this.listeners = new ArrayList (); 276 this.listeners.add (listener); 277 } 278 279 public final synchronized void removeChangeListener (ChangeListener listener) { 280 if (this.listeners == null) 281 return; 282 this.listeners.remove (listener); 283 } 284 285 public String getPlatformName() { 286 return jdkName.getText(); 287 } 288 289 String getSources () { 290 String val = this.sources.getText(); 291 return val.length() == 0 ? null : val; 292 } 293 294 void setSources (String sources) { 295 this.sources.setText (sources == null ? "" : sources); } 297 298 String getJavadoc () { 299 String val = this.javadoc.getText(); 300 return val.length() == 0 ? null : val; 301 } 302 303 void setJavadoc (String jdoc) { 304 this.javadoc.setText(jdoc == null ? "" : jdoc); } 306 307 protected final void fireChange () { 308 Iterator it = null; 309 synchronized (this) { 310 if (this.listeners == null) 311 return; 312 it = ((ArrayList)this.listeners.clone()).iterator(); 313 } 314 ChangeEvent event = new ChangeEvent (this); 315 while (it.hasNext()) { 316 ((ChangeListener)it.next()).stateChanged(event); 317 } 318 } 319 320 323 void updateData() { 324 Map m = primaryPlatform.getSystemProperties(); 325 if ("".equals(jdkName.getText())) { 327 jdkName.setText(getInitialName (m)); 328 this.jdkName.selectAll(); 329 } 330 } 331 332 333 private static String getInitialName (Map m) { 334 String vmVersion = (String )m.get("java.specification.version"); StringBuilder result = new StringBuilder (NbBundle.getMessage(DetectPanel.class,"TXT_DetectPanel_Java")); 336 if (vmVersion != null) { 337 result.append (vmVersion); 338 } 339 return result.toString(); 340 } 341 342 343 private String browse (String oldValue, String title) { 344 JFileChooser chooser = new JFileChooser (); 345 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 346 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 347 chooser.setFileFilter (new FileFilter () { 348 public boolean accept(File f) { 349 return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")))); 350 } 351 352 public String getDescription() { 353 return NbBundle.getMessage(DetectPanel.class,"TXT_ZipFilter"); 354 } 355 }); 356 File f = new File (oldValue); 357 chooser.setSelectedFile(f); 358 chooser.setDialogTitle (title); 359 if (chooser.showOpenDialog (this) == JFileChooser.APPROVE_OPTION) { 360 return chooser.getSelectedFile().getAbsolutePath(); 361 } 362 return null; 363 } 364 365 private javax.swing.JButton jButton1; 367 private javax.swing.JButton jButton2; 368 private javax.swing.JLabel jLabel1; 369 private javax.swing.JLabel jLabel3; 370 private javax.swing.JLabel jLabel4; 371 private javax.swing.JPanel jPanel1; 372 private javax.swing.JPanel jPanel2; 373 private javax.swing.JTextField javadoc; 374 private javax.swing.JTextField jdkName; 375 private javax.swing.JLabel progressLabel; 376 private javax.swing.JPanel progressPanel; 377 private javax.swing.JTextField sources; 378 380 384 static class WizardPanel implements WizardDescriptor.Panel, TaskListener, ChangeListener { 385 private DetectPanel component; 386 private RequestProcessor.Task task; 387 private final J2SEWizardIterator iterator; 388 private Collection changeList = new ArrayList(); 389 private boolean detected; 390 private boolean valid; 391 private boolean firstPass=true; 392 private WizardDescriptor wiz; 393 private ProgressHandle progressHandle; 394 395 WizardPanel(J2SEWizardIterator iterator) { 396 this.iterator = iterator; 397 } 398 399 public void addChangeListener(ChangeListener l) { 400 changeList.add(l); 401 } 402 403 public java.awt.Component getComponent() { 404 if (component == null) { 405 final NewJ2SEPlatform primaryPlatform = this.iterator.getPlatform(); 406 final NewJ2SEPlatform secondaryPlatform = this.iterator.getSecondaryPlatform(); 407 component = new DetectPanel(primaryPlatform); 408 component.addChangeListener (this); 409 task = RequestProcessor.getDefault().create( 410 new Runnable () { 411 public void run() { 412 primaryPlatform.run(); 413 if (secondaryPlatform != null) { 414 secondaryPlatform.run(); 415 } 416 } 417 }); 418 task.addTaskListener(this); 419 } 420 return component; 421 } 422 423 void setValid(boolean v) { 424 if (v == valid) 425 return; 426 valid = v; 427 fireStateChange(); 428 } 429 430 public HelpCtx getHelp() { 431 return new HelpCtx (DetectPanel.class); 432 } 433 434 public boolean isValid() { 435 return valid; 436 } 437 438 public void readSettings(Object settings) { 439 this.wiz = (WizardDescriptor) settings; 440 JavaPlatform platform = this.iterator.getPlatform(); 441 String srcPath = null; 442 String jdocPath = null; 443 ClassPath src = platform.getSourceFolders(); 444 if (src.entries().size()>0) { 445 URL folderRoot = ((ClassPath.Entry)src.entries().get(0)).getURL(); 446 if ("jar".equals(folderRoot.getProtocol())) { folderRoot = FileUtil.getArchiveFile (folderRoot); 448 } 449 srcPath = new File (URI.create(folderRoot.toExternalForm())).getAbsolutePath(); 450 } 451 else if (firstPass) { 452 Iterator il = platform.getInstallFolders().iterator(); 453 if (il.hasNext()) { 454 File base = FileUtil.toFile ((FileObject)il.next()); 455 if (base!=null) { 456 File f = new File (base,"src.zip"); if (f.canRead()) { 458 srcPath = f.getAbsolutePath(); 459 } 460 else { 461 f = new File (base,"src.jar"); if (f.canRead()) { 463 srcPath = f.getAbsolutePath(); 464 } 465 } 466 } 467 } 468 } 469 List jdoc = platform.getJavadocFolders(); 470 if (jdoc.size()>0) { 471 URL folderRoot = (URL )jdoc.get(0); 472 if ("jar".equals(folderRoot.getProtocol())) { 473 folderRoot = FileUtil.getArchiveFile (folderRoot); 474 } 475 jdocPath = new File (URI.create(folderRoot.toExternalForm())).getAbsolutePath(); 476 } 477 else if (firstPass) { 478 Iterator il = platform.getInstallFolders().iterator(); 479 if (il.hasNext()) { 480 File base = FileUtil.toFile ((FileObject)il.next()); 481 if (base!=null) { 482 File f = new File (base,"docs"); if (f.isDirectory() && f.canRead()) { 484 jdocPath = f.getAbsolutePath(); 485 } 486 } 487 } 488 firstPass = false; 489 } 490 this.component.setSources (srcPath); 491 this.component.setJavadoc (jdocPath); 492 this.component.jdkName.setEditable(false); 493 this.component.progressPanel.setVisible (true); 494 this.component.progressLabel.setVisible (true); 495 496 this.progressHandle = ProgressHandleFactory.createHandle(NbBundle.getMessage(DetectPanel.class,"TXT_PlatfromDetectProgress")); 497 this.component.progressPanel.removeAll(); 498 this.component.progressPanel.setLayout (new GridBagLayout ()); 499 GridBagConstraints c = new GridBagConstraints (); 500 c.gridx = c.gridy = GridBagConstraints.RELATIVE; 501 c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER; 502 c.fill = GridBagConstraints.HORIZONTAL; 503 c.weightx = 1.0; 504 JComponent pc = ProgressHandleFactory.createProgressComponent(this.progressHandle); 505 ((GridBagLayout )this.component.progressPanel.getLayout ()).setConstraints(pc,c); 506 this.component.progressPanel.add (pc); 507 this.progressHandle.start (); 508 task.schedule(0); 509 } 510 511 void fireStateChange() { 512 ChangeListener[] ll; 513 synchronized (this) { 514 if (changeList.isEmpty()) 515 return; 516 ll = (ChangeListener[])changeList.toArray(new ChangeListener[0]); 517 } 518 ChangeEvent ev = new ChangeEvent(this); 519 for (int i = 0; i < ll.length; i++) 520 ll[i].stateChanged(ev); 521 } 522 523 public void removeChangeListener(ChangeListener l) { 524 changeList.remove(l); 525 } 526 527 531 public void storeSettings(Object settings) { 532 if (isValid()) { 533 String name = component.getPlatformName(); 534 List src = new ArrayList (); 535 List jdoc = new ArrayList (); 536 String srcPath = this.component.getSources(); 537 if (srcPath!=null) { 538 File f = new File (srcPath); 539 try { 540 URL url = f.toURI().toURL(); 541 if (FileUtil.isArchiveFile(url)) { 542 url = FileUtil.getArchiveRoot(url); 543 FileObject fo = URLMapper.findFileObject(url); 544 if (fo != null) { 545 fo = fo.getFileObject("src"); if (fo != null) { 547 url = fo.getURL(); 548 } 549 } 550 src.add (ClassPathSupport.createResource(url)); 551 } 552 else { 553 src.add (ClassPathSupport.createResource(url)); 554 } 555 } catch (MalformedURLException mue) { 556 ErrorManager.getDefault().notify (mue); 557 } 558 catch (FileStateInvalidException e) { 559 ErrorManager.getDefault().notify(e); 560 } 561 } 562 String jdocPath = this.component.getJavadoc(); 563 if (jdocPath!=null) { 564 File f = new File (jdocPath); 565 try { 566 URL url = f.toURI().toURL(); 567 if (FileUtil.isArchiveFile(url)) { 568 url = FileUtil.getArchiveRoot(url); 569 } 570 else if (!f.exists()){ 571 url = new URL (url.toExternalForm()+'/'); 572 } 573 jdoc.add (url); 574 } catch (MalformedURLException mue) { 575 ErrorManager.getDefault().notify (mue); 576 } 577 } 578 579 NewJ2SEPlatform platform = this.iterator.getPlatform(); 580 platform.setDisplayName (name); 581 platform.setAntName (createAntName (name)); 582 platform.setSourceFolders (ClassPathSupport.createClassPath(src)); 583 platform.setJavadocFolders (jdoc); 584 585 platform = this.iterator.getSecondaryPlatform(); 586 if (platform != null) { 587 name = NbBundle.getMessage(DetectPanel.class,"FMT_64BIT", name); 588 platform.setDisplayName (name); 589 platform.setAntName (createAntName(name)); 590 platform.setSourceFolders (ClassPathSupport.createClassPath(src)); 591 platform.setJavadocFolders (jdoc); 592 } 593 } 594 } 595 596 599 public void taskFinished(Task task) { 600 SwingUtilities.invokeLater( new Runnable () { 601 public void run () { 602 component.updateData (); 603 component.jdkName.setEditable(true); 604 assert progressHandle != null; 605 progressHandle.finish (); 606 component.progressPanel.setVisible (false); 607 component.progressLabel.setVisible (false); 608 detected = iterator.getPlatform().isValid(); 609 checkValid (); 610 } 611 }); 612 } 613 614 615 public void stateChanged(ChangeEvent e) { 616 this.checkValid(); 617 } 618 619 private void checkValid () { 620 this.wiz.putProperty( "WizardPanel_errorMessage", ""); String name = this.component.getPlatformName (); 622 boolean validDisplayName = name.length() > 0; 623 boolean usedDisplayName = false; 624 if (!detected) { 625 this.wiz.putProperty( "WizardPanel_errorMessage",NbBundle.getMessage(DetectPanel.class,"ERROR_NoSDKRegistry")); } 627 else if (!validDisplayName) { 628 this.wiz.putProperty( "WizardPanel_errorMessage",NbBundle.getMessage(DetectPanel.class,"ERROR_InvalidDisplayName")); } 630 else { 631 JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms(); 632 for (int i=0; i<platforms.length; i++) { 633 if (name.equals (platforms[i].getDisplayName())) { 634 usedDisplayName = true; 635 this.wiz.putProperty( "WizardPanel_errorMessage",NbBundle.getMessage(DetectPanel.class,"ERROR_UsedDisplayName")); break; 637 } 638 } 639 } 640 boolean v = detected && validDisplayName && !usedDisplayName; 641 setValid(v); 642 } 643 644 private static String createAntName (String name) { 645 if (name == null || name.length() == 0) { 646 throw new IllegalArgumentException (); 647 } 648 String antName = PropertyUtils.getUsablePropertyName(name); 649 if (platformExists (antName)) { 650 String baseName = antName; 651 int index = 1; 652 antName = baseName + Integer.toString (index); 653 while (platformExists (antName)) { 654 index ++; 655 antName = baseName + Integer.toString (index); 656 } 657 } 658 return antName; 659 } 660 661 private static boolean platformExists (String antName) { 662 JavaPlatformManager mgr = JavaPlatformManager.getDefault(); 663 JavaPlatform[] platforms = mgr.getInstalledPlatforms(); 664 for (int i=0; i < platforms.length; i++) { 665 if (platforms[i] instanceof J2SEPlatformImpl) { 666 String val = ((J2SEPlatformImpl)platforms[i]).getAntName(); 667 if (antName.equals(val)) { 668 return true; 669 } 670 } 671 } 672 return false; 673 } 674 675 } 676 } 677 | Popular Tags |