Index: nbproject/project.xml =================================================================== RCS file: /cvs/java/freeform/nbproject/project.xml,v retrieving revision 1.3 diff -u -r1.3 project.xml --- nbproject/project.xml 23 Dec 2004 22:01:33 -0000 1.3 +++ nbproject/project.xml 13 Jan 2005 21:01:36 -0000 @@ -93,6 +93,14 @@ 1 + + org.netbeans.modules.project.libraries + + + + 1 + + org.netbeans.modules.java.freeform.spi Index: src/org/netbeans/modules/java/freeform/ui/Bundle.properties =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/Bundle.properties,v retrieving revision 1.2 diff -u -r1.2 Bundle.properties --- src/org/netbeans/modules/java/freeform/ui/Bundle.properties 7 Dec 2004 13:46:33 -0000 1.2 +++ src/org/netbeans/modules/java/freeform/ui/Bundle.properties 13 Jan 2005 21:01:37 -0000 @@ -6,7 +6,7 @@ # http://www.sun.com/ # # The Original Code is NetBeans. The Initial Developer of the Original -# Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun +# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun # Microsystems, Inc. All Rights Reserved. # OutputPanel @@ -75,3 +75,18 @@ LBL_ProjectCustomizer_Category_Sources=Sources LBL_ProjectCustomizer_Category_Classpath=Classpath LBL_ProjectCustomizer_Category_Output=Output + +TXT_Edit=Edit... +TXT_EditLibraryTitle=Edit Library +TXT_SourceFolder=Source Folder\: +TXT_BrowseJavadoc=Browse... +TXT_Browse_Sources=Browse... +TXT_JavaDocFolder=Javadoc Folder\: +TXT_OpenJavadoc=Open Javadoc +TXT_Javadoc=Javadoc +CTL_SelectJD=Open Javadoc +MNE_SelectJD=O +TXT_OpenSources=Open Sources +TXT_Sources=Sources +CTL_SelectSources=Open Sources +MNE_SelectSources=O Index: src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form,v retrieving revision 1.2 diff -u -r1.2 ClasspathPanel.form --- src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form 7 Dec 2004 13:46:33 -0000 1.2 +++ src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.form 13 Jan 2005 21:01:40 -0000 @@ -6,6 +6,12 @@ + + + + + + @@ -104,7 +110,7 @@ - + @@ -154,7 +160,7 @@ - + @@ -169,7 +175,7 @@ - + @@ -215,6 +221,21 @@ + + + + + + + + + + + + + + + Index: src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java,v retrieving revision 1.2 diff -u -r1.2 ClasspathPanel.java --- src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java 7 Dec 2004 13:46:33 -0000 1.2 +++ src/org/netbeans/modules/java/freeform/ui/ClasspathPanel.java 13 Jan 2005 21:01:45 -0000 @@ -7,7 +7,7 @@ * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun * Microsystems, Inc. All Rights Reserved. */ @@ -15,18 +15,31 @@ import java.awt.event.ItemEvent; import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; import javax.swing.DefaultListModel; import javax.swing.JComponent; import javax.swing.JFileChooser; +import org.netbeans.api.project.libraries.Library; +import org.netbeans.api.project.libraries.LibraryManager; import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; import org.netbeans.modules.ant.freeform.spi.support.Util; import org.netbeans.modules.java.freeform.JavaProjectGenerator; +import org.netbeans.spi.project.libraries.LibraryFactory; +import org.netbeans.spi.project.libraries.LibraryImplementation; +import org.netbeans.spi.project.libraries.LibraryTypeProvider; +import org.netbeans.spi.project.libraries.support.LibrariesSupport; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.ErrorManager; import org.openide.filesystems.FileUtil; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; @@ -153,6 +166,7 @@ moveDown = new javax.swing.JButton(); jTextArea1 = new javax.swing.JTextArea(); separateClasspath = new javax.swing.JCheckBox(); + jButton1 = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); @@ -222,7 +236,7 @@ gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 2; - gridBagConstraints.gridheight = 4; + gridBagConstraints.gridheight = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; @@ -261,7 +275,7 @@ gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; - gridBagConstraints.gridy = 6; + gridBagConstraints.gridy = 7; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); @@ -276,7 +290,7 @@ gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; - gridBagConstraints.gridy = 7; + gridBagConstraints.gridy = 8; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; add(moveDown, gridBagConstraints); @@ -310,8 +324,89 @@ gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0); add(separateClasspath, gridBagConstraints); + jButton1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("TXT_Edit")); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + editLibrary(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 6; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); + add(jButton1, gridBagConstraints); + }//GEN-END:initComponents + private void editLibrary(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editLibrary + String selectedEntry = (String) classpath.getSelectedValue(); + assert selectedEntry != null; + File f = FileUtil.normalizeFile (new File (selectedEntry)); + URL rootURL = null; + try { + rootURL = f.toURI().toURL(); + if (FileUtil.isArchiveFile(rootURL)) { + rootURL = FileUtil.getArchiveRoot(rootURL); + } + } catch (MalformedURLException mue) { + ErrorManager.getDefault().notify(mue); + return; + } + Library oldLibrary = LibraryManager.getDefault().getLibrary(selectedEntry); + LibraryEditor editor = new LibraryEditor (); + if (oldLibrary != null) { + List classpath = oldLibrary.getContent("classpath"); //NOI18N + List sources = oldLibrary.getContent("src"); //NOI18N + List javadoc = oldLibrary.getContent("javadoc"); //NOI18N + //If library exists allow to change only Library created by this support + if (classpath.size() == 1 && rootURL.equals(classpath.get(0)) && + sources.size() <= 1 && javadoc.size() <= 1) { + editor.setSourceFolder ((URL)sources.get(0)); + editor.setJavadocFolder((URL)javadoc.get(0)); + } + else { + return; + } + } + + DialogDescriptor dd = new DialogDescriptor (editor,NbBundle.getMessage(ClasspathPanel.class,"TXT_EditLibraryTitle"),true, + DialogDescriptor.OK_CANCEL_OPTION,DialogDescriptor.OK_OPTION, DialogDescriptor.DEFAULT_ALIGN, + new HelpCtx (LibraryEditor.class),null); + if (DialogDisplayer.getDefault().notify(dd) == DialogDescriptor.OK_OPTION) { + try { + if (oldLibrary != null) { + LibraryManager.getDefault().removeLibrary(oldLibrary); + } + URL sources = editor.getSourceFoler(); + URL javadoc = editor.getJavadocFolder(); + LibraryTypeProvider provider = LibrariesSupport.getLibraryTypeProvider("j2se"); //NOI18N + assert provider != null : "No J2SE LibraryTypeProvider"; //NOI18N + LibraryImplementation impl = provider.createLibrary(); + impl.setName (PropertyUtils.getUsablePropertyName(selectedEntry)); + impl.setContent ("classpath",Collections.singletonList(rootURL)); //NOI18N + if (sources != null) { + if (FileUtil.isArchiveFile(sources)) { + sources = FileUtil.getArchiveRoot (sources); + } + impl.setContent ("src",Collections.singletonList(sources)); //NOI18N + } + if (javadoc != null) { + if (FileUtil.isArchiveFile(javadoc)) { + javadoc = FileUtil.getArchiveRoot (javadoc); + } + impl.setContent ("javadoc",Collections.singletonList(javadoc)); //NOI18N + } + Library newLibrary = LibraryFactory.createLibrary(impl); + LibraryManager.getDefault().addLibrary(newLibrary); + } catch (IOException ioe) { + ErrorManager.getDefault().notify(ioe); + } + } + }//GEN-LAST:event_editLibrary + private void classpathValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_classpathValueChanged updateButtons(); }//GEN-LAST:event_classpathValueChanged @@ -565,6 +660,7 @@ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addClasspath; private javax.swing.JList classpath; + private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; Index: src/org/netbeans/modules/java/freeform/ui/LibraryEditor.form =================================================================== RCS file: src/org/netbeans/modules/java/freeform/ui/LibraryEditor.form diff -N src/org/netbeans/modules/java/freeform/ui/LibraryEditor.form --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/java/freeform/ui/LibraryEditor.form 13 Jan 2005 21:01:46 -0000 @@ -0,0 +1,100 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/org/netbeans/modules/java/freeform/ui/LibraryEditor.java =================================================================== RCS file: src/org/netbeans/modules/java/freeform/ui/LibraryEditor.java diff -N src/org/netbeans/modules/java/freeform/ui/LibraryEditor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/java/freeform/ui/LibraryEditor.java 13 Jan 2005 21:01:46 -0000 @@ -0,0 +1,215 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.freeform.ui; + + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import org.openide.ErrorManager; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +/** + * + * @author tom + */ +public class LibraryEditor extends javax.swing.JPanel { + + /** Creates new form LibraryEditor */ + public LibraryEditor() { + initComponents(); + } + + + public final URL getSourceFoler () { + File f = FileUtil.normalizeFile(new File (this.sources.getText())); + try { + return f.toURI().toURL(); + } catch (MalformedURLException mfu) { + ErrorManager.getDefault().notify (mfu); + return null; + } + } + + public final void setSourceFolder (URL folder) { + File f = new File (URI.create (folder.toExternalForm())); + this.sources.setText (f.getAbsolutePath()); + } + + public final URL getJavadocFolder () { + try { + File f = FileUtil.normalizeFile(new File (this.javadoc.getText())); + return f.toURI().toURL(); + } catch (MalformedURLException mfu) { + ErrorManager.getDefault().notify(mfu); + return null; + } + } + + public final void setJavadocFolder (URL folder) { + File f = new File (URI.create (folder.toExternalForm())); + this.javadoc.setText(f.getAbsolutePath()); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + private void initComponents() {//GEN-BEGIN:initComponents + java.awt.GridBagConstraints gridBagConstraints; + + jLabel1 = new javax.swing.JLabel(); + sources = new javax.swing.JTextField(); + jButton1 = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + javadoc = new javax.swing.JTextField(); + jButton2 = new javax.swing.JButton(); + jPanel1 = new javax.swing.JPanel(); + + setLayout(new java.awt.GridBagLayout()); + + jLabel1.setLabelFor(sources); + jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("TXT_SourceFolder")); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12); + add(jLabel1, gridBagConstraints); + + sources.setColumns(30); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12); + add(sources, gridBagConstraints); + + jButton1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("TXT_Browse_Sources")); + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseSources(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12); + add(jButton1, gridBagConstraints); + + jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("TXT_JavaDocFolder")); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12); + add(jLabel2, gridBagConstraints); + + javadoc.setColumns(30); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 12); + add(javadoc, gridBagConstraints); + + jButton2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/freeform/ui/Bundle").getString("TXT_BrowseJavadoc")); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseJavadoc(evt); + } + }); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 12); + add(jButton2, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + add(jPanel1, gridBagConstraints); + + }//GEN-END:initComponents + + private void browseJavadoc(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseJavadoc + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setDialogTitle(NbBundle.getMessage(LibraryEditor.class,"TXT_OpenJavadoc")); + chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(LibraryEditor.class,"TXT_Javadoc"))); //NOI18N + chooser.setApproveButtonText(NbBundle.getMessage(LibraryEditor.class,"CTL_SelectJD")); + chooser.setApproveButtonMnemonic(NbBundle.getMessage(LibraryEditor.class,"MNE_SelectJD").charAt(0)); + if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + this.javadoc.setText(chooser.getSelectedFile().getAbsolutePath()); + } + }//GEN-LAST:event_browseJavadoc + + private void browseSources(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseSources + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setAcceptAllFileFilterUsed(false); + chooser.setDialogTitle(NbBundle.getMessage(LibraryEditor.class,"TXT_OpenSources")); + chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(LibraryEditor.class,"TXT_Sources"))); //NOI18N + chooser.setApproveButtonText(NbBundle.getMessage(LibraryEditor.class,"CTL_SelectSources")); + chooser.setApproveButtonMnemonic(NbBundle.getMessage(LibraryEditor.class,"MNE_SelectSources").charAt(0)); + if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { + this.sources.setText(chooser.getSelectedFile().getAbsolutePath()); + } + }//GEN-LAST:event_browseSources + + + private static class SimpleFileFilter extends FileFilter { + + private String description; + + + public SimpleFileFilter(String description) { + this.description = description; + } + + public boolean accept(File f) { + if (f.isDirectory()) + return true; + try { + return FileUtil.isArchiveFile(FileUtil.normalizeFile(f).toURI().toURL()); + } catch (MalformedURLException mfu) { + ErrorManager.getDefault().notify(mfu); + return false; + } + } + + public String getDescription() { + return this.description; + } + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JPanel jPanel1; + private javax.swing.JTextField javadoc; + private javax.swing.JTextField sources; + // End of variables declaration//GEN-END:variables + +}