com.miginfocom.calendar.activity
Class ActivityInteractor

java.lang.Object
  extended by com.miginfocom.ashape.interaction.AbstractInteractor
      extended by com.miginfocom.calendar.activity.ActivityInteractor
All Implemented Interfaces:
Interactor, PropertyProvider, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListener, java.util.EventListener

public class ActivityInteractor
extends AbstractInteractor
implements java.beans.PropertyChangeListener, PropertyProvider

An Interactor that can listen to property and state changes in an Activity.

This class is also resposible for template text expansion. You can use, for instance, "$startTime$" in a text for an activity and it will be expanded for every activity to the start time of that activity. There are public static fields in this class that starts with TEMPL_xxx and those are the build in template texts. You can use .getName() on them to get the actual string. If the template does not match any of the build in strings a generic template of the activity will be fetched, matching the template without the dollar signs. The value of that property converted to a string with .toString() will be expanded inplace of the template. Also see setStaticOverride(String, com.miginfocom.util.PropertyKey, com.miginfocom.ashape.interaction.OverrideFilter) for yet another way to handle template texts, even dynamically.


Field Summary
protected  ActivityView activityView
          The activity to monitor.
protected  InteractionBroker broker
          The broker to interact with.
static PropertyKey PROPERTY
          A trigger to interact with the activitys properties.
static PropertyKey STATE
          A trigger to interact with the activitys states.
static PropertyKey TEMPL_DESCRIPTION
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the description of the contained activity view.
static PropertyKey TEMPL_DURATION
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the duration of the contained activity view.
static PropertyKey TEMPL_END_TIME_EXCL
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the end time (excluding) of the contained activity view.
static PropertyKey TEMPL_END_TIME_INCL
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the end time (including) of the contained activity view.
static PropertyKey TEMPL_LOCATION
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the description of the contained activity view.
static PropertyKey TEMPL_START_TIME
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the start time of the contained activity view.
static PropertyKey TEMPL_SUMMARY
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the summary of the contained activity view.
static PropertyKey TEMPL_TIME_ZONE_LONG
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return a human readable time zone in a longer format.
static PropertyKey TEMPL_TIME_ZONE_SHORT
          Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return a human readable time zone in a shorter format.
 
Fields inherited from class com.miginfocom.ashape.interaction.AbstractInteractor
TRIGGER_ONCE
 
Fields inherited from interface com.miginfocom.ashape.interaction.Interactor
TEMPLATE_CHAR
 
Constructor Summary
ActivityInteractor(ActivityView activityView, InteractionBroker broker, java.util.Collection interactions)
          Constructor
 
Method Summary
 void addInteraction(Interaction inter)
          Adds an interaction.
protected  void checkInteractions()
          Checks all interations and see if they are valid and if so, execute broker.handleCommand().
 boolean containsProperty(PropertyKey property)
          Empty implementation that always return false.
 ActivityView getActivityView()
          Returns the contained ActivityView
 java.text.DateFormat getDateTimeFormat()
          Returns the format object used to format start and/or end date/times.
static java.text.DateFormat getDefaultDateTimeFormat()
          Returns the default format object used to format start and/or end date/times that is used for new ActivityInteractors.
static java.lang.String getDefaultDurationFormat()
          Returns the duration format used by all newly created ActivityInteractors.
 java.lang.String getDurationFormat()
          Returns the string used for formatting duration.
 java.lang.Object getInteracted()
          Returns the object that this interactor is currently interacting with.
 InteractionBroker getInteractionBroker()
          Returns the interaction broker for this interactor.
 java.lang.Object getOverride(java.lang.String name, PropertyKey property, java.lang.Object def)
          Handles the overrider as specified in Interactor.getOverride(String, PropertyKey, Object).
 java.lang.Object getProperty(PropertyKey property)
          Empty implementation.
static java.lang.Object getStaticOverride(ActivityView activityView, java.lang.String name, PropertyKey property, java.lang.Object def)
           
 void propertyChange(java.beans.PropertyChangeEvent e)
           
static OverrideFilter removeStaticOverride(java.lang.String name, PropertyKey property)
          Removes the static override filter.
static void setCurrentInteractedActivityView(ActivityView av)
           
 void setDateTimeFormat(java.text.DateFormat dateTimeFormat)
          Sets the format object used to format start and/or end date/times.
static void setDefaultDateTimeFormat(java.text.DateFormat format)
          Sets the format object used to format start and/or end date/times.
static void setDefaultDurationFormat(java.lang.String format)
          Sets the duration format used by all newly created ActivityInteractors.
 void setDurationFormat(java.lang.String durationFormat)
          Sets the string to use for formatting duration.
static OverrideFilter setStaticOverride(java.lang.String name, PropertyKey property, OverrideFilter filter)
          Adds a static override filter that will be asked to return a possibly new or derived object for the name/PropName combination.
 
