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.ChangeEventon 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 voidadd(T item)Adds the item to the selection.voidaddAll(Array<T> items)protected voidchanged()Called after the selection changes.voidchoose(T item)Selects or deselects the specified item based on how the selection is configured, whether ctrl is currently pressed, etc.voidclear()booleancontains(T item)booleanfireChangeEvent()Fires a change event on the selection's actor, if any.Tfirst()Returns the first selected item, or null.TgetLastSelected()Makes a best effort to return the last item selected, else returns an arbitrary item or null if the selection is empty.booleangetMultiple()booleangetRequired()booleangetToggle()booleanhasItems()Deprecated.UsenotEmpty().booleanisDisabled()booleanisEmpty()OrderedSet<T>items()java.util.Iterator<T>iterator()booleannotEmpty()voidremove(T item)voidremoveAll(Array<T> items)voidset(T item)Sets the selection to only the specified item.voidsetActor(Actor actor)voidsetAll(Array<T> items)voidsetDisabled(boolean isDisabled)If true, preventschoose(Object)from changing the selection.voidsetMultiple(boolean multiple)If true, allowschoose(Object)to select multiple items.voidsetProgrammaticChangeEvents(boolean programmaticChangeEvents)If false, onlychoose(Object)will fire a change event.voidsetRequired(boolean required)If true, preventschoose(Object)from selecting none.voidsetToggle(boolean toggle)If true, preventschoose(Object)from clearing the selection.intsize()Array<T>toArray()Array<T>toArray(Array<T> array)java.lang.StringtoString()
-
-
-
Method Detail
-
setActor
public void setActor(@Null Actor actor)
- Parameters:
actor- An actor to fireChangeListener.ChangeEventon 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:
iteratorin interfacejava.lang.Iterable<T>
-
setDisabled
public void setDisabled(boolean isDisabled)
If true, preventschoose(Object)from changing the selection. Default is false.- Specified by:
setDisabledin interfaceDisableable
-
isDisabled
public boolean isDisabled()
- Specified by:
isDisabledin 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:
toStringin classjava.lang.Object
-
-