| |
|
| java.lang.Object com.jidesoft.swing.Searchable com.jidesoft.swing.TextComponentSearchable
TextComponentSearchable | public class TextComponentSearchable extends Searchable implements DocumentListener,PropertyChangeListener(Code) | | TextComponentSearchable is an concrete implementation of
Searchable that enables the search function in JTextComponent.
It's very simple to use it. Assuming you have a JTextComponent, all you need to do is to
call
JTextComponent textComponent = ....;
TextComponentSearchable searchable = new TextComponentSearchable(textComponent);
Now the JTextComponent will have the search function.
There is very little customization you need to do to ListSearchable. The only thing you might
need is when the element in the JTextComponent needs a special conversion to convert to string. If so, you can overide
convertElementToString() to provide you own algorithm to do the conversion.
JTextComponent textComponent = ....;
TextComponentSearchable searchable = new ListSearchable(textComponent) {
protected String convertElementToString(Object object) {
...
}
protected boolean isActivateKey(KeyEvent e) { // change to a different activation key
return (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_F && (KeyEvent.CTRL_MASK & e.getModifiers()) != 0);
}
};
Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes,
case sensitivity. TextComponentSearchable also has a special attribute called highlightColor. You can change it using
TextComponentSearchable.setHighlightColor(java.awt.Color) .
Due to the special case of JTextComponent, the searching doesn't
support wild card '*' or '?' as in other Searchables. The other difference is JTextComponent
will keep the highlights after search popup hides. If you want to hide the highlights, just press
ESC again (the first ESC will hide popup; the second ESC will hide all highlights if any).
|
addHighlight | protected void addHighlight(int index, String text, boolean incremental) throws BadLocationException(Code) | | Adds highlight to text component at specified index and text.
Parameters: index - the index of the text to be highlighted Parameters: text - the text to be highlighted Parameters: incremental - if this is an incremental adding highlight throws: BadLocationException - |
convertElementToString | protected String convertElementToString(Object object)(Code) | | Converts the element in JTextComponent to string. The returned value will be the
toString() of whatever element that returned from list.getModel().getElementAt(i) .
Parameters: object - the string representing the element in the JTextComponent. |
getElementCount | protected int getElementCount()(Code) | | |
getHighlightColor | public Color getHighlightColor()(Code) | | Gets the highlight color.
the highlight color. |
getSelectedIndex | protected int getSelectedIndex()(Code) | | |
installHighlightsRemover | public void installHighlightsRemover()(Code) | | Installs the handler for ESC key to remove all highlights
|
installListeners | public void installListeners()(Code) | | |
removeAllHighlights | protected void removeAllHighlights()(Code) | | Removes all highlights from the text component.
|
reverseFindFromCursor | public int reverseFindFromCursor(String s)(Code) | | |
setHighlightColor | public void setHighlightColor(Color highlightColor)(Code) | | Changes the highlight color.
Parameters: highlightColor - |
setSelectedIndex | protected void setSelectedIndex(int index, boolean incremental)(Code) | | |
uninstallHighlightsRemover | public void uninstallHighlightsRemover()(Code) | | Uninstalls the handler for ESC key to remove all highlights
|
uninstallListeners | public void uninstallListeners()(Code) | | |
|
|
|