2424import javax .swing .text .JTextComponent ;
2525import javax .swing .text .StyleConstants ;
2626import org .netbeans .api .editor .mimelookup .MimeLookup ;
27+ import org .netbeans .api .editor .settings .FontColorNames ;
2728import 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