Class ChoiceItem<T>

  • Type Parameters:
    T - The type of the contained item.
    All Implemented Interfaces:
    java.lang.Comparable<ChoiceItem<T>>

    public class ChoiceItem<T>
    extends java.lang.Object
    implements java.lang.Comparable<ChoiceItem<T>>
    Can be used as a single choice for the FreeColChoiceDialog.
    • Constructor Summary

      Constructors 
      Constructor Description
      ChoiceItem​(java.lang.String text, T object)
      Creates a new ChoiceItem with the given object.
      ChoiceItem​(java.lang.String text, T object, boolean enable)
      Creates a new ChoiceItem with the given object.
      ChoiceItem​(T object)
      Creates a new ChoiceItem with the given object.
    • Field Detail

      • text

        private java.lang.String text
      • object

        private final T object
      • icon

        private javax.swing.ImageIcon icon
      • enabled

        private final boolean enabled
      • optionOK

        private boolean optionOK
      • optionCancel

        private boolean optionCancel
      • optionDefault

        private boolean optionDefault
    • Constructor Detail

      • ChoiceItem

        public ChoiceItem​(java.lang.String text,
                          T object,
                          boolean enable)
        Creates a new ChoiceItem with the given object.
        Parameters:
        text - The text that should be used to represent this choice.
        object - The object contained by this choice.
        enable - Sets if the option should be enabled or not
      • ChoiceItem

        public ChoiceItem​(java.lang.String text,
                          T object)
        Creates a new ChoiceItem with the given object.
        Parameters:
        text - The text that should be used to represent this choice.
        object - The object contained by this choice.
      • ChoiceItem

        public ChoiceItem​(T object)
        Creates a new ChoiceItem with the given object.
        Parameters:
        object - The object contained by this choice.
    • Method Detail

      • getObject

        public T getObject()
        Gets the Object contained by this choice.
        Returns:
        The Object.
      • getChoice

        public int getChoice()
        Gets the choice as an int.
        Returns:
        The number representing this object.
        Throws:
        java.lang.ClassCastException - if the object is not an Integer.
      • isEnabled

        public boolean isEnabled()
        Should this item be enabled or not?
        Returns:
        The enable status.
      • getIcon

        public javax.swing.ImageIcon getIcon()
        Get any icon associated with this choice.
        Returns:
        An icon if present, or null if not found.
      • setIcon

        public ChoiceItem<T> setIcon​(javax.swing.ImageIcon icon)
        Add an icon to this choice.
        Parameters:
        icon - The ImageIcon to add.
        Returns:
        This choice.
      • isOK

        public boolean isOK()
        Is this choice the "OK" choice?
        Returns:
        True if this is the "OK" choice.
      • okOption

        public ChoiceItem<T> okOption()
        Make this choice the "OK" option.
        Returns:
        This choice.
      • isCancel

        public boolean isCancel()
        Is this choice the "cancel" choice?
        Returns:
        True if this is the "cancel" choice.
      • cancelOption

        public ChoiceItem<T> cancelOption()
        Make this choice the "cancel" option.
        Returns:
        This choice.
      • isDefault

        public boolean isDefault()
        Is this choice the default choice?
        Returns:
        True if this is the default choice.
      • defaultOption

        public ChoiceItem<T> defaultOption()
        Make this choice the default.
        Returns:
        This choice.
      • compareTo

        public int compareTo​(ChoiceItem<T> other)
        Specified by:
        compareTo in interface java.lang.Comparable<T>
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object