JIDE 3.5.15

com.jidesoft.editor
Class CodeEditorFindAndReplaceTarget

java.lang.Object
  extended by com.jidesoft.editor.CodeEditorFindAndReplaceTarget
All Implemented Interfaces:
FindAndReplaceTarget, EventListener, DocumentListener
Direct Known Subclasses:
CodeEditorSelectionFindAndReplaceTarget

public class CodeEditorFindAndReplaceTarget
extends Object
implements FindAndReplaceTarget, DocumentListener

A FindAndReplaceTarget implementation for CodeEditor.


Constructor Summary
CodeEditorFindAndReplaceTarget(CodeEditor codeEditor)
           
 
Method Summary
 void adjustCurrentPosition(String searchingText, boolean forward)
          Adjusts current position according to searching text in the first attempt to search.
 void changedUpdate(DocumentEvent e)
           
 CodeEditor getCodeEditor()
           
 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.
 void insertUpdate(DocumentEvent e)
           
 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 removeUpdate(DocumentEvent e)
           
 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.
protected  void setTargetChanged(boolean targetChanged)
           
 void showMessage(String message)
          Shows a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeEditorFindAndReplaceTarget

public CodeEditorFindAndReplaceTarget(CodeEditor codeEditor)
Method Detail

getIntepreter

public FindResultIntepreter getIntepreter()
Description copied from interface: FindAndReplaceTarget
Gets the interpreter that can understand the start offset and end offset in a FindResult. CodeEditor implements FindResultIntepreter.

Specified by:
getIntepreter in interface FindAndReplaceTarget
Returns:
the FindResultIntepreter.

getCodeEditor

public CodeEditor getCodeEditor()

getConfigurationPanel

public JComponent getConfigurationPanel()
Description copied from interface: FindAndReplaceTarget
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.

Specified by:
getConfigurationPanel in interface FindAndReplaceTarget
Returns:
the configuration panel.

hasNext

public boolean hasNext()
Description copied from interface: FindAndReplaceTarget
Checks if there is more chunk of text after the current text when FindAndReplace reaches the end of the current text when searching forward.

Specified by:
hasNext in interface FindAndReplaceTarget
Returns:
true if there is another piece of text after the current text.

next

public void next()
Description copied from interface: FindAndReplaceTarget
Changes the current text to the next one.

Specified by:
next in interface FindAndReplaceTarget

hasPrevious

public boolean hasPrevious()
Description copied from interface: FindAndReplaceTarget
Checks if there is more chunk of text before the current text when FindAndReplace reaches the start of the current text when searching backward.

Specified by:
hasPrevious in interface FindAndReplaceTarget
Returns:
true if there is another piece of text after the current text.

previous

public void previous()
Description copied from interface: FindAndReplaceTarget
Changes the current text to the previous one.

Specified by:
previous in interface FindAndReplaceTarget

getCurrentPosition

public int getCurrentPosition(boolean forward)
Description copied from interface: FindAndReplaceTarget
Gets the current position where the next search will start. Usually in a CodeEditor, it will be the caret position.

Specified by:
getCurrentPosition in interface FindAndReplaceTarget
Parameters:
forward - true or false.
Returns:
the current position.

adjustCurrentPosition

public void adjustCurrentPosition(String searchingText,
                                  boolean forward)
Description copied from interface: FindAndReplaceTarget
Adjusts current position according to searching text in the first attempt to search.

Specified by:
adjustCurrentPosition in interface FindAndReplaceTarget
Parameters:
searchingText - current searching text
forward - true or false.

highlight

public void highlight(int start,
                      int end)
Description copied from interface: FindAndReplaceTarget
Highlights the text to indicate the text matches the searching criteria.

Specified by:
highlight in interface FindAndReplaceTarget
Parameters:
start - the start offset of the text that is found.
end - the end offset of the text that is found.

replace

public void replace(int offset,
                    int len,
                    String str)
             throws BadLocationException
Description copied from interface: FindAndReplaceTarget
Replaces some text with the new text. This method is used to replace the text.

Specified by:
replace in interface FindAndReplaceTarget
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

getPromptDialogParent

public Window getPromptDialogParent()
Description copied from interface: FindAndReplaceTarget
Gets the window that can be used as the parent of the prompt dialog.

Specified by:
getPromptDialogParent in interface FindAndReplaceTarget
Returns:
the window that can be used as the parent of the prompt dialog.

getPromptDialogLocation

public Point getPromptDialogLocation(Rectangle dialogBounds)
Description copied from interface: FindAndReplaceTarget
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.

Specified by:
getPromptDialogLocation in interface FindAndReplaceTarget
Parameters:
dialogBounds - the bounds of the dialog before determining its location
Returns:
the prompt dialog location.

getPromptDialogLocation

public Point getPromptDialogLocation()
Description copied from interface: FindAndReplaceTarget
Gets the default prompt dialog location without concerning the caret position.

Specified by:
getPromptDialogLocation in interface FindAndReplaceTarget
Returns:
the prompt dialog location.

scrollToShowCaret

public void scrollToShowCaret(Rectangle promptDialogBounds)
Description copied from interface: FindAndReplaceTarget
Scrolls to show caret.

Specified by:
scrollToShowCaret in interface FindAndReplaceTarget
Parameters:
promptDialogBounds - the prompt dialog bounds

getCurrentName

public String getCurrentName()
Description copied from interface: FindAndReplaceTarget
Gets the name of the target.

Specified by:
getCurrentName in interface FindAndReplaceTarget
Returns:
the name of the target.

getCurrentText

public CharSequence getCurrentText()
Description copied from interface: FindAndReplaceTarget
Gets the current text.

Specified by:
getCurrentText in interface FindAndReplaceTarget
Returns:
the current text.

showMessage

public void showMessage(String message)
Description copied from interface: FindAndReplaceTarget
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.

Specified by:
showMessage in interface FindAndReplaceTarget
Parameters:
message - the message

replaceAllStarts

public void replaceAllStarts()
Description copied from interface: FindAndReplaceTarget
Replace all starts. This is used by undo feature so that when undo this operation, it undoes all string that were replaced.

Specified by:
replaceAllStarts in interface FindAndReplaceTarget

replaceAllEnds

public void replaceAllEnds()
Description copied from interface: FindAndReplaceTarget
Replace all ends. This is used by undo feature so that when undo this operation, it undoes all string that were replaced.

Specified by:
replaceAllEnds in interface FindAndReplaceTarget

setTargetChanged

protected void setTargetChanged(boolean targetChanged)

isTargetChanged

public boolean isTargetChanged()
Description copied from interface: FindAndReplaceTarget
Checks if the text in the target changes.

Specified by:
isTargetChanged in interface FindAndReplaceTarget
Returns:
true if the text changes. Otherwise false.

insertUpdate

public void insertUpdate(DocumentEvent e)
Specified by:
insertUpdate in interface DocumentListener

removeUpdate

public void removeUpdate(DocumentEvent e)
Specified by:
removeUpdate in interface DocumentListener

changedUpdate

public void changedUpdate(DocumentEvent e)
Specified by:
changedUpdate in interface DocumentListener

getResourceString

public String getResourceString(String key)
Description copied from interface: FindAndReplaceTarget
Gets resource string from target.

Specified by:
getResourceString in interface FindAndReplaceTarget
Parameters:
key - the resource key
Returns:
the localized resource string.

getLocale

public Locale getLocale()
Description copied from interface: FindAndReplaceTarget
Gets the target's locale.

Specified by:
getLocale in interface FindAndReplaceTarget
Returns:
the locale in use.

JIDE 3.5.15