javax.swing.text

Class GlyphView.GlyphPainter

public abstract static class GlyphView.GlyphPainter extends Object

An abstract base implementation for a glyph painter for GlyphView.
Constructor Summary
GlyphPainter()
Creates a new GlyphPainer.
Method Summary
abstract floatgetAscent(GlyphView v)
Returns the ascent of the font that is used by this glyph painter.
abstract intgetBoundedPosition(GlyphView v, int p0, float x, float len)
Determines the model offset, so that the text between p0 and this offset fits within the span starting at x with the length of len.
abstract floatgetDescent(GlyphView v)
Returns the descent of the font that is used by this glyph painter.
abstract floatgetHeight(GlyphView view)
Returns the full height of the rendered text.
intgetNextVisualPositionFrom(GlyphView v, int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the model location that should be used to place a caret when moving the caret through the document.
GlyphView.GlyphPaintergetPainter(GlyphView v, int p0, int p1)
Returns a painter that can be used to render the specified glyph view.
abstract floatgetSpan(GlyphView view, int p0, int p1, TabExpander te, float x)
Determine the span of the glyphs from location p0 to location p1.
abstract ShapemodelToView(GlyphView view, int pos, Position.Bias b, Shape a)
Maps a position in the document into the coordinate space of the View.
abstract voidpaint(GlyphView view, Graphics g, Shape a, int p0, int p1)
Paints the glyphs.
abstract intviewToModel(GlyphView v, float x, float y, Shape a, Position.Bias[] biasRet)
Maps a visual position into a document location.

Constructor Detail

GlyphPainter

public GlyphPainter()
Creates a new GlyphPainer.

Method Detail

getAscent

public abstract float getAscent(GlyphView v)
Returns the ascent of the font that is used by this glyph painter.

Parameters: v the glyph view

Returns: the ascent of the font that is used by this glyph painter

getBoundedPosition

public abstract int getBoundedPosition(GlyphView v, int p0, float x, float len)
Determines the model offset, so that the text between p0 and this offset fits within the span starting at x with the length of len.

Parameters: v the glyph view p0 the starting offset in the model x the start location in the view len the length of the span in the view

getDescent

public abstract float getDescent(GlyphView v)
Returns the descent of the font that is used by this glyph painter.

Parameters: v the glyph view

Returns: the descent of the font that is used by this glyph painter

getHeight

public abstract float getHeight(GlyphView view)
Returns the full height of the rendered text.

Returns: the full height of the rendered text

getNextVisualPositionFrom

public int getNextVisualPositionFrom(GlyphView v, int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the model location that should be used to place a caret when moving the caret through the document.

Parameters: v the glyph view pos the current model location b the bias for p a the allocated region for the glyph view direction the direction from the current position; Must be one of {@link SwingConstants#EAST}, {@link SwingConstants#WEST}, {@link SwingConstants#NORTH} or {@link SwingConstants#SOUTH} biasRet filled with the bias of the resulting location when method returns

Returns: the location within the document that should be used to place the caret when moving the caret around the document

Throws: BadLocationException if pos is an invalid model location IllegalArgumentException if d is invalid

getPainter

public GlyphView.GlyphPainter getPainter(GlyphView v, int p0, int p1)
Returns a painter that can be used to render the specified glyph view. If this glyph painter is stateful, then it should return a new instance. However, if this painter is stateless it should return itself. The default behaviour is to return itself.

Parameters: v the glyph view for which to create a painter p0 the start offset of the rendered area p1 the end offset of the rendered area

Returns: a painter that can be used to render the specified glyph view

getSpan

public abstract float getSpan(GlyphView view, int p0, int p1, TabExpander te, float x)
Determine the span of the glyphs from location p0 to location p1. If te is not null, then TABs are expanded using this TabExpander. The parameter x is the location at which the view is located (this is important when using TAB expansion).

Parameters: view the glyph view p0 the starting location in the document model p1 the end location in the document model te the tab expander to use x the location at which the view is located

Returns: the span of the glyphs from location p0 to location p1, possibly using TAB expansion

modelToView

public abstract Shape modelToView(GlyphView view, int pos, Position.Bias b, Shape a)
Maps a position in the document into the coordinate space of the View. The output rectangle usually reflects the font height but has a width of zero.

Parameters: view the glyph view pos the position of the character in the model a the area that is occupied by the view b either {@link Position.Bias#Forward} or {@link Position.Bias#Backward} depending on the preferred direction bias. If null this defaults to Position.Bias.Forward

Returns: a rectangle that gives the location of the document position inside the view coordinate space

Throws: BadLocationException if pos is invalid IllegalArgumentException if b is not one of the above listed valid values

paint

public abstract void paint(GlyphView view, Graphics g, Shape a, int p0, int p1)
Paints the glyphs.

Parameters: view the glyph view to paint g the graphics context to use for painting a the allocation of the glyph view p0 the start position (in the model) from which to paint p1 the end position (in the model) to which to paint

viewToModel

public abstract int viewToModel(GlyphView v, float x, float y, Shape a, Position.Bias[] biasRet)
Maps a visual position into a document location.

Parameters: v the glyph view x the X coordinate of the visual position y the Y coordinate of the visual position a the allocated region biasRet filled with the bias of the model location on method exit

Returns: the model location that represents the specified view location