Class JComboBoxConfigurableLookUp

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JComboBox
org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp
All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

public class JComboBoxConfigurableLookUp extends JComboBox implements Serializable
VERSION: BETA

A configurable combo box component that lists items that carry out with the criterions of a ILookUp agent, considering the text in its inner editor.

Key features:

  • Allows configure it's behaviour.
  • Inherits from JComboBox.
  • Has 6 flags to configure its behaviour.
  • It's made according the MVC (Model-View-Controller) pattern.
  • Uses a DefaultComboBoxConfigurableLookUpModel as a dataModel, which it's also configurable.

Configuration flags:

  • OnlyOneColorOnText: uses red if there is no item or only items that matches with the text written according the ILookUp agent, or uses always black color.
  • BeepEnabled: rings a beep sound if there is no item that matches with the text written according the ILookUp agent, or not.
  • HidePopupIfThereAreNoItems: hides popup (list box) if there is no item that matches with the text written according the ILookUp agent, or uses the default (JComboBox and more) behaviour.
  • ToForceSelectAnItem: forces to select an item (if the component looses the focus or user presses the Enter keyboard key), or uses the default (JComboBox and more) behaviour.
  • CompleteArrowKeySelection: writes in the editor the value of the element selected by the arrow keys (up or down) if its enabled, otherwise holds the previous text.
  • DisplayAllItemsWithArrowButton: true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel listed only the matches (flag: DefaultComboBoxConfigurableLookUpModel.showAllItemsInListBox == false); otherwise, if this flag isn't enabled, won't display all items in that situation.

Default flag values are:

  • OnlyOneColorOnText: false.
  • BeepEnabled: false.
  • HidePopupIfThereAreNoItems: true.
  • ToForceSelectAnItem: true.
  • CompleteArrowKeySelection: false.
  • DisplayAllItemsWithArrowButton: true.

More information about the behaviour of it's dataModel in DefaultComboBoxConfigurableLookUpModel .

