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

public Class DefaultHighlighter

extends LayeredHighlighter
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.basic.BasicTextUI.BasicHighlighter
Imports
java.util.Vector, java.awt.*, javax.swing.plaf.*, javax.swing.*

Implements the Highlighter interfaces. Implements a simple highlight painter that renders in a solid color.
Author
Timothy Prinzing
See Also
Highlighter

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
DefaultHighlighter.DefaultHighlightPainter

Simple highlight painter that fills a highlighted area with a solid color.

pack-priv static class
pack-priv static class
DefaultHighlighter.LayeredHighlightInfo

LayeredHighlightPainter is used when a drawsLayeredHighlights is true.

pack-priv class
DefaultHighlighter.SafeDamager

This class invokes mapper.damageRange in EventDispatchThread.

Field Summary

Modifier and TypeField and Description
private JTextComponent
public static final LayeredHighlighter.LayerPainter
DefaultPainter

Default implementation of LayeredHighlighter.LayerPainter that can be used for painting highlights.

private boolean
private Vector<DefaultHighlighter.HighlightInfo>
private static final Highlighter.Highlight[]
private DefaultHighlighter.SafeDamager

Constructor Summary

AccessConstructor and Description
public
DefaultHighlighter()

Creates a new DefaultHighlighter object.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

an object that can be used as a tag to refer to the highlight
addHighlight
(int
the start offset of the range to highlight >= 0
p0
,
int
the end offset of the range to highlight >= p0
p1
,
Highlighter.HighlightPainter
the painter to use to actually render the highlight
p
)

Implements javax.swing.text.Highlighter.addHighlight.

Adds a highlight to the view.

public void
changeHighlight(Object
the highlight tag
tag
,
int
the beginning of the range >= 0
p0
,
int
the end of the range >= p0
p1
)

Implements javax.swing.text.Highlighter.changeHighlight.

Changes a highlight.

public void
deinstall(JTextComponent
the component
c
)

Implements javax.swing.text.Highlighter.deinstall.

Called when the UI is being removed from the interface of a JTextComponent.

public boolean

Returns:

the draw layered highlights
getDrawsLayeredHighlights
()

Return the draw layered highlights.

public Highlighter.Highlight[]

Returns:

the copy
getHighlights
()

Implements javax.swing.text.Highlighter.getHighlights.

Makes a copy of the highlights.

public void
install(JTextComponent
the editor component
c
)

Implements javax.swing.text.Highlighter.install.

Called when the UI is being installed into the interface of a JTextComponent.

public void
paint(Graphics
the graphics context
g
)

Implements javax.swing.text.Highlighter.paint.

Renders the highlights.

public void
paintLayeredHighlights(Graphics
Graphics used to draw
g
,
int
starting offset of view
p0
,
int
ending offset of view
p1
,
Shape
Bounds of View
viewBounds
,
JTextComponent
JTextComponent
editor
,
View
View instance being rendered
view
)

Implements abstract javax.swing.text.LayeredHighlighter.paintLayeredHighlights.

When leaf Views (such as LabelView) are rendering they should call into this method.

public void
public void
removeHighlight(Object
the reference to the highlight
tag
)

Implements javax.swing.text.Highlighter.removeHighlight.

Removes a highlight from the view.

private void
safeDamageRange(final Position p0, final Position p1)

Queues damageRange() call into event dispatch thread to be sure that views are in consistent state.

private void
safeDamageRange(int a0, int a1)

Queues damageRange() call into event dispatch thread to be sure that views are in consistent state.

public void
setDrawsLayeredHighlights(boolean
the new value
newValue
)

If true, highlights are drawn as the Views draw the text.

Field Detail

componentback to summary
private JTextComponent component
DefaultPainterback to summary
public static final LayeredHighlighter.LayerPainter DefaultPainter

Default implementation of LayeredHighlighter.LayerPainter that can be used for painting highlights.

As of 1.4 this field is final.

drawsLayeredHighlightsback to summary
private boolean drawsLayeredHighlights
highlightsback to summary
private Vector<DefaultHighlighter.HighlightInfo> highlights
noHighlightsback to summary
private static final Highlighter.Highlight[] noHighlights
safeDamagerback to summary
private DefaultHighlighter.SafeDamager safeDamager

Constructor Detail

DefaultHighlighterback to summary
public DefaultHighlighter()

Creates a new DefaultHighlighter object.

Method Detail

addHighlightback to summary
public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p) throws BadLocationException

Implements javax.swing.text.Highlighter.addHighlight.

Adds a highlight to the view. Returns a tag that can be used to refer to the highlight.

Parameters
p0:int

the start offset of the range to highlight >= 0

p1:int

the end offset of the range to highlight >= p0

p:Highlighter.HighlightPainter

the painter to use to actually render the highlight

Returns:Object

an object that can be used as a tag to refer to the highlight

Exceptions
BadLocationException:
if the specified location is invalid
changeHighlightback to summary
public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException

Implements javax.swing.text.Highlighter.changeHighlight.

Changes a highlight.

Parameters
tag:Object

the highlight tag

p0:int

the beginning of the range >= 0

p1:int

