JIDE 3.5.15

com.jidesoft.editor
Class CodeEditorSearchable

java.lang.Object
  extended by com.jidesoft.swing.Searchable
      extended by com.jidesoft.editor.CodeEditorSearchable
All Implemented Interfaces:
WholeWordsSupport, PropertyChangeListener, EventListener, DocumentListener

public class CodeEditorSearchable
extends Searchable
implements DocumentListener, PropertyChangeListener, WholeWordsSupport

CodeEditorSearchable is an concrete implementation of Searchable that enables the search function in CodeEditor.

It's very simple to use it. Assuming you have a CodeEditor, all you need to do is to call

 CodeEditor editor = ....;
 CodeEditorSearchable searchable = new CodeEditorSearchable(editor);
 
Now the CodeEditor will have the search function.

Due to the special case of CodeEditor, the searching doesn't support wild card '*' or '?' as in other Searchables.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.swing.Searchable
Searchable.SearchField, Searchable.SearchPopup
 
Field Summary
 
Fields inherited from class com.jidesoft.swing.Searchable
_component, _componentListener, _focusListener, _keyListener, _matchCount, CLIENT_PROPERTY_SEARCHABLE, listenerList, PROPERTY_SEARCH_TEXT
 
Constructor Summary
CodeEditorSearchable(CodeEditor editor)
           
 
Method Summary
protected  void cancelHighlightAll()
          Cancel highlight all.
 void changedUpdate(DocumentEvent e)
           
protected  String convertElementToString(Object object)
          Converts the element in CodeEditor to string.
 int findFirst(String s)
          Finds the first element that matches the searching text.
 int findFromCursor(String s)
          Finds the next matching index from the cursor.
 int findLast(String s)
          Finds the last element that matches the searching text.
 int findNext(String s)
          Finds the next matching index from the cursor.
 int findPrevious(String s)
          Finds the previous matching index from the cursor.
 void firePropertyChangeEvent(String searchingText)
           
protected  Object getElementAt(int index)
          Gets the element at the specified index.
protected  int getElementCount()
          Gets the total element count in the component.
 Color getHighlightColor()
          Gets the highlight color.
protected  int getSelectedIndex()
          Gets the selected index in the component.
protected  void highlightAll()
          Highlight all matching cases in the target.
 void insertUpdate(DocumentEvent e)
           
 boolean isActivateKey(KeyEvent e)
          Checks if the key in KeyEvent should activate the search popup.
 boolean isWholeWords()
          Gets the wholeWords property.
 void propertyChange(PropertyChangeEvent evt)
           
 void removeUpdate(DocumentEvent e)
           
protected  void searchingTextEmpty()
          Actions to take on searching text empty scenario
 void setHighlightColor(Color highlightColor)
          Changes the highlight color.
protected  void setSelectedIndex(int index, boolean incremental)
          Sets the selected index.
 void setWholeWords(boolean wholeWords)
          Sets the wholeWords property.
 
Methods inherited from class com.jidesoft.swing.Searchable
addPropertyChangeListener, addSearchableListener, adjustSelectedIndex, compare, compare, convertToString, createComponentListener, createFocusListener, createKeyListener, createSearchPopup, findAll, fireSearchableEvent, getBackground, getComponent, getCurrentIndex, getCursor, getElementAtAsString, getForeground, getMismatchForeground, getPopupLocation, getPopupLocationRelativeTo, getPopupTimeout, getResourceString, getSearchable, getSearchableListeners, getSearchableProvider, getSearchingDelay, getSearchingText, getSearchLabel, getWildcardSupport, hidePopup, installListeners, isCaseSensitive, isCountMatch, isDeactivateKey, isFindFirstKey, isFindLastKey, isFindNextKey, isFindPreviousKey, isFromStart, isHeavyweightComponentEnabled, isHideSearchPopupOnEvent, isIncrementalSelectKey, isNavigationKey, isPopupVisible, isProcessModelChangeEvent, isRepeats, isReverseOrder, isSearchableListenerInstalled, isSelectAllKey, isWildcardEnabled, keyTypedOrPressed, removePropertyChangeListener, removeSearchableListener, reverseFindFromCursor, select, setBackground, setCaseSensitive, setCountMatch, setCursor, setCursor, setForeground, setFromStart, setHeavyweightComponentEnabled, setHideSearchPopupOnEvent, setMismatchForeground, setPopupLocation, setPopupLocationRelativeTo, setPopupTimeout, setProcessModelChangeEvent, setRepeats, setReverseOrder, setSearchableProvider, setSearchingDelay, setSearchLabel, setWildcardEnabled, setWildcardSupport, showPopup, textChanged, uninstallListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeEditorSearchable

public CodeEditorSearchable(CodeEditor editor)
Method Detail

getHighlightColor

public Color getHighlightColor()
Gets the highlight color.

Returns:
the highlight color.

setHighlightColor

public void setHighlightColor(Color highlightColor)
Changes the highlight color.

Parameters:
highlightColor - the hightlight color
See Also:
getHighlightColor()

firePropertyChangeEvent