Methods inherited from class com.miginfocom.ashape.interaction.AbstractInteractor
addInteractions, addOverride, addOverrideListener, addOverrideListener, fireOverrideChanged, getInteractions, getOverrideById, isOverridden, keyEventPost, keyEventPre, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseEventPost, mouseEventPre, mouseExited, mouseMoved, mousePressed, mouseReleased, processEvent, removeInteraction, removeOverride, removeOverrideById, removeOverrideListener, setInteractions, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEMPL_START_TIME

public static final PropertyKey TEMPL_START_TIME
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the start time of the contained activity view.

The value that can be used in a text is "$startTime$" and it will be expanded.

See Also:
setDateTimeFormat(java.text.DateFormat)

TEMPL_END_TIME_INCL

public static final PropertyKey TEMPL_END_TIME_INCL
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the end time (including) of the contained activity view.

The value that can be used in a text is "$endTimeIncl$" and it will be expanded.

See Also:
setDateTimeFormat(java.text.DateFormat)

TEMPL_END_TIME_EXCL

public static final PropertyKey TEMPL_END_TIME_EXCL
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the end time (excluding) of the contained activity view.

The value that can be used in a text is "$endTimeExcl$" and it will be expanded.

See Also:
setDateTimeFormat(java.text.DateFormat)

TEMPL_DURATION

public static final PropertyKey TEMPL_DURATION
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the duration of the contained activity view.

The value that can be used in a text is "$duration$" and it will be expanded.

See Also:
setDurationFormat(String)

TEMPL_SUMMARY

public static final PropertyKey TEMPL_SUMMARY
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the summary of the contained activity view.

The value that can be used in a text is "$summary$" and it will be expanded.


TEMPL_DESCRIPTION

public static final PropertyKey TEMPL_DESCRIPTION
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the description of the contained activity view.

The value that can be used in a text is "$description$" and it will be expanded.


TEMPL_LOCATION

public static final PropertyKey TEMPL_LOCATION
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return the description of the contained activity view.

The value that can be used in a text is "$location$" and it will be expanded.


TEMPL_TIME_ZONE_SHORT

public static final PropertyKey TEMPL_TIME_ZONE_SHORT
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return a human readable time zone in a shorter format.

The value that can be used in a text is "$timeZoneShort$" and it will be expanded.


TEMPL_TIME_ZONE_LONG

public static final PropertyKey TEMPL_TIME_ZONE_LONG
Template text (a variable) that when sent into getOverride(java.lang.String, PropertyKey, java.lang.Object) will return a human readable time zone in a longer format.

The value that can be used in a text is "$timeZoneLong$" and it will be expanded.


PROPERTY

public static final PropertyKey PROPERTY
A trigger to interact with the activitys properties.


STATE

public static final PropertyKey STATE
A trigger to interact with the activitys states. E.g. MOUSE_OVER


broker

protected final InteractionBroker broker
The broker to interact with.


activityView

protected final ActivityView activityView
The activity to monitor.

Constructor Detail

ActivityInteractor

public ActivityInteractor(ActivityView activityView,
                          InteractionBroker broker,
                          java.util.Collection interactions)
Constructor

Parameters:
activityView - The activity to monitor. Will be return as the "interacted".
broker - The broker to execute commands
interactions - The interactions installed to start with
Method Detail

getInteractionBroker

public InteractionBroker getInteractionBroker()
Description copied from interface: Interactor
Returns the interaction broker for this interactor. The broker is normally responsible for effectuating DefaultCommands.

Specified by:
getInteractionBroker in interface Interactor
Returns:
The interaction broker for this interactor. May be null if there is not broker.

getInteracted

public java.lang.Object getInteracted()
Description copied from interface: Interactor
Returns the object that this interactor is currently interacting with.

Specified by:
getInteracted in interface Interactor
Returns:
The object that this interactor is currently interacting with. May be null.

getOverride

public java.lang.Object getOverride(java.lang.String name,
                                    PropertyKey property,
                                    java.lang.Object def)
Description copied from class: AbstractInteractor
Handles the overrider as specified in Interactor.getOverride(String, PropertyKey, Object). If propName is surounded with Interactor.TEMPLATE_CHAR characters (e.g. "$summary$") and the object returned from Interactor.getInteracted() is instance of PropertyProvider the returned override will be the property returned from the interacted.

If the object to be returned (i.e. is stored as an override) is a OverrideFilter that filter will be asked to return the object instead and it is given the "interacted" object as the "subject". See Interactor.getInteracted()

Specified by:
getOverride in interface Interactor
Overrides:
getOverride in class AbstractInteractor
Parameters:
name - The target name. May for instance be the name of a sub shape in an AShape.
property - The name of the property. May for instance be a property name of an AShape. E.g. AShape.A_FONT
def - The default object returned if no override
Returns:
The object to replace another object or def if there are none.

