Class Selection<T>
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.utils.Selection<T>
-
- All Implemented Interfaces:
Disableable
,java.lang.Iterable<T>
- Direct Known Subclasses:
ArraySelection
public class Selection<T> extends java.lang.Object implements Disableable, java.lang.Iterable<T>
Manages selected objects. Optionally fires aChangeListener.ChangeEvent
on an actor. Selection changes can be vetoed viaEvent.cancel()
.
-
-
Constructor Summary
Constructors Constructor Description Selection()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(T item)
Adds the item to the selection.void
addAll(Array<T> items)
protected void
changed()
Called after the selection changes.void
choose(T item)
Selects or deselects the specified item based on how the selection is configured, whether ctrl is currently pressed, etc.void
clear()
boolean
contains(T item)
boolean
fireChangeEvent()
Fires a change event on the selection's actor, if any.T
first()
Returns the first selected item, or null.T
getLastSelected()
Makes a best effort to return the last item selected, else returns an arbitrary item or null if the selection is empty.boolean
getMultiple()
boolean
getRequired()
boolean
getToggle()
boolean
hasItems()
Deprecated.UsenotEmpty()
.boolean
isDisabled()
boolean
isEmpty()
OrderedSet<T>
items()
java.util.Iterator<T>
iterator()
boolean
notEmpty()
void
remove(T item)
void
removeAll(Array<T> items)
void
set(T item)
Sets the selection to only the specified item.void
setActor(Actor actor)
void
setAll(Array<T> items)
void
setDisabled(boolean isDisabled)
If true, preventschoose(Object)
from changing the selection.void
setMultiple(boolean multiple)
If true, allowschoose(Object)
to select multiple items.void
setProgrammaticChangeEvents(boolean programmaticChangeEvents)
If false, onlychoose(Object)
will fire a change event.void
setRequired(boolean required)
If true, preventschoose(Object)
from selecting none.void
setToggle(boolean toggle)
If true, preventschoose(Object)
from clearing the selection.int
size()
Array<T>
toArray()
Array<T>
toArray(Array<T> array)
java.lang.String
toString()
-
-
-
Method Detail
-
setActor
public void setActor(@Null Actor actor)
- Parameters:
actor
- An actor to fireChangeListener.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.UsenotEmpty()
.
-
notEmpty
public boolean notEmpty()
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
items
public OrderedSet<T> items()
-
set
public void set(T item)
Sets the selection to only the specified item.
-
add
public void add(T item)
Adds the item to the selection.
-
remove
public void remove(T item)
-
clear
public void clear()
-
changed
protected void changed()
Called after the selection changes. The default implementation does nothing.
-
fireChangeEvent
public boolean fireChangeEvent()
Fires a change event on the selection's actor, if any. Called internally when the selection changes, depending onsetProgrammaticChangeEvents(boolean)
.- Returns:
- true if the change should be undone.
-
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 java.util.Iterator<T> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
setDisabled
public void setDisabled(boolean isDisabled)
If true, preventschoose(Object)
from changing the selection. Default is false.- Specified by:
setDisabled
in interfaceDisableable
-
isDisabled
public boolean isDisabled()
- Specified by:
isDisabled
in interfaceDisableable
-
getToggle
public boolean getToggle()
-
setToggle
public void setToggle(boolean toggle)
If true, preventschoose(Object)
from clearing the selection. Default is false.
-
getMultiple
public boolean getMultiple()
-
setMultiple
public void setMultiple(boolean multiple)
If true, allowschoose(Object)
to select multiple items. Default is false.
-
getRequired
public boolean getRequired()
-
setRequired
public void setRequired(boolean required)
If true, preventschoose(Object)
from selecting none. Default is false.
-
setProgrammaticChangeEvents
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)
If false, onlychoose(Object)
will fire a change event. Default is true.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-