Class AbstractChooserPanel<T>

Type Parameters:
T - the type of object to handle
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
DirectoryChooserPanel, FileChooserPanel, FontChooserPanel

public abstract class AbstractChooserPanel<T> extends BasePanel
A panel that contains a text field with the current choice and a button for bringing up a dialog offering the choice.
Version:
$Revision: 15192 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
  • Field Details

    • m_Self

      protected AbstractChooserPanel m_Self
      the panel itself.
    • m_TextSelection

      protected JTextField 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 JButton m_ButtonSelection
      the button for bringing up the chooser dialog.
    • m_ChangeListeners

      protected HashSet<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.
  • Constructor Details

    • AbstractChooserPanel

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

    • 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
    • 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:
    • 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
    • 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.
    • 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
    • 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
    • pasteFromClipboard

      protected void pasteFromClipboard()
      Pastes the string representation from the clipboard.
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      Adds a listener for connect/disconnect events to the internal list.
      Parameters:
      l - the listener to add
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Removes a listener for connect/disconnect events from the internal list.
      Parameters:
      l - the listener to remove
    • notifyChangeListeners

      protected void notifyChangeListeners(ChangeEvent e)
      Notifies all listeners with the given event.
      Parameters:
      e - the event to send to the listeners
    • 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
    • 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
    • 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 JPopupMenu 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.