? copylibstask/test Index: src/org/netbeans/modules/java/j2seproject/J2SEProject.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java,v retrieving revision 1.73 diff -u -r1.73 J2SEProject.java --- src/org/netbeans/modules/java/j2seproject/J2SEProject.java 9 Feb 2007 10:50:38 -0000 1.73 +++ src/org/netbeans/modules/java/j2seproject/J2SEProject.java 26 Feb 2007 13:40:57 -0000 @@ -49,6 +49,7 @@ import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.modules.java.j2seproject.wsclient.J2SEProjectWebServicesClientSupport; import org.netbeans.modules.java.j2seproject.jaxws.J2SEProjectJAXWSClientSupport; +import org.netbeans.modules.java.j2seproject.queries.J2SEProjectEncodingQueryImpl; import org.netbeans.modules.java.j2seproject.queries.BinaryForSourceQueryImpl; import org.netbeans.modules.java.j2seproject.wsclient.J2SEProjectWebServicesSupportProvider; import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; @@ -255,6 +256,7 @@ UILookupMergerSupport.createPrivilegedTemplatesMerger(), UILookupMergerSupport.createRecommendedTemplatesMerger(), LookupProviderSupport.createSourcesMerger(), + new J2SEProjectEncodingQueryImpl (evaluator()), new J2SEPropertyEvaluatorImpl(evaluator()), new BinaryForSourceQueryImpl(this.sourceRoots, this.testRoots, this.helper, this.eval) //Does not use APH to get/put properties/cfgdata }); Index: src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java,v retrieving revision 1.53 diff -u -r1.53 J2SEProjectGenerator.java --- src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java 9 Jan 2007 13:59:04 -0000 1.53 +++ src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java 26 Feb 2007 13:40:57 -0000 @@ -21,12 +21,13 @@ import java.io.File; import java.io.IOException; -import java.util.Stack; +import java.nio.charset.Charset; import org.netbeans.api.java.platform.JavaPlatform; import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.java.project.JavaProjectConstants; +import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.EditableProperties; @@ -37,7 +38,6 @@ import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.openide.filesystems.Repository; -import org.openide.filesystems.FileStateInvalidException; import org.openide.loaders.DataFolder; import org.openide.loaders.DataObject; import org.openide.modules.SpecificationVersion; @@ -270,7 +270,8 @@ ep.setProperty(J2SEProjectProperties.JAVADOC_WINDOW_TITLE, ""); // NOI18N ep.setProperty(J2SEProjectProperties.JAVADOC_ENCODING, ""); // NOI18N ep.setProperty(J2SEProjectProperties.JAVADOC_ADDITIONALPARAM, ""); // NOI18N - + Charset enc = FileEncodingQuery.getDefaultEncoding(); + ep.setProperty(J2SEProjectProperties.PROJECT_ENCODING, enc.name()); if (manifestFile != null) { ep.setProperty("manifest.file", manifestFile); // NOI18N } Index: src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java =================================================================== RCS file: src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java diff -N src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/netbeans/modules/java/j2seproject/queries/J2SEProjectEncodingQueryImpl.java 26 Feb 2007 13:40:57 -0000 @@ -0,0 +1,73 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.j2seproject.queries; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.nio.charset.Charset; +import org.netbeans.api.queries.FileEncodingQuery; +import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.netbeans.spi.project.support.ant.PropertyEvaluator; +import org.openide.filesystems.FileObject; + +/** + * + * @author Tomas Zezula + */ +public class J2SEProjectEncodingQueryImpl implements FileEncodingQueryImplementation, PropertyChangeListener { + + + private final PropertyEvaluator eval; + private Charset cache; + + /** Creates a new instance of J2SEProjectEncodingQueryImpl */ + public J2SEProjectEncodingQueryImpl(final PropertyEvaluator eval) { + assert eval != null; + this.eval = eval; + this.eval.addPropertyChangeListener(this); + } + + public Charset getEncoding(FileObject file) { + assert file != null; + synchronized (this) { + if (cache != null) { + return cache; + } + } + String enc = eval.getProperty(J2SEProjectProperties.PROJECT_ENCODING); + synchronized (this) { + if (cache == null) { + cache = enc == null ? FileEncodingQuery.getDefaultEncoding() : Charset.forName(enc); + } + return cache; + } + } + + public void propertyChange(PropertyChangeEvent event) { + String propName = event.getPropertyName(); + if (propName == null || propName.equals(J2SEProjectProperties.PROJECT_ENCODING)) { + synchronized (this) { + cache = null; + } + } + } + +} Index: src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl,v retrieving revision 1.78 diff -u -r1.78 build-impl.xsl --- src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl 9 Jan 2007 16:32:07 -0000 1.78 +++ src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl 26 Feb 2007 13:40:58 -0000 @@ -178,6 +178,7 @@ + @@ -264,6 +265,7 @@ @{destdir} @{debug} ${javac.deprecation} + ${project.encoding} ${javac.source} ${javac.target} Index: src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties,v retrieving revision 1.84 diff -u -r1.84 Bundle.properties --- src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties 8 Feb 2007 10:11:43 -0000 1.84 +++ src/org/netbeans/modules/java/j2seproject/ui/customizer/Bundle.properties 26 Feb 2007 13:40:58 -0000 @@ -497,6 +497,8 @@ # {0} - name of configuration CustomizerRun.input.duplicate=Configuration {0} already exists. +TXT_Encoding=&Encoding\: + CustomizerApplication.titleLabel.text=Title\: CustomizerApplication.vendorLabel.text=Vendor\: CustomizerApplication.panelDescLabel.text=Common Application Properties Index: src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.form =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.form,v retrieving revision 1.7 diff -u -r1.7 CustomizerSources.form --- src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.form 9 Nov 2005 15:06:17 -0000 1.7 +++ src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.form 26 Feb 2007 13:40:58 -0000 @@ -3,6 +3,7 @@
+ @@ -337,7 +338,7 @@ - + @@ -357,19 +358,49 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.java,v retrieving revision 1.12 diff -u -r1.12 CustomizerSources.java --- src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.java 30 Jun 2006 20:07:43 -0000 1.12 +++ src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerSources.java 26 Feb 2007 13:40:58 -0000 @@ -19,13 +19,23 @@ package org.netbeans.modules.java.j2seproject.ui.customizer; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.File; +import java.nio.charset.Charset; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; +import org.netbeans.api.queries.FileEncodingQuery; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.HelpCtx; -import org.openide.util.NbBundle; import org.netbeans.modules.java.j2seproject.J2SEProject; /** @@ -33,6 +43,10 @@ * @author Tomas Zezula */ public class CustomizerSources extends javax.swing.JPanel implements HelpCtx.Provider { + + + private J2SEProjectProperties uiProperties; + private String originalEncoding; public CustomizerSources( J2SEProjectProperties uiProperties ) { initComponents(); @@ -86,6 +100,34 @@ } }); enableSourceLevel (); + this.uiProperties = uiProperties; + this.originalEncoding = this.uiProperties.getProject().evaluator().getProperty(J2SEProjectProperties.PROJECT_ENCODING); + if (this.originalEncoding == null) { + this.originalEncoding = FileEncodingQuery.getDefaultEncoding().name(); + } + + this.encoding.setModel(new EncodingModel(this.originalEncoding)); + this.encoding.setRenderer(new EncodingRenderer()); + + + this.encoding.addActionListener(new ActionListener () { + public void actionPerformed(ActionEvent arg0) { + handleEncodingChange(); + } + }); + } + + + private void handleEncodingChange () { + Charset enc = (Charset) encoding.getSelectedItem(); + String encName; + if (enc != null) { + encName = enc.name(); + } + else { + encName = originalEncoding; + } + this.uiProperties.putAdditionalProperty(J2SEProjectProperties.PROJECT_ENCODING, encName); } public HelpCtx getHelpCtx() { @@ -96,6 +138,55 @@ this.sourceLevel.setEnabled(sourceLevel.getItemCount()>0); } + + private static class EncodingRenderer extends DefaultListCellRenderer { + + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + assert value instanceof Charset; + return super.getListCellRendererComponent(list, ((Charset)value).displayName(), index, isSelected, cellHasFocus); + } + } + + private static class EncodingModel extends DefaultComboBoxModel { + + public EncodingModel (String originalEncoding) { + Charset defEnc = null; + for (Charset c : Charset.availableCharsets().values()) { + if (c.name().equals(originalEncoding)) { + defEnc = c; + } + addElement(c); + } + if (defEnc == null) { + //Create artificial Charset to keep the original value + //May happen when the project was set up on the platform + //which supports more encodings + defEnc = new UnknownCharset (originalEncoding); + addElement(defEnc); + } + setSelectedItem(defEnc); + } + } + + private static class UnknownCharset extends Charset { + + UnknownCharset (String name) { + super (name, new String[0]); + } + + public boolean contains(Charset c) { + throw new UnsupportedOperationException(); + } + + public CharsetDecoder newDecoder() { + throw new UnsupportedOperationException(); + } + + public CharsetEncoder newEncoder() { + throw new UnsupportedOperationException(); + } +} + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is @@ -127,12 +218,15 @@ jLabel4 = new javax.swing.JLabel(); sourceLevel = new javax.swing.JComboBox(); jPanel2 = new javax.swing.JPanel(); + jLabel5 = new javax.swing.JLabel(); + encoding = new javax.swing.JComboBox(); setLayout(new java.awt.GridBagLayout()); jLabel1.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_ProjectFolder").charAt(0)); jLabel1.setLabelFor(projectLocation); - jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_ProjectFolder")); + java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle"); // NOI18N + jLabel1.setText(bundle.getString("CTL_ProjectFolder")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); @@ -145,13 +239,13 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; add(projectLocation, gridBagConstraints); - projectLocation.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_projectLocation")); + projectLocation.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_projectLocation")); // NOI18N sourceRootsPanel.setLayout(new java.awt.GridBagLayout()); jLabel2.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_SourceRoots").charAt(0)); jLabel2.setLabelFor(sourceRoots); - jLabel2.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_SourceRoots")); + jLabel2.setText(bundle.getString("CTL_SourceRoots")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; @@ -186,7 +280,7 @@ } }); jScrollPane1.setViewportView(sourceRoots); - sourceRoots.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_sourceRoots")); + sourceRoots.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_sourceRoots")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; @@ -200,7 +294,7 @@ sourceRootsPanel.add(jScrollPane1, gridBagConstraints); addSourceRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_AddSourceRoot").charAt(0)); - addSourceRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_AddSourceRoot")); + addSourceRoot.setText(bundle.getString("CTL_AddSourceRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; @@ -208,10 +302,10 @@ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; sourceRootsPanel.add(addSourceRoot, gridBagConstraints); - addSourceRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_addSourceRoot")); + addSourceRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_addSourceRoot")); // NOI18N removeSourceRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_RemoveSourceRoot").charAt(0)); - removeSourceRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_RemoveSourceRoot")); + removeSourceRoot.setText(bundle.getString("CTL_RemoveSourceRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; @@ -220,10 +314,10 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0); sourceRootsPanel.add(removeSourceRoot, gridBagConstraints); - removeSourceRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_removeSourceRoot")); + removeSourceRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_removeSourceRoot")); // NOI18N upSourceRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_UpSourceRoot").charAt(0)); - upSourceRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_UpSourceRoot")); + upSourceRoot.setText(bundle.getString("CTL_UpSourceRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; @@ -232,10 +326,10 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0); sourceRootsPanel.add(upSourceRoot, gridBagConstraints); - upSourceRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_upSourceRoot")); + upSourceRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_upSourceRoot")); // NOI18N downSourceRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_DownSourceRoot").charAt(0)); - downSourceRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_DownSourceRoot")); + downSourceRoot.setText(bundle.getString("CTL_DownSourceRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; @@ -244,7 +338,7 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0); sourceRootsPanel.add(downSourceRoot, gridBagConstraints); - downSourceRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_downSourceRoot")); + downSourceRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_downSourceRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; @@ -260,7 +354,7 @@ jLabel3.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_TestRoots").charAt(0)); jLabel3.setLabelFor(testRoots); - jLabel3.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_TestRoots")); + jLabel3.setText(bundle.getString("CTL_TestRoots")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; @@ -296,7 +390,7 @@ } }); jScrollPane2.setViewportView(testRoots); - testRoots.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_testRoots")); + testRoots.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_testRoots")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; @@ -309,7 +403,7 @@ testRootsPanel.add(jScrollPane2, gridBagConstraints); addTestRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_AddTestRoot").charAt(0)); - addTestRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_AddTestRoot")); + addTestRoot.setText(bundle.getString("CTL_AddTestRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; @@ -318,10 +412,10 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 0); testRootsPanel.add(addTestRoot, gridBagConstraints); - addTestRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_addTestRoot")); + addTestRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_addTestRoot")); // NOI18N removeTestRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_RemoveTestRoot").charAt(0)); - removeTestRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_RemoveTestRoot")); + removeTestRoot.setText(bundle.getString("CTL_RemoveTestRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; @@ -330,10 +424,10 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); testRootsPanel.add(removeTestRoot, gridBagConstraints); - removeTestRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_removeTestRoot")); + removeTestRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_removeTestRoot")); // NOI18N upTestRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_UpTestRoot").charAt(0)); - upTestRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_UpTestRoot")); + upTestRoot.setText(bundle.getString("CTL_UpTestRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; @@ -342,10 +436,10 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 0); testRootsPanel.add(upTestRoot, gridBagConstraints); - upTestRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_upTestRoot")); + upTestRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_upTestRoot")); // NOI18N downTestRoot.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_DownTestRoot").charAt(0)); - downTestRoot.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("CTL_DownTestRoot")); + downTestRoot.setText(bundle.getString("CTL_DownTestRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; @@ -354,7 +448,7 @@ gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0); testRootsPanel.add(downTestRoot, gridBagConstraints); - downTestRoot.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_CustomizerSources_downTestRoot")); + downTestRoot.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizerSources_downTestRoot")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; @@ -371,31 +465,42 @@ jLabel4.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("MNE_SourceLevel").charAt(0)); jLabel4.setLabelFor(sourceLevel); - jLabel4.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("TXT_SourceLevel")); + jLabel4.setText(bundle.getString("TXT_SourceLevel")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12); jPanel1.add(jLabel4, gridBagConstraints); sourceLevel.setMinimumSize(this.sourceLevel.getPreferredSize()); gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 0.75; jPanel1.add(sourceLevel, gridBagConstraints); - sourceLevel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AN_SourceLevel")); - sourceLevel.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle").getString("AD_SourceLevel")); + sourceLevel.getAccessibleContext().setAccessibleName(bundle.getString("AN_SourceLevel")); // NOI18N + sourceLevel.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_SourceLevel")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; jPanel1.add(jPanel2, gridBagConstraints); + jLabel5.setLabelFor(encoding); + org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(CustomizerSources.class, "TXT_Encoding")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 12); + jPanel1.add(jLabel5, gridBagConstraints); + + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0); + jPanel1.add(encoding, gridBagConstraints); + gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; @@ -403,7 +508,6 @@ gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0); add(jPanel1, gridBagConstraints); - }// //GEN-END:initComponents @@ -412,10 +516,12 @@ private javax.swing.JButton addTestRoot; private javax.swing.JButton downSourceRoot; private javax.swing.JButton downTestRoot; + private javax.swing.JComboBox encoding; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; Index: src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java =================================================================== RCS file: /cvs/java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java,v retrieving revision 1.61 diff -u -r1.61 J2SEProjectProperties.java --- src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java 8 Feb 2007 10:11:43 -0000 1.61 +++ src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java 26 Feb 2007 13:40:58 -0000 @@ -23,12 +23,13 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.UnsupportedCharsetException; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; -import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.TreeMap; @@ -42,6 +43,7 @@ import javax.swing.table.DefaultTableModel; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import org.netbeans.api.queries.FileEncodingQuery; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; import org.netbeans.modules.java.j2seproject.J2SEProject; @@ -107,7 +109,7 @@ public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; // NOI18N public static final String NO_DEPENDENCIES="no.dependencies"; // NOI18N public static final String DEBUG_TEST_CLASSPATH = "debug.test.classpath"; // NOI18N - + public static final String PROJECT_ENCODING="project.encoding"; // NOI18N public static final String JAVADOC_PRIVATE="javadoc.private"; // NOI18N public static final String JAVADOC_NO_TREE="javadoc.notree"; // NOI18N @@ -436,8 +438,16 @@ // Store the property changes into the project updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties ); - updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties ); + updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties ); + String value = additionalProperties.getProperty(PROJECT_ENCODING); + if (value != null) { + try { + FileEncodingQuery.setDefaultEncoding(Charset.forName(value)); + } catch (UnsupportedCharsetException e) { + //When the encoding is not supported by JVM do not set it as default + } + } } private void storeAdditionalProperties(EditableProperties projectProperties) { Index: test/unit/src/org/netbeans/modules/java/j2seproject/queries/FileEncodingQueryTest.java =================================================================== RCS file: test/unit/src/org/netbeans/modules/java/j2seproject/queries/FileEncodingQueryTest.java diff -N test/unit/src/org/netbeans/modules/java/j2seproject/queries/FileEncodingQueryTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/unit/src/org/netbeans/modules/java/j2seproject/queries/FileEncodingQueryTest.java 26 Feb 2007 13:40:58 -0000 @@ -0,0 +1,122 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.modules.java.j2seproject.queries; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import org.netbeans.api.queries.FileEncodingQuery; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.java.j2seproject.J2SEProject; +import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator; +import org.openide.filesystems.FileObject; +import org.netbeans.junit.MockServices; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.netbeans.spi.project.support.ant.AntProjectHelper; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.FileUtil; +import org.openide.modules.SpecificationVersion; + +/** + * Tests for FileEncodingQuery + * + * @author Tomas Zezula + */ +public class FileEncodingQueryTest extends NbTestCase { + + public FileEncodingQueryTest(String testName) { + super(testName); + } + + private FileObject scratch; + private FileObject projdir; + private FileObject sources; + private AntProjectHelper helper; + private J2SEProject prj; + + protected void setUp() throws Exception { + MockServices.setServices(DummyXMLEncodingImpl.class); + super.setUp(); + this.clearWorkDir(); + } + + protected void tearDown() throws Exception { + scratch = null; + projdir = null; + prj = null; + super.tearDown(); + } + + + private void prepareProject () throws IOException { + File wd = getWorkDir(); + scratch = FileUtil.toFileObject(wd); + assertNotNull(wd); + projdir = scratch.createFolder("proj"); + J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); //NOI18N + helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null); + Project p = FileOwnerQuery.getOwner(projdir); + assertNotNull(p); + prj = p.getLookup().lookup(J2SEProject.class); + assertNotNull(prj); + sources = projdir.getFileObject("src"); + } + + public void testFileEncodingQuery () throws Exception { + this.prepareProject(); + final Charset UTF8 = Charset.forName("UTF-8"); + final Charset ISO15 = Charset.forName("ISO-8859-15"); + final Charset CP1252 = Charset.forName("CP1252"); + FileObject java = sources.createData("a.java"); + Charset enc = FileEncodingQuery.getEncoding(java); + assertEquals(UTF8,enc); + FileObject xml = sources.createData("b.xml"); + enc = FileEncodingQuery.getEncoding(xml); + assertEquals(ISO15,enc); + EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + ep.setProperty("project.encoding", CP1252.name()); + helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); + enc = FileEncodingQuery.getEncoding(java); + assertEquals(CP1252,enc); + FileObject standAloneJava = scratch.createData("b.java"); + enc = FileEncodingQuery.getEncoding(standAloneJava); + assertEquals(UTF8,enc); + } + + + public static class DummyXMLEncodingImpl implements FileEncodingQueryImplementation { + + + public Charset getEncoding(FileObject file) { + if ("xml".equals(file.getExt())) { + return Charset.forName("ISO-8859-15"); + } + else { + return null; + } + } + } + + + +}