the end of the range >= p0

Exceptions
BadLocationException:
if the specified location is invalid
deinstallback to summary
public void deinstall(JTextComponent c)

Implements javax.swing.text.Highlighter.deinstall.

Called when the UI is being removed from the interface of a JTextComponent.

Parameters
c:JTextComponent

the component

See Also
Highlighter#deinstall
getDrawsLayeredHighlightsback to summary
public boolean getDrawsLayeredHighlights()

Return the draw layered highlights.

Returns:boolean

the draw layered highlights

getHighlightsback to summary
public Highlighter.Highlight[] getHighlights()

Implements javax.swing.text.Highlighter.getHighlights.

Makes a copy of the highlights. Does not actually clone each highlight, but only makes references to them.

Returns:Highlighter.Highlight[]

the copy

See Also
Highlighter#getHighlights
installback to summary
public void install(JTextComponent c)

Implements javax.swing.text.Highlighter.install.

Called when the UI is being installed into the interface of a JTextComponent. Installs the editor, and removes any existing highlights.

Parameters
c:JTextComponent

the editor component

See Also
Highlighter#install
paintback to summary
public void paint(Graphics g)

Implements javax.swing.text.Highlighter.paint.

Renders the highlights.

Parameters
g:Graphics

the graphics context

paintLayeredHighlightsback to summary
public void paintLayeredHighlights(Graphics g, int p0, int p1, Shape viewBounds, JTextComponent editor, View view)

Implements abstract javax.swing.text.LayeredHighlighter.paintLayeredHighlights.

When leaf Views (such as LabelView) are rendering they should call into this method. If a highlight is in the given region it will be drawn immediately.

Parameters
g:Graphics

Graphics used to draw

p0:int

starting offset of view

p1:int

ending offset of view

viewBounds:Shape

Bounds of View

editor:JTextComponent

JTextComponent

view:View

View instance being rendered

removeAllHighlightsback to summary
public void removeAllHighlights()

Implements javax.swing.text.Highlighter.removeAllHighlights.

Removes all highlights.

removeHighlightback to summary
public void removeHighlight(Object tag)

Implements javax.swing.text.Highlighter.removeHighlight.

Removes a highlight from the view.

Parameters
tag:Object

the reference to the highlight

safeDamageRangeback to summary
private void safeDamageRange(final Position p0, final Position p1)

Queues damageRange() call into event dispatch thread to be sure that views are in consistent state.

safeDamageRangeback to summary
private void safeDamageRange(int a0, int a1) throws BadLocationException

Queues damageRange() call into event dispatch thread to be sure that views are in consistent state.

setDrawsLayeredHighlightsback to summary
public void setDrawsLayeredHighlights(boolean newValue)

If true, highlights are drawn as the Views draw the text. That is the Views will call into paintLayeredHighlight which will result in a rectangle being drawn before the text is drawn (if the offsets are in a highlighted region that is). For this to work the painter supplied must be an instance of LayeredHighlightPainter.

Parameters
newValue:boolean

the new value

javax.swing.text back to summary

public Class DefaultHighlighter.DefaultHighlightPainter

extends LayerPainter
Class Inheritance
Known Direct Subclasses
javax.swing.text.html.HTMLEditorKit.NavigateLinkAction.FocusHighlightPainter

Simple highlight painter that fills a highlighted area with a solid color.

Field Summary

Modifier and TypeField and Description
private Color

Constructor Summary

AccessConstructor and Description
public
DefaultHighlightPainter(Color
the color for the highlight
c
)

Constructs a new highlight painter.

Method Summary

Modifier and TypeMethod and Description
public Color

Returns:

the color
getColor
()

Returns the color of the highlight.

public void
paint(Graphics
the graphics context
g
,
int
the starting model offset >= 0
offs0
,
int
the ending model offset >= offs1
offs1
,
Shape
the bounding box for the highlight
bounds
,
JTextComponent
the editor
c
)

Implements javax.swing.text.Highlighter.HighlightPainter.paint.

Paints a highlight.

public Shape

Returns:

region drawing occurred in
paintLayer
(Graphics
the graphics context
g
,
int
the starting model offset >= 0
offs0
,
int
the ending model offset >= offs1
offs1
,
Shape
the bounding box of the view, which is not necessarily the region to paint.
bounds
,
JTextComponent
the editor
c
,
View
View painting for
view
)

Implements abstract javax.swing.text.LayeredHighlighter.LayerPainter.paintLayer.

Paints a portion of a highlight.

Field Detail

colorback to summary
private Color color

Constructor Detail

DefaultHighlightPainterback to summary
public DefaultHighlightPainter(Color c)

Constructs a new highlight painter. If c is null, the JTextComponent will be queried for its selection color.

Parameters
c:Color

the color for the highlight

Method Detail

getColorback to summary
public Color getColor()

Returns the color of the highlight.

Returns:Color

the color

paintback to summary
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c)

Implements javax.swing.text.Highlighter.HighlightPainter.paint.

Paints a highlight.

Parameters
g:Graphics

the graphics context

offs0:int

the starting model offset >= 0

offs1:int

the ending model offset >= offs1

