|
JIDE 3.5.15 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JToolBar
com.jidesoft.swing.SearchableBar
public class SearchableBar
SearchableBar is a convenient component to enable searching feature for components. As long as the
component support Searchable feature, it can work with SearchableBar.
Searchable feature which uses a small popup window to allow user typing in the searching
text, SearchableBar provides a full-size panel. Although they both pretty provide the same set of
features, they should be used in different cases to achieve the most desirable result.
First of all, SearchableBar is a lot bigger than Searchable's popup and need more space on
the screen. The component that installs SearchableBar should be large enough. In comparison,
Searchable can be installed on components of any size as it's a floating popup.
Secondly, SearchableBar can be set visible all the time or can be set visible by a keystroke and stay
visible unless user explicitly hides it. If your user is not computer savvy, SearchableBar is more
appropriate because user can see searching feature very easily. SearchableBar can also be a better
replacement the traditional "Find" or "Search" dialog because SearchableBar doesn't block user input
like modal dialog. In comparison, Searchable's popup is very transient. Mouse clicks outside the popup
will hide the popup. For computer savvy it is very helpful but it could be hard for non-computer savvy to
"understand" it. A good example is IntelliJ IDEA heavily uses Searchable popup because the users are all Java
developers. Firefox, on the other hand, uses SearchableBar because the users are just regular computer users.
Although appearance wise, these two are very different, they both based on Searchable interface. So as
developer, both are almost the same. SearchableBar based on Searchable. So if you have an
interface of Searchable, all you need is to call
SearchableBar.install(searchable, KeyStroke.getKeyStroke(KeyEvent.VK_F,
KeyEvent.CTRL_DOWN_MASK),
new SearchableBar.Installer() {
public void openSearchBar(SearchableBar searchableBar) {
// add code to show search bar
}
public void closeSearchBar(SearchableBar searchableBar) {
// add code to close search bar
}
});
Or if you want fully control the SearchableBar, you can create one using one of its constructors and add to wherever
you want.
There are a few options you can set on SearchableBar. You can set compact or full mode. Compact mode
will only use icon for buttons v.s. full mode will use both icon and text for buttons. All buttons on the
SearchableBar can be shown/hidden by using setVisibleButtons(int) method. You can also set the
text field background for mismatch by using setMismatchForeground(java.awt.Color).
| Nested Class Summary | |
|---|---|
static interface |
SearchableBar.Installer
The installer for SearchableBar. |
| Nested classes/interfaces inherited from class javax.swing.JToolBar |
|---|
JToolBar.AccessibleJToolBar, JToolBar.Separator |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected AbstractButton |
_closeButton
|
protected JComboBox |
_comboBox
|
protected AbstractButton |
_findNextButton
|
protected AbstractButton |
_findPrevButton
|
protected AbstractButton |
_highlightsButton
|
protected JLabel |
_leadingLabel
|
protected AbstractButton |
_matchCaseCheckBox
|
protected AbstractButton |
_repeatCheckBox
|
protected JLabel |
_statusLabel
|
protected JTextField |
_textField
|
protected AbstractButton |
_wholeWordsCheckBox
|
static String |
PROPERTY_MAX_HISTORY_LENGTH
|
static int |
SHOW_ALL
|
static int |
SHOW_CLOSE
|
static int |
SHOW_HIGHLIGHTS
|
static int |
SHOW_MATCHCASE
|
static int |
SHOW_NAVIGATION
|
static int |
SHOW_REPEATS
|
static int |
SHOW_STATUS
|
static int |
SHOW_WHOLE_WORDS
|
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface javax.swing.SwingConstants |
|---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
SearchableBar(Searchable searchable)
Creates a searchable bar. |
|
SearchableBar(Searchable searchable,
boolean compact)
Creates a searchable bar in compact mode or full mode. |
|
SearchableBar(Searchable searchable,
String initialText,
boolean compact)
Creates a searchable bar with initial searching text and in compact mode or full mode. |
|
| Method Summary | |
|---|---|
protected AbstractButton |
createCloseButton(AbstractAction closeAction)
Creates the close button. |
protected JComboBox |
createComboBox()
Creates the combo box where user types the text to be searched. |
protected AbstractButton |
createFindNextButton(AbstractAction findNextAction)
Creates the find next button. |
protected AbstractButton |
createFindPrevButton(AbstractAction findPrevAction)
Creates the find prev button. |
protected AbstractButton |
createHighlightButton()
Creates the highlight button. |
protected AbstractButton |
createMatchCaseButton()
Creates the match case button. |
protected AbstractButton |
createRepeatsButton()
Creates the repeat button. |
protected JTextField |
createTextField()
Creates the text field where user types the text to be searched. |
protected AbstractButton |
createWholeWordsButton()
Creates the whole words button. |
void |
focusSearchField()
Makes the search field having focus. |
protected ImageIcon |
getImageIcon(String name)
Gets the icons from SearchableBarIconsFactory. |
SearchableBar.Installer |
getInstaller()
|
int |
getMaxHistoryLength()
Gets the maximum search history length. |
Color |
getMismatchBackground()
Gets the background color when the searching text doesn't match with any of the elements in the component. |
protected String |
getResourceString(String key)
Gets the localized string from resource bundle. |
Searchable |
getSearchable()
Gets the underlying Searchable object. |
String[] |
getSearchHistory()
Gets the search history. |
String |
getSearchingText()
Gets the searching text. |
int |
getVisibleButtons()
|
static SearchableBar |
install(Searchable searchable,
KeyStroke keyStroke,
SearchableBar.Installer installer)
Installs a SearchableBar on a component. |
protected void |
installComponents()
Adds the buttons to the SearchableBar. |
boolean |
isCompact()
Checks if SearchableBar is in compact mode. |
boolean |
isHighlightAll()
Get if the SearchableBar is highlighting all matches. |
boolean |
isPassive()
Returns false. |
boolean |
isShowMatchCount()
Gets the flag indicating if the match count should be displayed in the status label. |
void |
processKeyEvent(KeyEvent e)
|
protected void |
select(int index,
String searchingText,
boolean incremental)
|
void |
setCompact(boolean compact)
Sets the SearchableBar to compact or full mode. |
void |
setHighlightAll(boolean highlightAll)
Set if the SearchableBar will highlight all matches. |
void |
setInstaller(SearchableBar.Installer installer)
Sets the installer. |
void |
setMaxHistoryLength(int maxHistoryLength)
Sets the maximum search history length. |
void |
setMismatchForeground(Color mismatchBackground)
Sets the background for mismatch. |
void |
setSearchHistory(String[] searchHistory)
Sets the search history. |
void |
setSearchingText(String searchingText)
Sets the searching text. |
void |
setShowMatchCount(boolean showMatchCount)
Sets the flag indicating if the match count should be displayed in the status label. |
void |
setVisibleButtons(int visibleButtons)
Sets visible buttons on SearchableBar. |
| Methods inherited from class javax.swing.JToolBar |
|---|
add, addImpl, addSeparator, addSeparator, createActionChangeListener, createActionComponent, getAccessibleContext, getComponentAtIndex, getComponentIndex, getMargin, getOrientation, getUI, getUIClassID, isBorderPainted, isFloatable, isRollover, paintBorder, paramString, setBorderPainted, setFloatable, setLayout, setMargin, setOrientation, setRollover, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected JLabel _statusLabel
protected JLabel _leadingLabel
protected JTextField _textField
protected JComboBox _comboBox
protected AbstractButton _closeButton
protected AbstractButton _findPrevButton
protected AbstractButton _findNextButton
protected AbstractButton _highlightsButton
protected AbstractButton _matchCaseCheckBox
protected AbstractButton _wholeWordsCheckBox
protected AbstractButton _repeatCheckBox
public static final int SHOW_CLOSE
public static final int SHOW_NAVIGATION
public static final int SHOW_HIGHLIGHTS
public static final int SHOW_MATCHCASE
public static final int SHOW_REPEATS
public static final int SHOW_STATUS
public static final int SHOW_WHOLE_WORDS
public static final int SHOW_ALL
public static final String PROPERTY_MAX_HISTORY_LENGTH
| Constructor Detail |
|---|
public SearchableBar(Searchable searchable)
searchable - the searchable
public SearchableBar(Searchable searchable,
boolean compact)
searchable - the searchablecompact - the flag indicating compact mode or full mode
public SearchableBar(Searchable searchable,
String initialText,
boolean compact)
searchable - the searchableinitialText - the initial textcompact - the flag indicating compact mode or full mode| Method Detail |
|---|
protected JTextField createTextField()
protected JComboBox createComboBox()
public Searchable getSearchable()
protected AbstractButton createCloseButton(AbstractAction closeAction)
closeAction - the close action
protected AbstractButton createFindNextButton(AbstractAction findNextAction)
findNextAction - the find next action
protected AbstractButton createFindPrevButton(AbstractAction findPrevAction)
findPrevAction - the find previous action
protected AbstractButton createHighlightButton()
protected AbstractButton createRepeatsButton()
protected AbstractButton createMatchCaseButton()
protected AbstractButton createWholeWordsButton()
protected void installComponents()
public boolean isHighlightAll()
public void setHighlightAll(boolean highlightAll)
highlightAll - the flagisHighlightAll()public void focusSearchField()
protected void select(int index,
String searchingText,
boolean incremental)
public String getSearchingText()
getSearchingText in interface SearchableProviderpublic void setSearchingText(String searchingText)
searchingText - the new searching text.public boolean isPassive()
isPassive in interface SearchableProviderpublic void setMismatchForeground(Color mismatchBackground)
mismatchBackground - the mismatch backgroundpublic Color getMismatchBackground()
setMismatchForeground(java.awt.Color). red
color will be used.public String[] getSearchHistory()
public void setSearchHistory(String[] searchHistory)
searchHistory - the search historypublic int getMaxHistoryLength()
#setMaxHistoryLength(int)}public void setMaxHistoryLength(int maxHistoryLength)
maxHistoryLength - the maximum history lengthpublic boolean isShowMatchCount()
setShowMatchCount(boolean)public void setShowMatchCount(boolean showMatchCount)
showMatchCount - public SearchableBar.Installer getInstaller()
public void setInstaller(SearchableBar.Installer installer)
installer - the installer
public static SearchableBar install(Searchable searchable,
KeyStroke keyStroke,
SearchableBar.Installer installer)
final SearchableBar searchableBar = new SearchableBar(searchable);
searchableBar.setInstaller(installer);
((JComponent) searchable.getComponent()).registerKeyboardAction(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
searchableBar.getInstaller().openSearchBar(searchableBar);
searchableBar.focusSearchField();
}
}, keyStroke, JComponent.WHEN_FOCUSED);
return searchableBar;
searchable - the searchablekeyStroke - the key strokeinstaller - the installer
public void processKeyEvent(KeyEvent e)
processKeyEvent in interface SearchableProviderprocessKeyEvent in class JComponentpublic int getVisibleButtons()
public void setVisibleButtons(int visibleButtons)
SearchableBar.
visibleButtons - bit-wise all of several constants. Valid constants are SHOW_CLOSE - the
close button SHOW_NAVIGATION - the find next and find previous buttons SHOW_HIGHLIGHTS - highlights all button SHOW_MATCHCASE - match case
button SHOW_WHOLE_WORDS - word only button SHOW_REPEATS - repeats
button SHOW_STATUS - status area SHOW_ALL - all buttons setVisibleButtons(SearchableBar.SHOW_CLOSE | SearchableBar.SHOW_HIGHLIGHTS).public boolean isCompact()
SearchableBar is in compact mode.
public void setCompact(boolean compact)
SearchableBar to compact or full mode. In compact mode will only use icon for buttons v.s.
full mode will use both icon and text for buttons.
compact - the flagprotected ImageIcon getImageIcon(String name)
name - the icon name
protected String getResourceString(String key)
key - the resource key
|
JIDE 3.5.15 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||