Class HotSpotController
- java.lang.Object
-
- gov.nasa.worldwindx.examples.util.HotSpotController
-
- All Implemented Interfaces:
SelectListener
,java.awt.event.MouseMotionListener
,java.util.EventListener
public class HotSpotController extends java.lang.Object implements SelectListener, java.awt.event.MouseMotionListener
Controller to forward selection, keyboard, and mouse events on the WorldWindow to the activeHotSpot
. The active HotSpot is updated onSelectEvent.ROLLOVER
select events, but not during a drag operation. This ensures that the active HotSpot remains active while it's being dragged, regardless of what's under the cursor.The active HotSpot is updated during non-drag rollover select events as follows:
- The select event's top
picked object, if the top picked object implements
HotSpot
. - The value for
SelectEvent.getTopPickedObject().getValue(AVKey.HOT_SPOT)
,if the value for keyAVKey.HOT_SPOT
implements HotSpot. null
if neither of the above conditions are true, or if the event isnull
.
-
-
Field Summary
Fields Modifier and Type Field Description protected HotSpot
activeHotSpot
protected boolean
customCursor
Indicates that the active HotSpot has set a custom cursor that must be reset when the HotSpot is deactivated.protected boolean
dragging
protected WorldWindow
wwd
-
Constructor Summary
Constructors Constructor Description HotSpotController(WorldWindow wwd)
Creates a new HotSpotController for a specified WorldWindow, and assigns the controller as aSelectListener
on the WorldWindow.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doSelected(SelectEvent event)
Updates the activeHotSpot
depending on the specified select event action:SelectEvent.DRAG_END
- Forwards the event to the activeHotSpot
, then updates the active HotSpot.SelectEvent.ROLLOVER
while not dragging - Updates the active HotSpot, then forwards the event to the active HotSpot. Other event types - forwards the event to the active HotSpotprotected HotSpot
getActiveHotSpot()
Returns the currently activeHotSpot
, ornull
if there is no active HotSpot.protected boolean
isDragging()
Returns whether the user is dragging the object under the cursor.void
mouseDragged(java.awt.event.MouseEvent e)
void
mouseMoved(java.awt.event.MouseEvent e)
Update the cursor when the mouse moves.void
selected(SelectEvent event)
Updates the activeHotSpot
if necessary, and forwards the select event to the active HotSpot.protected void
setActiveHotSpot(HotSpot hotSpot)
Sets the activeHotSpot
to the specified HotSpot.protected void
setDragging(boolean dragging)
Specifies whether the user is dragging the object under the cursor.protected void
updateActiveHotSpot(PickedObject po)
Updates the activeHotSpot
and the currently displayed cursor according to the picked objects in the specified event.
-
-
-
Field Detail
-
wwd
protected WorldWindow wwd
-
activeHotSpot
protected HotSpot activeHotSpot
-
dragging
protected boolean dragging
-
customCursor
protected boolean customCursor
Indicates that the active HotSpot has set a custom cursor that must be reset when the HotSpot is deactivated.
-
-
Constructor Detail
-
HotSpotController
public HotSpotController(WorldWindow wwd)
Creates a new HotSpotController for a specified WorldWindow, and assigns the controller as aSelectListener
on the WorldWindow.- Parameters:
wwd
- The WorldWindow to monitor selection events for.
-
-
Method Detail
-
selected
public void selected(SelectEvent event)
Updates the activeHotSpot
if necessary, and forwards the select event to the active HotSpot. This does nothing if the select event isnull
.This forwards the select event to
doSelected(gov.nasa.worldwind.event.SelectEvent)
, and catches and logs any exceptions thrown bydoSelected
.- Specified by:
selected
in interfaceSelectListener
- Parameters:
event
- A select event on the WorldWindow we're monitoring.
-
doSelected
protected void doSelected(SelectEvent event)
Updates the activeHotSpot
depending on the specified select event action:SelectEvent.DRAG_END
- Forwards the event to the activeHotSpot
, then updates the active HotSpot.SelectEvent.ROLLOVER
while not dragging - Updates the active HotSpot, then forwards the event to the active HotSpot.- Other event types - forwards the event to the active HotSpot
- Parameters:
event
- A select event on the WorldWindow we're monitoring.
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
Update the cursor when the mouse moves.- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
- Parameters:
e
- Mouse event.
-
isDragging
protected boolean isDragging()
Returns whether the user is dragging the object under the cursor.- Returns:
true
if the user is dragging the object under the cursor, otherwisefalse
.
-
setDragging
protected void setDragging(boolean dragging)
Specifies whether the user is dragging the object under the cursor.- Parameters:
dragging
-true
if the user is dragging the object under the cursor, otherwisefalse
.
-
getActiveHotSpot
protected HotSpot getActiveHotSpot()
Returns the currently activeHotSpot
, ornull
if there is no active HotSpot.- Returns:
- The currently active HotSpot, or
null
.
-
setActiveHotSpot
protected void setActiveHotSpot(HotSpot hotSpot)
Sets the activeHotSpot
to the specified HotSpot. The HotSpot may benull
, indicating that there is no active HotSpot. This registers the new HotSpot as key listener, mouse listener, mouse motion listener, and mouse wheel listener on the WorldWindow'sInputHandler
. This removes the previously active HotSpot as a listener on the World Window's InputHandler. This does nothing if the active HotSpot and the specified HotSpot are the same object.Additionally, this updates the WorldWindow's
Cursor
to the value returned byhotSpot.getCursor()
, ornull
if the specified hotSpot isnull
.- Parameters:
hotSpot
- The HotSpot that becomes the active HotSpot.null
to indicate that there is no active HotSpot.
-
updateActiveHotSpot
protected void updateActiveHotSpot(PickedObject po)
Updates the activeHotSpot
and the currently displayed cursor according to the picked objects in the specified event. The active HotSpot is assigned as follows:- The value for
event.getTopPickedObject().getValue(AVKey.HOT_SPOT)
, if the value for the keyAVKey.HOT_SPOT
implements HotSpot. - The event's top picked object, if the top picked object implements HotSpot.
null
if neither of the above conditions are true, or if the event isnull
.
- Parameters:
po
- Top picked object, which will provide the active HotSpot.
- The value for
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
-
-