public void firePropertyChangeEvent(String searchingText)
Overrides:
firePropertyChangeEvent in class Searchable

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

highlightAll

protected void highlightAll()
Description copied from class: Searchable
Highlight all matching cases in the target.

In default implementation, it will just search all texts in the target to highlight all. If you have a really huge text to search, you may want to override this method to have a lazy behavior on visible areas only.

Overrides:
highlightAll in class Searchable

cancelHighlightAll

protected void cancelHighlightAll()
Description copied from class: Searchable
Cancel highlight all.

By default, it does nothing. However, if you want to override Searchable.highlightAll(), you may want to override this method to notify your Searchable that the highlightAll button is to be released.

Overrides:
cancelHighlightAll in class Searchable

setSelectedIndex

protected void setSelectedIndex(int index,
                                boolean incremental)
Description copied from class: Searchable
Sets the selected index. The concrete implementation should call methods on the component to select the element at the specified index. The incremental flag is used to do multiple select. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.

Specified by:
setSelectedIndex in class Searchable
Parameters:
index - the index to be selected
incremental - a flag to enable multiple selection. If the flag is true, the element at the index should be added to current selection. If false, you should clear previous selection and then select the element.

getSelectedIndex

protected int getSelectedIndex()
Description copied from class: Searchable
Gets the selected index in the component. The concrete implementation should call methods on the component to retrieve the current selected index. If the component supports multiple selection, it's OK just return the index of the first selection.

Here are some examples. In the case of JList, the index is the row index. In the case of JTree, the index is the row index too. In the case of JTable, depending on the selection mode, the index could be row index (in row selection mode), could be column index (in column selection mode) or could the cell index (in cell selection mode).

Specified by:
getSelectedIndex in class Searchable
Returns:
the selected index.

getElementAt

protected Object getElementAt(int index)
Description copied from class: Searchable
Gets the element at the specified index. The element could be any data structure that internally used in the component. The convertElementToString method will give you a chance to convert the element to string which is used to compare with the string that user types in.

Specified by:
getElementAt in class Searchable
Parameters:
index - the index
Returns:
the element at the specified index.

getElementCount

protected int getElementCount()
Description copied from class: Searchable
Gets the total element count in the component. Different concrete implementation could have different interpretation of the count. This is totally OK as long as it's consistent in all the methods. For example, the index parameter in other methods should be always a valid value within the total count.

Specified by:
getElementCount in class Searchable
Returns:
the total element count.

convertElementToString

protected String convertElementToString(Object object)
Converts the element in CodeEditor to string. The returned value will be the toString() of whatever element that returned from list.getModel().getElementAt(i).

Specified by:
convertElementToString in class Searchable
Parameters:
object - the object to be converted to string
Returns:
the string representing the element in the CodeEditor.

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

isActivateKey

public boolean isActivateKey(KeyEvent e)
Description copied from class: Searchable
Checks if the key in KeyEvent should activate the search popup.

Overrides:
isActivateKey in class Searchable
Parameters:
e - the key event
Returns:
true if the keyChar is visible except space and tab.

findLast

public int findLast(String s)
Description copied from class: Searchable
Finds the last element that matches the searching text.

Overrides:
findLast in class Searchable
Parameters:
s - the searching text
Returns:
the last element that matches the searching text.

findFirst

public int findFirst(String s)
Description copied from class: Searchable
Finds the first element that matches the searching text.

Overrides:
findFirst in class Searchable
Parameters:
s - the searching text
Returns:
the first element that matches with the searching text.

findFromCursor

public int findFromCursor(String s)
Description copied from class: Searchable
Finds the next matching index from the cursor. If it reaches the end, it will restart from the beginning. However is the reverseOrder flag is true, it will finds the previous matching index from the cursor. If it reaches the beginning, it will restart from the end.

Overrides:
findFromCursor in class Searchable
Parameters:
s - the searching text
Returns:
the next index that the element matches the searching text.

findNext

public int findNext(String s)
Description copied from class: Searchable
Finds the next matching index from the cursor.

Overrides:
findNext in class Searchable
Parameters:
s - the searching text
Returns:
the next index that the element matches the searching text.

findPrevious

public int findPrevious(String s)
Description copied from class: Searchable
Finds the previous matching index from the cursor.

Overrides:
findPrevious in class Searchable
Parameters:
s - the searching text
Returns:
the previous index that the element matches the searching text.

isWholeWords

public boolean isWholeWords()
Gets the wholeWords property.

Specified by:
isWholeWords in interface WholeWordsSupport
Returns:
true or false.
Since:
3.5.2

setWholeWords

public void setWholeWords(boolean wholeWords)
Sets the wholeWords property.

Specified by:
setWholeWords in interface WholeWordsSupport
Parameters:
wholeWords - true if the comparison matches exactly the word only. Otherwise false.
Since:
3.5.2

searchingTextEmpty

protected void searchingTextEmpty()
Description copied from class: Searchable
Actions to take on searching text empty scenario

Overrides:
searchingTextEmpty in class Searchable

JIDE 3.5.15