Version:
07/02/2008
Author:
Pablo Piqueras Bartolomé
See Also:
  • Field Details

    • DEFAULT_ONLY_ONE_COLOR_ON_TEXT_CONFIGURATION

      public static final boolean DEFAULT_ONLY_ONE_COLOR_ON_TEXT_CONFIGURATION
      See Also:
    • DEFAULT_BEEP_ENABLED_CONFIGURATION

      public static final boolean DEFAULT_BEEP_ENABLED_CONFIGURATION
      See Also:
    • DEFAULT_HIDE_POPUP_IF_THERE_ARE_NO_ITEMS_CONFIGURATION

      public static final boolean DEFAULT_HIDE_POPUP_IF_THERE_ARE_NO_ITEMS_CONFIGURATION
      See Also:
    • DEFAULT_TO_FORCE_SELECT_AN_ITEM_CONFIGURATION

      public static final boolean DEFAULT_TO_FORCE_SELECT_AN_ITEM_CONFIGURATION
      See Also:
    • DEFAULT_COMPLETE_ARROW_KEY_SELECTION_CONFIGURATION

      public static final boolean DEFAULT_COMPLETE_ARROW_KEY_SELECTION_CONFIGURATION
      See Also:
    • DEFAULT_DISPLAY_ALL_ITEMS_WITH_ARROW_BUTTON_CONFIGURATION

      public static final boolean DEFAULT_DISPLAY_ALL_ITEMS_WITH_ARROW_BUTTON_CONFIGURATION
      See Also:
  • Constructor Details

    • JComboBoxConfigurableLookUp

      public JComboBoxConfigurableLookUp()

      Default constructor without parameters.

    • JComboBoxConfigurableLookUp

      public JComboBoxConfigurableLookUp(DefaultComboBoxConfigurableLookUpModel aModel)

      Default constructor with a DefaultComboBoxConfigurableLookUpModel as parameter.

      Parameters:
      aModel - javax.swing.ComboBoxModel
    • JComboBoxConfigurableLookUp

      public JComboBoxConfigurableLookUp(Object[] items)

      Default constructor with an array of objects as parameter.

      Parameters:
      items - An array of objects. All them must implement a 'String toStrin()' method
    • JComboBoxConfigurableLookUp

      public JComboBoxConfigurableLookUp(Vector<Object> items)

      Default constructor with a Vector of objects as parameter.

      Parameters:
      items - A Vector of objects. All them must implement a 'String toStrin()' method
  • Method Details

    • initialize

      protected void initialize()

      This method sets the start values of inner attributes and creates the necessary inner objects.

      Parameters:
      dataModel - dataModel used by this combo box instance
    • configure

      protected void configure()

      Configures the component and some of its elements.

    • configureEditor

      protected void configureEditor(ComboBoxEditor newEditor)

      Configures the editor ( ComboBoxEditor ) of this component.

      Parameters:
      newEditor - The new editor to configure
    • configureDocument

      protected void configureDocument()

      Configures the document of the editor of this component.

    • configurePopUp

      protected void configurePopUp(JComboBoxConfigurableLookUp comboBox)

      Configures the popup of this component.

      Parameters:
      comboBox - A reference of this component
    • getArrowMouseListener

      public MouseListener getArrowMouseListener()

      Returns the listener invoked when user presses the arrow button of this JComboBox.

      Returns:
      java.awt.event.MouseListener
    • setDefaultBehaviorFlagsConfiguration

      protected void setDefaultBehaviorFlagsConfiguration()

      Sets the default values of the flags.

    • setEditor

      public void setEditor(ComboBoxEditor anEditor)

      Sets the editor used to paint and edit the selected item in the JComboBox field. The editor is used only if the receiving JComboBox is editable. If not editable, the combo box uses the renderer to paint the selected item.

      The editor must be a JTextComponent, and its document a PlainDocument object.

      Overrides:
      setEditor in class JComboBox
      Parameters:
      anEditor - the ComboBoxEditor that displays the selected item
      See Also:
    • setModel

      public void setModel(ComboBoxModel aModel)
      Overrides:
      setModel in class JComboBox
    • setSelectedIndex

      public void setSelectedIndex(int anIndex)
      Overrides:
      setSelectedIndex in class JComboBox
    • setSelectedItem

      public void setSelectedItem(Object anObject)
      Overrides:
      setSelectedItem in class JComboBox
    • setEditable

      public void setEditable(boolean b)
      Overrides:
      setEditable in class JComboBox
    • removeAllItems

      public void removeAllItems()
      Overrides:
      removeAllItems in class JComboBox
    • addItem

      public void addItem(Object anObject)
      Overrides:
      addItem in class JComboBox
    • removeItem

      public void removeItem(Object anObject)
      Overrides:
      removeItem in class JComboBox
    • removeItemAt

      public void removeItemAt(int anIndex)
      Overrides:
      removeItemAt in class JComboBox
    • setUI

      protected void setUI(ComponentUI newUI)
      Overrides:
      setUI in class JComponent
    • selectWithKeyChar

      public boolean selectWithKeyChar(char keyChar)
      Overrides:
      selectWithKeyChar in class JComboBox
    • processKeyEvent

      public void processKeyEvent(KeyEvent e)
      Overrides:
      processKeyEvent in class JComboBox
    • createDefaultKeySelectionManager

      protected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
      Overrides:
      createDefaultKeySelectionManager in class JComboBox
    • paramString

      protected String paramString()
      Overrides:
      paramString in class JComboBox
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComboBox
    • showPopup

      public void showPopup()
      Overrides:
      showPopup in class JComboBox
    • setBlockPopupHided

      public void setBlockPopupHided(boolean b)

      Sets if the popup of this component will always remain hided, or can be shown when is invoked.

      Parameters:
      b - true if will remain blocked; false if can be shown
    • isBlockPopupHided

      public boolean isBlockPopupHided()

      Determines if the popup of this component will always remain hided.

      Parameters:
      b - true if will remain blocked; false if can be shown
    • isOnlyOneColorOnText

      public boolean isOnlyOneColorOnText()

      Returns the 'only_One_Color_On_Text' configuration value of this component. Configuration values are:

      • true: always uses black colour on text.
      • false: by default uses black colour on text, but if text written by user doesn't match with any item according the ILookUp agent, text will be on red colour.

      Returns:
      'only_One_Color_On_Text' configuration
    • setOnlyOneColorOnText

      public void setOnlyOneColorOnText(boolean b)

      Sets the 'only_One_Color_On_Text' configuration value for this component. Configuration values are:

      • true: always uses black colour on text.
      • false: by default uses black colour on text, but if text written by user doesn't match with any item according the ILookUp agent, text will be on red colour.

      Parameters:
      b - value for 'only_One_Color_On_Text' configuration flag
    • isBeepEnabled

      public boolean isBeepEnabled()

      Returns the 'beep_Enabled' configuration value of this component. Configuration values are:

      • true: a beep-sound is listened when no item matches with the text written according the ILookUp agent.
      • false: no sound is listened.

      Returns:
      'beep_Enabled' configuration
    • setBeepEnabled

      public void setBeepEnabled(boolean b)

      Sets the 'beep_Enabled' configuration value for this component. Configuration values are:

      • true: a beep-sound is listened when no item matches with the text written according the ILookUp agent.
      • false: no sound is listened.

      Parameters:
      b - value for 'beep_Enabled' configuration flag
    • isHidePopupIfThereAreNoItems

      public boolean isHidePopupIfThereAreNoItems()

      Returns the 'hidePopupIfThereAreNoItems' configuration value of this component. Configuration values are:

      • true: hides the popup if there are no items when you write.
      • false: default behaviour (if there are no items when you write, popup remains visible) .
      Returns:
      'hidePopupIfThereAreNoItems' configuration
    • setHidePopupIfThereAreNoItems

      public void setHidePopupIfThereAreNoItems(boolean b)

      Sets the 'hidePopupIfThereAreNoItems' configuration value for this component. Configuration values are:

      • true: hides the popup if there are no items when you write.
      • false: default behaviour (if there are no items when you write, popup remains visible) .
      Parameters:
      b - value for 'hidePopupIfThereAreNoItems' configuration flag
    • isToForceSelectAnItem

      public boolean isToForceSelectAnItem()

      Returns the 'toForceSelectAnItem' configuration value of this component. Configuration values are:

      • true: selects the previous selected item or the first of the list when user presses the Enter key or when the component loses the focus .
      • false: default behaviour .

      Returns:
      'toForceSelectAnItem' configuration
    • setToForceSelectAnItem

      public void setToForceSelectAnItem(boolean b)

      Sets the 'toForceSelectAnItem' configuration value for this component. Configuration values are:

      • true: selects the previous selected item or the first of the list when user presses the Enter key or when the component loses the focus .
      • false: default behaviour .

      Parameters:
      value - for 'toForceSelectAnItem' configuration flag
    • isCompleteArrowKeySelection

      public boolean isCompleteArrowKeySelection()

      Returns the 'completeArrowKeySelection' configuration value of this component. Configuration values are:

      • true: writes in the editor the value of the element selected by the arrow keys (up or down).
      • false: holds the previous text written .

      Returns:
      'completeArrowKeySelection' configuration
    • setCompleteArrowKeySelection

      public void setCompleteArrowKeySelection(boolean b)

      Sets the 'completeArrowKeySelection' configuration value for this component. Configuration values are:

      • true: writes in the editor the value of the element selected by the arrow keys (up or down).
      • false: holds the previous text written .

      Parameters:
      b - value for 'completeArrowKeySelection' configuration flag
    • isDisplayAllItemsWithArrowButton

      public boolean isDisplayAllItemsWithArrowButton()

      Returns the 'displayAllItemsWithArrowButton' configuration value of this component. Configuration values are:

      • true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel listed only the matches (flag: DefaultComboBoxConfigurableLookUpModel.showAllItemsInListBox == false).
      • false: normal behaviour according the other flags.

      Returns:
      'displayAllItemsWithArrowButton' configuration
    • setDisplayAllItemsWithArrowButton

      public void setDisplayAllItemsWithArrowButton(boolean b)

      Sets the 'toForceSelectAnItem' configuration value for this component. Configuration values are:

      • true: displays all this component's dataModel items if its popup it's hided, and this component's dataModel listed only the matches (flag: DefaultComboBoxConfigurableLookUpModel.showAllItemsInListBox == false).
      • false: normal behaviour according the other flags.

      Parameters:
      value - for 'displayAllItemsWithArrowButton' configuration flag