Class Selection<T>

java.lang.Object
com.prineside.tdi2.scene2d.utils.Selection<T>
All Implemented Interfaces:
Disableable, Iterable<T>
Direct Known Subclasses:
ArraySelection

public class Selection<T> extends Object implements Disableable, Iterable<T>
Manages selected objects. Optionally fires a ChangeListener.ChangeEvent on an actor. Selection changes can be vetoed via Event.cancel().
Author:
Nathan Sweet
  • Constructor Details

    • Selection

      public Selection()
  • Method Details

    • setActor

      public void setActor(@Null Actor actor)
      Parameters:
      actor - An actor to fire ChangeListener.ChangeEvent on when the selection changes, or null.
    • choose

      public void choose(T item)
      Selects or deselects the specified item based on how the selection is configured, whether ctrl is currently pressed, etc. This is typically invoked by user interaction.
    • hasItems

      @Deprecated public boolean hasItems()
      Deprecated.
    • notEmpty

      public boolean notEmpty()
    • isEmpty

      public boolean isEmpty()
    • size

      public int size()
    • items

      public OrderedSet<T> items()
    • first

      @Null public T first()
      Returns the first selected item, or null.
    • set

      public void set(T item)
      Sets the selection to only the specified item.
    • setAll

      public void setAll(Array<T> items)
    • add

      public void add(T item)
      Adds the item to the selection.
    • addAll

      public void addAll(Array<T> items)
    • remove

      public void remove(T item)
    • removeAll

      public void removeAll(Array<T> items)
    • clear

      public void clear()
    • fireChangeEvent

      public boolean fireChangeEvent()
      Fires a change event on the selection's actor, if any. Called internally when the selection changes, depending on setProgrammaticChangeEvents(boolean).
      Returns:
      true if the change should be undone.
    • contains

      public boolean contains(@Null T item)
      Parameters:
      item - May be null (returns false).
    • getLastSelected

      @Null public T getLastSelected()
      Makes a best effort to return the last item selected, else returns an arbitrary item or null if the selection is empty.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • toArray

      public Array<T> toArray()
    • toArray

      public Array<T> toArray(Array<T> array)
    • setDisabled

      public void setDisabled(boolean isDisabled)
      If true, prevents choose(Object) from changing the selection. Default is false.
      Specified by:
      setDisabled in interface Disableable
    • isDisabled

      public boolean isDisabled()
      Specified by:
      isDisabled in interface Disableable
    • getToggle

      public boolean getToggle()
    • setToggle

      public void setToggle(boolean toggle)
      If true, prevents choose(Object) from clearing the selection. Default is false.
    • getMultiple

      public boolean getMultiple()
    • setMultiple

      public void setMultiple(boolean multiple)
      If true, allows choose(Object) to select multiple items. Default is false.
    • getRequired

      public boolean getRequired()
    • setRequired

      public void setRequired(boolean required)
      If true, prevents choose(Object) from selecting none. Default is false.
    • setProgrammaticChangeEvents

      public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)
      If false, only choose(Object) will fire a change event. Default is true.
    • toString

      public String toString()
      Overrides:
      toString in class Object