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

public Class GlyphView

extends View
implements TabableView, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, javax.swing.text.TabableView
Known Direct Subclasses
javax.swing.text.LabelView
Imports
java.awt.*, java.text.BreakIterator, javax.swing.event.*, java.util.BitSet, .Locale, javax.swing.UIManager, sun.swing.SwingUtilities2

A GlyphView is a styled chunk of text that represents a view mapped over an element in the text model. This view is generally responsible for displaying text glyphs using character level attributes in some way. An implementation of the GlyphPainter class is used to do the actual rendering and model/view translations. This separates rendering from layout and management of the association with the model.

The view supports breaking for the purpose of formatting. The fragments produced by breaking share the view that has primary responsibility for the element (i.e. they are nested classes and carry only a small amount of state of their own) so they can share its resources.

Since this view represents text that may have tabs embedded in it, it implements the TabableView interface. Tabs will only be expanded if this view is embedded in a container that does tab expansion. ParagraphView is an example of a container that does tab expansion.

Author
Timothy Prinzing
Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
GlyphView.GlyphPainter

A class to perform rendering of the glyphs.

pack-priv static class
GlyphView.JustificationInfo

Class to hold data needed to justify this GlyphView in a ParagraphView.Row

Field Summary

Modifier and TypeField and Description
private int[]
breakSpots

Cached breakpoints within the view

pack-priv static GlyphView.GlyphPainter
defaultPainter

The prototype painter used by default.

pack-priv TabExpander
expander

how to expand tabs

pack-priv boolean
private GlyphView.JustificationInfo
pack-priv int
private float
minimumSpan

Cached minimum x-span value

pack-priv int
pack-priv GlyphView.GlyphPainter
painter

Glyph rendering functionality.

private byte[]
selections

Used by paint() to store highlighted view positions

pack-priv boolean
pack-priv int
x

location for determining tab expansion against.

Inherited from javax.swing.text.View:
BadBreakWeightExcellentBreakWeightfirstUpdateIndexForcedBreakWeightGoodBreakWeightlastUpdateIndexsharedBiasReturnX_AXISY_AXIS

Constructor Summary

AccessConstructor and Description
public
GlyphView(Element
the element
elem
)

Constructs a new view wrapped on an element.

Method Summary

Modifier and TypeMethod and Description
public View

Returns:

the fragment of the view that represents the given span, if the view can be broken. If the view doesn't support breaking behavior, the view itself is returned.
breakView
(int
may be either View.X_AXIS or View.Y_AXIS
axis
,
int
the location in the model where the fragment should start it's representation >= 0.
p0
,
float
the position along the axis that the broken view would occupy >= 0. This may be useful for things like tab calculations.
pos
,
float
specifies the distance along the axis where a potential break is desired >= 0.
len
)

Overrides javax.swing.text.View.breakView.

Breaks this view on the given axis at the given length.

public void
changedUpdate(DocumentEvent
the change information from the associated document
e
,
Shape
the current allocation of the view
a
,
ViewFactory
the factory to use to rebuild if the view has children
f
)

Overrides javax.swing.text.View.changedUpdate.

Gives notification from the document that attributes were changed in a location that this view is responsible for.

protected void
checkPainter()

Check to see that a glyph painter exists.

protected final Object

Returns:

the copy
clone
()

Overrides java.lang.Object.clone.

Creates a shallow copy.

public View

Returns:

the view fragment, or itself if the view doesn't support breaking into fragments
createFragment
(int
the starting offset >= 0. This should be a value greater or equal to the element starting offset and less than the element ending offset.
p0
,
int
the ending offset > p0. This should be a value less than or equal to the elements end offset and greater than the elements starting offset.
p1
)

Overrides javax.swing.text.View.createFragment.

Creates a view that represents a portion of the element.

public float

Returns:

the desired alignment. This should be a value between 0.0 and 1.0 inclusive, where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin. An alignment of 0.5 would be the center of the view.
getAlignment
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getAlignment.

Determines the desired alignment for this view along an axis.

public Color

Returns:

