APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.utils

public Class Selection<T>

extends Object
implements Disableable, Iterable<T>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable, com.badlogic.gdx.scenes.scene2d.utils.Disableable
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.utils.ArraySelection
Imports
com.badlogic.gdx.scenes.scene2d.Actor, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent, com.badlogic.gdx.utils.Array, .Null, .OrderedSet, java.util.Iterator

Manages selected objects. Optionally fires a ChangeEvent on an actor. Selection changes can be vetoed via ChangeEvent#cancel().
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private Actor
pack-priv boolean
pack-priv T
pack-priv boolean
private final OrderedSet<T>
private boolean
pack-priv boolean
pack-priv final OrderedSet<T>
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(T item)

Adds the item to the selection.

public void
addAll(Array<T> items)

protected void
changed()

Called after the selection changes.

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.

pack-priv void
public void
public boolean
contains(T
May be null (returns false).
item
)

public boolean

Returns:

true if the change should be undone.
fireChangeEvent
()

Fires a change event on the selection's actor, if any.

public T
first()

Returns the first selected item, or 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.

public boolean
public boolean
public boolean
public boolean
public boolean
hasItems()
Deprecated Use notEmpty().

public boolean
public boolean
public OrderedSet<T>
public Iterator<T>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public boolean
public void
remove(T item)

public void
removeAll(Array<T> items)

pack-priv void
public void
set(T item)

Sets the selection to only the specified item.

public void
setActor(Actor
An actor to fire ChangeEvent on when the selection changes, or null.
actor
)

public void
setAll(Array<T> items)

public void
setDisabled(boolean isDisabled)

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.setDisabled.

If true, prevents choose(Object) from changing the selection.

public void
setMultiple(boolean multiple)

If true, allows choose(Object) to select multiple items.

public void
setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, only choose(Object) will fire a change event.

public void
setRequired(boolean required)

If true, prevents choose(Object) from selecting none.

public void
setToggle(boolean toggle)

If true, prevents choose(Object) from clearing the selection.

public int
size()

pack-priv void
public Array<T>
public Array<T>
toArray(Array<T> array)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

actorback to summary
private Actor actor
Annotations
@Null
isDisabledback to summary
pack-priv boolean isDisabled
lastSelectedback to summary
pack-priv T lastSelected
Annotations
@Null
multipleback to summary
pack-priv boolean multiple
oldback to summary
private final OrderedSet<T> old
programmaticChangeEventsback to summary
private boolean programmaticChangeEvents
requiredback to summary
pack-priv boolean required
selectedback to summary
pack-priv final OrderedSet<T> selected
toggleback to summary
private boolean toggle

Constructor Detail

Selectionback to summary
public Selection()

Method Detail

addback to summary
public void add(T item)

Adds the item to the selection.

addAllback to summary
public void addAll(Array<T> items)
changedback to summary
protected void changed()

Called after the selection changes. The default implementation does nothing.

chooseback to summary
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.

cleanupback to summary
pack-priv void cleanup()
clearback to summary
public void clear()
containsback to summary
public boolean contains(T item)
Parameters
item:T

May be null (returns false).

fireChangeEventback to summary
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:boolean

true if the change should be undone.

firstback to summary
public T first()

Returns the first selected item, or null.

Annotations
@Null
getLastSelectedback to summary
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.

Annotations
@Null
getMultipleback to summary
public boolean getMultiple()
getProgrammaticChangeEventsback to summary
public boolean getProgrammaticChangeEvents()
getRequiredback to summary
public boolean getRequired()
getToggleback to summary
public boolean getToggle()
hasItemsback to summary
public boolean hasItems()

Deprecated

Use notEmpty().

Annotations
@Deprecated
isDisabledback to summary
public boolean isDisabled()

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.isDisabled.

isEmptyback to summary
public boolean isEmpty()
itemsback to summary
public OrderedSet<T> items()
iteratorback to summary
public Iterator<T> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

notEmptyback to summary
public boolean notEmpty()
removeback to summary
public void remove(T item)
removeAllback to summary
public void removeAll(Array<T> items)
revertback to summary
pack-priv void revert()
setback to summary
public void set(T item)

Sets the selection to only the specified item.

setActorback to summary
public void setActor(Actor actor)
Parameters
actor:Actor

An actor to fire ChangeEvent on when the selection changes, or null.

setAllback to summary
public void setAll(Array<T> items)
setDisabledback to summary
public void setDisabled(boolean isDisabled)

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.setDisabled.

If true, prevents choose(Object) from changing the selection. Default is false.

setMultipleback to summary
public void setMultiple(boolean multiple)

If true, allows choose(Object) to select multiple items. Default is false.

setProgrammaticChangeEventsback to summary
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, only choose(Object) will fire a change event. Default is true.

setRequiredback to summary
public void setRequired(boolean required)

If true, prevents choose(Object) from selecting none. Default is false.

setToggleback to summary
public void setToggle(boolean toggle)

If true, prevents choose(Object) from clearing the selection. Default is false.

sizeback to summary
public int size()
snapshotback to summary
pack-priv void snapshot()
toArrayback to summary
public Array<T> toArray()
toArrayback to summary
public Array<T> toArray(Array<T> array)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.