Package arc.scene.utils
Class Selection<T>
java.lang.Object
arc.scene.utils.Selection<T>
- All Implemented Interfaces:
Disableable
,Iterable<T>
Manages selected objects. Optionally fires a
ChangeListener.ChangeEvent
on an element. Selection changes can be vetoed via
SceneEvent.cancel()
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the item to the selection.void
protected void
changed()
Called after the selection changes.void
Selects or deselects the specified item based on how the selection is configured, whether ctrl is currently pressed, etc.void
clear()
boolean
boolean
Fires a change event on the selection's element, if any.first()
Returns the first selected item, or null.Makes a best effort to return the last item selected, else returns an arbitrary item or null if the selection is empty.boolean
boolean
boolean
boolean
hasItems()
boolean
boolean
isEmpty()
items()
iterator()
void
void
void
Sets the selection to only the specified item.void
void
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()
toArray()
toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Selection
public Selection()
-
-
Method Details
-
setActor
- Parameters:
element
- An element to fireChangeListener.ChangeEvent
on when the selection changes, or null.
-
choose
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
public boolean hasItems() -
isEmpty
public boolean isEmpty() -
size
public int size() -
items
-
first
Returns the first selected item, or null. -
set
Sets the selection to only the specified item. -
setAll
-
add
Adds the item to the selection. -
addAll
-
remove
-
removeAll
-
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 element, if any. Called internally when the selection changes, depending onsetProgrammaticChangeEvents(boolean)
.- Returns:
- true if the change should be undone.
-
contains
-
getLastSelected
Makes a best effort to return the last item selected, else returns an arbitrary item or null if the selection is empty. -
iterator
-
toArray
-
toArray
-
isDisabled
public boolean isDisabled()- Specified by:
isDisabled
in interfaceDisableable
-
setDisabled
public void setDisabled(boolean isDisabled) If true, preventschoose(Object)
from changing the selection. Default is false.- Specified by:
setDisabled
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
-