the background color to use to render the glyphs
getBackground
()

Fetch the background color to use to render the glyphs.

private BreakIterator
getBreaker()

Return break iterator appropriate for the current document.

private int
getBreakSpot(int p0, int p1)

Returns a location to break at in the passed in region, or BreakIterator.DONE if there isn't a good location to break at in the specified region.

public int

Returns:

the weight, which should be a value between View.ForcedBreakWeight and View.BadBreakWeight.
getBreakWeight
(int
may be either View.X_AXIS or View.Y_AXIS
axis
,
float
the potential location of the start of the broken view >= 0. This may be useful for calculating tab positions.
pos
,
float
specifies the relative length from pos where a potential break is desired >= 0.
len
)

Overrides javax.swing.text.View.getBreakWeight.

Determines how attractive a break opportunity in this view is.

public int

Returns:

the ending offset into the model
getEndOffset
()

Overrides javax.swing.text.View.getEndOffset.

Fetches the portion of the model that this view is responsible for.

public Font

Returns:

the font that the glyphs should be based upon
getFont
()

Fetch the font that the glyphs should be based upon.

public Color

Returns:

the foreground color to use to render the glyphs
getForeground
()

Fetch the foreground color to use to render the glyphs.

public GlyphView.GlyphPainter

Returns:

the currently installed glyph painter
getGlyphPainter
()

Fetch the currently installed glyph painter.

pack-priv GlyphView.JustificationInfo
getJustificationInfo(int rowStartOffset)

public float

Returns:

the minimum span the view can be rendered into
getMinimumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getMinimumSpan.

Determines the minimum span for this view along an axis.

public int

Returns:

the location within the model that best represents the next location visual position.
getNextVisualPositionFrom
(int
the position to convert
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.View.getNextVisualPositionFrom.

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

public float

Returns:

the span >= 0
getPartialSpan
(int
the starting document offset >= 0
p0
,
int
the ending document offset >= p0
p1
)

Implements javax.swing.text.TabableView.getPartialSpan.

Determines the span along the same axis as tab expansion for a portion of the view.

public float

Returns:

the span the view would like to be rendered into >= 0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
getPreferredSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Implements abstract javax.swing.text.View.getPreferredSpan.

Determines the preferred span for this view along an axis.

public int

Returns:

the starting offset into the model
getStartOffset
()

Overrides javax.swing.text.View.getStartOffset.

Fetches the portion of the model that this view is responsible for.

public float

Returns:

the desired span >= 0
getTabbedSpan
(float
the position the view would be located at for the purpose of tab expansion >= 0.
x
,
TabExpander
how to expand the tabs when encountered.
e
)

Implements javax.swing.text.TabableView.getTabbedSpan.

Determines the desired span when using the given tab expansion implementation.

public TabExpander

Returns:

the TabExpander to use if tabs are present in this view
getTabExpander
()

Fetch the TabExpander to use if tabs are present in this view.

public Segment

Returns:

the Segment containing the text
getText
(int
the starting document offset >= 0
p0
,
int
the ending document offset >= p0
p1
)

Fetch a reference to the text that occupies the given range.

private void
initSelections(int p0, int p1)

Lazily initializes the selections field

public void
insertUpdate(DocumentEvent
the change information from the associated document
e
,
Shape
the current allocation of the view
a
,
ViewFactory
the factory to use to rebuild if the view has children
f
)

Overrides javax.swing.text.View.insertUpdate.

Gives notification that something was inserted into the document in a location that this view is responsible for.

public boolean

Returns:

true if the glyphs should have a strikethrough line, otherwise false
isStrikeThrough
()

Determine if the glyphs should have a strikethrough line.

public boolean

Returns:

true if the glyphs should be rendered as superscript, otherwise false
isSubscript
()

Determine if the glyphs should be rendered as superscript.

public boolean

Returns:

true if the glyphs should be rendered as subscript, otherwise false
isSuperscript
()

Determine if the glyphs should be rendered as subscript.

public boolean

Returns:

true if the glyphs should be underlined, otherwise false
isUnderline
()

Determine if the glyphs should be underlined.

public Shape

Returns:

the bounding box of the given position
modelToView
(int
the position to convert >= 0
pos
,
Shape
the allocated region to render into
a
,
Position.Bias
either Position.Bias.Forward or Position.Bias.Backward
b
)

Implements abstract javax.swing.text.View.modelToView.

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

public void
paint(Graphics
the rendering surface to use
g
,
Shape
the allocated region to render into
a
)

Implements abstract javax.swing.text.View.paint.

Renders a portion of a text style run.

pack-priv final void
paintTextUsingColor(Graphics g, Shape a, Color c, int p0, int p1)

Paints the specified region of text in the specified color.

public void
removeUpdate(DocumentEvent
the change information from the associated document
e
,
Shape
the current allocation of the view
a
,
ViewFactory
the factory to use to rebuild if the view has children
f
)

Overrides javax.swing.text.View.removeUpdate.

Gives notification that something was removed from the document in a location that this view is responsible for.

public void
setGlyphPainter(GlyphView.GlyphPainter
the painter to use for rendering glyphs
p
)

Sets the painter to use for rendering glyphs.

private void
pack-priv void
updateAfterChange()

Overrides javax.swing.text.View.updateAfterChange.

Updates the view to reflect the changes.

public int

Returns:

the location within the model that best represents the given point of view >= 0
viewToModel
(float
the X coordinate >= 0
x
,
float
the Y coordinate >= 0
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.View.viewToModel.

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

Inherited from javax.swing.text.View:
appendcalculateUpdateIndexesforwardUpdateforwardUpdateToViewgetAttributesgetChildAllocationgetContainergetDocumentgetElementgetGraphicsgetMaximumSpangetParentgetResizeWeightgetToolTipTextgetViewgetViewCountgetViewFactorygetViewIndexgetViewIndexinsertisVisiblemodelToViewmodelToViewpreferenceChangedremoveremoveAllreplacesetParentsetSizeupdateChildrenupdateLayoutviewToModel

Field Detail

breakSpotsback to summary
private int[] breakSpots

Cached breakpoints within the view

defaultPainterback to summary
pack-priv static GlyphView.GlyphPainter defaultPainter

The prototype painter used by default.

expanderback to summary
pack-priv TabExpander expander

how to expand tabs

impliedCRback to summary
pack-priv boolean impliedCR
justificationInfoback to summary
private GlyphView.JustificationInfo justificationInfo
lengthback to summary
pack-priv int length
minimumSpanback to summary
private float minimumSpan

Cached minimum x-span value

offsetback to summary
pack-priv int offset
painterback to summary
pack-priv GlyphView.GlyphPainter painter

Glyph rendering functionality.

selectionsback to summary
private byte[] selections

Used by paint() to store highlighted view positions

skipWidthback to summary
pack-priv boolean skipWidth
xback to summary
pack-priv int x

location for determining tab expansion against.

Constructor Detail

GlyphViewback to summary
public GlyphView(Element elem)

Constructs a new view wrapped on an element.

Parameters
elem:Element

the element

Method Detail

breakViewback to summary
public View breakView(int axis, int p0, float pos, float len)

Overrides javax.swing.text.View.breakView.

Breaks this view on the given axis at the given length. This is implemented to attempt to break on a whitespace location, and returns a fragment with the whitespace at the end. If a whitespace location can't be found, the nearest character is used.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

p0:int

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

pos:float

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

len:float

specifies the distance along the axis where a potential break is desired >= 0.

Returns:View

the fragment of the view that represents the given span, if the view can be broken. If the view doesn't support breaking behavior, the view itself is returned.

See Also
View#breakView
changedUpdateback to summary
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)

Overrides javax.swing.text.View.changedUpdate.

Gives notification from the document that attributes were changed in a location that this view is responsible for. This is implemented to call preferenceChanged along both the horizontal and vertical axis.

Parameters
e:DocumentEvent

the change information from the associated document

a:Shape

the current allocation of the view

f:ViewFactory

the factory to use to rebuild if the view has children

See Also
View#changedUpdate
checkPainterback to summary
protected void checkPainter()

Check to see that a glyph painter exists. If a painter doesn't exist, a default glyph painter will be installed.

cloneback to summary
protected final Object clone()

Overrides java.lang.Object.clone.

Creates a shallow copy. This is used by the createFragment and breakView methods.

Returns:Object

the copy

createFragmentback to summary
public View createFragment(int p0, int p1)

Overrides javax.swing.text.View.createFragment.

Creates a view that represents a portion of the element. This is potentially useful during formatting operations for taking measurements of fragments of the view. If the view doesn't support fragmenting (the default), it should return itself.

This view does support fragmenting. It is implemented to return a nested class that shares state in this view representing only a portion of the view.

Parameters
p0:int

the starting offset >= 0. This should be a value greater or equal to the element starting offset and less than the element ending offset.

p1:int

the ending offset > p0. This should be a value less than or equal to the elements end offset and greater than the elements starting offset.

Returns:View

the view fragment, or itself if the view doesn't support breaking into fragments

See Also
LabelView
getAlignmentback to summary
public float getAlignment(int axis)

Overrides javax.swing.text.View.getAlignment.

Determines the desired alignment for this view along an axis. For the label, the alignment is along the font baseline for the y axis, and the superclasses alignment along the x axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the desired alignment. This should be a value between 0.0 and 1.0 inclusive, where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin. An alignment of 0.5 would be the center of the view.

getBackgroundback to summary
public Color getBackground()

Fetch the background color to use to render the glyphs. If there is no background color, null should be returned. This is implemented to call StyledDocument.getBackground if the associated document is a styled document, otherwise it returns null.

Returns:Color

the background color to use to render the glyphs

getBreakerback to summary
private BreakIterator getBreaker()

Return break iterator appropriate for the current document. For non-i18n documents a fast whitespace-based break iterator is used.

getBreakSpotback to summary
private int getBreakSpot(int p0, int p1)

Returns a location to break at in the passed in region, or BreakIterator.DONE if there isn't a good location to break at in the specified region.

getBreakWeightback to summary
public int getBreakWeight(int axis, float pos, float len)

Overrides javax.swing.text.View.getBreakWeight.

Determines how attractive a break opportunity in this view is. This can be used for determining which view is the most attractive to call breakView on in the process of formatting. The higher the weight, the more attractive the break. A value equal to or lower than View.BadBreakWeight should not be considered for a break. A value greater than or equal to View.ForcedBreakWeight should be broken.

This is implemented to forward to the superclass for the Y_AXIS. Along the X_AXIS the following values may be returned.

View.ExcellentBreakWeight
if there is whitespace proceeding the desired break location.
View.BadBreakWeight
if the desired break location results in a break location of the starting offset.
View.GoodBreakWeight
if the other conditions don't occur.
This will normally result in the behavior of breaking on a whitespace location if one can be found, otherwise breaking between characters.
Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

pos:float

the potential location of the start of the broken view >= 0. This may be useful for calculating tab positions.

len:float

specifies the relative length from pos where a potential break is desired >= 0.

Returns:int

the weight, which should be a value between View.ForcedBreakWeight and View.BadBreakWeight.

See Also
LabelView, ParagraphView, View#BadBreakWeight, View#GoodBreakWeight, View#ExcellentBreakWeight, View#ForcedBreakWeight
getEndOffsetback to summary
public int getEndOffset()

Overrides javax.swing.text.View.getEndOffset.

Fetches the portion of the model that this view is responsible for.

Returns:int

the ending offset into the model

See Also
View#getEndOffset
getFontback to summary
public Font getFont()

Fetch the font that the glyphs should be based upon. This is implemented to call StyledDocument.getFont if the associated document is a StyledDocument. If the associated document is not a StyledDocument, the associated components font is used. If there is no associated component, null is returned.

Returns:Font

the font that the glyphs should be based upon

getForegroundback to summary
public Color getForeground()

Fetch the foreground color to use to render the glyphs. If there is no foreground color, null should be returned. This is implemented to call StyledDocument.getBackground if the associated document is a StyledDocument. If the associated document is not a StyledDocument, the associated components foreground color is used. If there is no associated component, null is returned.

Returns:Color

the foreground color to use to render the glyphs

getGlyphPainterback to summary
public GlyphView.GlyphPainter getGlyphPainter()

Fetch the currently installed glyph painter. If a painter has not yet been installed, and a default was not yet needed, null is returned.

Returns:GlyphView.GlyphPainter

the currently installed glyph painter

getJustificationInfoback to summary
pack-priv GlyphView.JustificationInfo getJustificationInfo(int rowStartOffset)
getMinimumSpanback to summary
public float getMinimumSpan(int axis)

Overrides javax.swing.text.View.getMinimumSpan.

Determines the minimum span for this view along an axis.

This implementation returns the longest non-breakable area within the view as a minimum span for View.X_AXIS.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the minimum span the view can be rendered into

Annotations
@Override
Exceptions
IllegalArgumentException:
if the axis parameter is invalid
See Also
javax.swing.text.View#getMinimumSpan
getNextVisualPositionFromback to summary
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException

Overrides javax.swing.text.View.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. This method enables specifying a position to convert within the range of >=0. If the value is -1, a position will be calculated automatically. If the value < -1, the BadLocationException will be thrown.

Parameters
pos:int

the position to convert

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:
the given position is not a valid position within the document
IllegalArgumentException:
for an invalid direction
getPartialSpanback to summary
public float getPartialSpan(int p0, int p1)

Implements javax.swing.text.TabableView.getPartialSpan.

Determines the span along the same axis as tab expansion for a portion of the view. This is intended for use by the TabExpander for cases where the tab expansion involves aligning the portion of text that doesn't have whitespace relative to the tab stop. There is therefore an assumption that the range given does not contain tabs.

This method can be called while servicing the getTabbedSpan or getPreferredSize. It has to arrange for its own text buffer to make the measurements.

Parameters
p0:int

the starting document offset >= 0

p1:int

the ending document offset >= p0

Returns:float

the span >= 0

getPreferredSpanback to summary
public float getPreferredSpan(int axis)

Implements abstract javax.swing.text.View.getPreferredSpan.

Determines the preferred span for this view along an axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >= 0. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.

getStartOffsetback to summary
public int getStartOffset()

Overrides javax.swing.text.View.getStartOffset.

Fetches the portion of the model that this view is responsible for.

Returns:int

the starting offset into the model

See Also
View#getStartOffset
getTabbedSpanback to summary
public float getTabbedSpan(float x, TabExpander e)

Implements javax.swing.text.TabableView.getTabbedSpan.

Determines the desired span when using the given tab expansion implementation.

Parameters
x:float

the position the view would be located at for the purpose of tab expansion >= 0.

e:TabExpander

how to expand the tabs when encountered.

Returns:float

the desired span >= 0

See Also
TabableView#getTabbedSpan
getTabExpanderback to summary
public TabExpander getTabExpander()

Fetch the TabExpander to use if tabs are present in this view.

Returns:TabExpander

the TabExpander to use if tabs are present in this view

getTextback to summary
public Segment getText(int p0, int p1)

Fetch a reference to the text that occupies the given range. This is normally used by the GlyphPainter to determine what characters it should render glyphs for.

Parameters
p0:int

the starting document offset >= 0

p1:int

the ending document offset >= p0

Returns:Segment

the Segment containing the text

initSelectionsback to summary
private void initSelections(int p0, int p1)

Lazily initializes the selections field

insertUpdateback to summary
public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)

