|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjavax.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
| 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 |
|---|
private Map highlights
private Highlighter.HighlightPainter painter
| Constructor Detail |
|---|
public ProtectedHighlighter(JTextComponent component, Color highlightColor)
component - text componenthighlightColor - highlight color, when null is specifed a
"lighter" color of the text selection color
will be used.
| Method Detail |
|---|
de public public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter p)
p0 - start offsetp1 - end offsetp - painter
public Object addHighlight(int p0, int p1)
p0 - start offsetp1 - end offset
de public public void removeHighlight(Object tag)
p0 - start offsetp1 - end offsetp - painter
Groovy Documentation