Class ListItem

  • All Implemented Interfaces:
    IconProvider

    public class ListItem
    extends java.lang.Object
    implements IconProvider
    A list item is an item that can be placed in a list or combo box control in a DIY component's user interface. A list item will display one label for the user, but use a different string for the setting that the item is bound to in the DIY component. One use for this is to easily create components that support multiple languages: the localized text can be used for the label, and a unique internal value used for the setting value. In order to be displayed correctly, the list or combo box must use a ListItemRenderer to render the list items. (Lists and combo boxes created using the uicontrols library will use this renderer.)
    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Summary

      Constructors 
      Constructor Description
      ListItem​(java.lang.String settingValue, java.lang.Object labelObject)
      Creates a new list item with the given label and setting representation, but no icon.
      ListItem​(java.lang.String settingValue, java.lang.Object labelObject, javax.swing.Icon icon)
      Creates a new list item with the given label, setting representation, and icon.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Returns true if another object's string representation is equal to this item's setting value.
      javax.swing.Icon getIcon()
      Returns this item's icon, or null if it doesn't have an icon.
      java.lang.String getLabel()
      Returns the text to display to the user for this list item.
      java.lang.Object getLabelObject()
      Returns the object used to produce the item's label for the user.
      int hashCode()
      Returns a hash code for this list item.
      void setIcon​(javax.swing.Icon icon)
      Sets the item's icon.
      void setLabelObject​(java.lang.Object value)
      Sets the object used to produce the item's label for the user.
      java.lang.String toString()
      Returns a string representation of the item.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ListItem

        public ListItem​(java.lang.String settingValue,
                        java.lang.Object labelObject)
        Creates a new list item with the given label and setting representation, but no icon.
        Parameters:
        settingValue - the setting value to use for this item when copying the state of the DIY component to the UI control, or from the UI control to the DIY component when the user selects the item
        labelObject - an object used to create the label text for the item
        Throws:
        java.lang.NullPointerException - if the label object or setting value are null
      • ListItem

        public ListItem​(java.lang.String settingValue,
                        java.lang.Object labelObject,
                        javax.swing.Icon icon)
        Creates a new list item with the given label, setting representation, and icon.
        Parameters:
        settingValue - the setting value to use for this item when copying the state of the DIY component to the UI control, or from the UI control to the DIY component when the user selects the item
        labelObject - an object used to create the label text for the item
        icon - the item's icon (may be null)
        Throws:
        java.lang.NullPointerException - if the label object or setting value are null
    • Method Detail

      • setLabelObject

        public void setLabelObject​(java.lang.Object value)
        Sets the object used to produce the item's label for the user. The label text will consist of the object's string representation. If the item is already being displayed in a list, the list will not reflect this change until it is next repainted.
        Parameters:
        value - the object used to generate the item's label
        See Also:
        getLabel()
      • getLabelObject

        public java.lang.Object getLabelObject()
        Returns the object used to produce the item's label for the user.
        Returns:
        the current label object
        See Also:
        setLabelObject(java.lang.Object)
      • getLabel

        public java.lang.String getLabel()
        Returns the text to display to the user for this list item. The base class returns the string value of the label object.
        Returns:
        the label this item displays to the user
      • getIcon

        public javax.swing.Icon getIcon()
        Returns this item's icon, or null if it doesn't have an icon.
        Specified by:
        getIcon in interface IconProvider
        Returns:
        this item's icon, or null
      • setIcon

        public void setIcon​(javax.swing.Icon icon)
        Sets the item's icon. Note that if the item is displayed in a list, the list will not reflect the change until it is next repainted.
        Parameters:
        icon - the item's new icon
      • toString

        public java.lang.String toString()
        Returns a string representation of the item. The string representation of a list item is its setting value.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the item's setting value
      • equals

        public boolean equals​(java.lang.Object obj)
        Returns true if another object's string representation is equal to this item's setting value.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to check for equality with this item
        Returns:
        true if the object is not null and obj.toString() is equal to this item's setting value
      • hashCode

        public int hashCode()
        Returns a hash code for this list item. The hash code will be equal to the hash code of the setting value.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code for this item