org.graffiti.plugin.view.interactive
Class Slot<T>

java.lang.Object
  extended by org.graffiti.plugin.view.interactive.Slot<T>
Type Parameters:
T - the type of the slot.
Direct Known Subclasses:
BooleanSlot, CollectionSlot, DoubleSlot, IntSlot, MapSlot, Point2DSlot, StringSlot

public class Slot<T>
extends Object

Slots are typed containers that hold the values supplied by triggers and used by triggers and actions as parameters. Instances of Slot do not directly hold the values but rather describe its type, name, default values etc. The association of slots with values is maintained by SlotMap.

Overview of the trigger/action paradigm

Version:
$Revision$ $Date$
Author:
Andreas Gleißner

Field Summary
protected  T defaultValue
          The default value of this, when used as a parameter slot.
protected  Class<T> type
          The Class object modeling the type of this slot.
 
Constructor Summary
Slot(String id, Class<T> type, boolean acceptsNull)
          Constructs a new slot with the specified id and slot type.
Slot(String id, Class<T> type, T defaultValue, boolean acceptsNull)
          Constructs a new slot with the specified id, slot type and default value.
Slot(String id, String name, Class<T> type, String description)
          Creates a new slot with the specified id, slot type and description.
Slot(String id, String name, Class<T> type, String description, SlotEditorComponentBuilder<T> builder, T defaultValue, boolean acceptsNull)
          Constructs a new slot.
Slot(String id, String name, Class<T> type, String description, T defaultValue)
          Constructs a new slot.
 
Method Summary
 boolean acceptsNull()
          Returns whether null may be assigned to this slot.
 boolean acceptsValue(Object value)
          Returns whether the specified value may be assigned to this slot.
(package private) static Slot<Object> create(String id)
          Creates a new slot with the specified id and Object as slot type.
static
<S> Slot<S>
create(String id, Class<S> type)
          Creates a new slot with the specified id and slot type.
static
<S> Slot<S>
create(String id, Class<S> type, boolean acceptsNull)
          Creates a new slot with the specified id and slot type.
 void createDefaultPreferences(Preferences preferences)
          Prepares the specified preferences tree to store the value assigned to this slot.
static
<S> Slot<List<S>>
createListSlot(String id, Class<S> type)
          Creates a new slot with the specified id and List of the the specified type as its slot type.
static
<K,V> Slot<Map<K,V>>
createMapSlot(String id, Class<K> keyType, Class<V> valueType)
          Creates a new slot with the specified id and Map of the the specified types as its slot type.
static
<S> Slot<Set<S>>
createSetSlot(String id, Class<S> type)
          Creates a new slot with the specified id and Set of the the specified type as its slot type.
 boolean equals(Object other)
          Returns whether the other object is a Slot and has the same id as this.
 SlotEditorComponentBuilder<T> getBuilder()
          Returns a SlotEditorComponentBuilder for this slot.
 T getDefaultValue()
          Returns the default value of this, when used as a parameter slot.
 String getDescription()
          Returns the description of this slot as seen by the user when graphically editing the tools.
 String getId()
          Returns the id to address this slot from script code.
 String getName()
          Returns the name of this slot as seen by the user when graphically editing the tools.
 Class<T> getType()
          Returns the type of this slot.
 int hashCode()
          Returns a hash code for this slot.
 T loadValue(Preferences preferences)
          Returns the value that is assigned to this slot according to the specified preferences tree.
 void saveValue(Preferences preferences, T value)
          Stores the specified value in the specified preferences tree by means of this slot.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

protected Class<T> type
The Class object modeling the type of this slot.


defaultValue

protected T defaultValue
The default value of this, when used as a parameter slot.

Constructor Detail

Slot

public Slot(String id,
            Class<T> type,
            boolean acceptsNull)
Constructs a new slot with the specified id and slot type.

Parameters:
id - the id of the slot.
type - the Class representing the slot type.
acceptsNull - specifies whether this slot accepts null.
See Also:
acceptsNull()

Slot

public Slot(String id,
            Class<T> type,
            T defaultValue,
            boolean acceptsNull)
Constructs a new slot with the specified id, slot type and default value.

Parameters:
id - the id of the slot.
type - the Class representing the slot type.
acceptsNull - specifies whether this slot accepts null.
defaultValue - the default value of the slot.
See Also:
acceptsNull()

Slot

public Slot(String id,
            String name,
            Class<T> type,
            String description,
            SlotEditorComponentBuilder<T> builder,
            T defaultValue,
            boolean acceptsNull)
Constructs a new slot.

Parameters:
id - the id of the slot.
name - the name as seen by the user when graphically editing the tools.
type - the Class representing the slot type.
description - the description of the slot as seen by the user when graphically editing the tools.
builder - the SlotEditorComponentBuilder. When using this slot to define the parameter of a trigger, builder can be used to graphically edit that parameter. May be null. Then the tool system tries to infer an adequate component based on the slot type. If this fails, the parameter is not graphically editable.
defaultValue - the default value.
acceptsNull - specifies whether this slot accepts null.
See Also:
acceptsNull()

Slot

public Slot(String id,
            String name,
            Class<T> type,
            String description)
Creates a new slot with the specified id, slot type and description. The returned slot will not accept null.

Parameters:
id - the id of the slot.
name - the name of the slot as seen by the user when graphically editing the tools.
type - the Class representing the slot type.
description - the description as seen by the user when graphically editing the tools.
See Also:
acceptsNull()

Slot

public Slot(String id,
            String name,
            Class<T> type,
            String description,
            T defaultValue)
Constructs a new slot. The returned slot will not accept null.

Parameters:
id - the id of the slot.
name - the name of the slot as seen by the user when graphically editing the tools.
type - the Class representing the slot type.
description - the description of the slot as seen by the user when graphically editing the tools.
defaultValue - the default value.
See Also:
acceptsNull()
Method Detail

