Skip to content

Commit 01fb0c8

Browse files
committedSep 3, 2016
Use NetBeans utilities for font color settings
1 parent 0e5a868 commit 01fb0c8

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed
 

‎pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
<artifactId>org-netbeans-modules-editor</artifactId>
115115
<version>RELEASE80</version>
116116
</dependency>
117+
<dependency>
118+
<groupId>org.netbeans.api</groupId>
119+
<artifactId>org-netbeans-modules-editor-util</artifactId>
120+
<version>RELEASE80</version>
121+
</dependency>
117122
</dependencies>
118123
<properties>
119124
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

‎src/main/java/de/markiewb/netbeans/plugins/outline/ColorAndFontProvider.java

+13-17
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
import javax.swing.text.JTextComponent;
2525
import javax.swing.text.StyleConstants;
2626
import org.netbeans.api.editor.mimelookup.MimeLookup;
27+
import org.netbeans.api.editor.settings.FontColorNames;
2728
import org.netbeans.api.editor.settings.FontColorSettings;
28-
import org.netbeans.modules.editor.NbEditorUtilities;
29+
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
2930

3031
/**
3132
*
@@ -37,21 +38,11 @@ public class ColorAndFontProvider {
3738
* Get the colour for drawing text.
3839
*/
3940
public static Color getTextColor(JTextComponent jtc) {
40-
String mimeType = NbEditorUtilities.getMimeType(jtc);
41-
FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
42-
AttributeSet fontColors = fcs.getFontColors("default");
43-
Color fg = (Color) fontColors.getAttribute(StyleConstants.Foreground);
44-
return fg;
45-
// JTextComponent host = (JTextComponent) getContainer();
46-
// return (host.isEnabled()) ? host.getForeground() : host.getDisabledTextColor();
41+
return StyleConstants.getForeground(getFontColors(jtc));
4742
}
4843

4944
public static Color getBackgroundColor(JTextComponent jtc) {
50-
String mimeType = NbEditorUtilities.getMimeType(jtc);
51-
FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
52-
AttributeSet fontColors = fcs.getFontColors("default");
53-
Color bg = (Color) fontColors.getAttribute(StyleConstants.Background);
54-
return bg;
45+
return StyleConstants.getBackground(getFontColors(jtc));
5546
}
5647

5748
public static Color getHighlightColor(JTextComponent jtc) {
@@ -61,11 +52,16 @@ public static Color getHighlightColor(JTextComponent jtc) {
6152
public static Font getFont(JTextComponent jtc) {
6253
String defaultFontName = "Monospaced";
6354

64-
String mimeType = NbEditorUtilities.getMimeType(jtc);
65-
FontColorSettings fcs = MimeLookup.getLookup(mimeType).lookup(FontColorSettings.class);
66-
String fontName = (String) fcs.getFontColors("default").getAttribute(StyleConstants.FontFamily);
67-
55+
String fontName = StyleConstants.getFontFamily(getFontColors(jtc));
56+
6857
Font smallFont = new Font(fontName != null ? fontName : defaultFontName, Font.PLAIN, Options.getFontSize());
6958
return smallFont;
7059
}
60+
61+
private static AttributeSet getFontColors(JTextComponent textComponent) {
62+
String mimeType = DocumentUtilities.getMimeType(textComponent);
63+
return MimeLookup.getLookup(mimeType)
64+
.lookup(FontColorSettings.class)
65+
.getFontColors(FontColorNames.DEFAULT_COLORING);
66+
}
7167
}

0 commit comments

Comments
 (0)