JIDE 3.5.15

com.jidesoft.search
Interface FindAndReplaceTarget

All Known Implementing Classes:
CodeEditorDocumentPaneFindAndReplaceTarget, CodeEditorFindAndReplaceTarget, CodeEditorSelectionFindAndReplaceTarget

public interface FindAndReplaceTarget

FindAndReplaceTarget is the target that FindAndReplace works on. Basically it abstracts all the methods that FindAndReplace needs in order to perform find and replace on anything.

FindAndReplaceTarget can represent a piece of text, several pieces of text, a file, all files in the same folder, or a list of files at any location. By default, we provide CodeEditorFindAndReplaceTarget for one CodeEditor, CodeEditorSelectionFindAndReplaceTarget for the selection in a CodeEditor and CodeEditorDocumentPaneFindAndReplaceTarget for all CodeEditor inside a DocumentPane.


Method Summary
 void adjustCurrentPosition(String searchingText, boolean forward)
          Adjusts current position according to searching text in the first attempt to search.
 JComponent getConfigurationPanel()
          FindAndReplaceTarget can be added to FindAndReplacePanel so that user can configure it.
 String getCurrentName()
          Gets the name of the target.
 int getCurrentPosition(boolean forward)
          Gets the current position where the next search will start.
 CharSequence getCurrentText()
          Gets the current text.
 FindResultIntepreter getIntepreter()
          Gets the interpreter that can understand the start offset and end offset in a FindResult.
 Locale getLocale()
          Gets the target's locale.
 Point getPromptDialogLocation()
          Gets the default prompt dialog location without concerning the caret position.
 Point getPromptDialogLocation(Rectangle dialogBounds)
          Gets the prompt dialog location.
 Window getPromptDialogParent()
          Gets the window that can be used as the parent of the prompt dialog.
 String getResourceString(String key)
          Gets resource string from target.
 boolean hasNext()
          Checks if there is more chunk of text after the current text when FindAndReplace reaches the end of the current text when searching forward.
 boolean hasPrevious()
          Checks if there is more chunk of text before the current text when FindAndReplace reaches the start of the current text when searching backward.
 void highlight(int start, int end)
          Highlights the text to indicate the text matches the searching criteria.
 boolean isTargetChanged()
          Checks if the text in the target changes.
 void next()
          Changes the current text to the next one.
 void previous()
          Changes the current text to the previous one.
 void replace(int offset, int len, String str)
          Replaces some text with the new text.
 void replaceAllEnds()
          Replace all ends.
 void replaceAllStarts()
          Replace all starts.
 void scrollToShowCaret(Rectangle promptDialogBounds)
          Scrolls to show caret.
 void showMessage(String message)
          Shows a message.
 

Method Detail

getConfigurationPanel

JComponent getConfigurationPanel()
FindAndReplaceTarget can be added to FindAndReplacePanel so that user can configure it. The panel returned from this method is the panel. FindAndReplacePanel will add a radio button before the configuration panel, so there is no need to have a radio button inside the panel. If there is nothing to configure for this target, you just return a JLabel with the descriptive name. For example, something like new JLabel("Selection") if the target is for the selected text in a CodeEditor.

FindAndReplacePanel will arrange all configuration panels vertically, so you should make sure the configuration panel are arranged horizontally (very wide instead very tall) so that the overall appearance looks good. If for whatever reason you have to make the configuration very tall, you may need to override FindAndReplacePanel.createTargetPanel() method so that you can do the layout of the configuration panels yourself.

Returns:
the configuration panel.

getCurrentName

String getCurrentName()
Gets the name of the target.

Returns:
the name of the target.

getCurrentText

CharSequence getCurrentText()
Gets the current text.

Returns:
the current text.

getCurrentPosition

int getCurrentPosition(boolean forward)
Gets the current position where the next search will start. Usually in a CodeEditor, it will be the caret position.

Parameters:
forward - true or false.
Returns:
the current position.

adjustCurrentPosition

void adjustCurrentPosition(String searchingText,
                           boolean forward)
Adjusts current position according to searching text in the first attempt to search.

Parameters:
searchingText - current searching text
forward - true or false.

highlight

void highlight(int start,
               int end)
Highlights the text to indicate the text matches the searching criteria.

Parameters:
start - the start offset of the text that is found.
end - the end offset of the text that is found.

replace

void replace(int offset,
             int len,
             String str)
             throws BadLocationException
Replaces some text with the new text. This method is used to replace the text.

Parameters:
offset - the offset from the beginning.
len - the number of characters to be replaced.
str - the new text to replace the old text.
Throws:
BadLocationException - if the given offset is not a valid position within the document

replaceAllStarts

void replaceAllStarts()
Replace all starts. This is used by undo feature so that when undo this operation, it undoes all string that were replaced.


replaceAllEnds

void replaceAllEnds()
Replace all ends. This is used by undo feature so that when undo this operation, it undoes all string that were replaced.


getPromptDialogParent

Window getPromptDialogParent()
Gets the window that can be used as the parent of the prompt dialog.

Returns:
the window that can be used as the parent of the prompt dialog.

getPromptDialogLocation

Point getPromptDialogLocation(Rectangle dialogBounds)
Gets the prompt dialog location. Please note, the location is the screen location. We need this location in order to show the prompt dialog where it doesn't obscure the text behind especially where the text is found.

Parameters:
dialogBounds - the bounds of the dialog before determining its location
Returns:
the prompt dialog location.

getPromptDialogLocation

Point getPromptDialogLocation()
Gets the default prompt dialog location without concerning the caret position.

Returns:
the prompt dialog location.

scrollToShowCaret

void scrollToShowCaret(Rectangle promptDialogBounds)
Scrolls to show caret.

Parameters:
promptDialogBounds - the prompt dialog bounds

showMessage

void showMessage(String message)
Shows a message. FindAndReplace needs to provide some feedback to user. It will call this method to show user a message. It's up to you how to implement it. In CodeEditor, we use a JidePopup to display a tooltip-like popup near the caret. You can display a message in your status bar if you want.

Parameters:
message - the message

hasNext

boolean hasNext()
Checks if there is more chunk of text after the current text when FindAndReplace reaches the end of the current text when searching forward.

Returns:
true if there is another piece of text after the current text.

next

void next()
Changes the current text to the next one.


hasPrevious

boolean hasPrevious()
Checks if there is more chunk of text before the current text when FindAndReplace reaches the start of the current text when searching backward.

Returns:
true if there is another piece of text after the current text.

previous

void previous()
Changes the current text to the previous one.


getIntepreter

FindResultIntepreter getIntepreter()
Gets the interpreter that can understand the start offset and end offset in a FindResult. CodeEditor implements FindResultIntepreter.

Returns:
the FindResultIntepreter.

isTargetChanged

boolean isTargetChanged()
Checks if the text in the target changes.

Returns:
true if the text changes. Otherwise false.

getResourceString

String getResourceString(String key)
Gets resource string from target.

Parameters:
key - the resource key
Returns:
the localized resource string.

getLocale

Locale getLocale()
Gets the target's locale.

Returns:
the locale in use.

JIDE 3.5.15