Package adams.gui.core
Class SearchPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.core.SearchPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class SearchPanel extends BasePanel
A panel that displays a search box. With optional display of regular expression checkbox.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SearchPanel.LayoutType
The layout of the panel.-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
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
Fields Modifier and Type Field Description protected String
m_ButtonCaption
the caption (+ optional mnemonic indicator) for the search button.protected JLabel
m_ButtonClear
the button for clearing the search.protected JLabel
m_ButtonSearch
the button for performing the search.protected BaseCheckBox
m_CheckboxRegExp
whether to use regular expressions for searching or plain string comparison.protected boolean
m_Incremental
whether incremental search is enabled.protected JLabel
m_LabelPrefix
the label for the text field.protected String
m_LastSearch
the last search term.protected SearchPanel.LayoutType
m_LayoutType
the layout.protected int
m_MinimumChars
the minimum number of characters before triggering search events.protected JPanel
m_PanelButtons
the button panel.protected JPanel
m_PanelSearchText
the panel for the search text and clear button.protected JPanel
m_PanelWidgets
the panel with the buttons and search box.protected String
m_Prefix
the prefix (caption + optional mnemonic indicator).protected boolean
m_RegExpEnabled
whether regular expressions are enabled.protected Set<SearchListener>
m_SearchListeners
the listeners for a search being initiated.protected BaseTextField
m_TextSearch
the text field for entering the search text.protected List<Component>
m_Widgets
the widgets.-
Fields inherited from class adams.gui.core.BasePanel
m_FileChooser
-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description SearchPanel(SearchPanel.LayoutType layout, boolean regExp)
Initializes the panel.SearchPanel(SearchPanel.LayoutType layout, boolean regExp, String prefix, boolean incremental, String button)
Initializes the panel with optional incremental search (and no search button if incremental search turned on).SearchPanel(SearchPanel.LayoutType layout, boolean regExp, String prefix, String button)
Initializes the panel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSearchListener(SearchListener l)
Adds the specified listener to the internal list of listeners.void
addToWidgetsPanel(Component comp)
Adds the component to the panel with the Widgets.void
addToWidgetsPanel(Component comp, int index)
Adds the component to the panel with the Widgets.protected void
clearSearch()
Clears a previous search if the last search term had a non-zero length.void
clearWidgetsPanel()
Removes all components from the panel holding the Widgets.protected BasePopupMenu
createPopup(MouseEvent e)
Generates a popup for the search field.String
getButtonCaption()
Returns the current caption of the search button (incl.SearchPanel.LayoutType
getLayoutType()
Returns the type of layout.int
getMinimumChars()
Returns the minimum number of characters that the user needs to enter before triggering a search event.String
getSearchText()
Returns the text in the search box.int
getTextColumns()
Returns the number of columns of the text field.void
grabFocus()
The text field for the search tries to grab the focus.protected boolean
hasPrefix()
Checks whether a prefix string was provided.protected void
initGUI()
Initializes the widgets.protected void
initialize()
Initializes the members.boolean
isEnabled()
Returns whether the panel is enabled or not.boolean
isIncremental()
Returns whether incremental search is enabled.boolean
isRegularExpression()
Returns whether the search text is a regular expression one or not.boolean
isRegularExpressionEnabled()
Returns whether regular expressions are turned on.protected boolean
isValidSearch()
Checks whether the search is valid.protected void
notifySearchListeners(SearchEvent e)
Sends out the event to all listeners.protected void
performSearch()
Initiates a search.void
removeFromWidgetsPanel(Component comp)
Removes the component from the panel with the Widgets.void
removeSearchListener(SearchListener l)
Removes the specified listener from the internal list of listeners.void
search()
Imitates a click on the search button to initiate a search.void
setButtonCaption(String value)
The caption for the search button (incl.void
setEnabled(boolean value)
Sets the enabled state of the components.void
setIncremental(boolean value)
Sets whether to enabled incremental search.void
setMinimumChars(int value)
Sets the minimum number of characters that the user needs to enter before triggering a search event.void
setRegularExpression(boolean value)
Sets whether the search text is a regular expression one or not.void
setRegularExpressionEnabled(boolean value)
Sets whether to use regexp search or plain substring matching.void
setSearchText(String value)
Sets the search text.void
setTextColumns(int value)
Sets the number of columns for the text field.protected void
updateLayout()
Updates the layout.protected void
updateWidgets()
Lays out the widgets according to the layout.void
updateWidth(int width)
In case of vertical display, the size of the panel can be adjusted to the specified width.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_LayoutType
protected SearchPanel.LayoutType m_LayoutType
the layout.
-
m_RegExpEnabled
protected boolean m_RegExpEnabled
whether regular expressions are enabled.
-
m_Incremental
protected boolean m_Incremental
whether incremental search is enabled.
-
m_Prefix
protected String m_Prefix
the prefix (caption + optional mnemonic indicator).
-
m_ButtonCaption
protected String m_ButtonCaption
the caption (+ optional mnemonic indicator) for the search button.
-
m_LabelPrefix
protected JLabel m_LabelPrefix
the label for the text field.
-
m_PanelSearchText
protected JPanel m_PanelSearchText
the panel for the search text and clear button.
-
m_TextSearch
protected BaseTextField m_TextSearch
the text field for entering the search text.
-
m_CheckboxRegExp
protected BaseCheckBox m_CheckboxRegExp
whether to use regular expressions for searching or plain string comparison.
-
m_ButtonClear
protected JLabel m_ButtonClear
the button for clearing the search.
-
m_ButtonSearch
protected JLabel m_ButtonSearch
the button for performing the search.
-
m_PanelButtons
protected JPanel m_PanelButtons
the button panel.
-
m_PanelWidgets
protected JPanel m_PanelWidgets
the panel with the buttons and search box.
-
m_SearchListeners
protected Set<SearchListener> m_SearchListeners
the listeners for a search being initiated.
-
m_MinimumChars
protected int m_MinimumChars
the minimum number of characters before triggering search events.
-
m_LastSearch
protected String m_LastSearch
the last search term.
-
-
Constructor Detail
-
SearchPanel
public SearchPanel(SearchPanel.LayoutType layout, boolean regExp)
Initializes the panel.- Parameters:
layout
- the layout of the panelregExp
- whether to display regular expressions
-
SearchPanel
public SearchPanel(SearchPanel.LayoutType layout, boolean regExp, String prefix, String button)
Initializes the panel.- Parameters:
layout
- the layout of the panelregExp
- whether to display regular expressionsprefix
- the prefix label to use, use null to ignore. Mnemonics can be indicated by a preceding underscore "_".button
- the caption for the button. Mnemonics can be indicated by a preceding underscore "_".
-
SearchPanel
public SearchPanel(SearchPanel.LayoutType layout, boolean regExp, String prefix, boolean incremental, String button)
Initializes the panel with optional incremental search (and no search button if incremental search turned on).- Parameters:
layout
- the layout of the panelregExp
- whether to display regular expressionsprefix
- the prefix label to use, use null to ignore. Mnemonics can be indicated by a preceding underscore "_".incremental
- if true then no search button will be displayedbutton
- the caption for the button. Mnemonics can be indicated by a preceding underscore "_".
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classBasePanel
-
updateLayout
protected void updateLayout()
Updates the layout.
-
createPopup
protected BasePopupMenu createPopup(MouseEvent e)
Generates a popup for the search field.- Parameters:
e
- the mouse event
-
setEnabled
public void setEnabled(boolean value)
Sets the enabled state of the components.- Overrides:
setEnabled
in classJComponent
- Parameters:
value
- if true then the components are enabled otherwise not
-
isEnabled
public boolean isEnabled()
Returns whether the panel is enabled or not.
-
getLayoutType
public SearchPanel.LayoutType getLayoutType()
Returns the type of layout.- Returns:
- the layout
-
hasPrefix
protected boolean hasPrefix()
Checks whether a prefix string was provided.- Returns:
- true if a prefix string was supplied
-
setRegularExpressionEnabled
public void setRegularExpressionEnabled(boolean value)
Sets whether to use regexp search or plain substring matching.- Parameters:
value
- true if regular expression search is to be used
-
isRegularExpressionEnabled
public boolean isRegularExpressionEnabled()
Returns whether regular expressions are turned on.- Returns:
- true if regular expressions are enabled
-
setSearchText
public void setSearchText(String value)
Sets the search text.- Parameters:
value
- the new search text
-
getSearchText
public String getSearchText()
Returns the text in the search box.- Returns:
- the current search text
-
setRegularExpression
public void setRegularExpression(boolean value)
Sets whether the search text is a regular expression one or not.- Parameters:
value
- if true then regular expression search will be enabled
-
isRegularExpression
public boolean isRegularExpression()
Returns whether the search text is a regular expression one or not.- Returns:
- true if a regular expression search
-
setIncremental
public void setIncremental(boolean value)
Sets whether to enabled incremental search.- Parameters:
value
- true if incremental search enabled
-
isIncremental
public boolean isIncremental()
Returns whether incremental search is enabled.- Returns:
- true if incremental search enabled
-
setMinimumChars
public void setMinimumChars(int value)
Sets the minimum number of characters that the user needs to enter before triggering a search event.- Parameters:
value
- the minimum number of characters (>= 1)
-
getMinimumChars
public int getMinimumChars()
Returns the minimum number of characters that the user needs to enter before triggering a search event.- Returns:
- the minimum number of characters (>= 1)
-
setTextColumns
public void setTextColumns(int value)
Sets the number of columns for the text field.- Parameters:
value
- the number of columns (>0)
-
getTextColumns
public int getTextColumns()
Returns the number of columns of the text field.- Returns:
- the number of columns (>0)
-
setButtonCaption
public void setButtonCaption(String value)
The caption for the search button (incl. mnemonic). Ignored if button is not being displayed.- Parameters:
value
- the caption
-
getButtonCaption
public String getButtonCaption()
Returns the current caption of the search button (incl. mnemonic).- Returns:
- the caption or null if button not displayed
-
clearWidgetsPanel
public void clearWidgetsPanel()
Removes all components from the panel holding the Widgets.
-
addToWidgetsPanel
public void addToWidgetsPanel(Component comp, int index)
Adds the component to the panel with the Widgets.- Parameters:
comp
- the component to addindex
- the index where to add the component, -1 adds the component at the end
-
addToWidgetsPanel
public void addToWidgetsPanel(Component comp)
Adds the component to the panel with the Widgets.- Parameters:
comp
- the component to add
-
removeFromWidgetsPanel
public void removeFromWidgetsPanel(Component comp)
Removes the component from the panel with the Widgets.- Parameters:
comp
- the component to remove
-
updateWidgets
protected void updateWidgets()
Lays out the widgets according to the layout.
-
addSearchListener
public void addSearchListener(SearchListener l)
Adds the specified listener to the internal list of listeners.- Parameters:
l
- the listener to add
-
removeSearchListener
public void removeSearchListener(SearchListener l)
Removes the specified listener from the internal list of listeners.- Parameters:
l
- the listener to remove
-
notifySearchListeners
protected void notifySearchListeners(SearchEvent e)
Sends out the event to all listeners.- Parameters:
e
- the event to send
-
performSearch
protected void performSearch()
Initiates a search.
-
clearSearch
protected void clearSearch()
Clears a previous search if the last search term had a non-zero length.
-
isValidSearch
protected boolean isValidSearch()
Checks whether the search is valid.- Returns:
- true if the search is valid
-
search
public void search()
Imitates a click on the search button to initiate a search.
-
grabFocus
public void grabFocus()
The text field for the search tries to grab the focus.- Overrides:
grabFocus
in classJComponent
-
updateWidth
public void updateWidth(int width)
In case of vertical display, the size of the panel can be adjusted to the specified width.- Parameters:
width
- the new width
-
-