java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.autogui.swing.util.SearchTextField
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
- Direct Known Subclasses:
GuiSwingViewStringField.PropertyStringPane
,SearchTextFieldFilePath
a text-field implementation with supporting background searching.
[ icon: JButton | textField | popupButton ] [ popupMenu: model.getCandidates(textField.text,...) ]The popup menus are composition of
getMenuItemsSource()
-> PopupExtensionText.getEditActions(JTextComponent)
,
and
getSearchedItems()
whose items are set by
setCurrentSearchedItems(List, boolean)
or
setCurrentSearchedItems(List, PopupCategorized.CategorizedMenuItem)
,
called from SearchTextField.SearchTask
's background task via SearchTextField.SearchTextFieldModel
.
If a background task calls setCurrentSearchedItems and getSearchedItems()
is changed,
then SearchTextField.SearchedItemsListener
is called.
In initPopup()
, it registers a listener returned by
getPopupUpdateListener(PopupExtensionText, PopupCategorized)
,
which dynamically calls PopupExtension.setupMenu()
.
If the user edits texts, then it needs to dynamically update the popup.
To do this, initField()
sets up
EditingRunner
with updateField(List)
and registers it to the field as document listener, action listener and focus listener .
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
an action for searching, filtering and selecting itemsstatic class
an interface for painting backgroundstatic class
the painter impl.static interface
a listener interface for receiving the searched itemsstatic class
the background searching taskstatic interface
the interface for the searching modelstatic class
the empty model for searching nothingstatic interface
the intermediate items submission targetstatic class
empty impl.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
FieldsModifier and TypeFieldDescriptionprotected SearchTextField.SearchBackgroundPainter
protected JComponent
parent component ofpopupButton
protected List
<PopupCategorized.CategorizedMenuItem> protected SearchTextField.SearchTask
protected EditingRunner
protected static ImageIcon
protected JTextField
protected JButton
protected SearchTextField.SearchTextFieldModel
protected PopupExtensionText
protected JButton
protected List
<SearchTextField.SearchedItemsListener> protected KeyUndoManager
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
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addSearchItemsListener
(SearchTextField.SearchedItemsListener itemsListener) convertIcon
(Icon icon) createSearchTask
(String text) protected void
getDynamicItemAction
(String name, KeyStroke key, boolean put) an action for dynamic created menu items: the returned action searches an action by the specified key.protected int
getField()
static Color
getIcon()
getModel()
getPopup()
getPopupUpdateListener
(PopupExtensionText popup, PopupCategorized categorized) void
init()
void
void
void
void
initIcon()
void
protected List
<? extends JComponent> popupButton
by defaultprotected void
setting upbuttonsPane
void
initPopupCategorized
(Supplier<? extends Collection<PopupCategorized.CategorizedMenuItem>> itemSupplier, Consumer<PopupCategorized.CategorizedMenuItem> itemConsumer) boolean
boolean
boolean
isUpdateFieldImmediateEvent
(List<Object> events) boolean
boolean
isUpdateFieldModifiedEvents
(List<Object> events) protected void
void
removeSearchItemsListener
(SearchTextField.SearchedItemsListener itemsListener) void
the user selects the item from the menu.void
called when the search is done, and update only the iconvoid
setBackground
(Color bg) void
void
setCurrentSearchedItems
(List<PopupCategorized.CategorizedMenuItem> currentSearchedItems, boolean done) set the searched items from the background task: it might be an intermediate resultvoid
setCurrentSearchedItems
(List<PopupCategorized.CategorizedMenuItem> currentSearchedItems, PopupCategorized.CategorizedMenuItem selection) called once when the search is donevoid
void
void
void
setToolTipText
(String text) void
set the transfer handler to the pane, the field and the icon button.static void
setupCopyAndPaste
(JComponent component) void
shutdown()
void
updateField
(List<Object> events) After editing text or action performed, this method will be executed under the scheduler threadvoid
updateFieldInEvent
(boolean modified, boolean immediate) executed under event thread: start a new search task in backgroundMethods 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
Methods inherited from class java.awt.Container
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, getAccessibleContext, 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, isEnabled, 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 Details
-
model
-
icon
-
field
-
editingRunner
-
popup
-
popupButton
-
buttonsPane
parent component ofpopupButton
- Since:
- 1.5
-
currentSearchedItems
-
currentTask
-
searchedItemsListeners
-
emptyIcon
-
backgroundPainter
-
undoManager
-
-
Constructor Details
-
SearchTextField
public SearchTextField() -
SearchTextField
-
-
Method Details
-
init
public void init() -
initIcon
public void initIcon() -
getEmptyIcon
-
initField
public void initField() -
initAfter
public void initAfter() -
setTransferHandlerWithSettingExportingDragSource
set the transfer handler to the pane, the field and the icon button. Also, set up the dragging gesture with COPY operation for the field and the icon.- Parameters:
handler
- the target handler
-
setupCopyAndPaste
-
getEditingRunnerDelay
protected int getEditingRunnerDelay() -
initPopup
public void initPopup() -
initPopupCategorized
public PopupCategorized initPopupCategorized(Supplier<? extends Collection<PopupCategorized.CategorizedMenuItem>> itemSupplier, Consumer<PopupCategorized.CategorizedMenuItem> itemConsumer) -
setToolTipText
- Overrides:
setToolTipText
in classJComponent
-
getMenuItems
-
getMenuItemsSource
- Returns:
- list of menu items including
Action
orJComponent
-
getPopupUpdateListener
public SearchTextField.SearchedItemsListener getPopupUpdateListener(PopupExtensionText popup, PopupCategorized categorized) -
initLayout
public void initLayout() -
initLayoutButtonsPane
protected void initLayoutButtonsPane()setting upbuttonsPane
- Since:
- 1.5
-
initLayoutButtons
popupButton
by default- Returns:
- components added to
buttonsPane
- Since:
- 1.5
-
initBackgroundPainter
public void initBackgroundPainter() -
add
-
paintComponent
- Overrides:
paintComponent
in classJComponent
-
setBackground
- Overrides:
setBackground
in classJComponent
-
setBackgroundWithoutInit
-
getModel
-
getPopup
-
getPopupButton
-
getEditingRunner
-
getIcon
-
getField
-
getButtonsPane
- Returns:
- the pane at west
- Since:
- 1.5
-
getCurrentTask
-
addSearchItemsListener
-
removeSearchItemsListener
-
getSearchedItemsListeners
-
isSwingEditable
public boolean isSwingEditable() -
updateField
After editing text or action performed, this method will be executed under the scheduler thread- Parameters:
events
- the accumulated events
-
isUpdateFieldModifiedEvents
-
isUpdateFieldModifiedEvent
-
isUpdateFieldImmediateEvent
-
isUpdateFieldImmediateEvent
-
updateFieldInEvent
public void updateFieldInEvent(boolean modified, boolean immediate) executed under event thread: start a new search task in background- Parameters:
modified
- true if the field is actually editedimmediate
- if true, a background task will not be created even if the model supports it
-
doActionButtons
protected void doActionButtons()- Since:
- 1.5
-
createSearchTask
-
setCurrentSearchedItems
public void setCurrentSearchedItems(List<PopupCategorized.CategorizedMenuItem> currentSearchedItems, boolean done) set the searched items from the background task: it might be an intermediate result- Parameters:
currentSearchedItems
- the intermediate searched itemsdone
- true if the search is done
-
setCurrentSearchedItems
public void setCurrentSearchedItems(List<PopupCategorized.CategorizedMenuItem> currentSearchedItems, PopupCategorized.CategorizedMenuItem selection) called once when the search is done- Parameters:
currentSearchedItems
- the final result of the searchselection
- the selected item by the model
-
getSearchedItems
-
selectSearchedItemFromGui
the user selects the item from the menu. update selection in the model and also GUI display. It will stop the current running task if exists, and starts a new task.- Parameters:
item
- the selected item
-
selectSearchedItemFromModel
called when the search is done, and update only the icon- Parameters:
item
- the selected item by the model
-
setIconFromSearchedItem
-
convertIcon
-
setTextFromSearchedItem
-
setTextWithoutUpdateField
-
shutdown
public void shutdown() -
getFocusColor
-
getDynamicItemAction
public SearchTextField.DynamicItemAction getDynamicItemAction(String name, KeyStroke key, boolean put) an action for dynamic created menu items: the returned action searches an action by the specified key. SogetSearchedItems()
will contain an item with the key (PopupCategorized.CategorizedMenuItem.getKeyStroke()
).- Parameters:
name
- the name of the action, used for ActionMap and InputMap bindingkey
- the keystroke of the actionput
- if true, it binds to the component and also the field and the icon button- Returns:
- the created item
-