Interface Entry<G>

Type Parameters:
G - the GUI's type
All Known Implementing Classes:
AbstractEntry

public interface Entry<G>
The base class for objects that store generated information about a GUI.

This class model is not thread-safe in its internal implementation but could be so, if en own implementation would be provided. The reading/ generation process is as easy as it could be. Just follow the execution workflow presented at the SwingReader declaration.

The standard way how to create a simple GUI is the following:

     Entry<MyGUI> entry = Entry.of(MyGUI.class);
 
Since:
1.0
See Also:
SwingReader, SwingLinker, FieldReference
  • Method Summary

    Modifier and Type Method Description
    FieldReference<?> getDeclaredField​(java.lang.String name)
    Returns a field reference that is mapped to the given name.
    <V> FieldReference<V> getDeclaredField​(java.lang.String name, java.lang.Class<V> cls)
    Returns a field reference that is mapped to the given name.
    FieldReference<?>[] getDeclaredFields()
    Returns an array of FieldReference objects reflecting all the fields declared by the GUI class.
    G getGUI()
    Returns the GUI-object stored in this Entry.
    Entry<?> getNestedGUI​(java.lang.String name)
    If nested GUIs are provided they can be fetched from here.
    <T_G> Entry<T_G> getNestedGUI​(java.lang.String name, java.lang.Class<T_G> type)
    If nested GUIs are provided they can be fetched from here.
    Entry<?>[] getNestedGUIs()
    Returns all nested GUI entries.
    java.lang.Class<G> getType()  
    void linkAction​(java.lang.Object src)
    Searches for the ActionHandler annotation and tries to link the given EventListener to the specified target.
    <T extends java.util.EventListener>
    boolean
    linkAction​(java.lang.String fieldName, java.lang.Class<T> cls, T listener)
    Tries to link the given EventListener to the specified target.
    static <R> Entry<R> of​(java.lang.Class<R> cls, java.lang.Object... args)
    Generates a new GUI from the given class.
    <V> void putField​(FieldReference<V> reference)
    Tries to insert the given field and throws an exception on error.
    <T_G> void putNestedGUI​(java.lang.String name, Entry<T_G> entry)
    Tries to insert the given nested GUI entry and throws an exception on error.
    void setGUI​(G gui)
    Applies a new gui value.
    void start​(java.lang.Object... args)
    Searches for the EntryPoint annotation and executes the method with it.
  • Method Details

    • of

      static <R> Entry<R> of​(java.lang.Class<R> cls, java.lang.Object... args) throws java.lang.Exception
      Generates a new GUI from the given class. This method provides the internal implementation of the Entry interface. It can be used by default, but should be replaced in future releases.

      For the basic execution workflow see SwingReader. The used Entry implementation makes use of the HashMap to store field reference objects.

      It is also possible to provide constructor arguments for the given GUI class. They will be used to create an object of type <R>.

      Type Parameters:
      R - the GUI type
      Parameters:
      cls - the GUI's class
      args - the constructor arguments
      Returns:
      a new GUI instance
      Throws:
      java.lang.Exception - if an error occurs
    • getGUI

      G getGUI()
      Returns the GUI-object stored in this Entry. This method will throw a NullPointerException if the given instance is null.
      Returns:
      the stored GUI instance
      Throws:
      java.lang.NullPointerException - if the stored GUI is null
    • setGUI

      void setGUI​(G gui)
      Applies a new gui value.
      Parameters:
      gui - the new GUI instance
    • getType

      java.lang.Class<G> getType()
      Returns:
      The GUI's type
    • getNestedGUI

      <T_G> Entry<T_G> getNestedGUI​(java.lang.String name, java.lang.Class<T_G> type)
      If nested GUIs are provided they can be fetched from here.
      Type Parameters:
      T_G - the GUI type
      Parameters:
      name - the field's name
      type - gui's class type
      Returns:
      the Entry storing all information about the GUI
    • getNestedGUI

      Entry<?> getNestedGUI​(java.lang.String name)
      If nested GUIs are provided they can be fetched from here.
      Parameters:
      name - the field's name
      Returns:
      the Entry storing all information about the GUI
    • getNestedGUIs

      Entry<?>[] getNestedGUIs()
      Returns all nested GUI entries.
      Returns:
      all nested GUI entries
    • putNestedGUI

      <T_G> void putNestedGUI​(java.lang.String name, Entry<T_G> entry) throws java.lang.NullPointerException, java.nio.channels.AlreadyBoundException
      Tries to insert the given nested GUI entry and throws an exception on error.
      Type Parameters:
      T_G - the GUI type
      Parameters:
      name - the field's name
      entry - the Entry object
      Throws:
      java.lang.NullPointerException - if the given reference is null
      java.nio.channels.AlreadyBoundException - if there is already a mapping with the field's name
    • getDeclaredField

      FieldReference<?> getDeclaredField​(java.lang.String name)
      Returns a field reference that is mapped to the given name. The name will be the same as the one at the field's declaration.
      Parameters:
      name - the field's name
      Returns:
      the corresponding FieldReference; null if no mapping exists for the given name.
    • getDeclaredField

      <V> FieldReference<V> getDeclaredField​(java.lang.String name, java.lang.Class<V> cls) throws java.lang.ClassCastException
      Returns a field reference that is mapped to the given name. The name will be the same as the one at the field's declaration.

      This method will fail if the provided class type is not an assignable form of the stored one.

      Type Parameters:
      V - the component's type
      Parameters:
      name - the field's name
      cls - the component class type
      Returns:
      the corresponding FieldReference; null if no mapping exists for the given name.
      Throws:
      java.lang.ClassCastException - if there is an error while casting
    • putField

      <V> void putField​(FieldReference<V> reference) throws java.lang.NullPointerException, java.nio.channels.AlreadyBoundException
      Tries to insert the given field and throws an exception on error.
      Type Parameters:
      V - the component type
      Parameters:
      reference - the field's reference
      Throws:
      java.lang.NullPointerException - if the given reference is null
      java.nio.channels.AlreadyBoundException - if there is already a mapping with the field's name
    • getDeclaredFields

      FieldReference<?>[] getDeclaredFields()
      Returns an array of FieldReference objects reflecting all the fields declared by the GUI class.
      Returns:
      an array of FieldReference objects
    • start

      void start​(java.lang.Object... args) throws java.lang.NullPointerException
      Searches for the EntryPoint annotation and executes the method with it.
      Parameters:
      args - the method's arguments
      Throws:
      java.lang.NullPointerException - if no method was found
    • linkAction

      void linkAction​(java.lang.Object src)
      Searches for the ActionHandler annotation and tries to link the given EventListener to the specified target.
      Parameters:
      src - the event listener object
    • linkAction

      <T extends java.util.EventListener> boolean linkAction​(java.lang.String fieldName, java.lang.Class<T> cls, T listener)
      Tries to link the given EventListener to the specified target.
      Type Parameters:
      T - the listener type
      Parameters:
      fieldName - the target field name
      cls - the listener base class
      listener - the event listener object
      Returns:
      true if the listener has been added successfully