24
24
import javax .swing .text .JTextComponent ;
25
25
import javax .swing .text .StyleConstants ;
26
26
import org .netbeans .api .editor .mimelookup .MimeLookup ;
27
+ import org .netbeans .api .editor .settings .FontColorNames ;
27
28
import org .netbeans .api .editor .settings .FontColorSettings ;
28
- import org .netbeans .modules .editor .NbEditorUtilities ;
29
+ import org .netbeans .lib .editor .util . swing . DocumentUtilities ;
29
30
30
31
/**
31
32
*
@@ -37,21 +38,11 @@ public class ColorAndFontProvider {
37
38
* Get the colour for drawing text.
38
39
*/
39
40
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 ));
47
42
}
48
43
49
44
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 ));
55
46
}
56
47
57
48
public static Color getHighlightColor (JTextComponent jtc ) {
@@ -61,11 +52,16 @@ public static Color getHighlightColor(JTextComponent jtc) {
61
52
public static Font getFont (JTextComponent jtc ) {
62
53
String defaultFontName = "Monospaced" ;
63
54
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
+
68
57
Font smallFont = new Font (fontName != null ? fontName : defaultFontName , Font .PLAIN , Options .getFontSize ());
69
58
return smallFont ;
70
59
}
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
+ }
71
67
}
0 commit comments