Package gov.nasa.worldwind.awt
Class AbstractViewInputHandler
- java.lang.Object
-
- gov.nasa.worldwind.awt.AbstractViewInputHandler
-
- All Implemented Interfaces:
ViewInputHandler
,java.awt.event.FocusListener
,java.awt.event.KeyListener
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.awt.event.MouseWheelListener
,java.beans.PropertyChangeListener
,java.util.EventListener
- Direct Known Subclasses:
BasicViewInputHandler
public abstract class AbstractViewInputHandler extends java.lang.Object implements ViewInputHandler, java.beans.PropertyChangeListener
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AbstractViewInputHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply()
Implementations are expected to apply any changes to theView
state prior to the View setting the modelview matrix for rendering the current frame.double
computeDragSlope(java.awt.Point point1, java.awt.Point point2, Vec4 vec1, Vec4 vec2)
Compute the drag slope the given screen and world coordinates.protected Vec4
computeSelectedPointAt(java.awt.Point point)
protected Position
computeSelectedPosition()
protected static java.awt.Point
constrainToSourceBounds(java.awt.Point point, java.lang.Object source)
protected double
evaluateScaleFuncEyeAltitude()
protected double
evaluateScaleFuncZoom()
void
focusGained(java.awt.event.FocusEvent e)
void
focusLost(java.awt.event.FocusEvent e)
ViewInputAttributes
getAttributes()
Returns the values that are used to transform raw input events into view movments.protected LatLon
getChangeInLocation(java.awt.Point point1, java.awt.Point point2, Vec4 vec1, Vec4 vec2)
double
getDragSlopeFactor()
Returns thefactor
that dampens view movement when the user pans drags the cursor in a way that could cause an abrupt transition.protected java.awt.Point
getLastMousePoint()
java.awt.Point
getMouseDownPoint()
protected java.awt.Point
getMousePoint()
protected long
getPerFrameInputInterval()
protected double
getScaledValue(double minValue, double maxValue, java.lang.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 theWorldWindow
this ViewInputHandler is listening to for input events, and will modify in response to those eventsprotected void
handleFocusGained(java.awt.event.FocusEvent e)
protected void
handleFocusLost(java.awt.event.FocusEvent e)
protected void
handleKeyPressed(java.awt.event.KeyEvent e)
protected void
handleKeyReleased(java.awt.event.KeyEvent e)
protected void
handleMouseClicked(java.awt.event.MouseEvent e)
protected void
handleMouseDragged(java.awt.event.MouseEvent e)
protected void
handleMouseMoved(java.awt.event.MouseEvent e)
protected void
handleMousePressed(java.awt.event.MouseEvent e)
protected void
handleMouseReleased(java.awt.event.MouseEvent e)
protected void
handleMouseWheelMoved(java.awt.event.MouseWheelEvent e)
protected boolean
handlePerFrameAnimation(java.lang.String target)
protected boolean
handlePerFrameKeyState(KeyEventState keys, java.lang.String target)
protected boolean
handlePerFrameMouseState(KeyEventState keys, java.lang.String target)
protected void
handlePropertyChange(java.beans.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(java.awt.event.KeyEvent e)
void
keyReleased(java.awt.event.KeyEvent e)
void
keyTyped(java.awt.event.KeyEvent e)
void
mouseClicked(java.awt.event.MouseEvent e)
void
mouseDragged(java.awt.event.MouseEvent e)
void
mouseEntered(java.awt.event.MouseEvent e)
void
mouseExited(java.awt.event.MouseEvent e)
void
mouseMoved(java.awt.event.MouseEvent e)
void
mousePressed(java.awt.event.MouseEvent e)
void
mouseReleased(java.awt.event.MouseEvent e)
void
mouseWheelMoved(java.awt.event.MouseWheelEvent e)
protected void
onStopView()
void
propertyChange(java.beans.PropertyChangeEvent e)
protected double
rawInputToChangeInValue(double rawInput, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes, java.lang.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 thefactor
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(java.awt.Point mouseDownPoint)
protected void
setMouseDownView(View mouseDownView)
protected void
setPerFrameInputInterval(long milliseconds)
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 theWorldWindow
this ViewInputHandler should listen to for input events, and should modify in response to those events.protected void
setWorldWindowFocusOwner(boolean focusOwner)
protected void
updateMousePoint(java.awt.event.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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.awt.ViewInputHandler
addAnimator, goTo, isAnimating, stopAnimators
-
-
-
-
Field Detail
-
wwd
protected WorldWindow wwd
-
attributes
protected ViewInputAttributes attributes
-
mouseActionMap
protected ViewInputAttributes.ActionAttributesMap mouseActionMap
-
keyActionMap
protected ViewInputAttributes.ActionAttributesMap keyActionMap
-
keyModsActionMap
protected ViewInputAttributes.DeviceModifierMap keyModsActionMap
-
mouseModsActionMap
protected ViewInputAttributes.DeviceModifierMap mouseModsActionMap
-
mouseWheelModsActionMap
protected ViewInputAttributes.DeviceModifierMap mouseWheelModsActionMap
-
enableSmoothing
protected boolean enableSmoothing
-
lockHeading
protected boolean lockHeading
-
stopOnFocusLost
protected boolean stopOnFocusLost
-
wwdFocusOwner
protected boolean wwdFocusOwner
-
mouseDownPoint
protected java.awt.Point mouseDownPoint
-
lastMousePoint
protected java.awt.Point lastMousePoint
-
mousePoint
protected java.awt.Point mousePoint
-
selectedPosition
protected Position selectedPosition
-
mouseDownModelview
protected Matrix mouseDownModelview
-
mouseDownProjection
protected Matrix mouseDownProjection
-
mouseDownViewport
protected java.awt.Rectangle mouseDownViewport
-
keyEventState
protected KeyEventState keyEventState
-
dragSlopeFactor
protected double dragSlopeFactor
-
perFrameInputInterval
protected long perFrameInputInterval
-
lastPerFrameInputTime
protected long lastPerFrameInputTime
-
DEFAULT_DRAG_SLOPE_FACTOR
protected static final double DEFAULT_DRAG_SLOPE_FACTOR
- See Also:
- Constant Field Values
-
DEFAULT_PER_FRAME_INPUT_INTERVAL
protected static final long DEFAULT_PER_FRAME_INPUT_INTERVAL
- See Also:
- Constant Field Values
-
GENERATE_EVENTS
protected static final java.lang.String GENERATE_EVENTS
- See Also:
- Constant Field Values
-
QUERY_EVENTS
protected static final java.lang.String QUERY_EVENTS
- See Also:
- Constant Field Values
-
SCALE_FUNC_EYE_ALTITUDE
protected static final java.lang.String SCALE_FUNC_EYE_ALTITUDE
- See Also:
- Constant Field Values
-
SCALE_FUNC_EYE_ALTITUDE_EXP
protected static final java.lang.String SCALE_FUNC_EYE_ALTITUDE_EXP
- See Also:
- Constant Field Values
-
SCALE_FUNC_ZOOM
protected static final java.lang.String SCALE_FUNC_ZOOM
- See Also:
- Constant Field Values
-
SCALE_FUNC_ZOOM_EXP
protected static final java.lang.String SCALE_FUNC_ZOOM_EXP
- See Also:
- Constant Field Values
-
modifierList
protected int[] modifierList
-
NUM_MODIFIERS
protected final int NUM_MODIFIERS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getWorldWindow
public WorldWindow getWorldWindow()
Return theWorldWindow
this ViewInputHandler is listening to for input events, and will modify in response to those events- Specified by:
getWorldWindow
in interfaceViewInputHandler
- Returns:
- the
WorldWindow
this ViewInputHandler is listening to, and will modify in response to events.
-
setWorldWindow
public void setWorldWindow(WorldWindow newWorldWindow)
Sets theWorldWindow
this ViewInputHandler should listen to for input events, and should modify in response to those events. If the parameternewWorldWindow
is null, then this ViewInputHandler will do nothing.- Specified by:
setWorldWindow
in interfaceViewInputHandler
- Parameters:
newWorldWindow
- theWorldWindow
to listen on, and modify in response to events.
-
getAttributes
public ViewInputAttributes getAttributes()
Returns the values that are used to transform raw input events into view movments.- Specified by:
getAttributes
in interfaceViewInputHandler
- Returns:
- values that are be used to transform raw input into view movement.
-
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 interfaceViewInputHandler
- Parameters:
attributes
- values that will be used to transform raw input into view movement.- Throws:
java.lang.IllegalArgumentException
- ifattributes
is null.- See Also:
ViewInputAttributes
-
isEnableSmoothing
public boolean isEnableSmoothing()
Returns whether the ViewInputHandler will smooth view movements in response to input events.- Specified by:
isEnableSmoothing
in interfaceViewInputHandler
- Returns:
- true if the view will movements are smoothed; false otherwise.
-
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 itsViewInputAttributes
. A value of false will disable all smoothing.- Specified by:
setEnableSmoothing
in interfaceViewInputHandler
- Parameters:
enable
- true to smooth view movements; false otherwise.
-
isLockHeading
public boolean isLockHeading()
Returns whether the view's heading should stay the same unless explicitly changed.- Specified by:
isLockHeading
in interfaceViewInputHandler
- Returns:
- true if the view's heading will stay the same unless explicity changed; 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 interfaceViewInputHandler
- Parameters:
lock
- true if the view's heading should 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 interfaceViewInputHandler
- Returns:
- true if the view will stop when the WorldWindow looses focus; false otherwise.
-
setStopOnFocusLost
public void setStopOnFocusLost(boolean stop)
Sets whether the view should stop when the WorldWindow looses focus.- Specified by:
setStopOnFocusLost
in interfaceViewInputHandler
- Parameters:
stop
- true if the view should stop when the WorldWindow looses focus; false otherwise.
-
getDragSlopeFactor
public double getDragSlopeFactor()
Returns thefactor
that dampens view movement when the user pans drags the cursor in a way that could cause an abrupt transition.- Specified by:
getDragSlopeFactor
in interfaceViewInputHandler
- Returns:
- factor dampening view movement when a mouse drag event would cause an abrupt transition.
- See Also:
setDragSlopeFactor(double)
-
setDragSlopeFactor
public void setDragSlopeFactor(double factor)
Sets thefactor
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. Thisfactor
is the amount of damping applied to the view movement in such cases. Settingfactor
to zero will disable this behavior, while settingfactor
to a positive value may dampen the effects of mouse dragging.- Specified by:
setDragSlopeFactor
in interfaceViewInputHandler
- Parameters:
factor
- dampening view movement when a mouse drag event would cause an abrupt transition. Must be greater than or equal to zero.- Throws:
java.lang.IllegalArgumentException
- iffactor
is less than zero.
-
getPerFrameInputInterval
protected long getPerFrameInputInterval()
-
setPerFrameInputInterval
protected void setPerFrameInputInterval(long milliseconds)
-
getView
protected View getView()
-
isWorldWindowFocusOwner
protected boolean isWorldWindowFocusOwner()
-
setWorldWindowFocusOwner
protected void setWorldWindowFocusOwner(boolean focusOwner)
-
getMousePoint
protected java.awt.Point getMousePoint()
-
getLastMousePoint
protected java.awt.Point getLastMousePoint()
-
updateMousePoint
protected void updateMousePoint(java.awt.event.MouseEvent e)
-
getSelectedPosition
protected Position getSelectedPosition()
-
setSelectedPosition
protected void setSelectedPosition(Position position)
-
computeSelectedPosition
protected Position computeSelectedPosition()
-
onStopView
protected void onStopView()
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent e)
- Specified by:
keyTyped
in interfacejava.awt.event.KeyListener
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent e)
- Specified by:
keyPressed
in interfacejava.awt.event.KeyListener
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)
- Specified by:
keyReleased
in interfacejava.awt.event.KeyListener
-
handleKeyPressed
protected void handleKeyPressed(java.awt.event.KeyEvent e)
-
handleKeyReleased
protected void handleKeyReleased(java.awt.event.KeyEvent e)
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)
- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
-
handleMouseClicked
protected void handleMouseClicked(java.awt.event.MouseEvent e)
-
handleMousePressed
protected void handleMousePressed(java.awt.event.MouseEvent e)
-
handleMouseReleased
protected void handleMouseReleased(java.awt.event.MouseEvent e)
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
-
handleMouseDragged
protected void handleMouseDragged(java.awt.event.MouseEvent e)
-
handleMouseMoved
protected void handleMouseMoved(java.awt.event.MouseEvent e)
-
mouseWheelMoved
public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
- Specified by:
mouseWheelMoved
in interfacejava.awt.event.MouseWheelListener
-
handleMouseWheelMoved
protected void handleMouseWheelMoved(java.awt.event.MouseWheelEvent e)
-
focusGained
public void focusGained(java.awt.event.FocusEvent e)
- Specified by:
focusGained
in interfacejava.awt.event.FocusListener
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
- Specified by:
focusLost
in interfacejava.awt.event.FocusListener
-
handleFocusGained
protected void handleFocusGained(java.awt.event.FocusEvent e)
-
handleFocusLost
protected void handleFocusLost(java.awt.event.FocusEvent e)
-
apply
public void apply()
Description copied from interface:ViewInputHandler
Implementations are expected to apply any changes to theView
state prior to the View setting the modelview matrix for rendering the current frame.- Specified by:
apply
in interfaceViewInputHandler
-
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 interfaceViewInputHandler
-
handlePerFrameKeyState
protected boolean handlePerFrameKeyState(KeyEventState keys, java.lang.String target)
-
handlePerFrameMouseState
protected boolean handlePerFrameMouseState(KeyEventState keys, java.lang.String target)
-
handlePerFrameAnimation
protected boolean handlePerFrameAnimation(java.lang.String target)
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
handlePropertyChange
protected void handlePropertyChange(java.beans.PropertyChangeEvent e)
-
rawInputToChangeInValue
protected double rawInputToChangeInValue(double rawInput, ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes, java.lang.String scaleFunc)
-
getScaledValue
protected double getScaledValue(double minValue, double maxValue, java.lang.String scaleFunc)
-
evaluateScaleFuncEyeAltitude
protected double evaluateScaleFuncEyeAltitude()
-
evaluateScaleFuncZoom
protected double evaluateScaleFuncZoom()
-
getScaleValueElevation
protected double getScaleValueElevation(ViewInputAttributes.DeviceAttributes deviceAttributes, ViewInputAttributes.ActionAttributes actionAttributes)
-
getScaleValue
protected double getScaleValue(double minValue, double maxValue, double value, double range, boolean isExp)
-
computeSelectedPointAt
protected Vec4 computeSelectedPointAt(java.awt.Point point)
-
getChangeInLocation
protected LatLon getChangeInLocation(java.awt.Point point1, java.awt.Point point2, Vec4 vec1, Vec4 vec2)
-
computeDragSlope
public double computeDragSlope(java.awt.Point point1, java.awt.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 interfaceViewInputHandler
- 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.
-
constrainToSourceBounds
protected static java.awt.Point constrainToSourceBounds(java.awt.Point point, java.lang.Object source)
-
getMouseDownPoint
public java.awt.Point getMouseDownPoint()
-
setMouseDownPoint
public void setMouseDownPoint(java.awt.Point mouseDownPoint)
-
setMouseDownView
protected void setMouseDownView(View mouseDownView)
-
-