From 01fb0c8d14de8d8f1a127367b9aab3d224e6379f Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Sat, 3 Sep 2016 14:58:04 +0200 Subject: [PATCH] Use NetBeans utilities for font color settings --- pom.xml | 5 ++++ .../plugins/outline/ColorAndFontProvider.java | 30 ++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 74fa162..8ddf35f 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,11 @@ org-netbeans-modules-editor RELEASE80 + + org.netbeans.api + org-netbeans-modules-editor-util + RELEASE80 + UTF-8 diff --git a/src/main/java/de/markiewb/netbeans/plugins/outline/ColorAndFontProvider.java b/src/main/java/de/markiewb/netbeans/plugins/outline/ColorAndFontProvider.java index 6970c61..13a0b3e 100644 --- a/src/main/java/de/markiewb/netbeans/plugins/outline/ColorAndFontProvider.java +++ b/src/main/java/de/markiewb/netbeans/plugins/outline/ColorAndFontProvider.java @@ -24,8 +24,9 @@ import javax.swing.text.JTextComponent; import javax.swing.text.StyleConstants; import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.settings.FontColorNames; import org.netbeans.api.editor.settings.FontColorSettings; -import org.netbeans.modules.editor.NbEditorUtilities; +import org.netbeans.lib.editor.util.swing.DocumentUtilities; /** * @@ -37,21 +38,11 @@ public class ColorAndFontProvider { * Get the colour for drawing text. */ public static Color getTextColor(JTextComponent jtc) { - String mimeType = NbEditorUtilities.getMimeType(jtc); - FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); - AttributeSet fontColors = fcs.getFontColors("default"); - Color fg = (Color) fontColors.getAttribute(StyleConstants.Foreground); - return fg; -// JTextComponent host = (JTextComponent) getContainer(); -// return (host.isEnabled()) ? host.getForeground() : host.getDisabledTextColor(); + return StyleConstants.getForeground(getFontColors(jtc)); } public static Color getBackgroundColor(JTextComponent jtc) { - String mimeType = NbEditorUtilities.getMimeType(jtc); - FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); - AttributeSet fontColors = fcs.getFontColors("default"); - Color bg = (Color) fontColors.getAttribute(StyleConstants.Background); - return bg; + return StyleConstants.getBackground(getFontColors(jtc)); } public static Color getHighlightColor(JTextComponent jtc) { @@ -61,11 +52,16 @@ public static Color getHighlightColor(JTextComponent jtc) { public static Font getFont(JTextComponent jtc) { String defaultFontName = "Monospaced"; - String mimeType = NbEditorUtilities.getMimeType(jtc); - FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class); - String fontName = (String) fcs.getFontColors("default").getAttribute(StyleConstants.FontFamily); - + String fontName = StyleConstants.getFontFamily(getFontColors(jtc)); + Font smallFont = new Font(fontName != null ? fontName : defaultFontName, Font.PLAIN, Options.getFontSize()); return smallFont; } + + private static AttributeSet getFontColors(JTextComponent textComponent) { + String mimeType = DocumentUtilities.getMimeType(textComponent); + return MimeLookup.getLookup(mimeType) + .lookup(FontColorSettings.class) + .getFontColors(FontColorNames.DEFAULT_COLORING); + } }