From 86fe0a9ffa3edf32f8ef40d106747d6de31ac988 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 11 Feb 2025 15:49:17 +0100 Subject: [PATCH] Fixes several issues with the editor annotation options. - Make sure the current editor annotation profile is correctly copied on profile duplication. - Make sure annotation profile settings are correctly persisted and applied on change - All profiles must have annotation color configs to have inherited values work correctly (added missing) - EditorSettings: fix javadoc since the impl never returned null in the last 20 years. --- .../defaults/CityLights-annotations.xml | 122 ++++++++ .../defaults/NetBeans55-annotations.xml | 122 ++++++++ .../defaults/NetBeansEarth-annotations.xml | 122 ++++++++ .../netbeans/modules/defaults/mf-layer.xml | 10 +- .../settings/storage/EditorSettingsImpl.java | 10 +- .../settings/storage/SettingsProvider.java | 17 +- .../settings/storage/api/EditorSettings.java | 8 +- .../nbproject/project.properties | 2 +- .../options/colors/AnnotationsPanel.java | 271 ++++++++++-------- .../modules/options/colors/ColorModel.java | 15 +- .../options/colors/FontAndColorsPanel.java | 17 +- .../colors/spi/FontsColorsController.java | 9 + 12 files changed, 561 insertions(+), 164 deletions(-) create mode 100644 ide/defaults/src/org/netbeans/modules/defaults/CityLights-annotations.xml create mode 100644 ide/defaults/src/org/netbeans/modules/defaults/NetBeans55-annotations.xml create mode 100644 ide/defaults/src/org/netbeans/modules/defaults/NetBeansEarth-annotations.xml diff --git a/ide/defaults/src/org/netbeans/modules/defaults/CityLights-annotations.xml b/ide/defaults/src/org/netbeans/modules/defaults/CityLights-annotations.xml new file mode 100644 index 000000000000..1b902a29fe5b --- /dev/null +++ b/ide/defaults/src/org/netbeans/modules/defaults/CityLights-annotations.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ide/defaults/src/org/netbeans/modules/defaults/NetBeans55-annotations.xml b/ide/defaults/src/org/netbeans/modules/defaults/NetBeans55-annotations.xml new file mode 100644 index 000000000000..1b902a29fe5b --- /dev/null +++ b/ide/defaults/src/org/netbeans/modules/defaults/NetBeans55-annotations.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ide/defaults/src/org/netbeans/modules/defaults/NetBeansEarth-annotations.xml b/ide/defaults/src/org/netbeans/modules/defaults/NetBeansEarth-annotations.xml new file mode 100644 index 000000000000..1b902a29fe5b --- /dev/null +++ b/ide/defaults/src/org/netbeans/modules/defaults/NetBeansEarth-annotations.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ide/defaults/src/org/netbeans/modules/defaults/mf-layer.xml b/ide/defaults/src/org/netbeans/modules/defaults/mf-layer.xml index 3b267b873f6d..cc62b71a7224 100644 --- a/ide/defaults/src/org/netbeans/modules/defaults/mf-layer.xml +++ b/ide/defaults/src/org/netbeans/modules/defaults/mf-layer.xml @@ -1110,6 +1110,9 @@ + + + @@ -1123,10 +1126,12 @@ + + + - @@ -1137,6 +1142,9 @@ + + + diff --git a/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/EditorSettingsImpl.java b/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/EditorSettingsImpl.java index 4dda4ba3260b..a22b2fd822f7 100644 --- a/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/EditorSettingsImpl.java +++ b/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/EditorSettingsImpl.java @@ -428,10 +428,10 @@ public Map getAnnotations(String profile) { // imported from previous version some colorings can be missing. // See #119709 Map m = new HashMap<>(); - if (defaultProfileColorings != null) { - m.putAll(defaultProfileColorings); - } if (profileColorings != null) { + if (defaultProfileColorings != null) { + m.putAll(defaultProfileColorings); + } m.putAll(profileColorings); } @@ -442,7 +442,7 @@ public Map getAnnotations(String profile) { } Map h = annotations.get(profile); - return h == null ? Collections.emptyMap() : h; + return h == null ? Collections.emptyMap() : h; } @Override @@ -452,7 +452,7 @@ public Map getAnnotationDefaults(String profile) { return annotationsStorage.load(MimePath.EMPTY, profile, true); } catch (IOException ioe) { LOG.log(Level.WARNING, null, ioe); - return Collections.emptyMap(); + return Collections.emptyMap(); } } diff --git a/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/SettingsProvider.java b/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/SettingsProvider.java index 984b1b567905..454e1ce1076a 100644 --- a/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/SettingsProvider.java +++ b/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/SettingsProvider.java @@ -146,30 +146,24 @@ public void propertyChange(PropertyChangeEvent evt) { synchronized (this) { boolean fcsChanged = false; boolean kbsChanged = false; - -// if (mimePath.getPath().contains("xml")) { -// System.out.println("@@@ propertyChange: mimePath = " + mimePath.getPath() + " profile = " + fcsProfile + " property = " + evt.getPropertyName() + " oldValue = " + (evt.getOldValue() instanceof MimePath ? ((MimePath) evt.getOldValue()).getPath() : evt.getOldValue()) + " newValue = " + evt.getNewValue()); -// } // Determine what has changed + String prop = evt.getPropertyName(); if (this.kbsi == evt.getSource()) { kbsChanged = true; - - } else if (evt.getPropertyName() == null) { + } else if (prop == null) { // reset all if (!specialFcsProfile) { String currentProfile = EditorSettings.getDefault().getCurrentFontColorProfile(); fcsProfile = FontColorSettingsImpl.get(mimePath).getInternalFontColorProfile(currentProfile); } fcsChanged = true; - - } else if (evt.getPropertyName().equals(EditorSettingsImpl.PROP_HIGHLIGHT_COLORINGS)) { + } else if (prop.equals(EditorSettingsImpl.PROP_HIGHLIGHT_COLORINGS) || prop.equals(EditorSettingsImpl.PROP_ANNOTATION_COLORINGS)) { String changedProfile = (String) evt.getNewValue(); if (changedProfile.equals(fcsProfile)) { fcsChanged = true; } - - } else if (evt.getPropertyName().equals(EditorSettingsImpl.PROP_TOKEN_COLORINGS)) { + } else if (prop.equals(EditorSettingsImpl.PROP_TOKEN_COLORINGS)) { String changedProfile = (String) evt.getNewValue(); if (changedProfile.equals(fcsProfile)) { MimePath changedMimePath = (MimePath) evt.getOldValue(); @@ -177,8 +171,7 @@ public void propertyChange(PropertyChangeEvent evt) { fcsChanged = true; } } - - } else if (evt.getPropertyName().equals(EditorSettingsImpl.PROP_CURRENT_FONT_COLOR_PROFILE)) { + } else if (prop.equals(EditorSettingsImpl.PROP_CURRENT_FONT_COLOR_PROFILE)) { if (!specialFcsProfile) { String newProfile = (String) evt.getNewValue(); fcsProfile = FontColorSettingsImpl.get(mimePath).getInternalFontColorProfile(newProfile); diff --git a/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/api/EditorSettings.java b/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/api/EditorSettings.java index ee285e5f41cd..8741e0d1f3a4 100644 --- a/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/api/EditorSettings.java +++ b/ide/editor.settings.storage/src/org/netbeans/modules/editor/settings/storage/api/EditorSettings.java @@ -207,11 +207,11 @@ public abstract void setHighlightings ( ); /** - * Returns annotations properties for given profile or null, if the + * Returns annotations properties for given profile or an empty Map, if the * profile is not known. * * @param profile a profile name - * @return annotations properties for given profile or null + * @return annotations properties for given profile or an empty map */ public abstract Map getAnnotations ( String profile @@ -219,10 +219,10 @@ public abstract Map getAnnotations ( /** * Returns defaults for annotation properties for given profile, - * or null if the profile is not known. + * or an empty Map if the profile is not known. * * @param profile a profile name - * @return annotation properties for given profile or null + * @return annotation properties for given profile or an empty map */ public abstract Map getAnnotationDefaults ( String profile diff --git a/ide/options.editor/nbproject/project.properties b/ide/options.editor/nbproject/project.properties index cf753b9f551c..0f6ffac917aa 100644 --- a/ide/options.editor/nbproject/project.properties +++ b/ide/options.editor/nbproject/project.properties @@ -17,7 +17,7 @@ javac.compilerargs=-Xlint:unchecked -javac.source=1.8 +javac.release=17 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml test.unit.run.cp.extra=${java/javacore.dir}/modules/org-netbeans-modules-javacore.jar:${java/javamodel.dir}/modules/org-netbeans-jmi-javamodel.jar:${java/javamodel.dir}/modules/ext/jmi.jar diff --git a/ide/options.editor/src/org/netbeans/modules/options/colors/AnnotationsPanel.java b/ide/options.editor/src/org/netbeans/modules/options/colors/AnnotationsPanel.java index cc9d035464af..1842dfa5bf1a 100644 --- a/ide/options.editor/src/org/netbeans/modules/options/colors/AnnotationsPanel.java +++ b/ide/options.editor/src/org/netbeans/modules/options/colors/AnnotationsPanel.java @@ -29,7 +29,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -38,8 +37,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import javax.swing.text.AttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; @@ -59,12 +56,17 @@ public class AnnotationsPanel extends JPanel implements ActionListener, ItemListener, FontsColorsController { - private ColorModel colorModel; - private boolean listen = false; - private String currentScheme; - private Map> schemes = new HashMap>(); - private Set toBeSaved = new HashSet(); - private boolean changed = false; + private ColorModel colorModel; + /// Currently displayed profile. + private String currentProfile; + /// History of all profiles and their attributes which were at some point displayed in this panel. May hold modified data. + /// null value indicates the profile is marked for deletion. + private Map> profiles; + /// Profile names to save. + private Set toBeSaved; + + private boolean changed; + private boolean listen; /** Creates new form AnnotationsPanel1 */ @@ -84,10 +86,9 @@ public AnnotationsPanel() { lCategories.getAccessibleContext ().setAccessibleDescription (loc ("AD_Categories")); lCategories.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); lCategories.setVisibleRowCount (3); - lCategories.addListSelectionListener (new ListSelectionListener () { - public void valueChanged (ListSelectionEvent e) { - if (!listen) return; - refreshUI (); + lCategories.addListSelectionListener(evt -> { + if (listen) { + refreshUI(); } }); lCategories.setCellRenderer (new CategoryRenderer ()); @@ -106,6 +107,7 @@ public void valueChanged (ListSelectionEvent e) { cbEffects.getAccessibleContext ().setAccessibleName (loc ("AN_Effects")); cbEffects.getAccessibleContext ().setAccessibleDescription (loc ("AD_Effects")); cbEffects.addActionListener (this); + clearState(); } /** This method is called from within the constructor to @@ -212,6 +214,7 @@ private void initComponents() { // End of variables declaration//GEN-END:variables + @Override public void actionPerformed (ActionEvent evt) { if (!listen) return; if (evt.getSource () == cbEffects) { @@ -235,75 +238,94 @@ public void itemStateChanged( ItemEvent e ) { updateData (); fireChanged(); } + + private void clearState() { + toBeSaved = new HashSet<>(); + profiles = new HashMap<>(); + changed = false; + currentProfile = null; + } - public void update (ColorModel colorModel) { + @Override + public void update(ColorModel colorModel) { + clearState(); this.colorModel = colorModel; - listen = false; - currentScheme = colorModel.getCurrentProfile (); - lCategories.setListData (getAnnotations (currentScheme).toArray(new AttributeSet[]{})); - if (lCategories.getModel ().getSize () > 0) - lCategories.setSelectedIndex (0); - refreshUI (); - listen = true; + setCurrentProfile(colorModel.getCurrentProfile()); + toBeSaved.remove(currentProfile); changed = false; } - public void cancel () { - toBeSaved = new HashSet(); - schemes = new HashMap>(); - changed = false; + @Override + public void cancel() { + clearState(); } + @Override public void applyChanges() { if (colorModel == null) return; - for(String scheme : toBeSaved) { + boolean currentChanged = toBeSaved.remove(currentProfile); + for (String scheme : toBeSaved) { colorModel.setAnnotations(scheme, getAnnotations(scheme)); } - toBeSaved = new HashSet(); - schemes = new HashMap>(); - changed = false; + // TODO the editor sometimes refreshes to whatever is set last instead of the current profile + // Setting current profile last fixes it in most cases. Restart helps too. + if (currentChanged) { + colorModel.setAnnotations(currentProfile, getAnnotations(currentProfile)); + } + clearState(); } + @Override public boolean isChanged () { return changed; } - public void setCurrentProfile (String currentScheme) { - if (this.currentScheme.equals(currentScheme)) { + @Override + public void setCurrentProfile(String profile) { + if (profile.equals(currentProfile)) { return; } - String oldScheme = this.currentScheme; - this.currentScheme = currentScheme; - List v = getAnnotations(currentScheme); - if (v == null) { - // clone scheme - v = getAnnotations (oldScheme); - schemes.put (currentScheme, new ArrayList(v)); - toBeSaved.add (currentScheme); - v = getAnnotations (currentScheme); + // copy current if profile is new + if (!profiles.containsKey(profile)) { + if (!colorModel.getProfiles().contains(profile)) { + profiles.put(profile, copy(getAnnotations(currentProfile))); + } } - toBeSaved.add(currentScheme); - lCategories.setListData (v.toArray(new AttributeSet[0])); - if (lCategories.getModel ().getSize () > 0) - lCategories.setSelectedIndex (0); - refreshUI (); + toBeSaved.add(profile); + currentProfile = profile; + invokeWithoutListeners(() -> { + int selected = Math.max(lCategories.getSelectedIndex(), 0); + lCategories.setListData(getAnnotations(profile).toArray(AttributeSet[]::new)); + if (lCategories.getModel().getSize() > selected) { + lCategories.setSelectedIndex(selected); + } + }); + refreshUI(); fireChanged(); } - public void deleteProfile (String scheme) { - if (colorModel.isCustomProfile (scheme)) { - schemes.put(scheme,null); + @Override + public void deleteProfile(String profile) { + if (colorModel.isCustomProfile(profile)) { + // mark for deletion + profiles.put(profile, null); } else { - schemes.put (scheme, getDefaults (scheme)); - lCategories.setListData (getAnnotations(scheme).toArray(new AttributeSet[]{})); - lCategories.repaint(); - lCategories.setSelectedIndex (0); - refreshUI (); + // restore default profile + profiles.put(profile, copy(getDefaults(profile))); + invokeWithoutListeners(() -> { + int selected = Math.max(lCategories.getSelectedIndex(), 0); + lCategories.setListData(getAnnotations(profile).toArray(AttributeSet[]::new)); + if (lCategories.getModel().getSize() > selected) { + lCategories.setSelectedIndex(selected); + } + }); + refreshUI(); } - toBeSaved.add(scheme); // 'default' profile restored + toBeSaved.add(profile); // restore or delete fireChanged(); } + @Override public JComponent getComponent() { return this; } @@ -314,21 +336,25 @@ private static String loc (String key) { return NbBundle.getMessage (SyntaxColoringPanel.class, key); } - private static void loc (Component c, String key) { - if (c instanceof AbstractButton) - Mnemonics.setLocalizedText ( - (AbstractButton) c, - loc (key) - ); - else - Mnemonics.setLocalizedText ( - (JLabel) c, - loc (key) - ); + private static void loc(Component c, String key) { + if (c instanceof AbstractButton button) { + Mnemonics.setLocalizedText(button, loc(key)); + } else { + Mnemonics.setLocalizedText((JLabel) c,loc(key)); + } + } + + private void invokeWithoutListeners(Runnable run) { + try { + listen = false; + run.run(); + } finally { + listen = true; + } } private void updateData () { - List annotations = getAnnotations(currentScheme); + List annotations = getAnnotations(currentProfile); int index = lCategories.getSelectedIndex(); SimpleAttributeSet c = new SimpleAttributeSet(annotations.get(index)); @@ -356,8 +382,7 @@ private void updateData () { } annotations.set(index, c); - - toBeSaved.add(currentScheme); + toBeSaved.add(currentProfile); } private void fireChanged() { @@ -408,7 +433,7 @@ private boolean checkMaps(Map savedMap, Map toMap(Collection categories) { if (categories == null) return null; - Map result = new HashMap(); + Map result = new HashMap<>(); for(AttributeSet as : categories) { result.put((String) as.getAttribute(StyleConstants.NameAttribute), as); } @@ -428,76 +453,70 @@ private void refreshUI () { cbBackground.setEnabled (true); cbEffectColor.setEnabled (true); - listen = false; - - // set defaults - AttributeSet defAs = getDefaultColoring(); - if (defAs != null) { - Color inheritedForeground = (Color) defAs.getAttribute(StyleConstants.Foreground); - if (inheritedForeground == null) { - inheritedForeground = Color.black; - } - ColorComboBoxSupport.setInheritedColor((ColorComboBox)cbForeground, inheritedForeground); - - Color inheritedBackground = (Color) defAs.getAttribute(StyleConstants.Background); - if (inheritedBackground == null) { - inheritedBackground = Color.white; + invokeWithoutListeners(() -> { + // set defaults + AttributeSet defAs = getDefaultColoring(currentProfile); + if (defAs != null) { + Color inheritedForeground = (Color) defAs.getAttribute(StyleConstants.Foreground); + if (inheritedForeground == null) { + inheritedForeground = Color.black; + } + ColorComboBoxSupport.setInheritedColor((ColorComboBox)cbForeground, inheritedForeground); + + Color inheritedBackground = (Color) defAs.getAttribute(StyleConstants.Background); + if (inheritedBackground == null) { + inheritedBackground = Color.white; + } + ColorComboBoxSupport.setInheritedColor((ColorComboBox)cbBackground, inheritedBackground); } - ColorComboBoxSupport.setInheritedColor((ColorComboBox)cbBackground, inheritedBackground); - } - // set values - List annotations = getAnnotations (currentScheme); - AttributeSet c = annotations.get (index); - ColorComboBoxSupport.setSelectedColor( (ColorComboBox)cbForeground, (Color) c.getAttribute (StyleConstants.Foreground)); - ColorComboBoxSupport.setSelectedColor( (ColorComboBox)cbBackground, (Color) c.getAttribute (StyleConstants.Background)); - if (c.getAttribute(EditorStyleConstants.WaveUnderlineColor) != null) { - cbEffects.setSelectedIndex(1); - cbEffectColor.setEnabled(true); - ((ColorComboBox)cbEffectColor).setSelectedColor((Color) c.getAttribute (EditorStyleConstants.WaveUnderlineColor)); - } else { - cbEffects.setSelectedIndex(0); - cbEffectColor.setEnabled(false); - cbEffectColor.setSelectedIndex(-1); - } - listen = true; + // set values + AttributeSet c = getAnnotations(currentProfile).get(index); + ColorComboBoxSupport.setSelectedColor((ColorComboBox)cbForeground, (Color)c.getAttribute(StyleConstants.Foreground)); + ColorComboBoxSupport.setSelectedColor((ColorComboBox)cbBackground, (Color)c.getAttribute(StyleConstants.Background)); + + if (c.getAttribute(EditorStyleConstants.WaveUnderlineColor) != null) { + cbEffects.setSelectedIndex(1); + cbEffectColor.setEnabled(true); + ((ColorComboBox)cbEffectColor).setSelectedColor((Color) c.getAttribute (EditorStyleConstants.WaveUnderlineColor)); + } else { + cbEffects.setSelectedIndex(0); + cbEffectColor.setEnabled(false); + cbEffectColor.setSelectedIndex(-1); + } + }); } - private AttributeSet getDefaultColoring() { - Collection defaults = colorModel.getCategories(currentScheme, ColorModel.ALL_LANGUAGES); - - for(Iterator i = defaults.iterator(); i.hasNext(); ) { - AttributeSet as = (AttributeSet) i.next(); - String name = (String) as.getAttribute(StyleConstants.NameAttribute); - if (name != null && "default".equals(name)) { //NOI18N - return as; + private AttributeSet getDefaultColoring(String profile) { + for (AttributeSet set : colorModel.getCategories(profile, ColorModel.ALL_LANGUAGES)) { + if ("default".equals(set.getAttribute(StyleConstants.NameAttribute))) { //NOI18N + return set.copyAttributes(); } } - return null; } - private List getAnnotations(String scheme) { - if (!schemes.containsKey(scheme)) { - Collection c = colorModel.getAnnotations(currentScheme); - if (c == null) return null; - List l = new ArrayList(c); - l.sort(new CategoryComparator()); - schemes.put(scheme, new ArrayList(l)); + private List getAnnotations(String profile) { + if (!profiles.containsKey(profile)) { + List copy = copy(colorModel.getAnnotations(profile)); + copy.sort(new CategoryComparator()); + profiles.put(profile, copy); } - return schemes.get(scheme); + return profiles.get(profile); } - /** cache Map (String (profile name) > List (AttributeSet)). */ - private Map> profileToDefaults = new HashMap>(); private List getDefaults(String profile) { - if (!profileToDefaults.containsKey(profile)) { - Collection c = colorModel.getAnnotationsDefaults(profile); - List l = new ArrayList(c); - l.sort(new CategoryComparator()); - profileToDefaults.put(profile, l); + List defaults = new ArrayList<>(colorModel.getAnnotationsDefaults(profile)); + defaults.sort(new CategoryComparator()); + return defaults; + } + + private static List copy(Collection annotations) { + List copy = new ArrayList<>(annotations.size()); + for (AttributeSet set : annotations) { + copy.add(set.copyAttributes()); } - List defaultprofile = profileToDefaults.get(profile); - return new ArrayList(defaultprofile); + return copy; } + } diff --git a/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java b/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java index c439bf4e1a58..25e81df3f051 100644 --- a/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java +++ b/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java @@ -114,7 +114,7 @@ public Collection getAnnotationsDefaults(String profile) { } private List processAnnotations(Map annos, boolean isdefault) { - List annotations = new ArrayList(); + List annotations = new ArrayList<>(); for(Iterator it = AnnotationTypes.getTypes().getAnnotationTypeNames(); it.hasNext(); ) { String name = (String) it.next (); @@ -142,18 +142,23 @@ private List processAnnotations(Map annos, b LOG.log(Level.WARNING, "AnnotationType.getGlyph() returned invalid URI", e); } + AttributeSet as = annos.get(name); + // don't set if profile value is null so that inherited values don't show up as fixed colors Color bgColor = annotationType.getHighlight(); - if (annotationType.isUseHighlightColor() && bgColor != null) { + if (annotationType.isUseHighlightColor() && bgColor != null + && (as == null || as.getAttribute(StyleConstants.Background) != null)) { category.addAttribute(StyleConstants.Background, bgColor); } Color fgColor = annotationType.getForegroundColor(); - if (!annotationType.isInheritForegroundColor() && fgColor != null) { + if (!annotationType.isInheritForegroundColor() && fgColor != null + && (as == null || as.getAttribute(StyleConstants.Foreground) != null)) { category.addAttribute(StyleConstants.Foreground, fgColor); } Color underColor = annotationType.getWaveUnderlineColor(); - if (annotationType.isUseWaveUnderlineColor() && underColor != null) { + if (annotationType.isUseWaveUnderlineColor() && underColor != null + && (as == null || as.getAttribute(EditorStyleConstants.WaveUnderlineColor) != null)) { category.addAttribute(EditorStyleConstants.WaveUnderlineColor, underColor); } @@ -164,9 +169,7 @@ private List processAnnotations(Map annos, b category.removeAttribute(StyleConstants.Foreground); category.removeAttribute(EditorStyleConstants.WaveUnderlineColor); } - AttributeSet as = annos.get(name); category.addAttributes(as); - } annotations.add(category); diff --git a/ide/options.editor/src/org/netbeans/modules/options/colors/FontAndColorsPanel.java b/ide/options.editor/src/org/netbeans/modules/options/colors/FontAndColorsPanel.java index 1130fb1e513b..9203a58f8df6 100644 --- a/ide/options.editor/src/org/netbeans/modules/options/colors/FontAndColorsPanel.java +++ b/ide/options.editor/src/org/netbeans/modules/options/colors/FontAndColorsPanel.java @@ -270,11 +270,11 @@ public void actionPerformed (ActionEvent e) { loc ("CTL_Create_New_Profile_Message"), // NOI18N loc ("CTL_Create_New_Profile_Title") // NOI18N ); - il.setInputText (currentProfile); + il.setInputText(currentProfile + "_copy"); // NOI18N DialogDisplayer.getDefault ().notify (il); if (il.getValue () == NotifyDescriptor.OK_OPTION) { - String newScheme = il.getInputText (); - for (int i = 0; i < cbProfile.getItemCount(); i++) + String newScheme = il.getInputText(); + for (int i = 0; i < cbProfile.getItemCount(); i++) { if (newScheme.equals (cbProfile.getItemAt(i))) { Message md = new Message ( loc ("CTL_Duplicate_Profile_Name"), // NOI18N @@ -283,15 +283,14 @@ public void actionPerformed (ActionEvent e) { DialogDisplayer.getDefault ().notify (md); return; } - setCurrentProfile (newScheme); + } + setCurrentProfile(newScheme); listen = false; - cbProfile.addItem (il.getInputText ()); - cbProfile.setSelectedItem (il.getInputText ()); + cbProfile.addItem(newScheme); + cbProfile.setSelectedItem(newScheme); listen = true; } - return; - } - if (e.getSource () == bDelete) { + } else if (e.getSource () == bDelete) { deleteCurrentProfile (); } } diff --git a/ide/options.editor/src/org/netbeans/modules/options/colors/spi/FontsColorsController.java b/ide/options.editor/src/org/netbeans/modules/options/colors/spi/FontsColorsController.java index ff39b8614864..45aaa401b419 100644 --- a/ide/options.editor/src/org/netbeans/modules/options/colors/spi/FontsColorsController.java +++ b/ide/options.editor/src/org/netbeans/modules/options/colors/spi/FontsColorsController.java @@ -28,7 +28,16 @@ public interface FontsColorsController { public void update(ColorModel model); + + /** + * Changes the profile to the provided profile for configuration. If the + * profile name does not exist, the currently set profile will be copied + * into a new profile with the provided name. + * + * @param profile The next profile which should be configured. + */ public void setCurrentProfile(String profile); + public void deleteProfile(String profile); public void applyChanges(); public void cancel();