From dc450546f6b1a4d3741aadadbc2bef4452d3df69 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Thu, 10 Jan 2013 17:33:24 +0400 Subject: [PATCH] Return a color settings page of base attribute without a need to use a modified API --- .../options/colors/AttributesDescriptor.java | 23 -------- .../options/colors/ColorSettingsPages.java | 3 +- .../colors/ColorAndFontDescription.java | 4 +- .../colors/ColorAndFontDescriptionPanel.java | 9 +-- .../options/colors/ColorAndFontOptions.java | 7 ++- .../colors/pages/ColorSettingsPagesImpl.java | 11 ++-- .../pages/DefaultLanguageColorsPage.java | 58 +++++++++---------- 7 files changed, 48 insertions(+), 67 deletions(-) diff --git a/platform/lang-api/src/com/intellij/openapi/options/colors/AttributesDescriptor.java b/platform/lang-api/src/com/intellij/openapi/options/colors/AttributesDescriptor.java index 51e186fae053..71dda578d7dd 100644 --- a/platform/lang-api/src/com/intellij/openapi/options/colors/AttributesDescriptor.java +++ b/platform/lang-api/src/com/intellij/openapi/options/colors/AttributesDescriptor.java @@ -16,7 +16,6 @@ package com.intellij.openapi.options.colors; import com.intellij.openapi.editor.colors.TextAttributesKey; -import org.jetbrains.annotations.Nullable; /** * Describes a text attribute key the attributes for which can be configured in a custom @@ -27,20 +26,6 @@ import org.jetbrains.annotations.Nullable; public final class AttributesDescriptor { private final TextAttributesKey myKey; private final String myDisplayName; - private ColorSettingsPage mySettingsPage; - - /** - * Creates an attribute descriptor with the specified name and text attributes key. - * - * @param settingsPage The settings page hosting the attribute. - * @param displayName the name of the attribute shown in the colors list. - * @param key the attributes key for which the colors are specified. - */ - public AttributesDescriptor(ColorSettingsPage settingsPage, String displayName, TextAttributesKey key) { - myKey = key; - myDisplayName = displayName; - mySettingsPage = settingsPage; - } /** * Creates an attribute descriptor with the specified name and text attributes key. @@ -70,12 +55,4 @@ public final class AttributesDescriptor { public String getDisplayName() { return myDisplayName; } - - /** - * @return The settings page hosting the attribute. - */ - @Nullable - public ColorSettingsPage getSettingsPage() { - return mySettingsPage; - } } \ No newline at end of file diff --git a/platform/lang-api/src/com/intellij/openapi/options/colors/ColorSettingsPages.java b/platform/lang-api/src/com/intellij/openapi/options/colors/ColorSettingsPages.java index c002cf96b35f..37a63dad6697 100644 --- a/platform/lang-api/src/com/intellij/openapi/options/colors/ColorSettingsPages.java +++ b/platform/lang-api/src/com/intellij/openapi/options/colors/ColorSettingsPages.java @@ -17,6 +17,7 @@ package com.intellij.openapi.options.colors; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.Nullable; /** @@ -49,6 +50,6 @@ public abstract class ColorSettingsPages { public abstract ColorSettingsPage[] getRegisteredPages(); @Nullable - public abstract AttributesDescriptor getAttributeDescriptor(TextAttributesKey key); + public abstract Pair getAttributeDescriptor(TextAttributesKey key); } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescription.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescription.java index bf67ef42048e..4defbe5b748d 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescription.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescription.java @@ -20,6 +20,8 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.options.colors.AttributesDescriptor; +import com.intellij.openapi.options.colors.ColorSettingsPage; +import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -225,7 +227,7 @@ public abstract class ColorAndFontDescription extends TextAttributes implements } @Nullable - public AttributesDescriptor getBaseAttributeDescriptor() { + public Pair getBaseAttributeDescriptor() { return null; } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java index 2adfa463b06e..e3c0399b52b5 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontDescriptionPanel.java @@ -18,6 +18,7 @@ package com.intellij.application.options.colors; import com.intellij.icons.AllIcons; import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; +import com.intellij.openapi.util.Pair; import com.intellij.ui.ListCellRendererWrapper; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.diagnostic.Logger; @@ -397,12 +398,12 @@ public class ColorAndFontDescriptionPanel extends JPanel { if (description.isInherited()) { myInheritanceLabel.setIcon(INHERITED_ICON); - AttributesDescriptor baseDescriptor = description.getBaseAttributeDescriptor(); + Pair baseDescriptor = description.getBaseAttributeDescriptor(); String attrName = "?"; String pageName = "?"; - if (baseDescriptor != null && baseDescriptor.getDisplayName() != null) { - attrName = baseDescriptor.getDisplayName(); - ColorSettingsPage settingsPage = baseDescriptor.getSettingsPage(); + if (baseDescriptor != null && baseDescriptor.second.getDisplayName() != null) { + attrName = baseDescriptor.second.getDisplayName(); + ColorSettingsPage settingsPage = baseDescriptor.first; if (settingsPage != null) { pageName = settingsPage.getDisplayName(); } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java index e7638e924dc2..c195be03040a 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java @@ -760,7 +760,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract private final TextAttributes myAttributesToApply; private final TextAttributesKey key; private TextAttributes myFallbackAttributes; - private AttributesDescriptor myBaseAttributeDescriptor; + private Pair myBaseAttributeDescriptor; private SchemeTextAttributesDescription(String name, String group, TextAttributesKey key, MyColorScheme scheme, Icon icon, String toolTip) { @@ -774,7 +774,8 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract myFallbackAttributes = scheme.getAttributes(fallbackKey); myBaseAttributeDescriptor = ColorSettingsPages.getInstance().getAttributeDescriptor(fallbackKey); if (myBaseAttributeDescriptor == null) { - myBaseAttributeDescriptor = new AttributesDescriptor(fallbackKey.getExternalName(), fallbackKey); + myBaseAttributeDescriptor = + new Pair(null, new AttributesDescriptor(fallbackKey.getExternalName(), fallbackKey)); } } initCheckedStatus(); @@ -819,7 +820,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract @Nullable @Override - public AttributesDescriptor getBaseAttributeDescriptor() { + public Pair getBaseAttributeDescriptor() { return myBaseAttributeDescriptor; } } diff --git a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ColorSettingsPagesImpl.java b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ColorSettingsPagesImpl.java index 91d571585f7a..4f45976eaffa 100644 --- a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ColorSettingsPagesImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ColorSettingsPagesImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; import com.intellij.openapi.options.colors.ColorSettingsPages; +import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -27,7 +28,8 @@ import java.util.*; public class ColorSettingsPagesImpl extends ColorSettingsPages { private final List myPages = new ArrayList(); private boolean myExtensionsLoaded = false; - private Map myKeyToDescriptorMap = new HashMap(); + private Map> myKeyToDescriptorMap = + new HashMap>(); @Override public void registerPage(ColorSettingsPage page) { @@ -45,7 +47,7 @@ public class ColorSettingsPagesImpl extends ColorSettingsPages { @Override @Nullable - public AttributesDescriptor getAttributeDescriptor(TextAttributesKey key) { + public Pair getAttributeDescriptor(TextAttributesKey key) { if (myKeyToDescriptorMap.containsKey(key)) { return myKeyToDescriptorMap.get(key); } @@ -53,8 +55,9 @@ public class ColorSettingsPagesImpl extends ColorSettingsPages { for (ColorSettingsPage page : getRegisteredPages()) { for (AttributesDescriptor descriptor : page.getAttributeDescriptors()) { if (descriptor.getKey() == key) { - myKeyToDescriptorMap.put(key, descriptor); - return descriptor; + Pair result = new Pair(page, descriptor); + myKeyToDescriptorMap.put(key, result); + return result; } } } diff --git a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java index dc18b58a9e0d..6ae8a7b8fdd8 100644 --- a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java +++ b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/DefaultLanguageColorsPage.java @@ -68,36 +68,32 @@ public class DefaultLanguageColorsPage implements ColorSettingsPage, DisplayPrio TAG_HIGHLIGHTING_MAP.put("static_field", DefaultLanguageHighlighterColors.STATIC_FIELD); } - private final AttributesDescriptor[] myAttributesDescriptors; - - public DefaultLanguageColorsPage() { - myAttributesDescriptors = new AttributesDescriptor[]{ - new AttributesDescriptor(this, "Keyword", DefaultLanguageHighlighterColors.KEYWORD), - new AttributesDescriptor(this, "Identifier", DefaultLanguageHighlighterColors.IDENTIFIER), - new AttributesDescriptor(this, "String", DefaultLanguageHighlighterColors.STRING), - new AttributesDescriptor(this, "Number", DefaultLanguageHighlighterColors.NUMBER), - new AttributesDescriptor(this, "Operation sign", DefaultLanguageHighlighterColors.OPERATION_SIGN), - new AttributesDescriptor(this, "Braces", DefaultLanguageHighlighterColors.BRACES), - new AttributesDescriptor(this, "Parentheses", DefaultLanguageHighlighterColors.PARENTHESES), - new AttributesDescriptor(this, "Brackets", DefaultLanguageHighlighterColors.BRACKETS), - new AttributesDescriptor(this, "Dot", DefaultLanguageHighlighterColors.DOT), - new AttributesDescriptor(this, "Comma", DefaultLanguageHighlighterColors.COMMA), - new AttributesDescriptor(this, "Semicolon", DefaultLanguageHighlighterColors.SEMICOLON), - new AttributesDescriptor(this, "Line comment", DefaultLanguageHighlighterColors.LINE_COMMENT), - new AttributesDescriptor(this, "Block comment", DefaultLanguageHighlighterColors.BLOCk_COMMENT), - new AttributesDescriptor(this, "Doc comment", DefaultLanguageHighlighterColors.DOC_COMMENT), - new AttributesDescriptor(this, "Function declaration", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION), - new AttributesDescriptor(this, "Function call", DefaultLanguageHighlighterColors.FUNCTION_CALL), - new AttributesDescriptor(this, "Parameter", DefaultLanguageHighlighterColors.PARAMETER), - new AttributesDescriptor(this, "Class name", DefaultLanguageHighlighterColors.CLASS_NAME), - new AttributesDescriptor(this, "Class reference", DefaultLanguageHighlighterColors.CLASS_REFERENCE), - new AttributesDescriptor(this, "Instance method", DefaultLanguageHighlighterColors.INSTANCE_METHOD), - new AttributesDescriptor(this, "Instance field", DefaultLanguageHighlighterColors.INSTANCE_FIELD), - new AttributesDescriptor(this, "Static method", DefaultLanguageHighlighterColors.STATIC_METHOD), - new AttributesDescriptor(this, "Static field", DefaultLanguageHighlighterColors.STATIC_FIELD), - new AttributesDescriptor(this, "Template language", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR), - }; - } + private final static AttributesDescriptor[] ATTRIBUTES_DESCRIPTORS = { + new AttributesDescriptor("Keyword", DefaultLanguageHighlighterColors.KEYWORD), + new AttributesDescriptor("Identifier", DefaultLanguageHighlighterColors.IDENTIFIER), + new AttributesDescriptor("String", DefaultLanguageHighlighterColors.STRING), + new AttributesDescriptor("Number", DefaultLanguageHighlighterColors.NUMBER), + new AttributesDescriptor("Operation sign", DefaultLanguageHighlighterColors.OPERATION_SIGN), + new AttributesDescriptor("Braces", DefaultLanguageHighlighterColors.BRACES), + new AttributesDescriptor("Parentheses", DefaultLanguageHighlighterColors.PARENTHESES), + new AttributesDescriptor("Brackets", DefaultLanguageHighlighterColors.BRACKETS), + new AttributesDescriptor("Dot", DefaultLanguageHighlighterColors.DOT), + new AttributesDescriptor("Comma", DefaultLanguageHighlighterColors.COMMA), + new AttributesDescriptor("Semicolon", DefaultLanguageHighlighterColors.SEMICOLON), + new AttributesDescriptor("Line comment", DefaultLanguageHighlighterColors.LINE_COMMENT), + new AttributesDescriptor("Block comment", DefaultLanguageHighlighterColors.BLOCk_COMMENT), + new AttributesDescriptor("Doc comment", DefaultLanguageHighlighterColors.DOC_COMMENT), + new AttributesDescriptor("Function declaration", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION), + new AttributesDescriptor("Function call", DefaultLanguageHighlighterColors.FUNCTION_CALL), + new AttributesDescriptor("Parameter", DefaultLanguageHighlighterColors.PARAMETER), + new AttributesDescriptor("Class name", DefaultLanguageHighlighterColors.CLASS_NAME), + new AttributesDescriptor("Class reference", DefaultLanguageHighlighterColors.CLASS_REFERENCE), + new AttributesDescriptor("Instance method", DefaultLanguageHighlighterColors.INSTANCE_METHOD), + new AttributesDescriptor("Instance field", DefaultLanguageHighlighterColors.INSTANCE_FIELD), + new AttributesDescriptor("Static method", DefaultLanguageHighlighterColors.STATIC_METHOD), + new AttributesDescriptor("Static field", DefaultLanguageHighlighterColors.STATIC_FIELD), + new AttributesDescriptor("Template language", DefaultLanguageHighlighterColors.TEMPLATE_LANGUAGE_COLOR), + }; @Nullable @Override @@ -146,7 +142,7 @@ public class DefaultLanguageColorsPage implements ColorSettingsPage, DisplayPrio @NotNull @Override public AttributesDescriptor[] getAttributeDescriptors() { - return myAttributesDescriptors; + return ATTRIBUTES_DESCRIPTORS; } @NotNull