java.lang.Object
org.proto4j.swing.FieldReference<V>
- Type Parameters:
V
- the component's type (field's value type)
public final class FieldReference<V>
extends java.lang.Object
When a GUI is generated,
FieldReference
s are created automatically.
They are storing different informational data about the linked field.
This class is thread-safe: multiple threads can share a single FieldReference object without the need for external synchronization.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
THIS
When fields want to reference the root component, they should use this variable to point to it. -
Constructor Summary
Constructors Constructor Description FieldReference(int id)
Creates a newFieldReference
with the given id; -
Method Summary
Modifier and Type Method Description void
addEventListener(java.util.EventListener listener)
Appends the givenEventListener
at the end of the stored listeners.V
get()
Tries to return the stored field value and cast it to the referenced type<V>
.ComponentDesc
getDescription()
java.util.EventListener[]
getEventListeners()
int
getId()
java.lang.Class<?>
getType()
Returns the stored component type.void
set(V value)
Applies a new value to the linked field.void
setComponentDesc(ComponentDesc desc)
Applies a newComponentDesc
to this reference if there is none defined.void
setParent(java.lang.Object parent)
Sets the referenced GUI instance.
-
Field Details
-
THIS
public static final java.lang.String THISWhen fields want to reference the root component, they should use this variable to point to it.Note: The
get()
method will return the parent/ root component on field references with$this
as its name.- Since:
- 1.1.0
- See Also:
- Constant Field Values
-
-
Constructor Details
-
FieldReference
public FieldReference(int id)Creates a newFieldReference
with the given id;- Parameters:
id
- the field's component number
-
-
Method Details
-
get
Tries to return the stored field value and cast it to the referenced type<V>
.- Returns:
- the field's value
- Throws:
java.lang.NullPointerException
- if the stored instance isnull
java.lang.ClassCastException
- if the stored value can not be casted to<V>
-
set
Applies a new value to the linked field.- Parameters:
value
- the new value- Throws:
java.lang.NullPointerException
- if the value isnull
-
getId
public int getId()- Returns:
- the field's component number
-
getDescription
- Returns:
- the description for the linked component
-
getType
public java.lang.Class<?> getType()Returns the stored component type. This value may be null if the linked field has no value applied to it yet.- Returns:
- the stored component type
-
addEventListener
public void addEventListener(java.util.EventListener listener)Appends the givenEventListener
at the end of the stored listeners.- Parameters:
listener
- theEventListener
to add
-
getEventListeners
public java.util.EventListener[] getEventListeners()- Returns:
- all stored
EventListener
objects
-
setComponentDesc
Applies a newComponentDesc
to this reference if there is none defined.- Parameters:
desc
- the newComponentDesc
object
-
setParent
public void setParent(java.lang.Object parent)Sets the referenced GUI instance.- Parameters:
parent
- the GUI's instance
-