|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.malai.interaction.Interaction
public abstract class Interaction
Defines an interaction as defined in the Malai model.
An interaction is a state machine and a class.
This file is part of Malai.
Copyright (c) 2009-2012 Arnaud BLOUIN
Malai is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later version.
Malai is distributed without any warranty; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
10/10/2009
Field Summary | |
---|---|
protected boolean |
activated
Defines if the interaction is activated or not. |
protected IState |
currentState
The current state of the state machine when the state machine is executed. |
protected TimeoutTransition |
currentTimeout
The current timeout in progress. |
protected java.util.List<InteractionHandler> |
handlers
The handlers that want to be notified when the state machine of the interaction changed. |
protected InitState |
initState
The initial state the starts the state machine. |
protected int |
lastHIDUsed
Defines the ID of last HID that has been used by the interaction. |
protected java.util.List<IState> |
states
The states that compose the finite state machine. |
protected java.util.List<Event> |
stillProcessingEvents
The events still in process. |
Constructor Summary | |
---|---|
Interaction()
Creates the interaction with a init state. |
|
Interaction(InitState initState)
Creates the state machine. |
Method Summary | |
---|---|
protected void |
addEvent(Event event)
Adds the given event to the events 'still in process' list. |
void |
addHandler(InteractionHandler handler)
Adds an interaction handler. |
void |
addState(IState state)
Adds a state to the state machine. |
protected void |
checkTimeoutTransition()
Checks if the current state has a timeout transition. |
private boolean |
checkTransition(ITransition transition)
Checks if the transition can be executed and executes it if possible. |
void |
clearEventsStillInProcess()
Clears the events of the interaction still in process. |
private void |
executeTransition(ITransition transition)
Executes the given transition. |
java.util.List<InteractionHandler> |
getHandlers()
|
int |
getLastHIDUsed()
|
static Pickable |
getPickableAt(double x,
double y,
java.lang.Object source)
Try to find a Pickable object at the given coordinate in the given source object. |
protected abstract void |
initStateMachine()
Initialises the interaction: creates the states and the transitions. |
boolean |
isRunning()
|
void |
linkToEventable(Eventable eventable)
Links the interaction to an eventable object (e.g. a MPanel or a MButton). |
protected void |
notifyHandlersOnAborting()
Notifies handlers that the interaction stops. |
protected void |
notifyHandlersOnStart()
Notifies handlers that the interaction starts. |
protected void |
notifyHandlersOnStop()
Notifies handlers that the interaction stops. |
protected void |
notifyHandlersOnUpdate()
Notifies handlers that the interaction updates. |
void |
onAborting()
Aborts the state machine. |
void |
onButtonPressed(javax.swing.AbstractButton button)
Defines actions to do when a button is activated. |
void |
onCheckBoxModified(javax.swing.JCheckBox checkbox)
Defines actions to do when the given check box is selected/unselected. |
void |
onItemSelected(java.awt.ItemSelectable itemSelectable)
Defines actions to do when the selected items of the given list changed. |
void |
onKeyPressure(int key,
int idHID,
java.lang.Object object)
Defines actions to do when a key of a keyboard is pressed. |
void |
onKeyRelease(int key,
int idHID,
java.lang.Object object)
Defines actions to do when a key of a keyboard is released. |
void |
onMenuItemPressed(javax.swing.JMenuItem menuItem)
Defines actions to do when the given menu item is pressed. |
void |
onMove(int button,
int x,
int y,
boolean pressed,
int idHID,
java.lang.Object source)
Defines action to do when a mouse or something equivalent is moved. |
void |
onPressure(int button,
int x,
int y,
int idHID,
java.lang.Object source)
Defines action to do when the button of a mouse or something equivalent is pressed. |
void |
onRelease(int button,
int x,
int y,
int idHID,
java.lang.Object source)
Defines action to do when the button of a mouse or something equivalent is released. |
void |
onScroll(int posX,
int posY,
int direction,
int amount,
int type,
int idHID,
java.lang.Object src)
Defines actions to do when a scrolling device (e.g. a mouse wheel) is used. |
void |
onSpinnerChanged(javax.swing.JSpinner spinner)
Defines actions to do when the value of the given spinner change. |
void |
onStarting()
Starts the state machine. |
void |
onTabChanged(javax.swing.JTabbedPane tabbedPanel)
Defines actions to do when the selected tab of a tabbed panel has changed. |
void |
onTerminating()
Terminates the state machine. |
void |
onTextChanged(javax.swing.text.JTextComponent textComp)
Defines actions to do when the text of a text field or something equivalent is modified. |
void |
onTimeout(TimeoutTransition timeoutTransition)
Defines action to do when a timeout is elapsed. |
void |
onUpdating()
Updates the state machine. |
void |
onWindowClosed(MFrame frame)
Defines actions to do when the decorative close button of a frame is pressed. |
protected void |
processEvents()
At the end of the interaction, the events still in process must be recycled to be reused in the interaction. |
void |
reinit()
Reinits the state machine. |
protected void |
removeKeyEvent(int idHID,
int key)
Removes the given KeyPress event from the events 'still in process' list. |
protected void |
removePressEvent(int idHID)
Removes the given Press event from the events 'still in process' list. |
void |
setActivated(boolean activated)
Defines if the state machine is activated. |
void |
setLastHIDUsed(int hid)
|
protected void |
stopCurrentTimeout()
Stops the current timeout transition. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.List<IState> states
protected InitState initState
protected IState currentState
protected boolean activated
protected java.util.List<InteractionHandler> handlers
protected java.util.List<Event> stillProcessingEvents
protected TimeoutTransition currentTimeout
protected int lastHIDUsed
Constructor Detail |
---|
public Interaction()
public Interaction(InitState initState)
initState
- The initial state of the state machine.
java.lang.IllegalArgumentException
- If the given state is null.Method Detail |
---|
protected abstract void initStateMachine()
public void setActivated(boolean activated)
IStateMachine
setActivated
in interface IStateMachine
activated
- True: the state machine will be activated.public void reinit()
IStateMachine
reinit
in interface IStateMachine
public java.util.List<InteractionHandler> getHandlers()
public void addHandler(InteractionHandler handler)
handler
- The handler to add.protected void notifyHandlersOnStart() throws MustAbortStateMachineException
MustAbortStateMachineException
protected void notifyHandlersOnUpdate() throws MustAbortStateMachineException
MustAbortStateMachineException
protected void notifyHandlersOnStop() throws MustAbortStateMachineException
MustAbortStateMachineException
protected void notifyHandlersOnAborting()
public static Pickable getPickableAt(double x, double y, java.lang.Object source)
x
- The X-coordinate of the location to check.y
- The Y-coordinate of the location to check.source
- The source object in which the function will search.
public void addState(IState state)
IStateMachine
addState
in interface IStateMachine
state
- The state to add. Must not be null.public void linkToEventable(Eventable eventable)
eventable
- The Eventable object.public boolean isRunning()
isRunning
in interface IStateMachine
private void executeTransition(ITransition transition)
transition
- The transition to execute.protected void stopCurrentTimeout()
private boolean checkTransition(ITransition transition)
transition
- The transition to check.
public void onTextChanged(javax.swing.text.JTextComponent textComp)
EventHandler
onTextChanged
in interface EventHandler
textComp
- The text field.public void onScroll(int posX, int posY, int direction, int amount, int type, int idHID, java.lang.Object src)
EventHandler
onScroll
in interface EventHandler
posX
- The X-coordinate of the position where the event occurred.posY
- The Y-coordinate of the position where the event occurred.direction
- Defines if the scrolling is up (positive value) or down (negative value).amount
- The number of units to scroll by scroll.type
- The type of scrolling that should take place in response to this event (block or unit increment).idHID
- The identifier of the used HID.src
- The object that threw the event.public void onButtonPressed(javax.swing.AbstractButton button)
EventHandler
onButtonPressed
in interface EventHandler
button
- The pressed button.public void onItemSelected(java.awt.ItemSelectable itemSelectable)
EventHandler
onItemSelected
in interface EventHandler
itemSelectable
- The list that changed.public void onSpinnerChanged(javax.swing.JSpinner spinner)
EventHandler
onSpinnerChanged
in interface EventHandler
spinner
- The spinner that changed.public void onCheckBoxModified(javax.swing.JCheckBox checkbox)
EventHandler
onCheckBoxModified
in interface EventHandler
checkbox
- The modified check box;public void onMenuItemPressed(javax.swing.JMenuItem menuItem)
EventHandler
onMenuItemPressed
in interface EventHandler
menuItem
- The pressed menu item.public void onKeyPressure(int key, int idHID, java.lang.Object object)
EventHandler
onKeyPressure
in interface EventHandler
key
- The pressed key code.idHID
- The identifier of the HID that produced the event.object
- The object that produces the event.public void onKeyRelease(int key, int idHID, java.lang.Object object)
EventHandler
onKeyRelease
in interface EventHandler
key
- The released key code.idHID
- The identifier of the HID that produced the event.object
- The object that produces the event.public void onMove(int button, int x, int y, boolean pressed, int idHID, java.lang.Object source)
EventHandler
onMove
in interface EventHandler
button
- The identifier of the pressed button, if a button is pressed (else -1).x
- The X-coordinate of the pressure location.y
- The Y-coordinate of the pressure location.pressed
- True: a button of the mouse is pressed.idHID
- The identifier of the used HID.source
- The object that produces the event.public void onPressure(int button, int x, int y, int idHID, java.lang.Object source)
EventHandler
onPressure
in interface EventHandler
button
- The identifier of the pressed button.x
- The X-coordinate of the pressure location.y
- The Y-coordinate of the pressure location.idHID
- The identifier of the used HID.source
- The object that produces the event.public void onRelease(int button, int x, int y, int idHID, java.lang.Object source)
EventHandler
onRelease
in interface EventHandler
button
- The identifier of the released button.x
- The X-coordinate of the release location.y
- The Y-coordinate of the release location.idHID
- The identifier of the used HID.source
- The object that produces the event.public void onWindowClosed(MFrame frame)
EventHandler
onWindowClosed
in interface EventHandler
frame
- The frame closed.public void onTabChanged(javax.swing.JTabbedPane tabbedPanel)
EventHandler
onTabChanged
in interface EventHandler
tabbedPanel
- The tabbed panel that produces the event.public void onTimeout(TimeoutTransition timeoutTransition)
EventHandler
onTimeout
in interface EventHandler
timeoutTransition
- The transition which produced the timeout event.protected void addEvent(Event event)
event
- The event to add.protected void removeKeyEvent(int idHID, int key)
idHID
- The identifier of the HID which produced the event.key
- The key code of the event to remove.protected void removePressEvent(int idHID)
idHID
- The identifier of the HID which produced the event.protected void processEvents()
public void onTerminating() throws MustAbortStateMachineException
IStateMachine
onTerminating
in interface IStateMachine
MustAbortStateMachineException
- If something happens requiring the interaction to abort.public void onAborting()
IStateMachine
onAborting
in interface IStateMachine
public void onStarting() throws MustAbortStateMachineException
IStateMachine
onStarting
in interface IStateMachine
MustAbortStateMachineException
- If something happens requiring the interaction to abort.public void onUpdating() throws MustAbortStateMachineException
IStateMachine
onUpdating
in interface IStateMachine
MustAbortStateMachineException
- If something happens requiring the interaction to abort.protected void checkTimeoutTransition()
public int getLastHIDUsed()
public void setLastHIDUsed(int hid)
hid
- The ID of last HID that has been used by the interaction. If the interaction has stopped or is
aborted, the value of the attribute is -1.public void clearEventsStillInProcess()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |