Groovy Documentation

com.wordpress.tipsforjava.swing.text
[Java] Class ProtectedHighlighter

java.lang.Object
  javax.swing.text.LayeredHighlighter
      javax.swing.text.DefaultHighlighter
          com.wordpress.tipsforjava.swing.text.ProtectedHighlighter

public class ProtectedHighlighter
extends DefaultHighlighter

Class to manage highlighting of protected text within a Document. The default highlight color will the a "lighter" version of the text selection highlighter but can be chaged if desired. Normally highlights are stored with a starting and ending offset. However, this causes a problem as by default the ending offset will increase as text is added. This is a result of the default text processing whereby newly added characters inherit the attributes of the previous character. So to handle this situation an internal Map is used to store the start offset and the length of the highlight. The painting code has then be modified to use this information and not the provided offsets. (Note, I know its not a proper design, but I use a Point object to store the start and lenght values). Note: this class was designed to be used the the ProtectedTextComponent

Authors:
Rob Camick
Darryl Burke


Nested Class Summary
class ProtectedHighlighter.ProtectedHighlightPainter

Custom painter.

 
Field Summary
private Map highlights

private Highlighter.HighlightPainter painter

 
Fields inherited from class DefaultHighlighter
DefaultPainter
 
Constructor Summary
ProtectedHighlighter(JTextComponent component, Color highlightColor)

Create a highlighter for the given text component.

 
Method Summary
Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p)

Add a highlight to the highlighter.

Object addHighlight(int p0, int p1)

Add a highlight to the highlighter.

void removeHighlight(Object tag)

Remove a highlight from the highlighter.

 
Methods inherited from class DefaultHighlighter
install, paint, deinstall, addHighlight, removeHighlight, removeAllHighlights, changeHighlight, getHighlights, paintLayeredHighlights, setDrawsLayeredHighlights, getDrawsLayeredHighlights, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 
Methods inherited from class LayeredHighlighter
paintLayeredHighlights, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll, install, paint, deinstall, addHighlight, removeHighlight, removeAllHighlights, changeHighlight, getHighlights
 

Field Detail

highlights

private Map highlights


painter

private Highlighter.HighlightPainter painter


 
Constructor Detail

ProtectedHighlighter

public ProtectedHighlighter(JTextComponent component, Color highlightColor)
Create a highlighter for the given text component.
Parameters:
component - text component
highlightColor - highlight color, when null is specifed a "lighter" color of the text selection color will be used.


 
Method Detail

addHighlight

de
	public
public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p)
Add a highlight to the highlighter. Override to store the start/length information of the highlight
Parameters:
p0 - start offset
p1 - end offset
p - painter


addHighlight

public Object addHighlight(int p0, int p1)
Add a highlight to the highlighter. This method will make sure the proper painter is used to paint the protected highlights.
Parameters:
p0 - start offset
p1 - end offset


removeHighlight

de
	public
public void removeHighlight(Object tag)
Remove a highlight from the highlighter. Override to store the start/length information of the highlight
Parameters:
p0 - start offset
p1 - end offset
p - painter


 

Groovy Documentation