Class ScreenSelector
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwindx.examples.util.ScreenSelector
-
- All Implemented Interfaces:
AVList
,MessageListener
,SelectListener
,WWObject
,java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.beans.PropertyChangeListener
,java.util.EventListener
public class ScreenSelector extends WWObjectImpl implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, SelectListener
ScreenSelector is an application utility that provides interactive screen rectangle selection with visual feedback, and tracks the list of objects intersecting the screen rectangle. The screen rectangle is displayed on a layer created by ScreenSelector, and is used as the WorldWindow's pick rectangle to perform object selection. Objects intersecting the screen rectangle can be accessed by callinggetSelectedObjects()
.Using ScreenSelector
To use ScreenSelector in an application, create a new instance of ScreenSelector and specify the application's WorldWindow as the sole parameter. When the user wants to define a screen selection, call
enable()
and the ScreenSelector then translates mouse events to changes in the selection rectangle. The selection rectangle is displayed as a filled rectangle with a 1-pixel wide border drawn in the interiorColor and borderColor. The ScreenSelector consumes mouse events it responds in order to suppress navigation events while the user is performing a selection. When the user selection is complete, calldisable()
and the ScreenSelector stops responding to mouse events.While the ScreenSelector is enabled it keeps track of the objects intersecting the selection rectangle, which can be accessed by calling getSelectedObjects. When the list of selected objects changes, SceneSelector sends SELECTION_STARTED, SELECTION_CHANGED, and SELECTION_ENDED messages to its message listeners. These three messages correspond to the user starting a selection, changing what's in the selection, and completing the selection. To receive a notification when the list of selected objects changes, register a MessageListener with the SceneSelector by calling
addMessageListener(gov.nasa.worldwind.event.MessageListener)
.Note that enabling or disabling the ScreenSelector does not change its list of selected objects. The list of selected objects only changes in response to user input when the ScreenSelector is enabled.
User Input
When ScreenSelector is enabled, pressing the first mouse button causes ScreenSelector to set its selection to a rectangle at the cursor with zero width and height, then clear the list of selected objects. Subsequently dragging the mouse causes ScreenSelector to update its selection rectangle to include the starting point and the current cursor point, then update the list of objects intersecting that rectangle. Finally, releasing the first mouse button causes ScreenSelector to stop displaying the selection rectangle, but does not change the list of selected objects. Keeping the list of selected object available after the selection is complete enables applications to access the user's final selection by calling getSelectedObjects.
To customize ScreenSelector's response to mouse events, create a subclass of ScreenSelector and override the methods mousePressed, mouseReleased, and mouseDragged. To customize ScreenSelector's response to screen rectangle select events, override the method selected.
ScreenSelector translates its raw mouse events to the methods selectionStarted, selectionEnded, and selectionChanged. To customize how ScreenSelector responds to these semantic events without changing the user input model, create a subclass of ScreenSelector and override any of these methods.
Screen Rectangle Appearance
To customize the appearance of the rectangle displayed by ScreenRectangle, call
setInteriorColor(java.awt.Color)
andsetBorderColor(java.awt.Color)
to specify the rectangle's interior and border colors, respectively. Setting either value tonull
causes ScreenRectangle to use the default values: 25% opaque white interior, 100% opaque white border.To further customize the displayed rectangle, create a subclass of ScreenSelector, override the method createSelectionRectangle, and return a subclass of the internal class ScreenSelector.SelectionRectangle.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ScreenSelector.SelectionRectangle
-
Field Summary
Fields Modifier and Type Field Description protected boolean
armed
protected Layer
layer
protected java.util.List<MessageListener>
messageListeners
protected java.util.List<java.lang.Object>
selectedObjects
static java.lang.String
SELECTION_CHANGED
Message type indicating that the list of selected objects has changed.static java.lang.String
SELECTION_ENDED
Message type indicating that the user has completed their selection.static java.lang.String
SELECTION_STARTED
Message type indicating that the user has started their selection.protected ScreenSelector.SelectionRectangle
selectionRect
protected WorldWindow
wwd
-
Constructor Summary
Constructors Constructor Description ScreenSelector(WorldWindow worldWindow)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMessageListener(MessageListener listener)
protected Layer
createLayer()
protected ScreenSelector.SelectionRectangle
createSelectionRectangle()
void
disable()
void
enable()
java.awt.Color
getBorderColor()
java.awt.Color
getInteriorColor()
Layer
getLayer()
java.util.List<?>
getSelectedObjects()
WorldWindow
getWwd()
protected java.awt.Point
limitPointToWorldWindow(java.awt.Point point)
Limits the specified point's x and y coordinates to the WorldWindow's viewport, and returns a new point with the limited coordinates.void
mouseClicked(java.awt.event.MouseEvent mouseEvent)
void
mouseDragged(java.awt.event.MouseEvent mouseEvent)
void
mouseEntered(java.awt.event.MouseEvent mouseEvent)
void
mouseExited(java.awt.event.MouseEvent mouseEvent)
void
mouseMoved(java.awt.event.MouseEvent mouseEvent)
void
mousePressed(java.awt.event.MouseEvent mouseEvent)
void
mouseReleased(java.awt.event.MouseEvent mouseEvent)
void
removeMessageListener(MessageListener listener)
void
selected(SelectEvent event)
protected void
selectionChanged(java.awt.event.MouseEvent mouseEvent)
protected void
selectionEnded(java.awt.event.MouseEvent mouseEvent)
protected void
selectionStarted(java.awt.event.MouseEvent mouseEvent)
protected void
selectObjects(java.util.List<?> list)
protected void
sendMessage(Message message)
void
setBorderColor(java.awt.Color color)
void
setInteriorColor(java.awt.Color color)
-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
-
-
-
Field Detail
-
SELECTION_STARTED
public static final java.lang.String SELECTION_STARTED
Message type indicating that the user has started their selection. The ScreenSelector's list of selected objects is empty, and does not change until a subsequent SELECTION_CHANGED event, if any. If this is followed by a SELECTION_ENDED event without any SELECTION_CHANGED event in between, then the user has selected nothing.- See Also:
- Constant Field Values
-
SELECTION_CHANGED
public static final java.lang.String SELECTION_CHANGED
Message type indicating that the list of selected objects has changed. This may be followed by one or more SELECTION_CHANGED events before the final SELECTION_ENDED event.- See Also:
- Constant Field Values
-
SELECTION_ENDED
public static final java.lang.String SELECTION_ENDED
Message type indicating that the user has completed their selection. The ScreenSelector's list of selected objects does not changes until a subsequent SELECTION_STARTED event, if any.- See Also:
- Constant Field Values
-
wwd
protected WorldWindow wwd
-
layer
protected Layer layer
-
selectionRect
protected ScreenSelector.SelectionRectangle selectionRect
-
selectedObjects
protected java.util.List<java.lang.Object> selectedObjects
-
messageListeners
protected java.util.List<MessageListener> messageListeners
-
armed
protected boolean armed
-
-
Constructor Detail
-
ScreenSelector
public ScreenSelector(WorldWindow worldWindow)
-
-
Method Detail
-
createLayer
protected Layer createLayer()
-
createSelectionRectangle
protected ScreenSelector.SelectionRectangle createSelectionRectangle()
-
getWwd
public WorldWindow getWwd()
-
getLayer
public Layer getLayer()
-
getInteriorColor
public java.awt.Color getInteriorColor()
-
setInteriorColor
public void setInteriorColor(java.awt.Color color)
-
getBorderColor
public java.awt.Color getBorderColor()
-
setBorderColor
public void setBorderColor(java.awt.Color color)
-
enable
public void enable()
-
disable
public void disable()
-
getSelectedObjects
public java.util.List<?> getSelectedObjects()
-
addMessageListener
public void addMessageListener(MessageListener listener)
-
removeMessageListener
public void removeMessageListener(MessageListener listener)
-
sendMessage
protected void sendMessage(Message message)
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseClicked
in interfacejava.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
-
selectionStarted
protected void selectionStarted(java.awt.event.MouseEvent mouseEvent)
-
selectionEnded
protected void selectionEnded(java.awt.event.MouseEvent mouseEvent)
-
selectionChanged
protected void selectionChanged(java.awt.event.MouseEvent mouseEvent)
-
limitPointToWorldWindow
protected java.awt.Point limitPointToWorldWindow(java.awt.Point point)
Limits the specified point's x and y coordinates to the WorldWindow's viewport, and returns a new point with the limited coordinates. For example, if the WorldWindow's viewport rectangle is x=0, y=0, width=100, height=100 and the point's coordinates are x=50, y=200 this returns a new point with coordinates x=50, y=100. If the specified point is already inside the WorldWindow's viewport, this returns a new point with the same x and y coordinates as the specified point.- Parameters:
point
- the point to limit.- Returns:
- a new Point representing the specified point limited to the WorldWindow's viewport rectangle.
-
selected
public void selected(SelectEvent event)
- Specified by:
selected
in interfaceSelectListener
-
selectObjects
protected void selectObjects(java.util.List<?> list)
-
-