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
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for properties.Nested classes/interfaces inherited from interface io.github.cottonmc.cotton.gui.widget.data.ObservableView
ObservableView.ChangeListener<T> -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(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.booleanhasValue()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.voidremoveListener(ObservableView.ChangeListener<? super T> listener) Removes a change listener from this property view if present.voidSets this property to a constant value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:ObservableViewReturns whether this property has been set to a value.- Specified by:
hasValuein interfaceObservableView<T>- Returns:
- whether this property has been set to a value
-
get
Description copied from interface:ObservableViewReturns 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:ObservableViewAdds a change listener to this property view.- Specified by:
addListenerin interfaceObservableView<T>- Parameters:
listener- the added listener
-
removeListener
Description copied from interface:ObservableViewRemoves a change listener from this property view if present.- Specified by:
removeListenerin interfaceObservableView<T>- Parameters:
listener- the removed listener
-