edu.umd.cs.jazz.event
Class ZNavEventHandlerKeyBoard

java.lang.Object
  |
  +--edu.umd.cs.jazz.event.ZNavEventHandlerKeyBoard
All Implemented Interfaces:
java.util.EventListener, java.awt.event.KeyListener, java.io.Serializable, ZEventHandler, ZMouseMotionListener

public class ZNavEventHandlerKeyBoard
extends java.lang.Object
implements ZEventHandler, ZMouseMotionListener, java.awt.event.KeyListener, java.io.Serializable

ZNavEventHandlerKeyBoard provides event handlers for basic zooming and panning of a Jazz camera with the keyboard. Applications can define which keys are used for navigation, and how much each key moves the camera.

The camera is changed a little bit with each keypress. If a key is held down so it auto-repeats, that is detected, and the camera will then be continuously moved in until the key is released, or another key is pressed at which point it will return to the original behavior of one increment per key press.

The default parameters are: PageUp zooms in PageDown zooms out Arrow keys pan Each keypress zooms in 25%, or pans 25% Each camera change is animated over 250 milliseconds The camera is zoomed around the cursor

Warning: Serialized and ZSerialized objects of this class will not be compatible with future Jazz releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Jazz. A future release of Jazz will provide support for long term persistence.

Author:
Benjamin B. Bederson
See Also:
Serialized Form

Constructor Summary
ZNavEventHandlerKeyBoard(ZNode node, ZCanvas canvas)
          Constructs a new ZNavEventHandlerKeyBoard.
 
Method Summary
 boolean isActive()
          Determines if this event handler is active.
 boolean isAutoNav()
          Return true if currently auto-zooming
 void keyPressed(java.awt.event.KeyEvent e)
          Key press event handler
 void keyReleased(java.awt.event.KeyEvent e)
          Key release event handler
 void keyTyped(java.awt.event.KeyEvent e)
          Key typed event handler
 void mouseDragged(ZMouseEvent e)
          Watch mouse motion so we always know where the mouse is.
 void mouseMoved(ZMouseEvent e)
          Watch mouse motion so we always know where the mouse is.
 void navOneStep()
          Implements auto-navigation
 void setActive(boolean active)
          Specifies whether this event handler is active or not.
 void setHomeKey(int homeKey)
          Define the key that is used to home.
 void setMaxMagnification(double newMaxMag)
          Set the maximum magnification that the camera can be set to with this event handler.
 void setMinMagnification(double newMinMag)
          Set the minimum magnification that the camera can be set to with this event handler.
 void setPanKeys(int leftKey, int rightKey, int upKey, int downKey)
          Define the keys that are used to pan.
 void setZoomCenter(int x, int y)
          Specify the point (in screen coordinates) that the camera will be zoomed about.
 void setZoomKeys(int inKey, int outKey)
          Define the keys that are used to zoom.
 void startAutoNav()
          Start the auto navigation
 void stopAutoNav()
          Stops the auto navigation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZNavEventHandlerKeyBoard

public ZNavEventHandlerKeyBoard(ZNode node,
                                ZCanvas canvas)
Constructs a new ZNavEventHandlerKeyBoard.
Parameters:
node - The node this event handler attaches to.
canvas - The canvas this event handler attaches to
Method Detail

setActive

public void setActive(boolean active)
Specifies whether this event handler is active or not.
Specified by:
setActive in interface ZEventHandler
Parameters:
active - True to make this event handler active

isActive

public boolean isActive()
Determines if this event handler is active.
Specified by:
isActive in interface ZEventHandler
Returns:
True if active

setZoomKeys

public void setZoomKeys(int inKey,
                        int outKey)
Define the keys that are used to zoom. A key can be set to 0 to disable that function.
Parameters:
inKey - The keycode of the key that should trigger zoom in events.
outKey - The keycode of the key that should trigger zoom out events.

setPanKeys

public void setPanKeys(int leftKey,
                       int rightKey,
                       int upKey,
                       int downKey)
Define the keys that are used to pan. A key can be set to 0 to disable that function.
Parameters:
leftKey - The keycode of the key that should trigger pan left events.
rightKey - The keycode of the key that should trigger pan right events.
upKey - The keycode of the key that should trigger pan up events.
downKey - The keycode of the key that should trigger pan down events.

setHomeKey

public void setHomeKey(int homeKey)
Define the key that is used to home. A key can be set to 0 to disable that function.
Parameters:
homeKey - The keycode of the key that should trigger the home event.

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Key press event handler
Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - The event.

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Key release event handler
Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - The event.

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Key typed event handler
Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - The event.

mouseMoved

public void mouseMoved(ZMouseEvent e)
Watch mouse motion so we always know where the mouse is. We can use this info to zoom around the mouse position.
Specified by:
mouseMoved in interface ZMouseMotionListener

mouseDragged

public void mouseDragged(ZMouseEvent e)
Watch mouse motion so we always know where the mouse is. We can use this info to zoom around the mouse position.
Specified by:
mouseDragged in interface ZMouseMotionListener

setZoomCenter

public void setZoomCenter(int x,
                          int y)
Specify the point (in screen coordinates) that the camera will be zoomed about.
Parameters:
x,y - Screen coordinates of zoom center

isAutoNav

public boolean isAutoNav()
Return true if currently auto-zooming

startAutoNav

public void startAutoNav()
Start the auto navigation

stopAutoNav

public void stopAutoNav()
Stops the auto navigation

setMinMagnification

public void setMinMagnification(double newMinMag)
Set the minimum magnification that the camera can be set to with this event handler. Setting the min mag to <= 0 disables this feature. If the min mag if set to a value which is greater than the current camera magnification, then the camera is left at its current magnification.
Parameters:
newMinMag - the new minimum magnification

setMaxMagnification

public void setMaxMagnification(double newMaxMag)
Set the maximum magnification that the camera can be set to with this event handler. Setting the max mag to <= 0 disables this feature. If the max mag if set to a value which is less than the current camera magnification, then the camera is left at its current magnification.
Parameters:
newMaxMag - the new maximum magnification

navOneStep

public void navOneStep()
Implements auto-navigation


Copyright © 2001 by University of Maryland, College Park, MD 20742, USA All rights reserved.