NASA World Wind

gov.nasa.worldwind.awt
Class AbstractViewInputHandler

java.lang.Object
  extended by gov.nasa.worldwind.awt.AbstractViewInputHandler
All Implemented Interfaces:
ViewInputHandler, FocusListener, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, PropertyChangeListener, EventListener
Direct Known Subclasses:
BasicViewInputHandler

public abstract class AbstractViewInputHandler
extends Object
implements ViewInputHandler, PropertyChangeListener


Field Summary
protected  ViewInputAttributes attributes
           
protected static double DEFAULT_DRAG_SLOPE_FACTOR
           
protected static long DEFAULT_PER_FRAME_INPUT_DELAY
           
protected  double dragSlopeFactor
           
protected  boolean enableSmoothing
           
protected static String GENERATE_EVENTS
           
protected  ViewInputAttributes.ActionAttributesMap keyActionMap
           
protected  KeyEventState keyEventState
           
protected  ViewInputAttributes.DeviceModifierMap keyModsActionMap
           
protected  Point lastMousePoint
           
protected  long lastPerFrameInputTime
           
protected  boolean lockHeading
           
protected  int[] modifierList
           
protected  ViewInputAttributes.ActionAttributesMap mouseActionMap
           
protected  Point mouseDownPoint
           
protected  ViewInputAttributes.DeviceModifierMap mouseModsActionMap
           
protected  Point mousePoint
           
protected  ViewInputAttributes.DeviceModifierMap mouseWheelModsActionMap
           
protected  int NUM_MODIFIERS
           
protected static String QUERY_EVENTS
           
protected static String SCALE_FUNC_EYE_ALTITUDE
           
protected static String SCALE_FUNC_EYE_ALTITUDE_EXP
           
protected static String SCALE_FUNC_ZOOM
           
protected static String SCALE_FUNC_ZOOM_EXP
           
protected  Position selectedPosition
           
protected  boolean stopOnFocusLost
           
protected  WorldWindow wwd
           
protected  boolean wwdFocusOwner
           
 
Constructor Summary
AbstractViewInputHandler()
           
 
Method Summary
 void apply()
          Implementations are expected to apply any changes to the View state prior to the View setting the modelview matrix for rendering the current frame.
 boolean callActionListener(KeyEventState keys, String target, ViewInputAttributes.ActionAttributes action)
           
 double computeDragSlope(Point point1, Point point2, Vec4 vec1, Vec4 vec2)
          Compute the drag slope the given screen and world coordinates.
protected  Vec4 computeSelectedPointAt(Point point)
           
protected  Position computeSelectedPosition()
           
protected static Point constrainToSourceBounds(Point point, Object source)
           
protected  double evaluateScaleFuncEyeAltitude()
           
protected  double evaluateScaleFuncZoom()
           
 void focusGained(FocusEvent e)
           
 void focusLost(FocusEvent e)
           
 ViewInputAttributes getAttributes()
          Returns the values that are used to transform raw input events into view movments.
protected  LatLon getChangeInLocation(Point point1, Point point2, Vec4 vec1, Vec4 vec2)
           
 double getDragSlopeFactor()
          Returns the factor that dampens view movement when the user pans drags the cursor in a way that could cause an abrupt transition.
protected  Point getLastMousePoint()
           
 Point getMouseDownPoint()
           
protected  Point getMousePoint()
           
protected  double getScaledValue(double minValue, double maxValue, String scaleFunc)
           
protected  double getScaleValue(double minValue, double maxValue, double value, double range, boolean isExp)
           
protected  double getScaleValueElevation(ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes)
           
protected  Position getSelectedPosition()
           
protected  View getView()
           
 WorldWindow getWorldWindow()
          Return the WorldWindow this ViewInputHandler is listening to for input events, and will modify in response to those events
protected  void handleFocusGained(FocusEvent e)
           
protected  void handleFocusLost(FocusEvent e)
           
protected  void handleKeyPressed(KeyEvent e)
           
protected  void handleKeyReleased(KeyEvent e)
           
protected  void handleMouseClicked(MouseEvent e)
           
protected  void handleMouseDragged(MouseEvent e)
           
protected  void handleMouseMoved(MouseEvent e)
           
protected  void handleMousePressed(MouseEvent e)
           
protected  void handleMouseReleased(MouseEvent e)
           
