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,BaseTextComponent,ImageObserver,MenuContainer,Serializable,Accessible
- Direct Known Subclasses:
AbstractChooserPanelWithIOSupport,AbstractDateBasedChooserPanel,BaseTextChooserPanel,ColorChooserPanel,FieldChooserPanel,FileChooserPanel,FontChooserPanel,GenericArrayEditorPanel,GenericObjectEditorPanel,MultipleFileChooserPanel,SelectOptionPanel,SpreadSheetQueryChooserPanel,SQLStatementChooserPanel,WekaGenericArrayEditorPanel,WekaGenericObjectEditorPanel
public abstract class AbstractChooserPanel<T> extends BasePanel implements CleanUpHandler, BaseTextComponent
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 interfaceAbstractChooserPanel.ChooseListenerInterface for classes that listen to "choose" events.static interfaceAbstractChooserPanel.PopupMenuCustomizerInterface 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 BaseButtonm_ButtonFavoritesthe button for the favorites.protected BaseButtonm_ButtonSelectionthe button for bringing up the chooser dialog.protected Set<ChangeListener>m_ChangeListenerslisteners that listen to changes of the selected value.protected Set<AbstractChooserPanel.ChooseListener>m_ChooseListenersthe listeners for choose events.protected Colorm_ColorInvalidthe color for invalid input.protected Colorm_ColorValidthe color for valid input.protected booleanm_Editablewhether the chooser is editable.protected booleanm_InlineEditingEnabledwhether inline editing is enabled.protected JLabelm_LabelPrefixthe prefix label.protected JLabelm_LabelPrefixSpacera spacer for the prefix label.protected booleanm_NoChooseYetwhether this is the first choose action ever.protected JPanelm_PanelButtonsthe panel for the button(s).protected JPanelm_PanelPrefixthe panel for the prefix.protected AbstractChooserPanel.PopupMenuCustomizerm_PopupMenuCustomizeroptional customizer of the popup.protected AbstractChooserPanelm_Selfthe panel itself.protected BaseTextFieldm_TextSelectionthe text field.protected Stringm_ToolTipthe 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 protectedAbstractChooserPanel()Initializes the panel with no value.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(ChangeListener l)Adds a listener for change events to the internal list.voidaddChooseListener(AbstractChooserPanel.ChooseListener l)Adds a listener for choose events to the internal list.protected TafterChoose(T value)Hook method after choosing, but before setting the current value.protected voidafterPasteFromClipboard()Hook method after pasting from clipboard.protected voidafterSetCurrent(T value, boolean success)Hook method after setting the current value.protected voidbeforeChoose()Hook method before choosing.protected voidbeforePasteFromClipboard()Hook method before pasting from clipboard.protected TbeforeSetCurrent(T value)Hook method before setting the current value.voidchoose()Lets the user choose and updates the current value if choosing was successful.voidcleanUp()Cleans up data structures, frees up memory.protected voidcopyToClipboard()Copies the current settings to the clipboard.protected abstract TdoChoose()Performs the actual choosing of an object.voidfireCurrentValueChanged()Fires a change event to all subscribed listeners that the value has changed.protected abstract TfromString(String value)Converts the string representation into its object representation.TgetCurrent()Returns the current value.StringgetCurrentAsString()Returns the current value as string.protected StringgetDefaultString()The string that is used by default.protected ClassgetFavoritesClass()The class to use for the favorites (can be array class).protected BasePopupMenugetPopupMenu()Returns a popup menu when right-clicking on the edit field.AbstractChooserPanel.PopupMenuCustomizergetPopupMenuCustomizer()Returns the currently set customizer.StringgetPrefix()Returns the current text of the prefix label.JLabelgetPrefixLabel()Returns the prefix label.protected intgetSelectionColumns()Returns the number of columns in the selection text field.protected StringgetStringFromClipboard()Returns the current string from the clipboard.StringgetText()Returns the text in the field.intgetTextColumns()Returns the number of columns of the text field.voidgrabFocus()Lets the text component grab the focus.booleanhasValue()Checks whether the value of text field is different from the default value, i.e., a proper value.protected voidinitGUI()Initializes the GUI elements.protected voidinitialize()Initializes the members.booleanisEditable()Returns whether the chooser is editable or read-only.booleanisInlineEditingEnabled()Returns whether inline editing is enabled, i.e., editing without having to bring up the chooser.booleanisNoChooseYet()Returns whether no choose action has occurred yet (ie button click).protected booleanisValid(String value)Checks whether the string value is valid and can be parsed.voidmoveChooseButton(boolean left)Moves the "..." button to either the left or right.voidnotifyChangeListeners(ChangeEvent e)Notifies all change listeners with the given event.protected voidnotifyChooseListeners(boolean before)Notifies all choose listeners with the given event.protected voidpasteFromClipboard()Pastes the string representation from the clipboard.voidremoveChangeListener(ChangeListener l)Removes a listener for change events from the internal list.voidremoveChooseListener(AbstractChooserPanel.ChooseListener l)Removes a listener for choose events from the internal list.booleansetCurrent(T value)Sets the current value.booleansetCurrentAsString(String value)Sets the current value as string.voidsetDefault()Sets the default value.voidsetEditable(boolean value)Sets whether the chooser is editable or read-only.voidsetEnabled(boolean enabled)Sets the enabled state of the panel.voidsetInlineEditingEnabled(boolean value)Sets whether inline editing is enabled, i.e., editing without bringing up chooser.voidsetPopupMenuCustomizer(AbstractChooserPanel.PopupMenuCustomizer value)Sets the customizer.voidsetPrefix(String value)Sets the text for the prefix label.voidsetText(String value)Sets the text in the field.voidsetTextColumns(int value)Sets the number of columns for the text field.voidsetToolTipText(String text)Sets the tool tip, displayed when hovering with the mouse.protected voidshowFavoritesMenu()Displays the favorites menu.protected booleansupportsFavorites()Whether the favorites button is shown or not.protected StringtextFieldToolTipText()Returns the tooltip for the text field.protected abstract StringtoString(T value)Converts the value into its string representation.protected voidupdatePreferredSize()Updates the preferred size of the panel.protected voidupdateValidity()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:
initializein 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:
setEnabledin 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:
setToolTipTextin 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:
grabFocusin 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
-
setText
public void setText(String value)
Sets the text in the field.- Specified by:
setTextin interfaceBaseTextComponent- Parameters:
value- the text
-
getText
public String getText()
Returns the text in the field.- Specified by:
getTextin interfaceBaseTextComponent- Returns:
- the text
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.
Default implementation does nothing.- Specified by:
cleanUpin interfaceCleanUpHandler
-
-