javax.swing.text
Class GlyphPainter2

java.lang.Object
  extended byjavax.swing.text.GlyphView.GlyphPainter
      extended byjavax.swing.text.GlyphPainter2

class GlyphPainter2
extends GlyphView.GlyphPainter

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 Java 2 SDK. It uses the java.awt.font.TextLayout class to do i18n capable rendering.

Author:
Timothy Prinzing
See Also:
GlyphView

Field Summary
(package private)  TextLayout layout
           
 
Constructor Summary
GlyphPainter2(TextLayout layout)
           
 
Method Summary
 float getAscent(GlyphView v)
          Fetch the ascent above the baseline for the glyphs corresponding to the given range in the model.
 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.
 float getDescent(GlyphView v)
          Fetch the descent below the baseline for the glyphs corresponding to the given range in the model.
 float getHeight(GlyphView v)
           
 int getNextVisualPositionFrom(GlyphView v, int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
          Provides a way to determine the next visually represented model location that one might place a caret.
 GlyphView.GlyphPainter getPainter(GlyphView v, int p0, int p1)
          Create a painter to use for the given GlyphView.
 float getSpan(GlyphView v, int p0, int p1, TabExpander e, float x)
          Determine the span the glyphs given a start location (for tab expansion).
 Shape modelToView(GlyphView v, int pos, Position.Bias bias, Shape a)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 void paint(GlyphView v, Graphics g, Shape a, int p0, int p1)
          Paint the glyphs for the given view.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

layout

TextLayout layout
Constructor Detail

GlyphPainter2

public GlyphPainter2(TextLayout layout)
Method Detail

getPainter

public GlyphView.GlyphPainter getPainter(GlyphView v,
                                         int p0,
                                         int p1)
Create a painter to use for the given GlyphView.

Overrides:
getPainter in class GlyphView.GlyphPainter
Parameters:
v - the GlyphView to provide a painter for
p0 - the starting document offset >= 0
p1 - the ending document offset >= p0

getSpan

public float getSpan(GlyphView v,
                     int p0,
                     int p1,
                     TabExpander e,
                     float x)
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).

Specified by:
getSpan in class GlyphView.GlyphPainter

getHeight

public float getHeight(GlyphView v)
Specified by:
getHeight in class GlyphView.GlyphPainter

getAscent

public float getAscent(GlyphView v)
Fetch the ascent above the baseline for the glyphs corresponding to the given range in the model.

Specified by:
getAscent in class GlyphView.GlyphPainter

getDescent

public float getDescent(GlyphView v)
Fetch the descent below the baseline for the glyphs corresponding to the given range in the model.

Specified by:
getDescent in class GlyphView.GlyphPainter

paint

public void paint(GlyphView v,
                  Graphics g,
                  Shape a,
                  int p0,
                  int p1)
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 Java2 SDK).

Specified by:
paint in class GlyphView.GlyphPainter

modelToView

public Shape modelToView(GlyphView v,
                         int pos,
                         Position.Bias bias,
                         Shape a)
                  throws BadLocationException
Description copied from class: GlyphView.GlyphPainter
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.

Specified by:
modelToView in class GlyphView.GlyphPainter
Parameters:
v - the GlyphView containing the destination coordinate space
pos - the position to convert
bias - either Position.Bias.Forward or Position.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:
View.modelToView(int, java.awt.Shape, javax.swing.text.Position.Bias)

viewToModel

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

Specified by:
viewToModel in class GlyphView.GlyphPainter
Parameters:
v - the view containing the view coordinates
x - the X coordinate
y - the Y coordinate
a - the allocated region to render into
biasReturn - either Position.Bias.Forward or Position.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:
View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])

getBoundedPosition

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

Specified by:
getBoundedPosition in class GlyphView.GlyphPainter
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.
len - specifies the distance into the view where a potential break is desired >= 0.
x - the graphic location along the axis that the broken view would occupy >= 0. This may be useful for things like tab calculations.
Returns:
the maximum model location possible for a break.
See Also:
View.breakView(int, int, float, float)

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.

Overrides:
getNextVisualPositionFrom in class GlyphView.GlyphPainter
Parameters:
v - the view to use
pos - the position to convert >= 0
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.
b - either Position.Bias.Forward or Position.Bias.Backward
biasRet - either Position.Bias.Forward or Position.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
IllegalArgumentException - for an invalid direction