Class ObservableProperty<T>
java.lang.Object
io.github.cottonmc.cotton.gui.widget.data.ObservableProperty<T>
- Type Parameters:
T
- the contained value type
- All Implemented Interfaces:
ObservableView<T>
,Supplier<T>
An observable mutable property. Observable properties are containers for values
that can be modified and listened to.
The naming convention for ObservableProperty
getters follows the convention
<property name>Property
. For example, the WWidget.hovered
property can be retrieved with
hoveredProperty()
.
- Since:
- 4.2.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
A builder for properties.Nested classes/interfaces inherited from interface io.github.cottonmc.cotton.gui.widget.data.ObservableView
ObservableView.ChangeListener<T>
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(ObservableView.ChangeListener<? super T> listener) Adds a change listener to this property view.static <T> ObservableProperty.Builder
<T> empty()
Creates a "late init" property without an initial value.get()
Returns the value of this property.getName()
Returns the name of this property.boolean
hasValue()
Returns whether this property has been set to a value.static <T> ObservableProperty.Builder
<T> of
(T initialValue) Creates a property with an initial value.readOnly()
Returns a read-only view of this property.void
removeListener
(ObservableView.ChangeListener<? super T> listener) Removes a change listener from this property view if present.void
Sets this property to a constant value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.cottonmc.cotton.gui.widget.data.ObservableView
find, getOrNull
-
Method Details
-
empty
Creates a "late init" property without an initial value. The created property will throw an exception if it has not been initialised yet.- Type Parameters:
T
- the contained value type- Returns:
- the created empty property builder
-
of
Creates a property with an initial value.- Type Parameters:
T
- the contained value type- Parameters:
initialValue
- the initial value- Returns:
- the created property
-
hasValue
public boolean hasValue()Description copied from interface:ObservableView
Returns whether this property has been set to a value.- Specified by:
hasValue
in interfaceObservableView<T>
- Returns:
- whether this property has been set to a value
-
get
Description copied from interface:ObservableView
Returns the value of this property. -
set
Sets this property to a constant value.- Parameters:
value
- the new value- Throws:
NullPointerException
- if the value is null and nulls aren't allowed
-
readOnly
Returns a read-only view of this property. The result is not an instance ofObservableProperty
, and thus can't be mutated.- Returns:
- an observable view of this property
-
getName
Returns the name of this property.- Returns:
- the name of this property
-
addListener
Description copied from interface:ObservableView
Adds a change listener to this property view.- Specified by:
addListener
in interfaceObservableView<T>
- Parameters:
listener
- the added listener
-
removeListener
Description copied from interface:ObservableView
Removes a change listener from this property view if present.- Specified by:
removeListener
in interfaceObservableView<T>
- Parameters:
listener
- the removed listener
-