diva.sketch
Class MultiStateInterpreter

java.lang.Object
  extended by diva.canvas.interactor.AbstractInteractor
      extended by diva.sketch.BasicInterpreter
          extended by diva.sketch.MultiStateInterpreter
All Implemented Interfaces:
LayerListener, LayerMotionListener, Interactor, EventListener
Direct Known Subclasses:
CommandInterpreter, WhiteboardView.SketchInterpreter

public class MultiStateInterpreter
extends BasicInterpreter

A MultiStateInterpreter inherits from BasicInterpreter. It implements a FSM (finite state machine) in order to keep track of mouse states, for example, whether or not the mouse has been hold down in place for a while (hold listeners), how many clicks have been registered so far (click listeners), or it's simply a drawing event (stroke listeners). Different listeners can be added to receive different notification from the interpreter. For instance, a click listener will be notified only when mouse clicks happen whereas a hold listener will be notified only when the mouse has been hold for a while.

Version:
$Revision: 1.3 $
Author:
Michael Shilman (michaels@eecs.berkeley.edu), Heloise (hwawen@eecs.berkeley.edu)

Field Summary
static int CLICK_TIMEOUT
          The timeout for single/double/triple/..
static int HOLD_TIMEOUT
          The timeout for the popup hold, in milliseconds.
static int MIN_DRAG_DISTANCE
          The distance beyond which a click becomes a drag.
 
Fields inherited from class diva.sketch.BasicInterpreter
_controller, _curStroke, _curSymbol, _strokeBuffer
 
Constructor Summary
MultiStateInterpreter(SketchController c)
          Create a BasicInterpreter which is used by the specified controller to interpret sketch input.
 
Method Summary
 void addClickListener(Interactor l)
          Add a listener of clicks.
 void addHoldListener(Interactor l)
          Add a listener of hold invokations.
 void addStrokeListener(Interactor l)
          Add a stroke listener that gets mouse-down, mouse-moved, and mouse-released events for drawing strokes.
 int getClickCount()
           
 void mouseDragged(LayerEvent e)
          Consume the event so it doesn't get passed down to the layer below.
 void mousePressed(LayerEvent e)
          Consume the event so it doesn't get passed down to the * layer below.
 void mouseReleased(LayerEvent e)
          Consume the event.
 void removeClickListener(Interactor l)
          Removes a click listener that was added with addClickListener().
 void removeHoldListener(Interactor l)
          Removes a hold listener that was added with addHoldListener().
 void removeStrokeListener(Interactor l)
          Removes a stroke listener that was added with addStrokeListener().
 void timeout()
          Respond to the mouse released event.
 
Methods inherited from class diva.sketch.BasicInterpreter
appendStroke, finishStroke, getController, getCurrentStroke, getCurrentSymbol, isMotionEnabled, mouseEntered, mouseExited, mouseMoved, removeCurrentSymbol, startStroke
 
Methods inherited from class diva.canvas.interactor.AbstractInteractor
accept, getMouseFilter, isConsuming, isEnabled, mouseClicked, setConsuming, setEnabled, setMotionEnabled, setMouseFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_DRAG_DISTANCE

public static final int MIN_DRAG_DISTANCE
The distance beyond which a click becomes a drag.

See Also:
Constant Field Values

HOLD_TIMEOUT

public static final int HOLD_TIMEOUT
The timeout for the popup hold, in milliseconds.

See Also:
Constant Field Values

CLICK_TIMEOUT

public static final int CLICK_TIMEOUT
The timeout for single/double/triple/.. clicks, in milliseconds.

See Also:
Constant Field Values
Constructor Detail

MultiStateInterpreter

public MultiStateInterpreter(SketchController c)
Create a BasicInterpreter which is used by the specified controller to interpret sketch input.

Method Detail

addClickListener

public void addClickListener(Interactor l)
Add a listener of clicks. This listener will get MOUSE_CLICKED events when the mouse is clicked one or more times. It will only get the largest number of clicks in a sequence. So, for example, if the user triple-clicks, the listener will only get a triple- click event and won't get a double-click event.


addHoldListener

public void addHoldListener(Interactor l)
Add a listener of hold invokations. This listener will get an action event when the user presses the mouse button and holds for the duration of HOLD_TIMEOUT.


addStrokeListener

public void addStrokeListener(Interactor l)
Add a stroke listener that gets mouse-down, mouse-moved, and mouse-released events for drawing strokes. The click-count of the mouse events allows the client to do multiple modes based on a single/double/etc. click before the stroke was drawn.


getClickCount

public int getClickCount()

mouseDragged

public void mouseDragged(LayerEvent e)
Consume the event so it doesn't get passed down to the layer below. If the previous event was a mouse press, check to see how far the cursor has moved. If the distance is >= MIN_DRAG_DISTANCE, send each stroke listener both a pressed event(_pressedEvent) and a dragged event (e). If the previous event was a mouse drag, send the event (e) to the stroke listeners.

Specified by:
mouseDragged in interface LayerListener
Overrides:
mouseDragged in class BasicInterpreter

mousePressed

public void mousePressed(LayerEvent e)
Consume the event so it doesn't get passed down to the * layer below. Start a Timer for HOLD_TIMEOUT amount of time.

Specified by:
mousePressed in interface LayerListener
Overrides:
mousePressed in class BasicInterpreter

mouseReleased

public void mouseReleased(LayerEvent e)
Consume the event. If the previous event was a mouse press, start a Timer for CLICK_TIMEOUT amount of time. If the previous event was a mouse drag, notify stroke listeners of this mouse released event (e).

Specified by:
mouseReleased in interface LayerListener
Overrides:
mouseReleased in class BasicInterpreter

timeout

public void timeout()
Respond to the mouse released event. This adjusts the state based on the current state and outputs an event if the mouse has been pressed and we are now dragging.


removeClickListener

public void removeClickListener(Interactor l)
Removes a click listener that was added with addClickListener().

See Also:
#addClickListener(MouseListener)

removeHoldListener

public void removeHoldListener(Interactor l)
Removes a hold listener that was added with addHoldListener().

See Also:
#addHoldListener(ActionListener)

removeStrokeListener

public void removeStrokeListener(Interactor l)
Removes a stroke listener that was added with addStrokeListener().

See Also:
#addStrokeListener(MouseInputListener)


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.