Class 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
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • timer

        private javax.swing.Timer timer
      • DEFAULT_COLOR

        static final java.awt.Color DEFAULT_COLOR
        The default color used to mark occurrences.
    • 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 be null.
    • 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 interface java.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 interface javax.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)