APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.text

pack-priv Class GlyphPainter2

extends GlyphPainter
Class Inheritance
Imports
java.text.*, java.awt.*, java.awt.font.*, java.awt.geom.Rectangle2D

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).

This implementation is intended for operation under the JDK. It uses the java.awt.font.TextLayout class to do i18n capable rendering.

Author
Timothy Prinzing
See Also
GlyphView

Field Summary

Modifier and TypeField and Description
pack-priv TextLayout

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public float
getAscent(GlyphView v)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getAscent.

Fetch the ascent above the baseline for the glyphs corresponding to the given range in the model.

public int

Returns:

the maximum model location possible for a break.
getBoundedPosition
(GlyphView
the view to find the model location to break at.
v
,
int
the location in the model where the fragment should start it's representation >= 0.
p0
,
float
the graphic location along the axis that the broken view would occupy >= 0. This may be useful for things like tab calculations.
x
,
float
specifies the distance into the view where a potential break is desired >= 0.
len
)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getBoundedPosition.

Determines the model location that represents the maximum advance that fits within the given span.

public float
getDescent(GlyphView v)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getDescent.

Fetch the descent below the baseline for the glyphs corresponding to the given range in the model.

public float
getHeight(GlyphView v)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getHeight.

Returns of the height.

public int

Returns:

the location within the model that best represents the next location visual position.
getNextVisualPositionFrom
(GlyphView
the view to use
v
,
int
the position to convert >= 0
pos
,
Position.Bias b, Shape
the allocated region to render into
a
,
int
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.
direction
,
Position.Bias[] biasRet)

Overrides javax.swing.text.GlyphView.GlyphPainter.getNextVisualPositionFrom.

Provides a way to determine the next visually represented model location that one might place a caret.

public GlyphView.GlyphPainter
getPainter(GlyphView v, int p0, int p1)

Overrides javax.swing.text.GlyphView.GlyphPainter.getPainter.

Create a painter to use for the given GlyphView.

public float
getSpan(GlyphView v, int p0, int p1, TabExpander e, float x)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getSpan.

Determine the span the glyphs given a start location (for tab expansion).

public Shape
modelToView(GlyphView v, int pos, Position.Bias bias, Shape a)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.modelToView.

Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

public void
paint(GlyphView v, Graphics g, Shape a, int p0, int p1)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.paint.

Paint the glyphs for the given view.

public int

Returns:

the location within the model that best represents the given point of view
viewToModel
(GlyphView
the view containing the view coordinates
v
,
float
the X coordinate
x
,
float
the Y coordinate
y
,
Shape
the allocated region to render into
a
,
Position.Bias[]
either Position.Bias.Forward or Position.Bias.Backward is returned as the zero-th element of this array
biasReturn
)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Field Detail

layoutback to summary
pack-priv TextLayout layout

Constructor Detail

GlyphPainter2back to summary
public GlyphPainter2(TextLayout layout)

Method Detail

getAscentback to summary
public float getAscent(GlyphView v)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getAscent.

Fetch the ascent above the baseline for the glyphs corresponding to the given range in the model.

getBoundedPositionback to summary
public int getBoundedPosition(GlyphView v, int p0, float x, float len)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getBoundedPosition.

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:GlyphView

the view to find the model location to break at.

p0:int

the location in the model where the fragment should start it's representation >= 0.

x:float

the graphic location along the axis that the broken view would occupy >= 0. This may be useful for things like tab calculations.

len:float

specifies the distance into the view where a potential break is desired >= 0.

Returns:int

the maximum model location possible for a break.

See Also
View#breakView
getDescentback to summary
public float getDescent(GlyphView v)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getDescent.

Fetch the descent below the baseline for the glyphs corresponding to the given range in the model.

getHeightback to summary
public float getHeight(GlyphView v)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getHeight.

Doc from javax.swing.text.GlyphView.GlyphPainter.getHeight.

Returns of the height.

getNextVisualPositionFromback to summary
public int getNextVisualPositionFrom(GlyphView v, int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException

Overrides javax.swing.text.GlyphView.GlyphPainter.getNextVisualPositionFrom.

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:GlyphView

the view to use

pos:int

the position to convert >= 0

a:Shape

the allocated region to render into

direction:int

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.

Returns:int

the location within the model that best represents the next location visual position.

Exceptions
BadLocationException:

Doc from javax.swing.text.GlyphView.GlyphPainter.getNextVisualPositionFrom.

for a bad location within a document model

IllegalArgumentException:
for an invalid direction
getPainterback to summary
public GlyphView.GlyphPainter getPainter(GlyphView v, int p0, int p1)

Overrides javax.swing.text.GlyphView.GlyphPainter.getPainter.

Create a painter to use for the given GlyphView.

getSpanback to summary
public float getSpan(GlyphView v, int p0, int p1, TabExpander e, float x)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.getSpan.

Determine the span the glyphs given a start location (for tab expansion). This implementation assumes it has no tabs (i.e. TextLayout doesn't deal with tab expansion).

modelToViewback to summary
public Shape modelToView(GlyphView v, int pos, Position.Bias bias, Shape a) throws BadLocationException

Implements abstract javax.swing.text.GlyphView.GlyphPainter.modelToView.

Doc from javax.swing.text.GlyphView.GlyphPainter.modelToView.

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.

Exceptions
BadLocationException:
if the given position does not represent a valid location in the associated document
paintback to summary
public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.paint.

Paint the glyphs for the given view. This is implemented to only render if the Graphics is of type Graphics2D which is required by TextLayout (and this should be the case if running on the JDK).

viewToModelback to summary
public int viewToModel(GlyphView v, float x, float y, Shape a, Position.Bias[] biasReturn)

Implements abstract javax.swing.text.GlyphView.GlyphPainter.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Parameters
v:GlyphView

the view containing the view coordinates

x:float

the X coordinate

y:float

the Y coordinate

a:Shape

the allocated region to render into

biasReturn:Position.Bias[]

either Position.Bias.Forward or Position.Bias.Backward is returned as the zero-th element of this array

Returns:int

the location within the model that best represents the given point of view

See Also
View#viewToModel