Overrides javax.swing.text.View.insertUpdate.

Gives notification that something was inserted into the document in a location that this view is responsible for. This is implemented to call preferenceChanged along the axis the glyphs are rendered.

Parameters
e:DocumentEvent

the change information from the associated document

a:Shape

the current allocation of the view

f:ViewFactory

the factory to use to rebuild if the view has children

See Also
View#insertUpdate
isStrikeThroughback to summary
public boolean isStrikeThrough()

Determine if the glyphs should have a strikethrough line. If true, a line should be drawn through the center of the glyphs.

Returns:boolean

true if the glyphs should have a strikethrough line, otherwise false

isSubscriptback to summary
public boolean isSubscript()

Determine if the glyphs should be rendered as superscript.

Returns:boolean

true if the glyphs should be rendered as superscript, otherwise false

isSuperscriptback to summary
public boolean isSuperscript()

Determine if the glyphs should be rendered as subscript.

Returns:boolean

true if the glyphs should be rendered as subscript, otherwise false

isUnderlineback to summary
public boolean isUnderline()

Determine if the glyphs should be underlined. If true, an underline should be drawn through the baseline.

Returns:boolean

true if the glyphs should be underlined, otherwise false

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

Implements abstract javax.swing.text.View.modelToView.

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

Parameters
pos:int

