Class DefaultSelectable

  • All Implemented Interfaces:
    Selectable

    public class DefaultSelectable
    extends java.lang.Object
    implements Selectable
    The element used by CheckBoxList's ListModel. In order to allow check box in JList without messing up when list model changes, we use this class to store the object itself and a boolean to indicated if the row is selected.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean _enabled  
      protected java.lang.Object _object  
      protected boolean _selected  
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSelectable​(java.lang.Object object)
      Creates CheckBoxListElement with an actual object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      java.lang.Object getObject()
      Gets the actual element.
      int hashCode()
      Overrides to consider the hash code of the object only.
      void invertSelected()
      Inverts the selection status.
      boolean isEnabled()
      Checks if selection change is allowed.
      boolean isSelected()
      Gets the selected status.
      void setEnabled​(boolean enabled)
      Enabled selection change.
      void setObject​(java.lang.Object object)
      Sets the actual element.
      void setSelected​(boolean selected)
      Sets it as selected.
      java.lang.String toString()
      Overrides to consider the toString() of object only.
      • Methods inherited from class java.lang.Object

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

      • _object

        protected java.lang.Object _object
      • _selected

        protected boolean _selected
      • _enabled

        protected boolean _enabled
    • Constructor Detail

      • DefaultSelectable

        public DefaultSelectable​(java.lang.Object object)
        Creates CheckBoxListElement with an actual object. In the case of CheckBoxList, instead of add the object directly to ListModel, you should wrap it in CheckBoxListElement and add CheckBoxListElement into ListModel.
        Parameters:
        object - the actual object
    • Method Detail

      • setObject

        public void setObject​(java.lang.Object object)
        Sets the actual element.
        Parameters:
        object -
      • getObject

        public java.lang.Object getObject()
        Gets the actual element.
        Returns:
        the actual element.
      • setSelected

        public void setSelected​(boolean selected)
        Sets it as selected.
        Specified by:
        setSelected in interface Selectable
        Parameters:
        selected -
      • invertSelected

        public void invertSelected()
        Inverts the selection status.
        Specified by:
        invertSelected in interface Selectable
      • isSelected

        public boolean isSelected()
        Gets the selected status.
        Specified by:
        isSelected in interface Selectable
        Returns:
        true if it is selected. Otherwise, false.
      • setEnabled

        public void setEnabled​(boolean enabled)
        Enabled selection change. Enabled false doesn't mean selected is false. If it is selected before, setEnable(false) won't make selected become false. In the other word, setEnabled won't change the the value of isSelected().
        Specified by:
        setEnabled in interface Selectable
        Parameters:
        enabled -
      • isEnabled

        public boolean isEnabled()
        Checks if selection change is allowed.
        Specified by:
        isEnabled in interface Selectable
        Returns:
        true if selection change is allowed.
      • hashCode

        public int hashCode()
        Overrides to consider the hash code of the object only. From outside point of view, this class should behave just like object itself. That's why we override hashCode.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code.
      • toString

        public java.lang.String toString()
        Overrides to consider the toString() of object only. From outside point of view, this class should behave just like object itself. That's why we override toString.
        Overrides:
        toString in class java.lang.Object
        Returns:
        toString() of object.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object