Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use NetBeans utilities for font color settings #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(getFontAttributes(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(getFontAttributes(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(getFontAttributes(jtc));

Font smallFont = new Font(fontName != null ? fontName : defaultFontName, Font.PLAIN, Options.getFontSize());
return smallFont;
}

private static AttributeSet getFontAttributes(JTextComponent textComponent) {
String mimeType = DocumentUtilities.getMimeType(textComponent);
return MimeLookup.getLookup(mimeType)
.lookup(FontColorSettings.class)
.getFontColors(FontColorNames.DEFAULT_COLORING);
}
}