the position to convert >= 0

a:Shape

the allocated region to render into

b:Position.Bias

either Position.Bias.Forward or Position.Bias.Backward

Returns:Shape

the bounding box of the given position

Exceptions
BadLocationException:
if the given position does not represent a valid location in the associated document
See Also
View#modelToView
paintback to summary
public void paint(Graphics g, Shape a)

Implements abstract javax.swing.text.View.paint.

Renders a portion of a text style run.

Parameters
g:Graphics

the rendering surface to use

a:Shape

the allocated region to render into

paintTextUsingColorback to summary
pack-priv final void paintTextUsingColor(Graphics g, Shape a, Color c, int p0, int p1)

Paints the specified region of text in the specified color.

removeUpdateback to summary
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)

Overrides javax.swing.text.View.removeUpdate.

Gives notification that something was removed from the document in a location that this view is responsible for. This is implemented to call preferenceChanged along the axis the glyphs are rendered.

Parameters
e:DocumentEvent

the change information from the associated document

a:Shape

the current allocation of the view

f:ViewFactory

the factory to use to rebuild if the view has children

See Also
View#removeUpdate
setGlyphPainterback to summary
public void setGlyphPainter(GlyphView.GlyphPainter p)

Sets the painter to use for rendering glyphs.

Parameters
p:GlyphView.GlyphPainter

the painter to use for rendering glyphs

syncCRback to summary
private void syncCR()
updateAfterChangeback to summary
pack-priv void updateAfterChange()

Overrides javax.swing.text.View.updateAfterChange.

Doc from javax.swing.text.View.updateAfterChange.

Updates the view to reflect the changes.

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

Implements abstract javax.swing.text.View.viewToModel.

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

Parameters
x:float

the X coordinate >= 0

y:float

the Y coordinate >= 0

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 >= 0

See Also
View#viewToModel
javax.swing.text back to summary

public abstract Class GlyphView.GlyphPainter

extends Object
Class Inheritance
Known Direct Subclasses
javax.swing.text.GlyphPainter1, javax.swing.text.GlyphPainter2

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

Constructor Summary

AccessConstructor and Description
protected
GlyphPainter()

Constructor for subclasses to call.

Method Summary

Modifier and TypeMethod and Description
public abstract float

Returns:

of the ascent
getAscent
(GlyphView
the GlyphView
v
)

Returns of the ascent.

public abstract 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
)

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

public abstract float

Returns:

of the descent
getDescent
(GlyphView
the GlyphView
v
)

Returns of the descent.

public abstract float

Returns:

of the height
getHeight
(GlyphView
the GlyphView
v
)

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
either Position.Bias.Forward or Position.Bias.Backward
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[]
either Position.Bias.Forward or Position.Bias.Backward is returned as the zero-th element of this array
biasRet
)

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

public GlyphView.GlyphPainter

Returns:

a painter to use for the given GlyphView
getPainter
(GlyphView
the GlyphView to provide a painter for
v
,
int
the starting document offset >= 0
p0
,
int
the ending document offset >= p0
p1
)

Create a painter to use for the given GlyphView.

public abstract float