addInteraction

public void addInteraction(Interaction inter)
Description copied from interface: Interactor
Adds an interaction. No checking if the interaction already exists. Override to catch changes in the interaction list or to only add interactions that are of interest to the implementing class.

Specified by:
addInteraction in interface Interactor
Overrides:
addInteraction in class AbstractInteractor
Parameters:
inter - The interaction to add-

checkInteractions

protected void checkInteractions()
Checks all interations and see if they are valid and if so, execute broker.handleCommand().


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getProperty

public java.lang.Object getProperty(PropertyKey property)
Description copied from class: AbstractInteractor
Empty implementation. Override to to provide a property for a propertyName .

Specified by:
getProperty in interface PropertyProvider
Overrides:
getProperty in class AbstractInteractor
Parameters:
property - The property.
Returns:
The value, may be null.

containsProperty

public boolean containsProperty(PropertyKey property)
Description copied from class: AbstractInteractor
Empty implementation that always return false. Override to to provide meaningful return value.

Specified by:
containsProperty in interface PropertyProvider
Overrides:
containsProperty in class AbstractInteractor
Parameters:
property - The property.
Returns:
If the provider contains the property.

getDurationFormat

public java.lang.String getDurationFormat()
Returns the string used for formatting duration. See DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for an explanation of how the string is formatted.

Returns:
The current duration format. Not null.

setDurationFormat

public void setDurationFormat(java.lang.String durationFormat)
Sets the string to use for formatting duration. See DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for an explanation of how the string should be formatted.

Parameters:
durationFormat - The new duration format. Not null.

getDefaultDurationFormat

public static java.lang.String getDefaultDurationFormat()
Returns the duration format used by all newly created ActivityInteractors.

Returns:
The format. See DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for an explanation fo the format. Not null.

setDefaultDurationFormat

public static void setDefaultDurationFormat(java.lang.String format)
Sets the duration format used by all newly created ActivityInteractors.

Parameters:
format - The format. See DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for an explanation fo the format. Not null.

getDefaultDateTimeFormat

public static java.text.DateFormat getDefaultDateTimeFormat()
Returns the default format object used to format start and/or end date/times that is used for new ActivityInteractors.

Returns:
The current default format. Not null.

setDefaultDateTimeFormat

public static void setDefaultDateTimeFormat(java.text.DateFormat format)
Sets the format object used to format start and/or end date/times.

Parameters:
format - The new format. Not null.

getDateTimeFormat

public java.text.DateFormat getDateTimeFormat()
Returns the format object used to format start and/or end date/times.

Returns:
The current format. Not null.

setDateTimeFormat

public void setDateTimeFormat(java.text.DateFormat dateTimeFormat)
Sets the format object used to format start and/or end date/times.

Parameters:
dateTimeFormat - The new format. Not null.

getActivityView

public ActivityView getActivityView()
Returns the contained ActivityView

Returns:
The contained ActivityView

setStaticOverride

public static OverrideFilter setStaticOverride(java.lang.String name,
                                               PropertyKey property,
                                               OverrideFilter filter)
Adds a static override filter that will be asked to return a possibly new or derived object for the name/PropName combination. The filter will always be fed a ActivityView as subject.

If there is another filter for the name/propName combination it will be replaced.

It is from version 5.5.13 possible to add an override for template texts as well. You can for instance add code like this to expand a template text for an AShape any way you'd like:

 
 ActivityInteractor.setStaticOverride(AShapeUtil.DEFAULT_TITLE_TEXT_SHAPE_NAME, PropertyKey.getKey("$firstLetterOfSummary$"), new OverrideFilter() {
  public Object getOverride(Object subject, Object defaultObject)
  {
           Activity activity = ((ActivityView) subject).getModel();
     return activity.getSummary().substring(0, 1);   // As an example
  }
 });
 
 

Parameters:
name - The name. Normally a name of a subshape in a RootAShape. E.g. "backgroundShape"
property - The name of the property. Normally a property name of an AShape. E.g. AShape.A_PAINT
Returns:
The old OverrideFilter or null if none.

removeStaticOverride

public static OverrideFilter removeStaticOverride(java.lang.String name,
                                                  PropertyKey property)
Removes the static override filter.

Parameters:
name - The name. Normally a name of a subshape in a RootAShape. E.g. "backgroundShape"
property - The name of the property. Normally a property name of an AShape. E.g. AShape.A_PAINT
Returns:
The old OverrideFilter or null if none.
See Also:
setStaticOverride(String, PropertyKey, com.miginfocom.ashape.interaction.OverrideFilter)

setCurrentInteractedActivityView

public static void setCurrentInteractedActivityView(ActivityView av)

getStaticOverride

public static java.lang.Object getStaticOverride(ActivityView activityView,
                                                 java.lang.String name,
                                                 PropertyKey property,
                                                 java.lang.Object def)


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.