com.miginfocom.ashape.interaction
Class MouseKeyInteractor

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

public class MouseKeyInteractor
extends AbstractInteractor

Extends AbstractInteractor with common mouse and key event handling. Calls the provided InteractionBroker to handle the commands.
This class is normally the glue between, for instance, an AShape and a JComponent.


Field Summary
protected  InteractionBroker broker
          The broker to interact with
static PropertyKey KEY_EVENT_POST
          A trigger that "fires" when any key event occurs.
static PropertyKey KEY_EVENT_PRE
          A trigger that "fires" when any key event occurs.
static PropertyKey KEY_PRESS
          A trigger that "fires" when a key event is sent to this interactor.
static PropertyKey KEY_RELEASE
          A trigger that "fires" when a key event is sent to this interactor.
static PropertyKey KEY_TYPE
          A trigger that "fires" when a key event is sent to this interactor.
static PropertyKey MOUSE_CLICK
          A trigger that "fires" when the mouse is clicked over a registerd hit area.
static PropertyKey MOUSE_DOUBLE_CLICK
          A trigger that "fires" when the mouse is double clicked over a registerd hit area.
static PropertyKey MOUSE_DRAG
          A trigger that "fires" when the mouse is ragged in a registerd hit area.
static PropertyKey MOUSE_ENTER
          A trigger that "fires" when the mouse enteres a registerd hit area.
static PropertyKey MOUSE_EVENT_POST
          A trigger that "fires" when any mouse event occurs.
static PropertyKey MOUSE_EVENT_PRE
          A trigger that "fires" when any mouse event occurs.
static PropertyKey MOUSE_EXIT
          A trigger that "fires" when the mouse exits a registerd hit area.
static PropertyKey MOUSE_MOVE
          A trigger that "fires" when the mouse is moved over a registerd hit area.
static PropertyKey MOUSE_OVER_CHANGE
          A trigger that "fires" when the mouse exits OR enters a registerd hit area.
static PropertyKey MOUSE_OVER_TOPMOST_CHANGE
          A trigger that "fires" when the top most hit area that the mouse is over changes.
static PropertyKey MOUSE_POPUP_TRIGGER
          A trigger that "fires" when the normally right mouse button is pressed/released (depending on platform) registerd hit area.
static PropertyKey MOUSE_PRESS
          A trigger that "fires" when the mouse is pressed over a registerd hit area.
static PropertyKey MOUSE_RELEASE
          A trigger that "fires" when the mouse is relesed over a registerd hit area.
static PropertyKey PROP_EVENT_TYPE
          The event type that is firering.
static PropertyKey PROP_MOUSE_BUTTON
          For a mouse event this property contains an Integer with the button number that was changed.
E.g.
static PropertyKey PROP_MOUSE_CLICK_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was clicked.
static PropertyKey PROP_MOUSE_DOUBLE_CLICK_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was double clicked.
static PropertyKey PROP_MOUSE_DRAG_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was dragged.
static PropertyKey PROP_MOUSE_ENTER_LIST
          This property contains a List with all names of the hit areas that the mouse just entered.
static PropertyKey PROP_MOUSE_EXIT_LIST
          This property contains a List with all names of the hit areas that the mouse just exited.
static PropertyKey PROP_MOUSE_MOVE_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was moved.
static PropertyKey PROP_MOUSE_OVER_LIST
          The one of PROP_MOUSE_MOVE_LIST or PROP_MOUSE_DRAG_LIST that are newest.
static PropertyKey PROP_MOUSE_OVER_TOPMOST_ENTER
          This property contains the name of the topmost hit area that the mouse is over or null if the mouse is over no hit area.
static PropertyKey PROP_MOUSE_OVER_TOPMOST_EXIT
          This property contains the name of the topmost hit area that the mouse WAS over the last time top most changed or null if the mouse was over no hit area before entering a new top most area.