Returns:

the span the glyphs given a start location
getSpan
(GlyphView
the GlyphView
v
,
int
the beginning position
p0
,
int
the ending position
p1
,
TabExpander
how to expand the tabs when encountered
e
,
float
the X coordinate
x
)

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

public abstract Shape

Returns:

the bounding box of the given position
modelToView
(GlyphView
the GlyphView containing the destination coordinate space
v
,
int
the position to convert
pos
,
Position.Bias
either Position.Bias.Forward or Position.Bias.Backward
bias
,
Shape
Bounds of the View
a
)

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

public abstract void
paint(GlyphView
the GlyphView
v
,
Graphics
the graphics context
g
,
Shape
the current allocation of the view
a
,
int
the beginning position
p0
,
int
the ending position
p1
)

Paint the glyphs representing the given range.

public abstract int

Returns:

the location within the model that best represents the given point of view
viewToModel
(GlyphView
the GlyphView to provide a mapping for
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
)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

GlyphPainterback to summary
protected GlyphPainter()

Constructor for subclasses to call.

Method Detail

getAscentback to summary
public abstract float getAscent(GlyphView v)

Returns of the ascent.

Parameters
v:GlyphView

the GlyphView

Returns:float

of the ascent

getBoundedPositionback to summary
public abstract 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.

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 abstract float getDescent(GlyphView v)

Returns of the descent.

Parameters
v:GlyphView

the GlyphView

Returns:float

of the descent

getHeightback to summary
public abstract float getHeight(GlyphView v)

Returns of the height.

Parameters
v:GlyphView

the GlyphView

Returns:float

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

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

b:Position.Bias

either Position.Bias.Forward or Position.Bias.Backward

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.

biasRet: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 next location visual position.

Exceptions
BadLocationException:
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)

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.

Parameters
v:GlyphView

the GlyphView to provide a painter for

p0:int

the starting document offset >= 0

p1:int

the ending document offset >= p0

Returns:GlyphView.GlyphPainter

a painter to use for the given GlyphView

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

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

Parameters
v:GlyphView

the GlyphView

p0:int

the beginning position

p1:int

the ending position

e:TabExpander

how to expand the tabs when encountered

x:float

the X coordinate

Returns:float

the span the glyphs given a start location

modelToViewback to summary
public abstract 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.

Parameters
v:GlyphView

the GlyphView containing the destination coordinate space

pos:int

the position to convert

bias:Position.Bias

either Position.Bias.Forward or Position.Bias.Backward

a:Shape

Bounds of the View

Returns:Shape

the bounding box of the given position

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

Paint the glyphs representing the given range.

Parameters
v:GlyphView

the GlyphView

g:Graphics

the graphics context

a:Shape

the current allocation of the view

p0:int

the beginning position

p1:int

the ending position

viewToModelback to summary
public abstract 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.

Parameters
v:GlyphView

the GlyphView to provide a mapping for

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
javax.swing.text back to summary

pack-priv Class GlyphView.JustificationInfo

extends Object
Class Inheritance

Class to hold data needed to justify this GlyphView in a ParagraphView.Row

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int
pack-priv final boolean
pack-priv final int
pack-priv final BitSet
pack-priv final int
pack-priv final int

Constructor Summary

AccessConstructor and Description
pack-priv
JustificationInfo(int start, int end, int leadingSpaces, int contentSpaces, int trailingSpaces, boolean hasTab, BitSet spaceMap)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentSpacesback to summary
pack-priv final int contentSpaces
endback to summary
pack-priv final int end
hasTabback to summary
pack-priv final boolean hasTab
leadingSpacesback to summary
pack-priv final int leadingSpaces
spaceMapback to summary
pack-priv final BitSet spaceMap
startback to summary
pack-priv final int start
trailingSpacesback to summary
pack-priv final int trailingSpaces

Constructor Detail

JustificationInfoback to summary
pack-priv JustificationInfo(int start, int end, int leadingSpaces, int contentSpaces, int trailingSpaces, boolean hasTab, BitSet spaceMap)