javax.swing.text
public class GlyphView extends View implements TabableView, Cloneable
View
subclass paints the
characters of the Element
it is responsible for using
the style information from that Element
.Modifier and Type | Class and Description |
---|---|
static class |
GlyphView.GlyphPainter
An abstract base implementation for a glyph painter for
GlyphView . |
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
Constructor and Description |
---|
GlyphView(Element element)
Creates a new
GlyphView for the given Element . |
Modifier and Type | Method and Description |
---|---|
View |
breakView(int axis,
int p0,
float pos,
float len)
Tries to break the view near the specified view span
len . |
void |
changedUpdate(DocumentEvent e,
Shape a,
ViewFactory vf)
Receives notification that some text attributes have changed within the
text fragment that this view is responsible for.
|
protected void |
checkPainter()
Checks if a
GlyphPainer is installed. |
protected Object |
clone()
Creates and returns a shallow clone of this GlyphView.
|
View |
createFragment(int p0,
int p1)
Creates a fragment view of this view that starts at
p0 and
ends at p1 . |
float |
getAlignment(int axis)
Returns the alignment of this view along the specified axis.
|
Color |
getBackground()
Returns the background color which should be used to paint the text.
|
int |
getBreakWeight(int axis,
float pos,
float len)
Determines how well the specified view location is suitable for inserting
a line break.
|
int |
getEndOffset()
Returns the end offset in the document model of the portion
of text that this view is responsible for.
|
Font |
getFont()
Returns the font for the text run for which this
GlyphView
is responsible. |
Color |
getForeground()
Returns the foreground color which should be used to paint the text.
|
GlyphView.GlyphPainter |
getGlyphPainter()
Returns the
GlyphPainter that is used by this
GlyphView . |
int |
getNextVisualPositionFrom(int pos,
Position.Bias bias,
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.
|
float |
getPartialSpan(int p0,
int p1)
Returns the span of a portion of the view.
|
float |
getPreferredSpan(int axis)
Returns the preferred span of the content managed by this
View along the specified axis . |
int |
getStartOffset()
Returns the start offset in the document model of the portion
of text that this view is responsible for.
|
float |
getTabbedSpan(float x,
TabExpander te)
Returns the preferred span of this view for tab expansion.
|
TabExpander |
getTabExpander()
Return the
TabExpander to use. |
Segment |
getText(int p0,
int p1)
Returns the text segment that this view is responsible for.
|
void |
insertUpdate(DocumentEvent e,
Shape a,
ViewFactory vf)
Receives notification that some text has been inserted within the
text fragment that this view is responsible for.
|
boolean |
isStrikeThrough()
Determines whether the text should be rendered strike-through or not.
|
boolean |
isSubscript()
Determines whether the text should be rendered as subscript or not.
|
boolean |
isSuperscript()
Determines whether the text should be rendered as superscript or not.
|
boolean |
isUnderline()
Determines whether the text should be rendered as underlined or not.
|
Shape |
modelToView(int pos,
Shape a,
Position.Bias b)
Maps a position in the document into the coordinate space of the View.
|
void |
paint(Graphics g,
Shape a)
Renders the
Element that is associated with this
View . |
void |
removeUpdate(DocumentEvent e,
Shape a,
ViewFactory vf)
Receives notification that some text has been removed within the
text fragment that this view is responsible for.
|
void |
setGlyphPainter(GlyphView.GlyphPainter painter)
Sets the
GlyphView.GlyphPainter to be used for this GlyphView . |
int |
viewToModel(float x,
float y,
Shape a,
Position.Bias[] b)
Maps coordinates from the
View 's space into a position
in the document model. |
append, dump, forwardUpdate, forwardUpdateToView, getAttributes, getChildAllocation, getContainer, getDocument, getElement, getGraphics, getMaximumSpan, getMinimumSpan, getParent, getResizeWeight, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, replace, setParent, setSize, updateChildren, updateLayout, viewToModel
public GlyphView.GlyphPainter getGlyphPainter()
GlyphPainter
that is used by this
GlyphView
. If no GlyphPainer
has been installed
null
is returned.null
if no glyph painter has been
installedpublic void setGlyphPainter(GlyphView.GlyphPainter painter)
GlyphView.GlyphPainter
to be used for this GlyphView
.painter
- the glyph painter to be used for this glyph viewprotected void checkPainter()
GlyphPainer
is installed. If this is not the
case, a default painter is installed.public float getPreferredSpan(int axis)
View
along the specified axis
.getPreferredSpan
in class View
axis
- the axisView
.public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
modelToView
in class View
pos
- the position of the character in the modela
- the area that is occupied by the viewb
- either Position.Bias.Forward
or
Position.Bias.Backward
depending on the preferred
direction bias. If null
this defaults to
Position.Bias.Forward
BadLocationException
- if pos
is invalidIllegalArgumentException
- if b is not one of the above listed
valid valuespublic int viewToModel(float x, float y, Shape a, Position.Bias[] b)
View
's space into a position
in the document model.viewToModel
in class View
x
- the x coordinate in the view spacey
- the y coordinate in the view spacea
- the allocation of this View
b
- the bias to usex, y
public TabExpander getTabExpander()
TabExpander
to use.TabExpander
to usepublic float getTabbedSpan(float x, TabExpander te)
getTabbedSpan
in interface TabableView
x
- the location of the viewte
- the tab expander to usepublic float getPartialSpan(int p0, int p1)
getPartialSpan
in interface TabableView
p0
- the start indexp1
- the end indexpublic int getStartOffset()
getStartOffset
in class View
public int getEndOffset()
getEndOffset
in class View
public Segment getText(int p0, int p1)
p0
- the start index in the document modelp1
- the end index in the document modelpublic Font getFont()
GlyphView
is responsible.GlyphView
is responsiblepublic Color getForeground()
StyleConstants.getForeground(javax.swing.text.AttributeSet)
.public Color getBackground()
StyleConstants.getBackground(javax.swing.text.AttributeSet)
.public boolean isStrikeThrough()
StyleConstants.isStrikeThrough(AttributeSet)
on the element of
this view.public boolean isSubscript()
StyleConstants.isSubscript(AttributeSet)
on the element of
this view.public boolean isSuperscript()
StyleConstants.isSuperscript(AttributeSet)
on the element of
this view.public boolean isUnderline()
StyleConstants.isUnderline(AttributeSet)
on the element of
this view.protected final Object clone()
createFragment(int, int)
and breakView(int, int, float, float)
methods.public View breakView(int axis, int p0, float pos, float len)
len
.
The glyph view can only be broken in the X direction. For Y direction it
returns itself.breakView
in class View
axis
- the axis for breaking, may be View.X_AXIS
or
View.Y_AXIS
p0
- the model location where the fragment should startpos
- the view position along the axis where the fragment startslen
- the desired length of the fragment viewthis
if breaking was not
possiblepublic int getBreakWeight(int axis, float pos, float len)
axis
is View.Y_AXIS
, then
this method forwards to the superclass, if axis
is
View.X_AXIS
then this method returns
View.ExcellentBreakWeight
if there is a suitable break location
(usually whitespace) within the specified view span, or
View.GoodBreakWeight
if not.getBreakWeight
in class View
axis
- the axis along which the break weight is requestedpos
- the starting view locationlen
- the length of the span at which the view should be brokenpublic void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf)
View.preferenceChanged(View, boolean, boolean)
on the parent for
both width and height.changedUpdate
in class View
e
- the document event describing the change; not used herea
- the view allocation on screen; not used herevf
- the view factory; not used herepublic void insertUpdate(DocumentEvent e, Shape a, ViewFactory vf)
View.preferenceChanged(View, boolean, boolean)
for the
direction in which the glyphs are rendered.insertUpdate
in class View
e
- the document event describing the change; not used herea
- the view allocation on screen; not used herevf
- the view factory; not used herepublic void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf)
View.preferenceChanged(View, boolean, boolean)
on the parent for
width.removeUpdate
in class View
e
- the document event describing the change; not used herea
- the view allocation on screen; not used herevf
- the view factory; not used herepublic View createFragment(int p0, int p1)
p0
and
ends at p1
.createFragment
in class View
p0
- the start location for the fragment viewp1
- the end location for the fragment viewpublic float getAlignment(int axis)
(height - descent) / height
for the used font,
so that it is aligned along the baseline.
For the X axis the superclass is called.getAlignment
in class View
axis
- the axispublic int getNextVisualPositionFrom(int pos, Position.Bias bias, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
getNextVisualPositionFrom
in class View
pos
- the current model locationbias
- the bias for p
a
- the allocated region for the glyph viewdirection
- the direction from the current position; Must be one of
SwingConstants.EAST
, SwingConstants.WEST
,
SwingConstants.NORTH
or SwingConstants.SOUTH
biasRet
- filled with the bias of the resulting location when method
returnsBadLocationException
- if pos
is an invalid model
locationIllegalArgumentException
- if d
is invalid