static PropertyKey PROP_MOUSE_POPUP_TRIGGER_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when normally the right mouse button it pressed (but it's really platform dependant).
static PropertyKey PROP_MOUSE_PRESS_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was pressed.
static PropertyKey PROP_MOUSE_RELEASE_LIST
          This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was released.
 
Fields inherited from class com.miginfocom.ashape.interaction.AbstractInteractor
TRIGGER_ONCE
 
Fields inherited from interface com.miginfocom.ashape.interaction.Interactor
TEMPLATE_CHAR
 
Constructor Summary
MouseKeyInteractor(java.lang.Object interacted, InteractionBroker broker, java.util.Collection interactions)
          Constructor.
 
Method Summary
protected  void checkInteractions(PropertyKey trigger, java.awt.event.InputEvent e, boolean affectingShape)
          checks triggers and evaluate if trigger occured.
 boolean containsProperty(PropertyKey property)
          Empty implementation that always return false.
protected  java.util.List getHitList(java.awt.event.MouseEvent ev)
          Returns all hitted hitarea's names.
 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 getProperty(PropertyKey property)
          Empty implementation.
 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 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 setHitAreas(java.util.ArrayList list, ListenerSet mouseInputListeners)
          Sets a list of hit areas with corresponding names as id.
 
Methods inherited from class com.miginfocom.ashape.interaction.AbstractInteractor
addInteraction, addInteractions, addOverride, addOverrideListener, addOverrideListener, fireOverrideChanged, getInteractions, getOverride, getOverrideById, isOverridden, mouseEntered, 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

MOUSE_EVENT_PRE

public static final PropertyKey MOUSE_EVENT_PRE
A trigger that "fires" when any mouse event occurs. More specific event type will be called afterwards, if not consumed already.


MOUSE_EVENT_POST

public static final PropertyKey MOUSE_EVENT_POST
A trigger that "fires" when any mouse event occurs. More specific event type will be called before and this is called after both the PRE event and any specific event such as MOUSE_ENTERED.


MOUSE_ENTER

public static final PropertyKey MOUSE_ENTER
A trigger that "fires" when the mouse enteres a registerd hit area. Don't have to be top most.


MOUSE_EXIT

public static final PropertyKey MOUSE_EXIT
A trigger that "fires" when the mouse exits a registerd hit area. Don't have to be top most.


MOUSE_OVER_CHANGE

public static final PropertyKey MOUSE_OVER_CHANGE
A trigger that "fires" when the mouse exits OR enters a registerd hit area. Don't have to be top most.


MOUSE_OVER_TOPMOST_CHANGE

public static final PropertyKey MOUSE_OVER_TOPMOST_CHANGE
A trigger that "fires" when the top most hit area that the mouse is over changes.


MOUSE_PRESS

public static final PropertyKey MOUSE_PRESS
A trigger that "fires" when the mouse is pressed over a registerd hit area.


MOUSE_RELEASE

public static final PropertyKey MOUSE_RELEASE
A trigger that "fires" when the mouse is relesed over a registerd hit area.


MOUSE_POPUP_TRIGGER

public static final PropertyKey MOUSE_POPUP_TRIGGER
A trigger that "fires" when the normally right mouse button is pressed/released (depending on platform) registerd hit area.


MOUSE_CLICK

public static final PropertyKey MOUSE_CLICK
A trigger that "fires" when the mouse is clicked over a registerd hit area. Note that this triggers also on a double click.

See Also:
MOUSE_DOUBLE_CLICK

MOUSE_DOUBLE_CLICK

public static final PropertyKey MOUSE_DOUBLE_CLICK
A trigger that "fires" when the mouse is double clicked over a registerd hit area.


MOUSE_DRAG

public static final PropertyKey MOUSE_DRAG
A trigger that "fires" when the mouse is ragged in a registerd hit area.


MOUSE_MOVE

public static final PropertyKey MOUSE_MOVE
A trigger that "fires" when the mouse is moved over a registerd hit area.


KEY_EVENT_PRE

public static final PropertyKey KEY_EVENT_PRE
A trigger that "fires" when any key event occurs. More specific event type will be called afterwards, if not consumed already.


KEY_EVENT_POST

public static final PropertyKey KEY_EVENT_POST
A trigger that "fires" when any key event occurs. More specific event type will be called before and this is called after both the PRE event and any specific event such as KEY_PRESSED.


KEY_PRESS

public static final PropertyKey KEY_PRESS
A trigger that "fires" when a key event is sent to this interactor.


KEY_RELEASE

public static final PropertyKey KEY_RELEASE
A trigger that "fires" when a key event is sent to this interactor.


KEY_TYPE

public static final PropertyKey KEY_TYPE
A trigger that "fires" when a key event is sent to this interactor.


PROP_MOUSE_MOVE_LIST

public static final PropertyKey PROP_MOUSE_MOVE_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was moved. Topmost area is first and then in ascending order.
null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_DRAG_LIST

public static final PropertyKey PROP_MOUSE_DRAG_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was dragged. Topmost area is first and then in ascending order.
null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_OVER_LIST

public static final PropertyKey PROP_MOUSE_OVER_LIST
The one of PROP_MOUSE_MOVE_LIST or PROP_MOUSE_DRAG_LIST that are newest. Thus it contains the most up-to-date list of which hit areas the mouse is over.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_PRESS_LIST

public static final PropertyKey PROP_MOUSE_PRESS_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was pressed. Topmost area is first and then in ascending order.
null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_RELEASE_LIST

public static final PropertyKey PROP_MOUSE_RELEASE_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was released. Topmost area is first and then in ascending order.
null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_POPUP_TRIGGER_LIST

public static final PropertyKey PROP_MOUSE_POPUP_TRIGGER_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when normally the right mouse button it pressed (but it's really platform dependant). Topmost area is first and then in ascending order.

null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_CLICK_LIST

public static final PropertyKey PROP_MOUSE_CLICK_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was clicked. Topmost area is first and then in ascending order.
null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_DOUBLE_CLICK_LIST

public static final PropertyKey PROP_MOUSE_DOUBLE_CLICK_LIST
This property contains a List with all names of the hit areas that the mouse was situated over when the mouse was double clicked. Topmost area is first and then in ascending order.
null if the mouse wasn't over one of the contained areas when the event occured.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_ENTER_LIST

public static final PropertyKey PROP_MOUSE_ENTER_LIST
This property contains a List with all names of the hit areas that the mouse just entered. Topmost area is first and then in ascending order.
null if no mouse enter state changed at last mouse move.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_EXIT_LIST

public static final PropertyKey PROP_MOUSE_EXIT_LIST
This property contains a List with all names of the hit areas that the mouse just exited. Topmost area is first and then in ascending order.
null if no mouse exit state changed at last mouse move.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_OVER_TOPMOST_ENTER

public static final PropertyKey PROP_MOUSE_OVER_TOPMOST_ENTER
This property contains the name of the topmost hit area that the mouse is over or null if the mouse is over no hit area.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_OVER_TOPMOST_EXIT

public static final PropertyKey PROP_MOUSE_OVER_TOPMOST_EXIT
This property contains the name of the topmost hit area that the mouse WAS over the last time top most changed or null if the mouse was over no hit area before entering a new top most area.

See Also:
getProperty(PropertyKey)

PROP_MOUSE_BUTTON

public static final PropertyKey PROP_MOUSE_BUTTON
For a mouse event this property contains an Integer with the button number that was changed.
E.g. MouseEvent.BUTTON1 or MouseEvent.NOBUTTON.


PROP_EVENT_TYPE

public static final PropertyKey PROP_EVENT_TYPE
The event type that is firering. An Integer, for instance MouseEvent.MOUSE_MOVED.


broker

protected final InteractionBroker broker
The broker to interact with

Constructor Detail

MouseKeyInteractor

public MouseKeyInteractor(java.lang.Object interacted,
                          InteractionBroker broker,
                          java.util.Collection interactions)
Constructor.

Parameters:
interacted - The object that this interactor is interacting with.
broker - The object responsible for carrying out a lot of the work, mostly effectuating the commands
interactions - The interactions that this AbstractInteractor should handle.
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.

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.

Returns:
The object that this interactor is currently interacting with. May be null.

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.

checkInteractions

protected void checkInteractions(PropertyKey trigger,
                                 java.awt.event.InputEvent e,
                                 boolean affectingShape)
checks triggers and evaluate if trigger occured. If evaluation is true the broker will handle the command.

Parameters:
trigger - The interaction trigger.
e - The mouse event that started it. Will be consumed if that is indicated in the interaction.

mouseEventPre

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

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

Overrides:
mouseEventPre in class AbstractInteractor
Parameters:
e - The event.

mouseEventPost

public void mouseEventPost(java.awt.event.MouseEvent e)
Description copied from class: AbstractInteractor
Empty implementation. Override to handle. Dispatched from AbstractInteractor.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.

Overrides:
mouseEventPost in class AbstractInteractor

mousePressed

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

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

mouseReleased

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

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

mouseMoved

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

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

mouseDragged

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

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

mouseClicked

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

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

mouseExited

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

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

keyEventPre

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

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

Overrides:
keyEventPre in class AbstractInteractor
Parameters:
e - The event.

keyEventPost

public void keyEventPost(java.awt.event.KeyEvent e)
Description copied from class: AbstractInteractor
Empty implementation. Override to handle. Dispatched from AbstractInteractor.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.

Overrides:
keyEventPost in class AbstractInteractor
Parameters:
e - The event.

keyPressed

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

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

keyReleased

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

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

keyTyped

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

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

getHitList

protected final java.util.List getHitList(java.awt.event.MouseEvent ev)
Returns all hitted hitarea's names. Topmost first and then descending.

Parameters:
ev - The event. If consumed null will be returned.
Returns:
All hitted hitarea's names with the top most first and then descending. null instead of size 0! Will be a newly created list.

setHitAreas

public void setHitAreas(java.util.ArrayList list,
                        ListenerSet mouseInputListeners)
Sets a list of hit areas with corresponding names as id. Element type must be NameValuePair with the value being a Shape that denotes the hit area, or null if no hit areas was spanned.

Parameters:
list - A list of NameValuePairs that may be null.
mouseInputListeners - A set with MouseInputListeners. Not null but might be of length 0.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.