Skip to content

Commit

Permalink
Use NetBeans utilities for font color settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Shredder121 committed Sep 3, 2016
1 parent 0e5a868 commit 01fb0c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<artifactId>org-netbeans-modules-editor</artifactId>
<version>RELEASE80</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-editor-util</artifactId>
<version>RELEASE80</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand All @@ -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) {
Expand All @@ -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);
}
}

0 comments on commit 01fb0c8

Please sign in to comment.