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 independant of a particular version
of JVM and selection of capabilities (i.e.
shaping for i18n, etc).
| Method from javax.swing.text.GlyphView$GlyphPainter Detail: |
abstract public float getAscent(GlyphView v)
|
abstract 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. |
abstract public float getDescent(GlyphView v)
|
abstract public float getHeight(GlyphView v)
|
public int getNextVisualPositionFrom(GlyphView v,
int pos,
Position.Bias b,
Shape a,
int direction,
Position.Bias[] biasRet) throws BadLocationException {
int startOffset = v.getStartOffset();
int endOffset = v.getEndOffset();
Segment text;
switch (direction) {
case View.NORTH:
case View.SOUTH:
if (pos != -1) {
// Presumably pos is between startOffset and endOffset,
// since GlyphView is only one line, we won't contain
// the position to the nort/south, therefore return -1.
return -1;
}
Container container = v.getContainer();
if (container instanceof JTextComponent) {
Caret c = ((JTextComponent)container).getCaret();
Point magicPoint;
magicPoint = (c != null) ? c.getMagicCaretPosition() :null;
if (magicPoint == null) {
biasRet[0] = Position.Bias.Forward;
return startOffset;
}
int value = v.viewToModel(magicPoint.x, 0f, a, biasRet);
return value;
}
break;
case View.EAST:
if(startOffset == v.getDocument().getLength()) {
if(pos == -1) {
biasRet[0] = Position.Bias.Forward;
return startOffset;
}
// End case for bidi text where newline is at beginning
// of line.
return -1;
}
if(pos == -1) {
biasRet[0] = Position.Bias.Forward;
return startOffset;
}
if(pos == endOffset) {
return -1;
}
if(++pos == endOffset) {
// Assumed not used in bidi text, GlyphPainter2 will
// override as necessary, therefore return -1.
return -1;
}
else {
biasRet[0] = Position.Bias.Forward;
}
return pos;
case View.WEST:
if(startOffset == v.getDocument().getLength()) {
if(pos == -1) {
biasRet[0] = Position.Bias.Forward;
return startOffset;
}
// End case for bidi text where newline is at beginning
// of line.
return -1;
}
if(pos == -1) {
// Assumed not used in bidi text, GlyphPainter2 will
// override as necessary, therefore return -1.
biasRet[0] = Position.Bias.Forward;
return endOffset - 1;
}
if(pos == startOffset) {
return -1;
}
biasRet[0] = Position.Bias.Forward;
return (pos - 1);
default:
throw new IllegalArgumentException("Bad direction: " + direction);
}
return pos;
}
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. |
public GlyphView.GlyphPainter getPainter(GlyphView v,
int p0,
int p1) {
return this;
}
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. |
abstract 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). |
abstract public 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. |
abstract public void paint(GlyphView v,
Graphics g,
Shape a,
int p0,
int p1)
Paint the glyphs representing the given range. |
abstract 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. |