Package org.fife.ui.rsyntaxtextarea
Class MarkOccurrencesSupport
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.MarkOccurrencesSupport
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.util.EventListener
,javax.swing.event.CaretListener
class MarkOccurrencesSupport extends java.lang.Object implements javax.swing.event.CaretListener, java.awt.event.ActionListener
Marks all occurrences of the token at the current caret position, if it is an identifier.- Version:
- 1.0
- See Also:
OccurrenceMarker
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.awt.Color
DEFAULT_COLOR
The default color used to mark occurrences.(package private) static int
DEFAULT_DELAY_MS
The default delay.private SmartHighlightPainter
p
private RSyntaxTextArea
textArea
private javax.swing.Timer
timer
-
Constructor Summary
Constructors Constructor Description MarkOccurrencesSupport()
Constructor.MarkOccurrencesSupport(int delay)
Constructor.MarkOccurrencesSupport(int delay, java.awt.Color color)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
Called after the caret has been moved and a fixed time delay has elapsed.void
caretUpdate(javax.swing.event.CaretEvent e)
Called when the caret moves in the text area.(package private) void
clear()
Removes all highlights added to the text area by this listener.void
doMarkOccurrences()
Immediately marks all occurrences of the token at the current caret position.java.awt.Color
getColor()
Returns the color being used to mark occurrences.int
getDelay()
Returns the delay, in milliseconds.boolean
getPaintBorder()
Returns whether a border is painted around marked occurrences.void
install(RSyntaxTextArea textArea)
Installs this listener on a text area.void
setColor(java.awt.Color color)
Sets the color to use when marking occurrences.void
setDelay(int delay)
Sets the delay between the last caret position change and when the text is scanned for matching identifiers.void
setPaintBorder(boolean paint)
Toggles whether a border is painted around marked highlights.void
uninstall()
Uninstalls this listener from the current text area.
-
-
-
Field Detail
-
textArea
private RSyntaxTextArea textArea
-
timer
private javax.swing.Timer timer
-
p
private SmartHighlightPainter p
-
DEFAULT_COLOR
static final java.awt.Color DEFAULT_COLOR
The default color used to mark occurrences.
-
DEFAULT_DELAY_MS
static final int DEFAULT_DELAY_MS
The default delay.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MarkOccurrencesSupport
MarkOccurrencesSupport()
Constructor. Creates a listener with a 1-second delay.
-
MarkOccurrencesSupport
MarkOccurrencesSupport(int delay)
Constructor.- Parameters:
delay
- The delay between when the caret last moves and when the text should be scanned for matching occurrences. This should be in milliseconds.
-
MarkOccurrencesSupport
MarkOccurrencesSupport(int delay, java.awt.Color color)
Constructor.- Parameters:
delay
- The delay between when the caret last moves and when the text should be scanned for matching occurrences. This should be in milliseconds.color
- The color to use to mark the occurrences. This cannot benull
.
-
-
Method Detail
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Called after the caret has been moved and a fixed time delay has elapsed. This locates and highlights all occurrences of the identifier at the caret position, if any.Callers should not call this method directly, but should rather prefer
doMarkOccurrences()
to mark occurrences.- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
- Parameters:
e
- The event.- See Also:
doMarkOccurrences()
-
caretUpdate
public void caretUpdate(javax.swing.event.CaretEvent e)
Called when the caret moves in the text area.- Specified by:
caretUpdate
in interfacejavax.swing.event.CaretListener
- Parameters:
e
- The event.
-
clear
void clear()
Removes all highlights added to the text area by this listener.
-
doMarkOccurrences
public void doMarkOccurrences()
Immediately marks all occurrences of the token at the current caret position.
-
getColor
public java.awt.Color getColor()
Returns the color being used to mark occurrences.- Returns:
- The color being used.
- See Also:
setColor(Color)
-
getDelay
public int getDelay()
Returns the delay, in milliseconds.- Returns:
- The delay.
- See Also:
setDelay(int)
-
getPaintBorder
public boolean getPaintBorder()
Returns whether a border is painted around marked occurrences.- Returns:
- Whether a border is painted.
- See Also:
setPaintBorder(boolean)
,getColor()
-
install
public void install(RSyntaxTextArea textArea)
Installs this listener on a text area. If it is already installed on another text area, it is uninstalled first.- Parameters:
textArea
- The text area to install on.
-
setColor
public void setColor(java.awt.Color color)
Sets the color to use when marking occurrences.- Parameters:
color
- The color to use.- See Also:
getColor()
,setPaintBorder(boolean)
-
setDelay
public void setDelay(int delay)
Sets the delay between the last caret position change and when the text is scanned for matching identifiers. A delay is recommended to prevent repeated scanning while the user is typing.- Parameters:
delay
- The new delay.- See Also:
getDelay()
-
setPaintBorder
public void setPaintBorder(boolean paint)
Toggles whether a border is painted around marked highlights.- Parameters:
paint
- Whether to paint a border.- See Also:
getPaintBorder()
,setColor(Color)
-
uninstall
public void uninstall()
Uninstalls this listener from the current text area. Does nothing if it not currently installed on any text area.- See Also:
install(RSyntaxTextArea)
-
-