NASA World Wind

gov.nasa.worldwind.awt
Class ViewInputHandler

java.lang.Object
  extended by gov.nasa.worldwind.awt.ViewInputHandler
All Implemented Interfaces:
RenderingListener, FocusListener, KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, PropertyChangeListener, EventListener

public class ViewInputHandler
extends Object
implements KeyListener, MouseListener, MouseMotionListener, MouseWheelListener, FocusListener, RenderingListener, PropertyChangeListener


Field Summary
protected static String GENERATE_EVENTS
           
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
           
 
Constructor Summary
ViewInputHandler()
           
 
Method Summary
protected  void changeHeading(OrbitView view, Angle change, ViewInputAttributes.ActionAttributes attrib)
           
protected  void changePitch(OrbitView view, Angle change, ViewInputAttributes.ActionAttributes attrib)
           
protected  void changeZoom(OrbitView view, double change, ViewInputAttributes.ActionAttributes attrib)
           
protected  double computeDragSlope(Point point1, Point point2, Vec4 vec1, Vec4 vec2)
           
protected static double computeNewZoomTarget(double curZoom, double change)
           
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()
           
protected  Point getMousePoint()
           
protected  double getScaledValue(double minValue, double maxValue, String scaleFunc)
           
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 handleBeforeRendering(RenderingEvent e)
           
protected  boolean handleKeyPan(KeyEventState keys, String target)
           
protected  void handleKeyPressed(KeyEvent e)
           
protected  boolean handleKeyRotate(KeyEventState keys, String target)
           
protected  boolean handleKeyZoom(KeyEventState keys, String target)
           
protected  void handleMouseClicked(MouseEvent e)
           
protected  void handleMouseDragged(MouseEvent e)
           
protected  void handleMouseFocus(MouseEvent e)
           
protected  void handleMousePan(MouseEvent e)
           
protected  void handleMouseRotate(MouseEvent e)
           
protected  void handleMouseWheelMoved(MouseWheelEvent e)
           
protected  void handleMouseWheelZoom(MouseWheelEvent e)
           
protected  void handleMouseZoom(MouseEvent e)
           
protected  void handleOrbitViewCenterStopped()
           
protected  void handlePerFrameInput()
           
protected  boolean handlePerFrameKeyState(KeyEventState keys, String target)
           
protected  void handleViewStopped()
           
 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 isPointBehindLineOrigin(Line line, Vec4 point)
           
 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  Vec4 nearestIntersectionPoint(Line line, Intersection[] intersections)
           
protected  void onFocusView(Position focalPosition, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected  void onPanViewAbsolute(Angle latitudeChange, Angle longitudeChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected  void onPanViewRelative(Angle forwardChange, Angle sideChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected  void onResetHeading()
           
protected  void onResetHeadingAndPitch()
           
protected  void onRotateView(Angle headingChange, Angle pitchChange, ViewInputAttributes.ActionAttributes actionAttribs)
           
protected  void onStopView()
           
protected  void onZoomView(double zoomChange, 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.
protected  void setCenterPosition(OrbitView view, Position position, ViewInputAttributes.ActionAttributes attrib)
           
 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.
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)
           
 void stageChanged(RenderingEvent e)
           
protected static Point subtract(Point a, Point b)
           
protected  void updateMousePoint(MouseEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERATE_EVENTS

protected static final String GENERATE_EVENTS
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
Constructor Detail

ViewInputHandler

public ViewInputHandler()
Method Detail

changeHeading

protected void changeHeading(OrbitView view,
                             Angle change,
                             ViewInputAttributes.ActionAttributes attrib)

changePitch

protected void changePitch(OrbitView view,
                           Angle change,
                           ViewInputAttributes.ActionAttributes attrib)

changeZoom

protected void changeZoom(OrbitView view,
                          double change,
                          ViewInputAttributes.ActionAttributes attrib)

computeDragSlope

protected double computeDragSlope(Point point1,
                                  Point point2,
                                  Vec4 vec1,
                                  Vec4 vec2)

computeNewZoomTarget

protected static double computeNewZoomTarget(double curZoom,
                                             double change)

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.

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.

Returns:
factor dampening view movement when a mouse drag event would cause an abrupt transition.
See Also:
setDragSlopeFactor(double)

getLastMousePoint

protected Point getLastMousePoint()

getMousePoint

protected Point getMousePoint()

getScaledValue

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

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

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

handleBeforeRendering

protected void handleBeforeRendering(RenderingEvent e)

handleKeyPan

protected boolean handleKeyPan(KeyEventState keys,
                               String target)

handleKeyPressed

protected void handleKeyPressed(KeyEvent e)

handleKeyRotate

protected boolean handleKeyRotate(KeyEventState keys,
                                  String target)

handleKeyZoom

protected boolean handleKeyZoom(KeyEventState keys,
                                String target)

handleMouseClicked

protected void handleMouseClicked(MouseEvent e)

handleMouseDragged

protected void handleMouseDragged(MouseEvent e)

handleMouseFocus

protected void handleMouseFocus(MouseEvent e)

handleMousePan

protected void handleMousePan(MouseEvent e)

handleMouseRotate

protected void handleMouseRotate(MouseEvent e)

handleMouseWheelMoved

protected void handleMouseWheelMoved(MouseWheelEvent e)

handleMouseWheelZoom

protected void handleMouseWheelZoom(MouseWheelEvent e)

handleMouseZoom

protected void handleMouseZoom(MouseEvent e)

handleOrbitViewCenterStopped

protected void handleOrbitViewCenterStopped()

handlePerFrameInput

protected void handlePerFrameInput()

handlePerFrameKeyState

protected boolean handlePerFrameKeyState(KeyEventState keys,
                                         String target)

handleViewStopped

protected void handleViewStopped()

isEnableSmoothing

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

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.

Returns:
true if the view's heading will stay the same unless explicity changed; false otherwise.

isPointBehindLineOrigin

public boolean isPointBehindLineOrigin(Line line,
                                       Vec4 point)

isStopOnFocusLost

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

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

nearestIntersectionPoint

protected Vec4 nearestIntersectionPoint(Line line,
                                        Intersection[] intersections)

onFocusView

protected void onFocusView(Position focalPosition,
                           ViewInputAttributes.ActionAttributes actionAttribs)

onPanViewAbsolute

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

onPanViewRelative

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

onResetHeading

protected void onResetHeading()

onResetHeadingAndPitch

protected void onResetHeadingAndPitch()

onRotateView

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

onStopView

protected void onStopView()

onZoomView

protected void onZoomView(double zoomChange,
                          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.

Parameters:
attributes - values that will be used to transform raw input into view movement.
Throws:
IllegalArgumentException - if attributes is null.
See Also:
@ViewInputAttributes

setCenterPosition

protected void setCenterPosition(OrbitView view,
                                 Position position,
                                 ViewInputAttributes.ActionAttributes attrib)

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.

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.

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.

Parameters:
lock - true if the view's heading should stay the same unless explicity changed; false otherwise.

setSelectedPosition

protected void setSelectedPosition(Position position)

setStopOnFocusLost

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

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.

Parameters:
newWorldWindow - the WorldWindow to listen on, and modify in response to events.

setWorldWindowFocusOwner

protected void setWorldWindowFocusOwner(boolean focusOwner)

stageChanged

public void stageChanged(RenderingEvent e)
Specified by:
stageChanged in interface RenderingListener

subtract

protected static Point subtract(Point a,
                                Point b)

updateMousePoint

protected void updateMousePoint(MouseEvent e)

NASA World Wind