bounds:Shape

the bounding box for the highlight

c:JTextComponent

the editor

Annotations
@SuppressWarnings:deprecation
paintLayerback to summary
public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view)

Implements abstract javax.swing.text.LayeredHighlighter.LayerPainter.paintLayer.

Paints a portion of a highlight.

Parameters
g:Graphics

the graphics context

offs0:int

the starting model offset >= 0

offs1:int

the ending model offset >= offs1

bounds:Shape

the bounding box of the view, which is not necessarily the region to paint.

c:JTextComponent

the editor

view:View

View painting for

Returns:Shape

region drawing occurred in

javax.swing.text back to summary

pack-priv Class DefaultHighlighter.HighlightInfo

extends Object
implements Highlight
Class Inheritance
All Implemented Interfaces
javax.swing.text.Highlighter.Highlight
Known Direct Subclasses
javax.swing.text.DefaultHighlighter.LayeredHighlightInfo

Field Summary

Modifier and TypeField and Description
pack-priv Position
pack-priv Position
pack-priv Highlighter.HighlightPainter

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
getEndOffset()

Implements javax.swing.text.Highlighter.Highlight.getEndOffset.

Gets the ending model offset for the highlight.

public Highlighter.HighlightPainter
getPainter()

Implements javax.swing.text.Highlighter.Highlight.getPainter.

Gets the painter for the highlighter.

public int
getStartOffset()

Implements javax.swing.text.Highlighter.Highlight.getStartOffset.

Gets the starting model offset for the highlight.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

p0back to summary
pack-priv Position p0
p1back to summary
pack-priv Position p1
painterback to summary
pack-priv Highlighter.HighlightPainter painter

Constructor Detail

HighlightInfoback to summary
pack-priv HighlightInfo()

Method Detail

getEndOffsetback to summary
public int getEndOffset()

Implements javax.swing.text.Highlighter.Highlight.getEndOffset.

Doc from javax.swing.text.Highlighter.Highlight.getEndOffset.

Gets the ending model offset for the highlight.

getPainterback to summary
public Highlighter.HighlightPainter getPainter()

Implements javax.swing.text.Highlighter.Highlight.getPainter.

Doc from javax.swing.text.Highlighter.Highlight.getPainter.

Gets the painter for the highlighter.

getStartOffsetback to summary
public int getStartOffset()

Implements javax.swing.text.Highlighter.Highlight.getStartOffset.

Doc from javax.swing.text.Highlighter.Highlight.getStartOffset.

Gets the starting model offset for the highlight.

javax.swing.text back to summary

pack-priv Class DefaultHighlighter.LayeredHighlightInfo

extends HighlightInfo
Class Inheritance

LayeredHighlightPainter is used when a drawsLayeredHighlights is true. It maintains a rectangle of the region to paint.

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int
pack-priv int
x

pack-priv int
y

Inherited from javax.swing.text.DefaultHighlighter.HighlightInfo:
p0p1painter

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
paintLayeredHighlights(Graphics g, int p0, int p1, Shape viewBounds, JTextComponent editor, View view)

Restricts the region based on the receivers offsets and messages the painter to paint the region.

pack-priv void
union(Shape bounds)

Inherited from javax.swing.text.DefaultHighlighter.HighlightInfo:
getEndOffsetgetPaintergetStartOffset

Field Detail

heightback to summary
pack-priv int height
widthback to summary
pack-priv int width
xback to summary
pack-priv int x
yback to summary
pack-priv int y

Constructor Detail

LayeredHighlightInfoback to summary
pack-priv LayeredHighlightInfo()

Method Detail

paintLayeredHighlightsback to summary
pack-priv void paintLayeredHighlights(Graphics g, int p0, int p1, Shape viewBounds, JTextComponent editor, View view)

Restricts the region based on the receivers offsets and messages the painter to paint the region.

unionback to summary
pack-priv void union(Shape bounds)
javax.swing.text back to summary

pack-priv Class DefaultHighlighter.SafeDamager

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

This class invokes mapper.damageRange in EventDispatchThread. The only one instance per Highlighter is created. When a number of ranges should be damaged it collects them into queue and damages them in consecutive order in run call.

Field Summary

Modifier and TypeField and Description
private Document
private Vector<Position>
private Vector<Position>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public synchronized void
damageRange(Position pos0, Position pos1)

Adds the range to be damaged into the range queue.

public synchronized void
run()

Implements java.lang.Runnable.run.

Executes range(s) damage and cleans range queue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lastDocback to summary
private Document lastDoc
p0back to summary
private Vector<Position> p0
p1back to summary
private Vector<Position> p1

Constructor Detail

SafeDamagerback to summary
pack-priv SafeDamager()

Method Detail

damageRangeback to summary
public synchronized void damageRange(Position pos0, Position pos1)

Adds the range to be damaged into the range queue. If the range queue is empty (the first call or run() was already invoked) then adds this class instance into EventDispatch queue. The method also tracks if the current document changed or component is null. In this case it removes all ranges added before from range queue.

runback to summary
public synchronized void run()

Implements java.lang.Runnable.run.

Executes range(s) damage and cleans range queue.