edu.umd.cs.piccolox.event
Class PNavigationEventHandler

java.lang.Object
  extended by edu.umd.cs.piccolo.event.PBasicInputEventHandler
      extended by edu.umd.cs.piccolox.event.PNavigationEventHandler
All Implemented Interfaces:
PInputEventListener, EventListener

public class PNavigationEventHandler
extends PBasicInputEventHandler

PNavigationEventHandler implements simple focus based navigation. Uses mouse button one or the arrow keys to set a new focus. Animates the canvas view to keep the focus node on the screen and at 100 percent scale with minimal view movement.

Version:
1.0
Author:
Jesse Grosjean

Field Summary
static int EAST
          The RIGHT direction on the screen.
static int IN
          The IN direction on the scene.
static int NORTH
          The UP direction on the screen.
static int OUT
          The OUT direction on the scene.
static int SOUTH
          The DOWN direction on the screen.
static int WEST
          The LEFT direction on the screen.
 
Constructor Summary
PNavigationEventHandler()
          Constructs a Navigation Event Handler that will only accepts left mouse clicks.
 
Method Summary
protected  PActivity animateCameraViewTransformTo(PCamera camera, AffineTransform targetTransform, int duration)
          Animates the camera's view transform into the provided one over the duration provided.
 PActivity directCameraViewToFocus(PCamera camera, PNode newFocus, int duration)
          Animates the Camera's view so that it contains the new focus node.
protected  void fillViewWhiteSpace(PCamera camera)
          Instantaneously transforms the provided camera so that it does not contain any extra white space.
 PNode getNeighborInDirection(int direction)
          Returns the nearest node in the given direction.
 List getNeighbors()
          Returns all pickable nodes that are 1 hop away from the currently focused node.
 void keyPressed(PInputEvent event)
          Processes key pressed events.
 void mousePressed(PInputEvent event)
          Animates the camera to the node that has been pressed.
 void moveFocusDown(PInputEvent event)
          Moves the focus in the downward direction.
 void moveFocusIn(PInputEvent event)
          Moves the focus "into" the scene.
 void moveFocusLeft(PInputEvent event)
          Moves the focus in the left direction.
 void moveFocusOut(PInputEvent event)
          Moves the focus "out" of scene.
 void moveFocusRight(PInputEvent event)
          Moves the focus in the right direction.
 void moveFocusToMouseOver(PInputEvent event)
          Moves the focus to the mouse under the mouse.
 void moveFocusUp(PInputEvent event)
          Moves the focus in the up direction.
 boolean nodeIsNeighborInDirection(PNode node, int direction)
          Returns true if the given node is a neighbor in the given direction relative to the current focus.
 void sortNodesByDistanceFromPoint(List nodes, Point2D point)
          Modifies the array so that it's sorted in ascending order based on the distance from the given point.
 
Methods inherited from class edu.umd.cs.piccolo.event.PBasicInputEventHandler
acceptsEvent, getEventFilter, keyboardFocusGained, keyboardFocusLost, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseReleased, mouseWheelRotated, mouseWheelRotatedByBlock, paramString, processEvent, setEventFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
The UP direction on the screen.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
The DOWN direction on the screen.

See Also:
Constant Field Values

EAST

public static final int EAST
The RIGHT direction on the screen.

See Also:
Constant Field Values

WEST

public static final int WEST
The LEFT direction on the screen.

See Also:
Constant Field Values

IN

public static final int IN
The IN direction on the scene.

See Also:
Constant Field Values

OUT

public static final int OUT
The OUT direction on the scene.

See Also:
Constant Field Values
Constructor Detail

PNavigationEventHandler

public PNavigationEventHandler()
Constructs a Navigation Event Handler that will only accepts left mouse clicks.

Method Detail

keyPressed

public void keyPressed(PInputEvent event)
Processes key pressed events.

Overrides:
keyPressed in class PBasicInputEventHandler
Parameters:
event - event representing the key press

mousePressed

public void mousePressed(PInputEvent event)
Animates the camera to the node that has been pressed.

Overrides:
mousePressed in class PBasicInputEventHandler
Parameters:
event - event representing the mouse press

moveFocusDown

public void moveFocusDown(PInputEvent event)
Moves the focus in the downward direction. Animating the camera accordingly.

Parameters:
event - ignored

moveFocusIn

public void moveFocusIn(PInputEvent event)
Moves the focus "into" the scene. So smaller nodes appear larger on screen. Animates the camera accordingly.

Parameters:
event - ignored

moveFocusLeft

public void moveFocusLeft(PInputEvent event)
Moves the focus in the left direction. Animating the camera accordingly.

Parameters:
event - ignored

moveFocusOut

public void moveFocusOut(PInputEvent event)
Moves the focus "out" of scene. So larger nodes appear smaller on screen. Animates the camera accordingly.

Parameters:
event - ignored

moveFocusRight

public void moveFocusRight(PInputEvent event)
Moves the focus in the right direction. Animating the camera accordingly.

Parameters:
event - ignored

moveFocusUp

public void moveFocusUp(PInputEvent event)
Moves the focus in the up direction. Animating the camera accordingly.

Parameters:
event - ignored

moveFocusToMouseOver

public void moveFocusToMouseOver(PInputEvent event)
Moves the focus to the mouse under the mouse. Animating the camera appropriately.

Parameters:
event - mouse event

getNeighborInDirection

public PNode getNeighborInDirection(int direction)
Returns the nearest node in the given direction.

Parameters:
direction - direction in which to look the nearest node
Returns:
nearest node in the given direction

getNeighbors

public List getNeighbors()
Returns all pickable nodes that are 1 hop away from the currently focused node. This includes, parent, children, and siblings.

Returns:
list of nodes that are 1 hop away from the current focusNode

nodeIsNeighborInDirection

public boolean nodeIsNeighborInDirection(PNode node,
                                         int direction)
Returns true if the given node is a neighbor in the given direction relative to the current focus.

Parameters:
node - the node being tested
direction - the direction in which we're testing
Returns:
true if node is a neighbor in the direction provided

sortNodesByDistanceFromPoint

public void sortNodesByDistanceFromPoint(List nodes,
                                         Point2D point)
Modifies the array so that it's sorted in ascending order based on the distance from the given point.

Parameters:
nodes - list of nodes to be sorted
point - point from which distance is being computed

animateCameraViewTransformTo

protected PActivity animateCameraViewTransformTo(PCamera camera,
                                                 AffineTransform targetTransform,
                                                 int duration)
Animates the camera's view transform into the provided one over the duration provided.

Parameters:
camera - camera being animated
targetTransform - the transform to which the camera's transform will be animated
duration - the number of milliseconds the animation should last
Returns:
an activity object that represents the animation

directCameraViewToFocus

public PActivity directCameraViewToFocus(PCamera camera,
                                         PNode newFocus,
                                         int duration)
Animates the Camera's view so that it contains the new focus node.

Parameters:
camera - The camera to be animated
newFocus - the node that will gain focus
duration - number of milliseconds that animation should last for
Returns:
an activity object representing the scheduled animation

fillViewWhiteSpace

protected void fillViewWhiteSpace(PCamera camera)
Instantaneously transforms the provided camera so that it does not contain any extra white space.

Parameters:
camera - the camera to be transformed


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.