Package com.prineside.tdi2.scene2d.utils
Class Selection<T>
java.lang.Object
com.prineside.tdi2.scene2d.utils.Selection<T>
- All Implemented Interfaces:
Disableable,Iterable<T>
- Direct Known Subclasses:
ArraySelection
Manages selected objects. Optionally fires a
ChangeListener.ChangeEvent on an actor. Selection changes can be vetoed via
Event.cancel().- Author:
- Nathan Sweet
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the item to the selection.voidvoidSelects or deselects the specified item based on how the selection is configured, whether ctrl is currently pressed, etc.voidclear()booleanbooleanFires a change event on the selection's actor, 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.booleanbooleanbooleanbooleanhasItems()Deprecated.booleanbooleanisEmpty()items()iterator()booleannotEmpty()voidvoidvoidSets the selection to only the specified item.voidvoidvoidsetDisabled(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()toArray()toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Selection
public Selection()
-
-
Method Details
-
setActor
- Parameters:
actor- An actor to fireChangeListener.ChangeEventon 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
Deprecated.UsenotEmpty(). -
notEmpty
public boolean notEmpty() -
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() -
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.
-
contains
- Parameters:
item- May be null (returns false).
-
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
-
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
-
notEmpty().