com.miginfocom.ashape.interaction
Class AbstractInteractor

java.lang.Object
  extended by com.miginfocom.ashape.interaction.AbstractInteractor
All Implemented Interfaces:
Interactor, PropertyProvider, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener
Direct Known Subclasses:
ActivityInteractor, GridRowInteractor, MouseKeyInteractor, TimerInteractor

public abstract class AbstractInteractor
extends java.lang.Object
implements Interactor, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener

Connects some Interactions to an object. The actual actions that are handled, how they are filtered and what to do when the action occurs is listed in Interaction.

Also handles the override support in a very efficient way. The check doesn't create any objects and is heavily optimized for many checks and just a few sets.


Field Summary
static PropertyKey TRIGGER_ONCE
          A trigger that is triggered the first time and then the interaction is removed.
 
Fields inherited from interface com.miginfocom.ashape.interaction.Interactor
TEMPLATE_CHAR
 
Constructor Summary
AbstractInteractor()
           
 
Method Summary
 void addInteraction(Interaction interaction)
          Adds an interaction.
 void addInteractions(java.util.Collection interactions)
          Adds interactions.
 void addOverride(java.lang.String target, PropertyKey property, java.lang.Object id, java.lang.Object o)
          Adds an object to the override map.
 void addOverrideListener(java.beans.PropertyChangeListener l)
          Adds a listener that listens to InteractionEvents.
 void addOverrideListener(java.beans.PropertyChangeListener l, boolean asWeakRef)
          Adds a listener that listens to InteractionEvents.
 boolean containsProperty(PropertyKey property)
          Empty implementation that always return false.
