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 classan action for searching, filtering and selecting itemsstatic classan interface for painting backgroundstatic classthe painter impl.static interfacea listener interface for receiving the searched itemsstatic classthe background searching taskstatic interfacethe interface for the searching modelstatic classthe empty model for searching nothingstatic interfacethe intermediate items submission targetstatic classempty impl.Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SearchTextField.SearchBackgroundPainterprotected JComponentparent component ofpopupButtonprotected List<PopupCategorized.CategorizedMenuItem> protected SearchTextField.SearchTaskprotected EditingRunnerprotected static ImageIconprotected JTextFieldprotected JButtonprotected SearchTextField.SearchTextFieldModelprotected PopupExtensionTextprotected JButtonprotected List<SearchTextField.SearchedItemsListener> protected KeyUndoManagerFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidaddSearchItemsListener(SearchTextField.SearchedItemsListener itemsListener) convertIcon(Icon icon) createSearchTask(String text) protected voidgetDynamicItemAction(String name, KeyStroke key, boolean put) an action for dynamic created menu items: the returned action searches an action by the specified key.protected intgetField()static ColorgetIcon()getModel()getPopup()getPopupUpdateListener(PopupExtensionText popup, PopupCategorized categorized) voidinit()voidvoidvoidvoidinitIcon()voidprotected List<? extends JComponent> popupButtonby defaultprotected voidsetting upbuttonsPanevoidinitPopupCategorized(Supplier<? extends Collection<PopupCategorized.CategorizedMenuItem>> itemSupplier, Consumer<PopupCategorized.CategorizedMenuItem> itemConsumer) booleanbooleanbooleanisUpdateFieldImmediateEvent(List<Object> events) booleanbooleanisUpdateFieldModifiedEvents(List<Object> events) protected voidvoidremoveSearchItemsListener(SearchTextField.SearchedItemsListener itemsListener) voidthe user selects the item from the menu.voidcalled when the search is done, and update only the iconvoidsetBackground(Color bg) voidvoidsetCurrentSearchedItems(List<PopupCategorized.CategorizedMenuItem> currentSearchedItems, boolean done) set the searched items from the background task: it might be an intermediate resultvoidsetCurrentSearchedItems(List<PopupCategorized.CategorizedMenuItem> currentSearchedItems, PopupCategorized.CategorizedMenuItem selection) called once when the search is donevoidvoidvoidvoidsetToolTipText(String text) voidset the transfer handler to the pane, the field and the icon button.static voidsetupCopyAndPaste(JComponent component) voidshutdown()voidupdateField(List<Object> events) After editing text or action performed, this method will be executed under the scheduler threadvoidupdateFieldInEvent(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, updateUIMethods 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, validateTreeMethods 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:
setToolTipTextin classJComponent
-
getMenuItems
-
getMenuItemsSource
- Returns:
- list of menu items including
ActionorJComponent
-
getPopupUpdateListener
public SearchTextField.SearchedItemsListener getPopupUpdateListener(PopupExtensionText popup, PopupCategorized categorized) -
initLayout
public void initLayout() -
initLayoutButtonsPane
protected void initLayoutButtonsPane()setting upbuttonsPane- Since:
- 1.5
-
initLayoutButtons
popupButtonby default- Returns:
- components added to
buttonsPane - Since:
- 1.5
-
initBackgroundPainter
public void initBackgroundPainter() -
add
-
paintComponent
- Overrides:
paintComponentin classJComponent
-
setBackground
- Overrides:
setBackgroundin 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
-