Class FieldReference<V>

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, FieldReferences 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 new FieldReference with the given id;
  • Method Summary

    Modifier and Type Method Description
    void addEventListener​(java.util.EventListener listener)
    Appends the given EventListener 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 new ComponentDesc to this reference if there is none defined.
    void setParent​(java.lang.Object parent)
    Sets the referenced GUI instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • THIS

      public static final java.lang.String THIS
      When 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 new FieldReference with the given id;
      Parameters:
      id - the field's component number
  • Method Details

    • get

      public V get() throws java.lang.NullPointerException, java.lang.ClassCastException
      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 is null
      java.lang.ClassCastException - if the stored value can not be casted to <V>
    • set

      public void set​(V value) throws java.lang.NullPointerException
      Applies a new value to the linked field.
      Parameters:
      value - the new value
      Throws:
      java.lang.NullPointerException - if the value is null
    • getId

      public int getId()
      Returns:
      the field's component number
    • getDescription

      public ComponentDesc 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 given EventListener at the end of the stored listeners.
      Parameters:
      listener - the EventListener to add
    • getEventListeners

      public java.util.EventListener[] getEventListeners()
      Returns:
      all stored EventListener objects
    • setComponentDesc

      public void setComponentDesc​(ComponentDesc desc)
      Applies a new ComponentDesc to this reference if there is none defined.
      Parameters:
      desc - the new ComponentDesc object
    • setParent

      public void setParent​(java.lang.Object parent)
      Sets the referenced GUI instance.
      Parameters:
      parent - the GUI's instance