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 tonullcauses 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 classScreenSelector.SelectionRectangle
-
Field Summary
Fields Modifier and Type Field Description protected booleanarmedprotected Layerlayerprotected java.util.List<MessageListener>messageListenersprotected java.util.List<java.lang.Object>selectedObjectsstatic java.lang.StringSELECTION_CHANGEDMessage type indicating that the list of selected objects has changed.static java.lang.StringSELECTION_ENDEDMessage type indicating that the user has completed their selection.static java.lang.StringSELECTION_STARTEDMessage type indicating that the user has started their selection.protected ScreenSelector.SelectionRectangleselectionRectprotected WorldWindowwwd
-
Constructor Summary
Constructors Constructor Description ScreenSelector(WorldWindow worldWindow)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMessageListener(MessageListener listener)protected LayercreateLayer()protected ScreenSelector.SelectionRectanglecreateSelectionRectangle()voiddisable()voidenable()java.awt.ColorgetBorderColor()java.awt.ColorgetInteriorColor()LayergetLayer()java.util.List<?>getSelectedObjects()WorldWindowgetWwd()protected java.awt.PointlimitPointToWorldWindow(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.voidmouseClicked(java.awt.event.MouseEvent mouseEvent)voidmouseDragged(java.awt.event.MouseEvent mouseEvent)voidmouseEntered(java.awt.event.MouseEvent mouseEvent)voidmouseExited(java.awt.event.MouseEvent mouseEvent)voidmouseMoved(java.awt.event.MouseEvent mouseEvent)voidmousePressed(java.awt.event.MouseEvent mouseEvent)voidmouseReleased(java.awt.event.MouseEvent mouseEvent)voidremoveMessageListener(MessageListener listener)voidselected(SelectEvent event)protected voidselectionChanged(java.awt.event.MouseEvent mouseEvent)protected voidselectionEnded(java.awt.event.MouseEvent mouseEvent)protected voidselectionStarted(java.awt.event.MouseEvent mouseEvent)protected voidselectObjects(java.util.List<?> list)protected voidsendMessage(Message message)voidsetBorderColor(java.awt.Color color)voidsetInteriorColor(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:
mouseClickedin interfacejava.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent mouseEvent)
- Specified by:
mouseMovedin 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:
selectedin interfaceSelectListener
-
selectObjects
protected void selectObjects(java.util.List<?> list)
-
-