Class AbstractChooserPanel<T>

    • Field Detail

      • 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_ChangeListeners

        protected Set<ChangeListener> m_ChangeListeners
        listeners that listen to changes of the selected value.
      • 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_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).
    • Constructor Detail

      • AbstractChooserPanel

        protected AbstractChooserPanel()
        Initializes the panel with no value.
    • Method Detail

      • initialize

        protected void initialize()
        Initializes the members.
        Overrides:
        initialize in class BasePanel
      • initGUI

        protected void initGUI()
        Initializes the GUI elements.
        Overrides:
        initGUI in class BasePanel
      • 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 set
        success - 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 class JComponent
        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 class JComponent
        Parameters:
        text - the text, null to turn off
      • 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 class JComponent
      • 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
      • 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 interface CleanUpHandler