Class GenericDesc<A extends java.lang.annotation.Annotation>

java.lang.Object
org.proto4j.swing.core.desc.GenericDesc<A>
Type Parameters:
A - the annotation type
Direct Known Subclasses:
BoundsDesc, LayoutDesc, MarginDesc, ModelDesc, OptionDesc, PositionDesc, WindowDesc

public abstract class GenericDesc<A extends java.lang.annotation.Annotation>
extends java.lang.Object
The base class for all option related descriptions.

This class is used to be the base for all attribute descriptions and their implementations. It is bound to an annotation type in order to make it easier to filter them in a list (concurrency).

  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int INVALID_INT
    A simple constant specifying whether the option is valid.
    static java.lang.String UNDEFINED
    A simple property descriptor indicating that a property wasn't found.
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected GenericDesc​(java.lang.Class<A> cls)
    Creates a new GenericDesc from the given annotation class.
  • Method Summary

    Modifier and Type Method Description
    java.lang.Class<A> annotationType()  
    abstract void applyTo​(java.awt.Component component)
    Applies the stored options on the given component.
    java.lang.Object get​(java.lang.String key)
    Returns the value to which the specified key is mapped, or null if this description contains no mapping for the key.
    java.util.Properties getDefinedOptions()  
    <R> R getOption​(java.lang.String key, java.lang.Class<R> cls)
    Returns the value to which the specified key is mapped, or null if this description contains no mapping for the key and casts it to the given format.
    boolean hasOption​(java.lang.String key)
    Tests if the specified object is a key in this description.
    java.util.Set<java.lang.Object> keys()
    Returns a Set view of the keys contained in this GenericDesc.
    void put​(java.lang.String key, java.lang.Object value)
    If the specified key is not already associated with a value (or is mapped to null) associates it with the given value.
    void read​(A value)
    Tries to insert all attributes provided by the given Annotation object.
    void read​(GenericDesc<A> desc)
    Tries to insert all attributes provided by the given GenericDesc object.

    Methods inherited from class java.lang.Object

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

    • UNDEFINED

      public static final java.lang.String UNDEFINED
      A simple property descriptor indicating that a property wasn't found.
      Since:
      1.1.0
      See Also:
      Constant Field Values
    • INVALID_INT

      public static final int INVALID_INT
      A simple constant specifying whether the option is valid.
      Since:
      1.1.0
      See Also:
      Constant Field Values
  • Constructor Details

    • GenericDesc

      protected GenericDesc​(java.lang.Class<A> cls)
      Creates a new GenericDesc from the given annotation class.
      Parameters:
      cls - the annotation class
      Throws:
      java.lang.NullPointerException - if the given annotation class is null
  • Method Details

    • applyTo

      public abstract void applyTo​(java.awt.Component component)
      Applies the stored options on the given component.
      Parameters:
      component - the Component reference
    • annotationType

      public java.lang.Class<A> annotationType()
      Returns:
      The annotation type this description is bound to.
    • get

      public java.lang.Object get​(java.lang.String key)
      Returns the value to which the specified key is mapped, or null if this description contains no mapping for the key.
      Parameters:
      key - the option's name
      Returns:
      the value to which the specified key is mapped, or null if this description contain no mapping for the key
    • put

      public void put​(java.lang.String key, java.lang.Object value)
      If the specified key is not already associated with a value (or is mapped to null) associates it with the given value.
      Parameters:
      key - the option's name
      value - the option's value
    • getOption

      public <R> R getOption​(java.lang.String key, java.lang.Class<R> cls) throws java.lang.NullPointerException, java.lang.ClassCastException
      Returns the value to which the specified key is mapped, or null if this description contains no mapping for the key and casts it to the given format.
      Type Parameters:
      R - the return type
      Parameters:
      key - the option's name
      cls - the type's class
      Returns:
      the value to which the specified key is mapped, or null if this description contain no mapping for the key
      Throws:
      java.lang.NullPointerException - if any of the provided arguments is null
      java.lang.ClassCastException - if an error is thrown during the object casting
    • hasOption

      public boolean hasOption​(java.lang.String key)
      Tests if the specified object is a key in this description.
      Parameters:
      key - the option's name
      Returns:
      true if and only if the specified object is a key in this description object; false otherwise.
    • read

      public void read​(A value)
      Tries to insert all attributes provided by the given Annotation object.
      Parameters:
      value - the annotation instance
    • read

      public void read​(GenericDesc<A> desc) throws java.lang.NullPointerException
      Tries to insert all attributes provided by the given GenericDesc object.
      Parameters:
      desc - the parent description
      Throws:
      java.lang.NullPointerException
    • keys

      public java.util.Set<java.lang.Object> keys()
      Returns a Set view of the keys contained in this GenericDesc.
      Returns:
      a Set view of the keys contained in this GenericDesc.
    • getDefinedOptions

      public java.util.Properties getDefinedOptions()
      Returns:
      the defined option namespace for this description