Class GlyphView.GlyphPainter
java.lang.Object
javax.swing.text.GlyphView.GlyphPainter
- Enclosing class:
- GlyphView
public abstract static class GlyphView.GlyphPainter extends Object
A class to perform rendering of the glyphs. This can be implemented to be stateless, or to hold some information as a cache to facilitate faster rendering and model/view translation. At a minimum, the GlyphPainter allows a View implementation to perform its duties independent of a particular version of JVM and selection of capabilities (i.e. shaping for i18n, etc).
- Since:
- 1.3
Constructor Summary
Modifier | Constructor | Description |
---|---|---|
protected |
Constructor for subclasses to call. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
abstract float |
getAscent |
Returns of the ascent. |
abstract int |
getBoundedPosition |
Determines the model location that represents the maximum advance that fits within the given span. |
abstract float |
getDescent |
Returns of the descent. |
abstract float |
getHeight |
Returns of the height. |
int |
getNextVisualPositionFrom |
Provides a way to determine the next visually represented model location that one might place a caret. |
GlyphView.GlyphPainter |
getPainter |
Create a painter to use for the given GlyphView. |
abstract float |
getSpan |
Determine the span the glyphs given a start location (for tab expansion). |
abstract Shape |
modelToView |
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. |
abstract void |
paint |
Paint the glyphs representing the given range. |
abstract int |
viewToModel |
Provides a mapping from the view coordinate space to the logical coordinate space of the model. |
Constructor Details
GlyphPainter
protected GlyphPainter()
Constructor for subclasses to call.
Method Details
getSpan
public abstract float getSpan(GlyphView v, int p0, int p1, TabExpander e, float x)
Determine the span the glyphs given a start location (for tab expansion).
- Parameters:
-
v
- theGlyphView
-
p0
- the beginning position -
p1
- the ending position -
e
- how to expand the tabs when encountered -
x
- the X coordinate - Returns:
- the span the glyphs given a start location
getHeight
public abstract float getHeight(GlyphView v)
Returns of the height.
- Parameters:
-
v
- theGlyphView
- Returns:
- of the height
getAscent
public abstract float getAscent(GlyphView v)
Returns of the ascent.
- Parameters:
-
v
- theGlyphView
- Returns:
- of the ascent
getDescent
public abstract float getDescent(GlyphView v)
Returns of the descent.
- Parameters:
-
v
- theGlyphView
- Returns:
- of the descent
paint
public abstract void paint(GlyphView v, Graphics g, Shape a, int p0, int p1)
Paint the glyphs representing the given range.
- Parameters:
-
v
- theGlyphView
-
g
- the graphics context -
a
- the current allocation of the view -
p0
- the beginning position -
p1
- the ending position
modelToView
public abstract Shape modelToView(GlyphView v, int pos, Position.Bias bias, Shape a) throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. This is shared by the broken views.
- Parameters:
-
v
- theGlyphView
containing the destination coordinate space -
pos
- the position to convert -
bias
- eitherPosition.Bias.Forward
orPosition.Bias.Backward
-
a
- Bounds of the View - Returns:
- the bounding box of the given position
- Throws:
-
BadLocationException
- if the given position does not represent a valid location in the associated document - See Also:
viewToModel
public abstract int viewToModel(GlyphView v, float x, float y, Shape a, Position.Bias[] biasReturn)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.
- Parameters:
-
v
- theGlyphView
to provide a mapping for -
x
- the X coordinate -
y
- the Y coordinate -
a
- the allocated region to render into -
biasReturn
- eitherPosition.Bias.Forward
orPosition.Bias.Backward
is returned as the zero-th element of this array - Returns:
- the location within the model that best represents the given point of view
- See Also:
getBoundedPosition
public abstract int getBoundedPosition(GlyphView v, int p0, float x, float len)
Determines the model location that represents the maximum advance that fits within the given span. This could be used to break the given view. The result should be a location just shy of the given advance. This differs from viewToModel which returns the closest position which might be proud of the maximum advance.
- Parameters:
-
v
- the view to find the model location to break at. -
p0
- the location in the model where the fragment should start it's representation >= 0. -
x
- the graphic location along the axis that the broken view would occupy >= 0. This may be useful for things like tab calculations. -
len
- specifies the distance into the view where a potential break is desired >= 0. - Returns:
- the maximum model location possible for a break.
- See Also:
getPainter
public GlyphView.GlyphPainter getPainter(GlyphView v, int p0, int p1)
Create a painter to use for the given GlyphView. If the painter carries state it can create another painter to represent a new GlyphView that is being created. If the painter doesn't hold any significant state, it can return itself. The default behavior is to return itself.
- Parameters:
-
v
- theGlyphView
to provide a painter for -
p0
- the starting document offset >= 0 -
p1
- the ending document offset >= p0 - Returns:
- a painter to use for the given GlyphView
getNextVisualPositionFrom
public int getNextVisualPositionFrom(GlyphView v, int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
Provides a way to determine the next visually represented model location that one might place a caret. Some views may not be visible, they might not be in the same order found in the model, or they just might not allow access to some of the locations in the model.
- Parameters:
-
v
- the view to use -
pos
- the position to convert >= 0 -
b
- eitherPosition.Bias.Forward
orPosition.Bias.Backward
-
a
- the allocated region to render into -
direction
- the direction from the current position that can be thought of as the arrow keys typically found on a keyboard. This may be SwingConstants.WEST, SwingConstants.EAST, SwingConstants.NORTH, or SwingConstants.SOUTH. -
biasRet
- eitherPosition.Bias.Forward
orPosition.Bias.Backward
is returned as the zero-th element of this array - Returns:
- the location within the model that best represents the next location visual position.
- Throws:
-
BadLocationException
- for a bad location within a document model -
IllegalArgumentException
- for an invalid direction
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/text/GlyphView.GlyphPainter.html