protected  void fireOverrideChanged(java.beans.PropertyChangeEvent e)
          Notifies all listeners of the the event but stops as soon as the event get's consumed.
 java.util.ArrayList getInteractions()
          Returns the interactions.
 java.lang.Object getOverride(java.lang.String target, PropertyKey property, java.lang.Object def)
          Handles the overrider as specified in Interactor.getOverride(String, PropertyKey, Object).
 java.lang.Object getOverrideById(java.lang.Object id, java.lang.Object def)
          Returns the override for the id.
 java.lang.Object getProperty(PropertyKey property)
          Empty implementation.
 boolean isOverridden(java.lang.String target, PropertyKey property)
          Returns if the propName for target is currently overridden or not.
 void keyEventPost(java.awt.event.KeyEvent e)
          Empty implementation.
 void keyEventPre(java.awt.event.KeyEvent e)
          Empty implementation.
 void keyPressed(java.awt.event.KeyEvent e)
          Empty implementation.
 void keyReleased(java.awt.event.KeyEvent e)
          Empty implementation.
 void keyTyped(java.awt.event.KeyEvent e)
          Empty implementation.
 void mouseClicked(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseDragged(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseEntered(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseEventPost(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseEventPre(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseExited(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseMoved(java.awt.event.MouseEvent e)
          Empty implementation.
 void mousePressed(java.awt.event.MouseEvent e)
          Empty implementation.
 void mouseReleased(java.awt.event.MouseEvent e)
          Empty implementation.
 void processEvent(java.awt.event.InputEvent e)
          Overridden to redispatch the events to empty methods.
 Interaction removeInteraction(Interaction interaction)
          Removes an interaction.
 void removeOverride(java.lang.String target, PropertyKey property, java.lang.Object id)
          Removes an object from the override map.
 void removeOverrideById(java.lang.Object id)
          Removes all (only one normally) overrides with id.
 void removeOverrideListener(java.beans.PropertyChangeListener l)
          Removes the listener.
 void setInteractions(java.util.Collection newList)
          Set the new interactions that this list should have, clearing the old ones.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.miginfocom.ashape.interaction.Interactor
getInteracted, getInteractionBroker
 

Field Detail

TRIGGER_ONCE

public static final PropertyKey TRIGGER_ONCE
A trigger that is triggered the first time and then the interaction is removed. The expression still gets evaluated though and the command only executed if it evaluates to true.

Constructor Detail

AbstractInteractor

public AbstractInteractor()
Method Detail

addInteractions

public void addInteractions(java.util.Collection interactions)
Adds interactions. No checking if the interactions already exists. Will call addInteraction(Interaction) for every interaction so only that method (and removeInteraction(Interaction) has to be overridden to catch all changes.

Parameters:
interactions - The interactions to add via addInteraction(Interaction). Can be null.

addInteraction

public void addInteraction(Interaction interaction)
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
Parameters:
interaction - The interaction to add-

setInteractions

public void setInteractions(java.util.Collection newList)
Set the new interactions that this list should have, clearing the old ones.

Parameters:
newList - The new list. Will be cloned. Can be null-

getInteractions

public java.util.ArrayList getInteractions()
Description copied from interface: Interactor
Returns the interactions. Note, this is the live collection.

Specified by:
getInteractions in interface Interactor
Returns:
The interactions, never null.

removeInteraction

public Interaction removeInteraction(Interaction interaction)
Description copied from interface: Interactor
Removes an interaction.

Specified by:
removeInteraction in interface Interactor
Parameters:
interaction - The interaction to remove.
Returns:
The interaction that was removed or null if nothing was changed.

processEvent

public void processEvent(java.awt.event.InputEvent e)
Overridden to redispatch the events to empty methods. E.g to mouseClicked(java.awt.event.MouseEvent) and keyPressed(java.awt.event.KeyEvent).
Handles MouseEvents and KeyEvents.

Specified by:
processEvent in interface Interactor
Parameters:
e - The event.

mouseEventPre

public void mouseEventPre(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Will be called for all mouse events. If consumed the more specific method will not be called.

Parameters:
e - The event.

mouseEventPost

public void mouseEventPost(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Will be called for all mouse events after the pre version and the specific version. Only called if the event hasn't already been consumed.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - The event.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - The event.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - The event.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - The event.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - The event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - The event.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - The event.

keyEventPre

public void keyEventPre(java.awt.event.KeyEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Will be called for all key events. If consumed the more specific method will not be called.

Parameters:
e - The event.

keyEventPost

public void keyEventPost(java.awt.event.KeyEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Will be called for all key events after the pre version and the specific version. Only called if the event hasn't already been consumed.

Parameters:
e - The event.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - The event.

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - The event.

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Empty implementation. Override to handle. Dispatched from processEvent(java.awt.event.InputEvent).

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - The event.

getProperty

public java.lang.Object getProperty(PropertyKey property)
Empty implementation. Override to to provide a property for a propertyName .

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

containsProperty

public boolean containsProperty(PropertyKey property)
Empty implementation that always return false. Override to to provide meaningful return value.

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

getOverrideById

public java.lang.Object getOverrideById(java.lang.Object id,
                                        java.lang.Object def)
Description copied from interface: Interactor
Returns the override for the id.

Specified by:
getOverrideById in interface Interactor
Parameters:
id - The id of the override to return. Not null.
def - The object to return if no overrider is registered for id.
Returns:
The new object to use. Might be null.

getOverride

public java.lang.Object getOverride(java.lang.String target,
                                    PropertyKey property,
                                    java.lang.Object def)
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
Parameters:
target - 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.

addOverride

public void addOverride(java.lang.String target,
                        PropertyKey property,
                        java.lang.Object id,
                        java.lang.Object o)
Description copied from interface: Interactor
Adds an object to the override map. Replaces if id exists.

Specified by:
addOverride in interface Interactor
Parameters:
target - The target for the command. Up to the implementation to interpret. Not null.
property - The name of the object that have the object to be overridden. Not null.
id - Id for the override. Not null. Id is uniqe so if an override with this id already exists it will first be removed.
o - The object. May be null, which is not same as NO override.

removeOverrideById

public void removeOverrideById(java.lang.Object id)
Removes all (only one normally) overrides with id.

Parameters:
id - The id sent in as id when adding the override. Compared with .equals().

removeOverride

public void removeOverride(java.lang.String target,
                           PropertyKey property,
                           java.lang.Object id)
Description copied from interface: Interactor
Removes an object from the override map.

Note that removeOverrideObject(null, null, null) will remove all overrides.

Specified by:
removeOverride in interface Interactor
Parameters:
target - The target that should have its override removed. If null should be equal to all targets.
property - The property that should have its override removed. If null should be equal to all propNames.
id - The id for the override to remove. If null should be equal to all id:s.

isOverridden

public boolean isOverridden(java.lang.String target,
                            PropertyKey property)
Description copied from interface: Interactor
Returns if the propName for target is currently overridden or not.

Specified by:
isOverridden in interface Interactor
Parameters:
target - The target for the command. Up to the implementation to interpret.
property - The property that should be checked

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addOverrideListener

public void addOverrideListener(java.beans.PropertyChangeListener l)
Description copied from interface: Interactor
Adds a listener that listens to InteractionEvents. Interaction events are normally fired by the Interaction/Interactor/AbstractInteractionBroker framework, used for instance by the AShape framework.
This class is actually a re-dispatcher of these events. It is itself an InteractionListener and registers itself on the interaction observable objects it creates. For instance ActivityViews.

Specified by:
addOverrideListener in interface Interactor
Parameters:
l - The listener to add

addOverrideListener

public void addOverrideListener(java.beans.PropertyChangeListener l,
                                boolean asWeakRef)
Description copied from interface: Interactor
Adds a listener that listens to InteractionEvents. Interaction events are normally fired by the Interaction/Interactor/AbstractInteractionBroker framework, used for instance by the AShape framework.

Specified by:
addOverrideListener in interface Interactor
Parameters:
l - The listener to add
asWeakRef - If the listener should be added wrapped in a WeakReference. This defers memory leak problems since the garbage collector can collect the listener if it is only referenced from this list.
Note! This (weak reference) can not be used with listeners that doesn't have another real (a.k.a Strong) reference to it, as for instance an annonymous inner class. If one such listener is added it will be removed almost immediately by the garbage collector.

removeOverrideListener

public void removeOverrideListener(java.beans.PropertyChangeListener l)
Description copied from interface: Interactor
Removes the listener.

Specified by:
removeOverrideListener in interface Interactor
Parameters:
l - The listener to remove.

fireOverrideChanged

protected void fireOverrideChanged(java.beans.PropertyChangeEvent e)
Notifies all listeners of the the event but stops as soon as the event get's consumed.



Copyright © 2009 MiG InfoCom AB. All Rights Reserved.