create

static Slot<Object> create(String id)
Creates a new slot with the specified id and Object as slot type. The returned slot will not accept null.

Parameters:
id - the id of the slot.
Returns:
a new Slot with the specified id and Object as slot type.
See Also:
acceptsNull()

create

public static <S> Slot<S> create(String id,
                                 Class<S> type)
Creates a new slot with the specified id and slot type. The returned slot will not accept null.

Type Parameters:
S - the type of the slot.
Parameters:
id - the id of the slot.
type - the Class representing the slot type.
Returns:
a new Slot with the specified id and slot type.
See Also:
acceptsNull()

create

public static <S> Slot<S> create(String id,
                                 Class<S> type,
                                 boolean acceptsNull)
Creates a new slot with the specified id and slot type.

Type Parameters:
S - the type of the slot.
Parameters:
id - the id of the slot.
type - the Class representing the slot type.
acceptsNull - specifies whether this slot accepts null.
Returns:
a new Slot with the specified id and slot type.
See Also:
acceptsNull()

createSetSlot

public static <S> Slot<Set<S>> createSetSlot(String id,
                                             Class<S> type)
Creates a new slot with the specified id and Set of the the specified type as its slot type. The returned slot will not accept null.

Type Parameters:
S - Set<S> is the slot type of the returned slot.
Parameters:
id - the id of the slot.
type - the Class representing S.
Returns:
a new Slot with the specified id and Set of the the specified type as its slot type.
See Also:
acceptsNull()

createListSlot

public static <S> Slot<List<S>> createListSlot(String id,
                                               Class<S> type)
Creates a new slot with the specified id and List of the the specified type as its slot type. The returned slot will not accept null.

Type Parameters:
S - List<S> is the slot type of the returned slot.
Parameters:
id - the id of the slot.
type - the Class representing S.
Returns:
a new Slot with the specified id and List of the the specified type as its slot type.
See Also:
acceptsNull()

createMapSlot

public static <K,V> Slot<Map<K,V>> createMapSlot(String id,
                                                 Class<K> keyType,
                                                 Class<V> valueType)
Creates a new slot with the specified id and Map of the the specified types as its slot type. The returned slot will not accept null.

Type Parameters:
K - Map<K, V> is the slot type of the returned slot.
V - Map<K, V> is the slot type of the returned slot.
Parameters:
id - the id of the slot.
keyType - the Class representing K.
valueType - the Class representing V.
Returns:
a new Slot with the specified id and Map of the the specified type as its slot type.
See Also:
acceptsNull()

getId

public final String getId()
Returns the id to address this slot from script code.

Returns:
the id to address this slot from script code.

getName

public final String getName()
Returns the name of this slot as seen by the user when graphically editing the tools.

Returns:
the name of this slot as seen by the user when graphically editing the tools.

getDescription

public final String getDescription()
Returns the description of this slot as seen by the user when graphically editing the tools.

Returns:
the description of this slot as seen by the user when graphically editing the tools.

getType

public final Class<T> getType()
Returns the type of this slot.

Returns:
the type of this slot.

getDefaultValue

public final T getDefaultValue()
Returns the default value of this, when used as a parameter slot.

Returns:
the default value of this, when used as a parameter slot.

acceptsValue

public boolean acceptsValue(Object value)
Returns whether the specified value may be assigned to this slot. If one tries to assign an unsupported value to a slot, SlotAssignmentException may be thrown. At least values, that are not assignment-compatible with the slot type, and null, if acceptsNull() returns false, are not accepted.

Parameters:
value - the value in question.
Returns:
true, if the specified value may be assigned to this slot.
See Also:
acceptsNull(), SlotMap.put(Slot, Object), SlotMap.put(String, Object)

acceptsNull

public boolean acceptsNull()
Returns whether null may be assigned to this slot.

Returns:
true, if null may be assigned to this slot.
See Also:
acceptsValue(Object), SlotMap.put(Slot, Object), SlotMap.put(String, Object)

equals

public final boolean equals(Object other)
Returns whether the other object is a Slot and has the same id as this.

Overrides:
equals in class Object
Returns:
true, if the other object is a Slot and has the same id as this.

hashCode

public final int hashCode()
Returns a hash code for this slot. This method is overridden in order to comply the general contract for the equals(Object) method.

Overrides:
hashCode in class Object
Returns:
a hash code for this slot.

getBuilder

public final SlotEditorComponentBuilder<T> getBuilder()
Returns a SlotEditorComponentBuilder for this slot. When using this slot to define the parameter of a trigger, the builder can be used to graphically edit that parameter. May return null. Then the tool system tries to infer an adequate component based on the slot type. If this fails, the parameter is not graphically editable.

Returns:
a SlotEditorComponentBuilder for this slot.

createDefaultPreferences

public void createDefaultPreferences(Preferences preferences)
Prepares the specified preferences tree to store the value assigned to this slot. The default implementation throws an UnsupportedOperationException.

Parameters:
preferences - the preferences tree where the value assigned to this slot will be stored.

loadValue

public T loadValue(Preferences preferences)
Returns the value that is assigned to this slot according to the specified preferences tree. The default implementation throws an UnsupportedOperationException.

Parameters:
preferences - the preferences tree from where the value is to be obtained.
Returns:
the value that is assigned to this slot according to the specified preferences tree.

saveValue

public void saveValue(Preferences preferences,
                      T value)
Stores the specified value in the specified preferences tree by means of this slot. The default implementation throws an UnsupportedOperationException.

Parameters:
preferences - the preferences tree where the value is to be stored.
value - the value that is to be stored.


Generated at 2012-05-30 11:00:36 PM CEST