Package adams.gui.chooser
Class AbstractChooserPanel<T>
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.chooser.AbstractChooserPanel<T>
-
- Type Parameters:
T
- the type of object to handle
- All Implemented Interfaces:
CleanUpHandler
,ImageObserver
,MenuContainer
,Serializable
,Accessible
- Direct Known Subclasses:
AbstractChooserPanelWithIOSupport
,AbstractDateBasedChooserPanel
,BaseTextChooserPanel
,ColorChooserPanel
,FieldChooserPanel
,FileChooserPanel
,FontChooserPanel
,GenericArrayEditorPanel
,GenericObjectEditorPanel
,SelectOptionPanel
,SpreadSheetQueryChooserPanel
,SQLStatementChooserPanel
,WekaGenericArrayEditorPanel
,WekaGenericObjectEditorPanel
public abstract class AbstractChooserPanel<T> extends BasePanel implements CleanUpHandler
A panel that contains a text field with the current choice and a button for bringing up a dialog offering the choice.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractChooserPanel.ChooseListener
Interface for classes that listen to "choose" events.static interface
AbstractChooserPanel.PopupMenuCustomizer
Interface for editors that can customize the popup menu.-
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 BaseButton
m_ButtonFavorites
the button for the favorites.protected BaseButton
m_ButtonSelection
the button for bringing up the chooser dialog.protected Set<ChangeListener>
m_ChangeListeners
listeners that listen to changes of the selected value.protected Set<AbstractChooserPanel.ChooseListener>
m_ChooseListeners
the listeners for choose events.protected Color
m_ColorInvalid
the color for invalid input.protected Color
m_ColorValid
the color for valid input.protected boolean
m_Editable
whether the chooser is editable.protected boolean
m_InlineEditingEnabled
whether inline editing is enabled.protected JLabel
m_LabelPrefix
the prefix label.protected JLabel
m_LabelPrefixSpacer
a spacer for the prefix label.protected boolean
m_NoChooseYet
whether this is the first choose action ever.protected JPanel
m_PanelButtons
the panel for the button(s).protected JPanel
m_PanelPrefix
the panel for the prefix.protected AbstractChooserPanel.PopupMenuCustomizer
m_PopupMenuCustomizer
optional customizer of the popup.protected AbstractChooserPanel
m_Self
the panel itself.protected BaseTextField
m_TextSelection
the text field.protected String
m_ToolTip
the tool tip (ignore if null).-
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 Modifier Constructor Description protected
AbstractChooserPanel()
Initializes the panel with no value.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(ChangeListener l)
Adds a listener for change events to the internal list.void
addChooseListener(AbstractChooserPanel.ChooseListener l)
Adds a listener for choose events to the internal list.protected T
afterChoose(T value)
Hook method after choosing, but before setting the current value.protected void
afterPasteFromClipboard()
Hook method after pasting from clipboard.protected void
afterSetCurrent(T value, boolean success)
Hook method after setting the current value.protected void
beforeChoose()
Hook method before choosing.protected void
beforePasteFromClipboard()
Hook method before pasting from clipboard.protected T
beforeSetCurrent(T value)
Hook method before setting the current value.void
choose()
Lets the user choose and updates the current value if choosing was successful.void
cleanUp()
Cleans up data structures, frees up memory.protected void
copyToClipboard()
Copies the current settings to the clipboard.protected abstract T
doChoose()
Performs the actual choosing of an object.void
fireCurrentValueChanged()
Fires a change event to all subscribed listeners that the value has changed.protected abstract T
fromString(String value)
Converts the string representation into its object representation.T
getCurrent()
Returns the current value.String
getCurrentAsString()
Returns the current value as string.protected String
getDefaultString()
The string that is used by default.protected Class
getFavoritesClass()
The class to use for the favorites (can be array class).protected BasePopupMenu
getPopupMenu()
Returns a popup menu when right-clicking on the edit field.AbstractChooserPanel.PopupMenuCustomizer
getPopupMenuCustomizer()
Returns the currently set customizer.String
getPrefix()
Returns the current text of the prefix label.JLabel
getPrefixLabel()
Returns the prefix label.protected int
getSelectionColumns()
Returns the number of columns in the selection text field.protected String
getStringFromClipboard()
Returns the current string from the clipboard.int
getTextColumns()
Returns the number of columns of the text field.void
grabFocus()
Lets the text component grab the focus.boolean
hasValue()
Checks whether the value of text field is different from the default value, i.e., a proper value.protected void
initGUI()
Initializes the GUI elements.protected void
initialize()
Initializes the members.boolean
isEditable()
Returns whether the chooser is editable or read-only.boolean
isInlineEditingEnabled()
Returns whether inline editing is enabled, i.e., editing without having to bring up the chooser.boolean
isNoChooseYet()
Returns whether no choose action has occurred yet (ie button click).protected boolean
isValid(String value)
Checks whether the string value is valid and can be parsed.void
moveChooseButton(boolean left)
Moves the "..." button to either the left or right.void
notifyChangeListeners(ChangeEvent e)
Notifies all change listeners with the given event.protected void
notifyChooseListeners(boolean before)
Notifies all choose listeners with the given event.protected void
pasteFromClipboard()
Pastes the string representation from the clipboard.void
removeChangeListener(ChangeListener l)
Removes a listener for change events from the internal list.void
removeChooseListener(AbstractChooserPanel.ChooseListener l)
Removes a listener for choose events from the internal list.boolean
setCurrent(T value)
Sets the current value.boolean
setCurrentAsString(String value)
Sets the current value as string.void
setDefault()
Sets the default value.void
setEditable(boolean value)
Sets whether the chooser is editable or read-only.void
setEnabled(boolean enabled)
Sets the enabled state of the panel.void
setInlineEditingEnabled(boolean value)
Sets whether inline editing is enabled, i.e., editing without bringing up chooser.void
setPopupMenuCustomizer(AbstractChooserPanel.PopupMenuCustomizer value)
Sets the customizer.void
setPrefix(String value)
Sets the text for the prefix label.void
setTextColumns(int value)
Sets the number of columns for the text field.void
setToolTipText(String text)
Sets the tool tip, displayed when hovering with the mouse.protected void
showFavoritesMenu()
Displays the favorites menu.protected boolean
supportsFavorites()
Whether the favorites button is shown or not.protected String
textFieldToolTipText()
Returns the tooltip for the text field.protected abstract String
toString(T value)
Converts the value into its string representation.protected void
updatePreferredSize()
Updates the preferred size of the panel.protected void
updateValidity()
Updates the validity indicator.-
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, 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, 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 Detail
-
m_Self
protected AbstractChooserPanel m_Self
the panel itself.
-
m_TextSelection
protected BaseTextField m_TextSelection
the text field.
-
m_PanelPrefix
protected JPanel m_PanelPrefix
the panel for the prefix.
-
m_LabelPrefix
protected JLabel m_LabelPrefix
the prefix label.
-
m_LabelPrefixSpacer
protected JLabel m_LabelPrefixSpacer
a spacer for the prefix label.
-
m_PanelButtons
protected JPanel m_PanelButtons
the panel for the button(s).
-
m_ButtonSelection
protected BaseButton m_ButtonSelection
the button for bringing up the chooser dialog.
-
m_ButtonFavorites
protected BaseButton m_ButtonFavorites
the button for the favorites.
-
m_ChangeListeners
protected Set<ChangeListener> m_ChangeListeners
listeners that listen to changes of the selected value.
-
m_PopupMenuCustomizer
protected AbstractChooserPanel.PopupMenuCustomizer m_PopupMenuCustomizer
optional customizer of the popup.
-
m_Editable
protected boolean m_Editable
whether the chooser is editable.
-
m_InlineEditingEnabled
protected boolean m_InlineEditingEnabled
whether inline editing is enabled.
-
m_NoChooseYet
protected boolean m_NoChooseYet
whether this is the first choose action ever.
-
m_ChooseListeners
protected Set<AbstractChooserPanel.ChooseListener> m_ChooseListeners
the listeners for choose events.
-
m_ColorValid
protected Color m_ColorValid
the color for valid input.
-
m_ColorInvalid
protected Color m_ColorInvalid
the color for invalid input.
-
m_ToolTip
protected String m_ToolTip
the tool tip (ignore if null).
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classBasePanel
-
initGUI
protected void initGUI()
Initializes the GUI elements.
-
supportsFavorites
protected boolean supportsFavorites()
Whether the favorites button is shown or not.- Returns:
- true if to show
-
getFavoritesClass
protected Class getFavoritesClass()
The class to use for the favorites (can be array class).
Subclasses must override this.- Returns:
- the class
-
showFavoritesMenu
protected void showFavoritesMenu()
Displays the favorites menu.
-
textFieldToolTipText
protected String textFieldToolTipText()
Returns the tooltip for the text field.
Default implementation returns null.- Returns:
- the tooltip
-
getSelectionColumns
protected int getSelectionColumns()
Returns the number of columns in the selection text field.- Returns:
- the number of columns
-
setPrefix
public void setPrefix(String value)
Sets the text for the prefix label. Mnemonics can be indicated by a preceding underscore "_".- Parameters:
value
- the text to display- See Also:
GUIHelper.MNEMONIC_INDICATOR
-
getPrefix
public String getPrefix()
Returns the current text of the prefix label.- Returns:
- the text currently being displayed
-
getPrefixLabel
public JLabel getPrefixLabel()
Returns the prefix label.- Returns:
- the label
-
getDefaultString
protected String getDefaultString()
The string that is used by default. E.g., if a "null" value is provided.- Returns:
- the default string
-
setDefault
public void setDefault()
Sets the default value.
-
toString
protected abstract String toString(T value)
Converts the value into its string representation.- Parameters:
value
- the value to convert- Returns:
- the generated string
-
beforeSetCurrent
protected T beforeSetCurrent(T value)
Hook method before setting the current value.- Parameters:
value
- the value to set- Returns:
- the potentially updated value
-
afterSetCurrent
protected void afterSetCurrent(T value, boolean success)
Hook method after setting the current value.- Parameters:
value
- the value to setsuccess
- whether setting was successful
-
setCurrentAsString
public boolean setCurrentAsString(String value)
Sets the current value as string.- Parameters:
value
- the value to use- Returns:
- if successfully set
-
setCurrent
public boolean setCurrent(T value)
Sets the current value.- Parameters:
value
- the value to use, can be null- Returns:
- if successfully set
-
fireCurrentValueChanged
public void fireCurrentValueChanged()
Fires a change event to all subscribed listeners that the value has changed.
-
isValid
protected boolean isValid(String value)
Checks whether the string value is valid and can be parsed.
Default implementation returns true as long as the string is not null.- Parameters:
value
- the value to check- Returns:
- true if valid
-
updateValidity
protected void updateValidity()
Updates the validity indicator.
-
fromString
protected abstract T fromString(String value)
Converts the string representation into its object representation.- Parameters:
value
- the string value to convert- Returns:
- the generated object
-
getCurrent
public T getCurrent()
Returns the current value.- Returns:
- the current value
-
getCurrentAsString
public String getCurrentAsString()
Returns the current value as string.- Returns:
- the string
-
copyToClipboard
protected void copyToClipboard()
Copies the current settings to the clipboard.
-
getStringFromClipboard
protected String getStringFromClipboard()
Returns the current string from the clipboard.- Returns:
- the string, null if not available
-
beforePasteFromClipboard
protected void beforePasteFromClipboard()
Hook method before pasting from clipboard.
Default implementation does nothing.
-
afterPasteFromClipboard
protected void afterPasteFromClipboard()
Hook method after pasting from clipboard.
Default implementation does nothing.
-
pasteFromClipboard
protected void pasteFromClipboard()
Pastes the string representation from the clipboard.
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds a listener for change events to the internal list.- Parameters:
l
- the listener to add
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes a listener for change events from the internal list.- Parameters:
l
- the listener to remove
-
notifyChangeListeners
public void notifyChangeListeners(ChangeEvent e)
Notifies all change listeners with the given event.- Parameters:
e
- the event to send to the listeners
-
addChooseListener
public void addChooseListener(AbstractChooserPanel.ChooseListener l)
Adds a listener for choose events to the internal list.- Parameters:
l
- the listener to add
-
removeChooseListener
public void removeChooseListener(AbstractChooserPanel.ChooseListener l)
Removes a listener for choose events from the internal list.- Parameters:
l
- the listener to remove
-
notifyChooseListeners
protected void notifyChooseListeners(boolean before)
Notifies all choose listeners with the given event.- Parameters:
before
- whether before or after choosing
-
setEnabled
public void setEnabled(boolean enabled)
Sets the enabled state of the panel.- Overrides:
setEnabled
in classJComponent
- Parameters:
enabled
- if true then the sub-elements will be enabled
-
setEditable
public void setEditable(boolean value)
Sets whether the chooser is editable or read-only.- Parameters:
value
- if true then the user can change the value
-
isEditable
public boolean isEditable()
Returns whether the chooser is editable or read-only.- Returns:
- true if the user can change the value
-
setInlineEditingEnabled
public void setInlineEditingEnabled(boolean value)
Sets whether inline editing is enabled, i.e., editing without bringing up chooser.- Parameters:
value
- true if inlined editing enabled
-
isInlineEditingEnabled
public boolean isInlineEditingEnabled()
Returns whether inline editing is enabled, i.e., editing without having to bring up the chooser.- Returns:
- true if inline editing enabled
-
isNoChooseYet
public boolean isNoChooseYet()
Returns whether no choose action has occurred yet (ie button click).- Returns:
- true if no choose action has occurred yet
-
setToolTipText
public void setToolTipText(String text)
Sets the tool tip, displayed when hovering with the mouse.- Overrides:
setToolTipText
in classJComponent
- Parameters:
text
- the text, null to turn off
-
beforeChoose
protected void beforeChoose()
Hook method before choosing.- See Also:
notifyChooseListeners(boolean)
-
doChoose
protected abstract T doChoose()
Performs the actual choosing of an object.- Returns:
- the chosen object or null if none chosen
-
afterChoose
protected T afterChoose(T value)
Hook method after choosing, but before setting the current value.
Default implementation just returns the value- Parameters:
value
- the chosen value- Returns:
- the potentially updated value
- See Also:
notifyChooseListeners(boolean)
-
choose
public void choose()
Lets the user choose and updates the current value if choosing was successful.
-
hasValue
public boolean hasValue()
Checks whether the value of text field is different from the default value, i.e., a proper value.- Returns:
- true if a proper value is available
-
updatePreferredSize
protected void updatePreferredSize()
Updates the preferred size of the panel.
-
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)
-
grabFocus
public void grabFocus()
Lets the text component grab the focus.- Overrides:
grabFocus
in classJComponent
-
getPopupMenu
protected BasePopupMenu getPopupMenu()
Returns a popup menu when right-clicking on the edit field.- Returns:
- the menu, null if non available
-
setPopupMenuCustomizer
public void setPopupMenuCustomizer(AbstractChooserPanel.PopupMenuCustomizer value)
Sets the customizer. Use null do disable.- Parameters:
value
- the customizer, or null to disable
-
getPopupMenuCustomizer
public AbstractChooserPanel.PopupMenuCustomizer getPopupMenuCustomizer()
Returns the currently set customizer.- Returns:
- the customizer, or null if none set
-
moveChooseButton
public void moveChooseButton(boolean left)
Moves the "..." button to either the left or right.- Parameters:
left
- if true the button gets moved to the left, otherwise to the right
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.
Default implementation does nothing.- Specified by:
cleanUp
in interfaceCleanUpHandler
-
-