diff -r 00b61a6ecacf java.api.common/src/org/netbeans/modules/java/api/common/project/ui/Bundle.properties --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/Bundle.properties Thu Mar 12 21:08:41 2009 -0500 +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/Bundle.properties Mon Mar 16 14:44:27 2009 -0500 @@ -68,3 +68,5 @@ LBL_Properties_Action=Properties # {0} - folder name JavaSourceNodeFactory.gensrc=Generated Sources ({0}) +UNSUPPORTED_ENCODING=Project {0} specifies an unknown character encoding {1} +CLOSE=Close diff -r 00b61a6ecacf java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectUISupport.java --- a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectUISupport.java Thu Mar 12 21:08:41 2009 -0500 +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/ProjectUISupport.java Mon Mar 16 14:44:27 2009 -0500 @@ -41,6 +41,7 @@ package org.netbeans.modules.java.api.common.project.ui; +import java.nio.charset.Charset; import javax.swing.AbstractAction; import javax.swing.Icon; import org.netbeans.api.project.Project; @@ -108,4 +109,8 @@ return new JavaSourceNodeFactory.PreselectPropertiesAction(project, nodeName, panelName); } + public static Charset showUnsupportedEncodingDialog(String projectName, String unknownCharset) { + return UnsupportedEncodingDialog.showDialog (projectName, unknownCharset); + } + } diff -r 00b61a6ecacf java.api.common/src/org/netbeans/modules/java/api/common/project/ui/UnsupportedEncodingDialog.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/UnsupportedEncodingDialog.form Mon Mar 16 14:44:27 2009 -0500 @@ -0,0 +1,50 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 00b61a6ecacf java.api.common/src/org/netbeans/modules/java/api/common/project/ui/UnsupportedEncodingDialog.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/UnsupportedEncodingDialog.java Mon Mar 16 14:44:27 2009 -0500 @@ -0,0 +1,162 @@ +package org.netbeans.modules.java.api.common.project.ui; + +import java.awt.Cursor; +import java.awt.EventQueue; +import java.nio.charset.Charset; +import java.text.MessageFormat; +import java.util.Map; +import java.util.SortedMap; +import javax.swing.DefaultComboBoxModel; +import org.netbeans.api.queries.FileEncodingQuery; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.RequestProcessor; + +/** + * + * @author Tim Boudreau + */ +final class UnsupportedEncodingDialog extends javax.swing.JPanel implements Runnable { + + private final DefaultComboBoxModel mdl = new DefaultComboBoxModel(); + private DialogDescriptor descriptor; + + /** Creates new form UnsupportedEncodingDialog */ + public UnsupportedEncodingDialog() { + initComponents(); + Cursor cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); + setCursor(cursor); + instructions.setCursor(cursor); + charsetComboBox.setCursor(cursor); + } + + void setDialogDescriptor(DialogDescriptor d) { + this.descriptor = d; + } + + public static Charset showDialog(String projectName, String requestedCharset) { + UnsupportedEncodingDialog pnl = new UnsupportedEncodingDialog(); + String s = pnl.instructions.getText(); + MessageFormat.format(s, new Object[] { requestedCharset }); + String title = NbBundle.getMessage(UnsupportedEncodingDialog.class, + "UNSUPPORTED_ENCODING", requestedCharset, projectName); //NO18N + String close = NbBundle.getMessage(UnsupportedEncodingDialog.class, + "CLOSE"); //NOI18N + DialogDescriptor des = new DialogDescriptor (pnl, + title, true, new Object[] { close }, + close, DialogDescriptor.DEFAULT_ALIGN, + HelpCtx.DEFAULT_HELP, null); //NOI18N + pnl.setDialogDescriptor(des); + DialogDisplayer.getDefault().notify(des); + return pnl.getSelectedCharset(); + } + + private Charset getSelectedCharset() { + Object o = charsetComboBox.getSelectedItem(); + if (o instanceof Entry) { + return ((Entry) o).charset; + } else { + //should never happen + return FileEncodingQuery.getDefaultEncoding(); + } + } + + /** 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. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + instructions = new javax.swing.JLabel(); + charsetComboBox = new javax.swing.JComboBox(); + + setLayout(new java.awt.GridBagLayout()); + + instructions.setLabelFor(charsetComboBox); + instructions.setText(org.openide.util.NbBundle.getMessage(UnsupportedEncodingDialog.class, "UnsupportedEncodingDialog.instructions.text", new Object[] {})); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12); + add(instructions, gridBagConstraints); + + charsetComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "[Loading all character sets]" })); + charsetComboBox.setEnabled(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; + gridBagConstraints.weightx = 0.5; + gridBagConstraints.insets = new java.awt.Insets(5, 12, 12, 12); + add(charsetComboBox, gridBagConstraints); + }// //GEN-END:initComponents + + @Override + public void addNotify() { + super.addNotify(); + RequestProcessor.getDefault().post(this); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox charsetComboBox; + private javax.swing.JLabel instructions; + // End of variables declaration//GEN-END:variables + + @Override + public void run() { + if (!EventQueue.isDispatchThread()) { + try { + Entry use = null; + Charset def = FileEncodingQuery.getDefaultEncoding(); + if (!EventQueue.isDispatchThread()) { + SortedMap m = Charset.availableCharsets(); + for (Map.Entry e : m.entrySet()) { + Entry entry = new Entry(e.getKey(), e.getValue()); + if (def.equals(e.getValue())) { + use = entry; + } + mdl.addElement(entry); + } + } + if (use != null) { + mdl.setSelectedItem(use); + } + } finally { + EventQueue.invokeLater(this); + } + } else { + charsetComboBox.setModel(mdl); + charsetComboBox.setEnabled(true); + Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); + setCursor(cursor); + instructions.setCursor(cursor); + charsetComboBox.setCursor(cursor); + if (descriptor != null) { + descriptor.setValid(false); + } + } + } + + private static final class Entry { + + String nm; + Charset charset; + + public Entry(String nm, Charset charset) { + this.nm = nm; + this.charset = charset; + } + + @Override + public String toString() { + return charset.displayName(); + } + } +} diff -r 00b61a6ecacf java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java Thu Mar 12 21:08:41 2009 -0500 +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java Mon Mar 16 14:44:27 2009 -0500 @@ -82,6 +82,7 @@ import org.netbeans.modules.java.api.common.classpath.ClassPathModifier; import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl; import org.netbeans.modules.java.api.common.project.ProjectProperties; +import org.netbeans.modules.java.api.common.project.ui.ProjectUISupport; import org.netbeans.modules.java.api.common.queries.QuerySupport; import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator; import org.netbeans.modules.java.j2seproject.ui.J2SELogicalViewProvider; @@ -540,6 +541,28 @@ //the updater is active only on the opened projects mainClassUpdater = new MainClassUpdater (J2SEProject.this, eval, updateHelper, cpProvider.getProjectClassPaths(ClassPath.SOURCE)[0], J2SEProjectProperties.MAIN_CLASS); + String prop = eval.getProperty(J2SEProjectProperties.SOURCE_ENCODING); + Charset c = null; + boolean updated = false; + if (prop != null) { + try { + c = Charset.forName(prop); + } catch (IllegalCharsetNameException e) { + //Broken property, log & ignore + Logger LOG = Logger.getLogger(J2SEProject.class.getName()); + LOG.warning("Illegal charset: " + prop + " in project: " + FileUtil.getFileDisplayName(getProjectDirectory())); //NOI18N + } catch (UnsupportedCharsetException e) { + //todo: Needs UI notification like broken references. + Logger LOG = Logger.getLogger(J2SEProject.class.getName()); + LOG.warning("Unsupported charset: " + prop + " in project: " + FileUtil.getFileDisplayName(getProjectDirectory())); //NOI18N + } + if (c == null) { + String name = getLookup().lookup(ProjectInformation.class).getDisplayName(); + c = ProjectUISupport.showUnsupportedEncodingDialog(name, prop); + updated = true; + } + } + final Charset updatedCharset = updated ? c : null; // Make it easier to run headless builds on the same machine at least. try { @@ -586,6 +609,10 @@ updateHelper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + if (updatedCharset != null) { + ep.setProperty(J2SEProjectProperties.SOURCE_ENCODING, + updatedCharset.name()); + } if (!ep.containsKey(ProjectProperties.INCLUDES)) { ep.setProperty(ProjectProperties.INCLUDES, "**"); // NOI18N } @@ -620,19 +647,6 @@ if (physicalViewProvider != null && physicalViewProvider.hasBrokenLinks()) { BrokenReferencesSupport.showAlert(); } - String prop = eval.getProperty(J2SEProjectProperties.SOURCE_ENCODING); - if (prop != null) { - try { - Charset c = Charset.forName(prop); - } catch (IllegalCharsetNameException e) { - //Broken property, log & ignore - LOG.warning("Illegal charset: " + prop+ " in project: " + FileUtil.getFileDisplayName(getProjectDirectory())); //NOI18N - } - catch (UnsupportedCharsetException e) { - //todo: Needs UI notification like broken references. - LOG.warning("Unsupported charset: " + prop+ " in project: " + FileUtil.getFileDisplayName(getProjectDirectory())); //NOI18N - } - } } protected void projectClosed() {