1 /* |
1 /* |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
100 |
100 |
101 /** |
101 /** |
102 * Fetch the currently installed glyph painter. |
102 * Fetch the currently installed glyph painter. |
103 * If a painter has not yet been installed, and |
103 * If a painter has not yet been installed, and |
104 * a default was not yet needed, null is returned. |
104 * a default was not yet needed, null is returned. |
|
105 * @return the currently installed glyph painter |
105 */ |
106 */ |
106 public GlyphPainter getGlyphPainter() { |
107 public GlyphPainter getGlyphPainter() { |
107 return painter; |
108 return painter; |
108 } |
109 } |
109 |
110 |
110 /** |
111 /** |
111 * Sets the painter to use for rendering glyphs. |
112 * Sets the painter to use for rendering glyphs. |
|
113 * @param p the painter to use for rendering glyphs |
112 */ |
114 */ |
113 public void setGlyphPainter(GlyphPainter p) { |
115 public void setGlyphPainter(GlyphPainter p) { |
114 painter = p; |
116 painter = p; |
115 } |
117 } |
116 |
118 |
142 * Fetch the background color to use to render the |
144 * Fetch the background color to use to render the |
143 * glyphs. If there is no background color, null should |
145 * glyphs. If there is no background color, null should |
144 * be returned. This is implemented to call |
146 * be returned. This is implemented to call |
145 * <code>StyledDocument.getBackground</code> if the associated |
147 * <code>StyledDocument.getBackground</code> if the associated |
146 * document is a styled document, otherwise it returns null. |
148 * document is a styled document, otherwise it returns null. |
|
149 * @return the background color to use to render the glyphs |
147 */ |
150 */ |
148 public Color getBackground() { |
151 public Color getBackground() { |
149 Document doc = getDocument(); |
152 Document doc = getDocument(); |
150 if (doc instanceof StyledDocument) { |
153 if (doc instanceof StyledDocument) { |
151 AttributeSet attr = getAttributes(); |
154 AttributeSet attr = getAttributes(); |
163 * <code>StyledDocument.getBackground</code> if the associated |
166 * <code>StyledDocument.getBackground</code> if the associated |
164 * document is a StyledDocument. If the associated document |
167 * document is a StyledDocument. If the associated document |
165 * is not a StyledDocument, the associated components foreground |
168 * is not a StyledDocument, the associated components foreground |
166 * color is used. If there is no associated component, null |
169 * color is used. If there is no associated component, null |
167 * is returned. |
170 * is returned. |
|
171 * @return the foreground color to use to render the glyphs |
168 */ |
172 */ |
169 public Color getForeground() { |
173 public Color getForeground() { |
170 Document doc = getDocument(); |
174 Document doc = getDocument(); |
171 if (doc instanceof StyledDocument) { |
175 if (doc instanceof StyledDocument) { |
172 AttributeSet attr = getAttributes(); |
176 AttributeSet attr = getAttributes(); |
185 * <code>StyledDocument.getFont</code> if the associated |
189 * <code>StyledDocument.getFont</code> if the associated |
186 * document is a StyledDocument. If the associated document |
190 * document is a StyledDocument. If the associated document |
187 * is not a StyledDocument, the associated components font |
191 * is not a StyledDocument, the associated components font |
188 * is used. If there is no associated component, null |
192 * is used. If there is no associated component, null |
189 * is returned. |
193 * is returned. |
|
194 * @return the font that the glyphs should be based upon |
190 */ |
195 */ |
191 public Font getFont() { |
196 public Font getFont() { |
192 Document doc = getDocument(); |
197 Document doc = getDocument(); |
193 if (doc instanceof StyledDocument) { |
198 if (doc instanceof StyledDocument) { |
194 AttributeSet attr = getAttributes(); |
199 AttributeSet attr = getAttributes(); |
202 } |
207 } |
203 |
208 |
204 /** |
209 /** |
205 * Determine if the glyphs should be underlined. If true, |
210 * Determine if the glyphs should be underlined. If true, |
206 * an underline should be drawn through the baseline. |
211 * an underline should be drawn through the baseline. |
|
212 * @return if the glyphs should be underlined |
207 */ |
213 */ |
208 public boolean isUnderline() { |
214 public boolean isUnderline() { |
209 AttributeSet attr = getAttributes(); |
215 AttributeSet attr = getAttributes(); |
210 return StyleConstants.isUnderline(attr); |
216 return StyleConstants.isUnderline(attr); |
211 } |
217 } |
212 |
218 |
213 /** |
219 /** |
214 * Determine if the glyphs should have a strikethrough |
220 * Determine if the glyphs should have a strikethrough |
215 * line. If true, a line should be drawn through the center |
221 * line. If true, a line should be drawn through the center |
216 * of the glyphs. |
222 * of the glyphs. |
|
223 * @return if the glyphs should have a strikethrough line |
217 */ |
224 */ |
218 public boolean isStrikeThrough() { |
225 public boolean isStrikeThrough() { |
219 AttributeSet attr = getAttributes(); |
226 AttributeSet attr = getAttributes(); |
220 return StyleConstants.isStrikeThrough(attr); |
227 return StyleConstants.isStrikeThrough(attr); |
221 } |
228 } |
222 |
229 |
223 /** |
230 /** |
224 * Determine if the glyphs should be rendered as superscript. |
231 * Determine if the glyphs should be rendered as superscript. |
|
232 * @return if the glyphs should be rendered as superscript |
225 */ |
233 */ |
226 public boolean isSubscript() { |
234 public boolean isSubscript() { |
227 AttributeSet attr = getAttributes(); |
235 AttributeSet attr = getAttributes(); |
228 return StyleConstants.isSubscript(attr); |
236 return StyleConstants.isSubscript(attr); |
229 } |
237 } |
230 |
238 |
231 /** |
239 /** |
232 * Determine if the glyphs should be rendered as subscript. |
240 * Determine if the glyphs should be rendered as subscript. |
|
241 * @return if the glyphs should be rendered as subscript |
233 */ |
242 */ |
234 public boolean isSuperscript() { |
243 public boolean isSuperscript() { |
235 AttributeSet attr = getAttributes(); |
244 AttributeSet attr = getAttributes(); |
236 return StyleConstants.isSuperscript(attr); |
245 return StyleConstants.isSuperscript(attr); |
237 } |
246 } |
238 |
247 |
239 /** |
248 /** |
240 * Fetch the TabExpander to use if tabs are present in this view. |
249 * Fetch the TabExpander to use if tabs are present in this view. |
|
250 * @return the TabExpander to use if tabs are present in this view |
241 */ |
251 */ |
242 public TabExpander getTabExpander() { |
252 public TabExpander getTabExpander() { |
243 return expander; |
253 return expander; |
244 } |
254 } |
245 |
255 |
1146 public static abstract class GlyphPainter { |
1156 public static abstract class GlyphPainter { |
1147 |
1157 |
1148 /** |
1158 /** |
1149 * Determine the span the glyphs given a start location |
1159 * Determine the span the glyphs given a start location |
1150 * (for tab expansion). |
1160 * (for tab expansion). |
|
1161 * @param v the {@code GlyphView} |
|
1162 * @param p0 the beginning position |
|
1163 * @param p1 the ending position |
|
1164 * @param e how to expand the tabs when encountered |
|
1165 * @param x the X coordinate |
|
1166 * @return the span the glyphs given a start location |
1151 */ |
1167 */ |
1152 public abstract float getSpan(GlyphView v, int p0, int p1, TabExpander e, float x); |
1168 public abstract float getSpan(GlyphView v, int p0, int p1, TabExpander e, float x); |
1153 |
1169 |
|
1170 /** |
|
1171 * Returns of the height. |
|
1172 * @param v the {@code GlyphView} |
|
1173 * @return of the height |
|
1174 */ |
1154 public abstract float getHeight(GlyphView v); |
1175 public abstract float getHeight(GlyphView v); |
1155 |
1176 |
|
1177 /** |
|
1178 * Returns of the ascent. |
|
1179 * @param v the {@code GlyphView} |
|
1180 * @return of the ascent |
|
1181 */ |
1156 public abstract float getAscent(GlyphView v); |
1182 public abstract float getAscent(GlyphView v); |
1157 |
1183 |
|
1184 /** |
|
1185 * Returns of the descent. |
|
1186 * @param v the {@code GlyphView} |
|
1187 * @return of the descent |
|
1188 */ |
1158 public abstract float getDescent(GlyphView v); |
1189 public abstract float getDescent(GlyphView v); |
1159 |
1190 |
1160 /** |
1191 /** |
1161 * Paint the glyphs representing the given range. |
1192 * Paint the glyphs representing the given range. |
|
1193 * @param v the {@code GlyphView} |
|
1194 * @param g the graphics context |
|
1195 * @param a the current allocation of the view |
|
1196 * @param p0 the beginning position |
|
1197 * @param p1 the ending position |
1162 */ |
1198 */ |
1163 public abstract void paint(GlyphView v, Graphics g, Shape a, int p0, int p1); |
1199 public abstract void paint(GlyphView v, Graphics g, Shape a, int p0, int p1); |
1164 |
1200 |
1165 /** |
1201 /** |
1166 * Provides a mapping from the document model coordinate space |
1202 * Provides a mapping from the document model coordinate space |
1229 * the painter doesn't hold any significant state, it can |
1265 * the painter doesn't hold any significant state, it can |
1230 * return itself. The default behavior is to return itself. |
1266 * return itself. The default behavior is to return itself. |
1231 * @param v the <code>GlyphView</code> to provide a painter for |
1267 * @param v the <code>GlyphView</code> to provide a painter for |
1232 * @param p0 the starting document offset >= 0 |
1268 * @param p0 the starting document offset >= 0 |
1233 * @param p1 the ending document offset >= p0 |
1269 * @param p1 the ending document offset >= p0 |
|
1270 * @return a painter to use for the given GlyphView |
1234 */ |
1271 */ |
1235 public GlyphPainter getPainter(GlyphView v, int p0, int p1) { |
1272 public GlyphPainter getPainter(GlyphView v, int p0, int p1) { |
1236 return this; |
1273 return this; |
1237 } |
1274 } |
1238 |
1275 |