Extension SDK 10.1.2

oracle.javatools.editor.plugins
Class FindHighlightPlugin

java.lang.Object
  extended byoracle.javatools.editor.plugins.FindHighlightPlugin
All Implemented Interfaces:
javax.swing.event.DocumentListener, EditorPlugin, java.util.EventListener, java.beans.PropertyChangeListener

public final class FindHighlightPlugin
extends java.lang.Object
implements EditorPlugin, javax.swing.event.DocumentListener

The FindHighlightPlugin provides support for finding and highlighting occurrences of text. Highlights are added to the editor pane for the given search text, and maintained across document modifications until the next find is issued, or until clients clear them explicitly.

To use this plugin, install it into the editor pane by calling installPlugin() on the BasicEditorPane. Once it is installed, you can use the plugin by just calling findText() with the appropriate parameters.


Field Summary
static int DEFAULT_FIND_PRIORITY
          The default priority level given to the highlight find results.
static java.lang.String HIGHLIGHT_FIND_RESULT
          The name of the highlight style for find results.
 
Constructor Summary
FindHighlightPlugin()
          Constructs a new FindHighlightPlugin that is not currently associated with any editor or document.
 
Method Summary
 void changedUpdate(javax.swing.event.DocumentEvent event)
          Gives notification that an attribute or set of attributes changed.
 void clearFindHighlighting()
          Clears the results of a previous find highlighting request.
 void deinstall(BasicEditorPane editor)
          Called when the plugin is being removed from the BasicEditorPane (for example when the editor is closed.) This is used to notify plugins that they should unregister any listeners that were attached.
 int findText(java.lang.String searchText, int startOffset, boolean searchForward, boolean matchCase, boolean wrapAround, boolean highlightOccurrences)
          This is the public entrypoint for users of this plugin for the find operation.
 int findText(java.lang.String searchText, int startOffset, boolean searchForward, boolean matchCase, boolean wrapAround, boolean wholeWordOnly, boolean highlightOccurrences)
          This is the public entrypoint for users of this plugin for the find operation.
 boolean hasFindHighlighting()
          Fetches whether there is an active find highlighting enabled.
 void insertUpdate(javax.swing.event.DocumentEvent event)
          Gives notification that there was an insert into the document.
 void install(BasicEditorPane editor)
          Called when this plugin is being installed into the BasicEditorPane.
 void propertyChange(java.beans.PropertyChangeEvent event)
          This method gets called when a bound property is changed.
 void removeUpdate(javax.swing.event.DocumentEvent event)
          Gives notification that a portion of the document has been removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_FIND_PRIORITY

public static final int DEFAULT_FIND_PRIORITY
The default priority level given to the highlight find results.

See Also:
Constant Field Values

HIGHLIGHT_FIND_RESULT

public static final java.lang.String HIGHLIGHT_FIND_RESULT
The name of the highlight style for find results.

See Also:
Constant Field Values
Constructor Detail

FindHighlightPlugin

public FindHighlightPlugin()
Constructs a new FindHighlightPlugin that is not currently associated with any editor or document.

Method Detail

install

public void install(BasicEditorPane editor)
Called when this plugin is being installed into the BasicEditorPane.

Specified by:
install in interface EditorPlugin
Parameters:
editor - the editor pane

deinstall

public void deinstall(BasicEditorPane editor)
Called when the plugin is being removed from the BasicEditorPane (for example when the editor is closed.) This is used to notify plugins that they should unregister any listeners that were attached.

Specified by:
deinstall in interface EditorPlugin
Parameters:
editor - the editor pane

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
This method gets called when a bound property is changed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
event - A PropertyChangeEvent object describing the event source and the property that has changed.

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent event)
Gives notification that there was an insert into the document. The range given by the DocumentEvent bounds the freshly inserted region.

Specified by:
insertUpdate in interface javax.swing.event.DocumentListener
Parameters:
event - the document event

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent event)
Gives notification that a portion of the document has been removed. The range is given in terms of what the view last saw (that is, before updating sticky positions).

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener
Parameters:
event - the document event

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent event)
Gives notification that an attribute or set of attributes changed.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener
Parameters:
event - the document event

findText

public int findText(java.lang.String searchText,
                    int startOffset,
                    boolean searchForward,
                    boolean matchCase,
                    boolean wrapAround,
                    boolean highlightOccurrences)
This is the public entrypoint for users of this plugin for the find operation. To do a "Find next..." type operation, make sure to specify the appropriate start offset. If wrapAround is requested, it will start at the beginning of the document as well and search until startOffset. If highlightOccurrences is true, it will enable find occurrence highlighting, otherwise, it will disable it. Note that this will disable whole-word only matching.

Parameters:
searchText - the search text to find
startOffset - the starting location to do the search
searchForward - whether to search forward
matchCase - whether to match case, true to perform case-sensitive matches
wrapAround - whether to wrap-around to the beginning of the document in case the search text was not found, true to wrap around
Returns:
the offset of the first matching location, or -1 if not found

findText

public int findText(java.lang.String searchText,
                    int startOffset,
                    boolean searchForward,
                    boolean matchCase,
                    boolean wrapAround,
                    boolean wholeWordOnly,
                    boolean highlightOccurrences)
This is the public entrypoint for users of this plugin for the find operation. To do a "Find next..." type operation, make sure to specify the appropriate start offset. If wrapAround is requested, it will start at the beginning of the document as well and search until startOffset. If wholeWordOnly is requested, it will match only whole words. If highlightOccurrences is true, it will enable find occurrence highlighting, otherwise, it will disable it.

Parameters:
searchText - the search text to find
startOffset - the starting location to do the search
searchForward - whether to search forward
matchCase - whether to match case, true to perform case-sensitive matches
wrapAround - whether to wrap-around to the beginning of the document in case the search text was not found, true to wrap around
wholeWordOnly - whether to check for whole-word occurrences only, true to check for whole word only
Returns:
the offset of the first matching location, or -1 if not found

clearFindHighlighting

public void clearFindHighlighting()
Clears the results of a previous find highlighting request. All enabled highlights will be removed.


hasFindHighlighting

public boolean hasFindHighlighting()
Fetches whether there is an active find highlighting enabled. It is possible to have find highlighting enabled, but nothing actually highlighted.

Returns:
true if find highlighting is active for the last search performed

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.