protected  void handleMouseWheelMoved(MouseWheelEvent e)
           
protected  boolean handlePerFrameKeyState(KeyEventState keys, String target)
           
protected  boolean handlePerFrameMouseState(KeyEventState keys, String target)
           
protected  void handlePropertyChange(PropertyChangeEvent e)
           
 boolean isEnableSmoothing()
          Returns whether the ViewInputHandler will smooth view movements in response to input events.
 boolean isLockHeading()
          Returns whether the view's heading should stay the same unless explicitly changed.
 boolean isStopOnFocusLost()
          Returns whether the view will stop when the WorldWindow looses focus.
protected  boolean isWorldWindowFocusOwner()
           
 void keyPressed(KeyEvent e)
           
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
 void mouseClicked(MouseEvent e)
           
 void mouseDragged(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void mouseWheelMoved(MouseWheelEvent e)
           
protected abstract  void onHorizontalTranslateAbs(Angle latitudeChange, Angle longitudeChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onHorizontalTranslateRel(Angle forwardChange, Angle sideChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onHorizontalTranslateRel(double sideInput, double forwardInput, double sideInputFromMouseDown, double forwardInputFromMouseDown, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes)
           
protected abstract  void onMoveTo(Position focalPosition, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onMoveTo(Position focalPosition, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onResetHeading(ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onResetHeadingPitchRoll(ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onRotateView(Angle headingChange, Angle pitchChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected abstract  void onRotateView(double headingInput, double pitchInput, double totalHeadingInput, double totalPitchInput, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes)
           
protected  void onStopView()
           
protected abstract  void onVerticalTranslate(double translateChange, double totalTranslateChange, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes)
           
protected abstract  void onVerticalTranslate(double translateChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
 void propertyChange(PropertyChangeEvent e)
           
protected  double rawInputToChangeInValue(double rawInput, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes, String scaleFunc)
           
 void setAttributes(ViewInputAttributes attributes)
          Sets the values that will be used to transform raw input events into view movements.
 void setDragSlopeFactor(double factor)
          Sets the factor that dampens view movement when a mouse drag event would cause an abrupt transition.
 void setEnableSmoothing(boolean enable)
          Sets whether the ViewInputHandler should smooth view movements in response to input events.
 void setLockHeading(boolean lock)
          Sets whether the view's heading should stay the same unless explicitly changed.
 void setMouseDownPoint(Point mouseDownPoint)
           
protected  void setSelectedPosition(Position position)
           
 void setStopOnFocusLost(boolean stop)
          Sets whether the view should stop when the WorldWindow looses focus.
 void setWorldWindow(WorldWindow newWorldWindow)
          Sets the WorldWindow this ViewInputHandler should listen to for input events, and should modify in response to those events.
protected  void setWorldWindowFocusOwner(boolean focusOwner)
           
protected  void updateMousePoint(MouseEvent e)
           
 void viewApplied()
          Called just after the view applies its state and computes its internal transforms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nasa.worldwind.awt.ViewInputHandler
addAnimator, goTo, isAnimating, stopAnimators
 

Field Detail

attributes

protected ViewInputAttributes attributes

DEFAULT_DRAG_SLOPE_FACTOR

protected static final double DEFAULT_DRAG_SLOPE_FACTOR
See Also:
Constant Field Values

DEFAULT_PER_FRAME_INPUT_DELAY

protected static final long DEFAULT_PER_FRAME_INPUT_DELAY
See Also:
Constant Field Values

dragSlopeFactor

protected double dragSlopeFactor

enableSmoothing

protected boolean enableSmoothing

GENERATE_EVENTS

protected static final String GENERATE_EVENTS
See Also:
Constant Field Values

keyActionMap

protected ViewInputAttributes.ActionAttributesMap keyActionMap

keyEventState

protected KeyEventState keyEventState

keyModsActionMap

protected ViewInputAttributes.DeviceModifierMap keyModsActionMap

lastMousePoint

protected Point lastMousePoint

lastPerFrameInputTime

protected long lastPerFrameInputTime

lockHeading

protected boolean lockHeading

modifierList

protected int[] modifierList

mouseActionMap

protected ViewInputAttributes.ActionAttributesMap mouseActionMap

mouseDownPoint

protected Point mouseDownPoint

mouseModsActionMap

protected ViewInputAttributes.DeviceModifierMap mouseModsActionMap

mousePoint

protected Point mousePoint

mouseWheelModsActionMap

protected ViewInputAttributes.DeviceModifierMap mouseWheelModsActionMap

NUM_MODIFIERS

protected final int NUM_MODIFIERS
See Also:
Constant Field Values

QUERY_EVENTS

protected static final String QUERY_EVENTS
See Also:
Constant Field Values

SCALE_FUNC_EYE_ALTITUDE

protected static final String SCALE_FUNC_EYE_ALTITUDE
See Also:
Constant Field Values

SCALE_FUNC_EYE_ALTITUDE_EXP

protected static final String SCALE_FUNC_EYE_ALTITUDE_EXP
See Also:
Constant Field Values

SCALE_FUNC_ZOOM

protected static final String SCALE_FUNC_ZOOM
See Also:
Constant Field Values

SCALE_FUNC_ZOOM_EXP

protected static final String SCALE_FUNC_ZOOM_EXP
See Also:
Constant Field Values

selectedPosition

protected Position selectedPosition

stopOnFocusLost

protected boolean stopOnFocusLost

wwd

protected WorldWindow wwd

wwdFocusOwner

protected boolean wwdFocusOwner
Constructor Detail

AbstractViewInputHandler

public AbstractViewInputHandler()
Method Detail

apply

public void apply()
Description copied from interface: ViewInputHandler
Implementations are expected to apply any changes to the View state prior to the View setting the modelview matrix for rendering the current frame.

Specified by:
apply in interface ViewInputHandler

callActionListener

public boolean callActionListener(KeyEventState keys,
                                  String target,
                                  ViewInputAttributes.ActionAttributes action)

computeDragSlope

public double computeDragSlope(Point point1,
                               Point point2,
                               Vec4 vec1,
                               Vec4 vec2)
Description copied from interface: ViewInputHandler
Compute the drag slope the given screen and world coordinates. The drag slope is the ratio of screen pixels to Cartesian distance moved, measured by the previous and current mouse points.

Specified by:
computeDragSlope in interface ViewInputHandler
Parameters:
point1 - The previous mouse coordinate.
point2 - The current mouse coordinate.
vec1 - The first cartesian world space coordinate.
vec2 - The second cartesion world space coordinate.
Returns:
the ratio of screen pixels to Cartesian distance moved.

computeSelectedPointAt

protected Vec4 computeSelectedPointAt(Point point)

computeSelectedPosition

protected Position computeSelectedPosition()

constrainToSourceBounds

protected static Point constrainToSourceBounds(Point point,
                                               Object source)

evaluateScaleFuncEyeAltitude

protected double evaluateScaleFuncEyeAltitude()

evaluateScaleFuncZoom

protected double evaluateScaleFuncZoom()

focusGained

public void focusGained(FocusEvent e)
Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Specified by:
focusLost in interface FocusListener

getAttributes

public ViewInputAttributes getAttributes()
Returns the values that are used to transform raw input events into view movments.

Specified by:
getAttributes in interface ViewInputHandler
Returns:
values that are be used to transform raw input into view movement.

getChangeInLocation

protected LatLon getChangeInLocation(Point point1,
                                     Point point2,
                                     Vec4 vec1,
                                     Vec4 vec2)

getDragSlopeFactor

public double getDragSlopeFactor()
Returns the factor that dampens view movement when the user pans drags the cursor in a way that could cause an abrupt transition.

Specified by:
getDragSlopeFactor in interface ViewInputHandler
Returns:
factor dampening view movement when a mouse drag event would cause an abrupt transition.
See Also:
setDragSlopeFactor(double)

getLastMousePoint

protected Point getLastMousePoint()

getMouseDownPoint

public Point getMouseDownPoint()

getMousePoint

protected Point getMousePoint()

getScaledValue

protected double getScaledValue(double minValue,
                                double maxValue,
                                String scaleFunc)

getScaleValue

protected double getScaleValue(double minValue,
                               double maxValue,
                               double value,
                               double range,
                               boolean isExp)

getScaleValueElevation

protected double getScaleValueElevation(ViewInputAttributes.DeviceAttributes deviceAttributes,
                                        ViewInputAttributes.ActionAttributes actionAttributes)

getSelectedPosition

protected Position getSelectedPosition()

getView

protected View getView()

getWorldWindow

public WorldWindow getWorldWindow()
Return the WorldWindow this ViewInputHandler is listening to for input events, and will modify in response to those events

Specified by:
getWorldWindow in interface ViewInputHandler
Returns:
the WorldWindow this ViewInputHandler is listening to, and will modify in response to events.

handleFocusGained

protected void handleFocusGained(FocusEvent e)

handleFocusLost

protected void handleFocusLost(FocusEvent e)

handleKeyPressed

protected void handleKeyPressed(KeyEvent e)

handleKeyReleased

protected void handleKeyReleased(KeyEvent e)

handleMouseClicked

protected void handleMouseClicked(MouseEvent e)

handleMouseDragged

protected void handleMouseDragged(MouseEvent e)

handleMouseMoved

protected void handleMouseMoved(MouseEvent e)

handleMousePressed

protected void handleMousePressed(MouseEvent e)

handleMouseReleased

protected void handleMouseReleased(MouseEvent e)

handleMouseWheelMoved

protected void handleMouseWheelMoved(MouseWheelEvent e)

handlePerFrameKeyState

protected boolean handlePerFrameKeyState(KeyEventState keys,
                                         String target)

handlePerFrameMouseState

protected boolean handlePerFrameMouseState(KeyEventState keys,
                                           String target)

handlePropertyChange

protected void handlePropertyChange(PropertyChangeEvent e)

isEnableSmoothing

public boolean isEnableSmoothing()
Returns whether the ViewInputHandler will smooth view movements in response to input events.

Specified by:
isEnableSmoothing in interface ViewInputHandler
Returns:
true if the view will movements are smoothed; false otherwise.

isLockHeading

public boolean isLockHeading()
Returns whether the view's heading should stay the same unless explicitly changed.

Specified by:
isLockHeading in interface ViewInputHandler
Returns:
true if the view's heading will stay the same unless explicity changed; false otherwise.

isStopOnFocusLost

public boolean isStopOnFocusLost()
Returns whether the view will stop when the WorldWindow looses focus.

Specified by:
isStopOnFocusLost in interface ViewInputHandler
Returns:
true if the view will stop when the WorldWindow looses focus; false otherwise.

isWorldWindowFocusOwner

protected boolean isWorldWindowFocusOwner()

keyPressed

public void keyPressed(KeyEvent e)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent e)
Specified by:
mouseWheelMoved in interface MouseWheelListener

onHorizontalTranslateAbs

protected abstract void onHorizontalTranslateAbs(Angle latitudeChange,
                                                 Angle longitudeChange,
                                                 ViewInputAttributes.ActionAttributes actionAttribs)

onHorizontalTranslateRel

protected abstract void onHorizontalTranslateRel(Angle forwardChange,
                                                 Angle sideChange,
                                                 ViewInputAttributes.ActionAttributes actionAttribs)

onHorizontalTranslateRel

protected abstract void onHorizontalTranslateRel(double sideInput,
                                                 double forwardInput,
                                                 double sideInputFromMouseDown,
                                                 double forwardInputFromMouseDown,
                                                 ViewInputAttributes.DeviceAttributes deviceAttributes,
                                                 ViewInputAttributes.ActionAttributes actionAttributes)

onMoveTo

protected abstract void onMoveTo(Position focalPosition,
                                 ViewInputAttributes.ActionAttributes actionAttribs)

onMoveTo

protected abstract void onMoveTo(Position focalPosition,
                                 ViewInputAttributes.DeviceAttributes deviceAttributes,
                                 ViewInputAttributes.ActionAttributes actionAttribs)

onResetHeading

protected abstract void onResetHeading(ViewInputAttributes.ActionAttributes actionAttribs)

onResetHeadingPitchRoll

protected abstract void onResetHeadingPitchRoll(ViewInputAttributes.ActionAttributes actionAttribs)

onRotateView

protected abstract void onRotateView(Angle headingChange,
                                     Angle pitchChange,
                                     ViewInputAttributes.ActionAttributes actionAttribs)

onRotateView

protected abstract void onRotateView(double headingInput,
                                     double pitchInput,
                                     double totalHeadingInput,
                                     double totalPitchInput,
                                     ViewInputAttributes.DeviceAttributes deviceAttributes,
                                     ViewInputAttributes.ActionAttributes actionAttributes)

onStopView

protected void onStopView()

onVerticalTranslate

protected abstract void onVerticalTranslate(double translateChange,
                                            double totalTranslateChange,
                                            ViewInputAttributes.DeviceAttributes deviceAttributes,
                                            ViewInputAttributes.ActionAttributes actionAttributes)

onVerticalTranslate

protected abstract void onVerticalTranslate(double translateChange,
                                            ViewInputAttributes.ActionAttributes actionAttribs)

propertyChange

public void propertyChange(PropertyChangeEvent e)
Specified by:
propertyChange in interface PropertyChangeListener

rawInputToChangeInValue

protected double rawInputToChangeInValue(double rawInput,
                                         ViewInputAttributes.DeviceAttributes deviceAttributes,
                                         ViewInputAttributes.ActionAttributes actionAttributes,
                                         String scaleFunc)

setAttributes

public void setAttributes(ViewInputAttributes attributes)
Sets the values that will be used to transform raw input events into view movements. ViewInputAttributes define a calibration value for each combination of device and action, and a general sensitivity value for each device.

Specified by:
setAttributes in interface ViewInputHandler
Parameters:
attributes - values that will be used to transform raw input into view movement.
Throws:
IllegalArgumentException - if attributes is null.
See Also:
ViewInputAttributes

setDragSlopeFactor

public void setDragSlopeFactor(double factor)
Sets the factor that dampens view movement when a mouse drag event would cause an abrupt transition. The drag slope is the ratio of screen pixels to Cartesian distance moved, measured by the previous and current mouse points. As drag slope gets larger, it becomes more difficult to operate the view. This typically happens while dragging over and around the horizon, where movement of a few pixels can cause the view to move many kilometers. This factor is the amount of damping applied to the view movement in such cases. Setting factor to zero will disable this behavior, while setting factor to a positive value may dampen the effects of mouse dragging.

Specified by:
setDragSlopeFactor in interface ViewInputHandler
Parameters:
factor - dampening view movement when a mouse drag event would cause an abrupt transition. Must be greater than or equal to zero.
Throws:
IllegalArgumentException - if factor is less than zero.

setEnableSmoothing

public void setEnableSmoothing(boolean enable)
Sets whether the ViewInputHandler should smooth view movements in response to input events. A value of true will cause the ViewInputHandler to delegate decisions about whether to smooth a certain input event to its ViewInputAttributes. A value of false will disable all smoothing.

Specified by:
setEnableSmoothing in interface ViewInputHandler
Parameters:
enable - true to smooth view movements; false otherwise.

setLockHeading

public void setLockHeading(boolean lock)
Sets whether the view's heading should stay the same unless explicitly changed. For example, moving forward along a great arc would suggest a change in position and heading. If the heading had been locked, the ViewInputHandler will move forward in a way that doesn't change the heading.

Specified by:
setLockHeading in interface ViewInputHandler
Parameters:
lock - true if the view's heading should stay the same unless explicity changed; false otherwise.

setMouseDownPoint

public void setMouseDownPoint(Point mouseDownPoint)

setSelectedPosition

protected void setSelectedPosition(Position position)

setStopOnFocusLost

public void setStopOnFocusLost(boolean stop)
Sets whether the view should stop when the WorldWindow looses focus.

Specified by:
setStopOnFocusLost in interface ViewInputHandler
Parameters:
stop - true if the view should stop when the WorldWindow looses focus; false otherwise.

setWorldWindow

public void setWorldWindow(WorldWindow newWorldWindow)
Sets the WorldWindow this ViewInputHandler should listen to for input events, and should modify in response to those events. If the parameter newWorldWindow is null, then this ViewInputHandler will do nothing.

Specified by:
setWorldWindow in interface ViewInputHandler
Parameters:
newWorldWindow - the WorldWindow to listen on, and modify in response to events.

setWorldWindowFocusOwner

protected void setWorldWindowFocusOwner(boolean focusOwner)

updateMousePoint

protected void updateMousePoint(MouseEvent e)

viewApplied

public void viewApplied()
Description copied from interface: ViewInputHandler
Called just after the view applies its state and computes its internal transforms.

Specified by:
viewApplied in interface ViewInputHandler

NASA World Wind