Class 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 calling getSelectedObjects().

    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, call disable() 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) and setBorderColor(java.awt.Color) to specify the rectangle's interior and border colors, respectively. Setting either value to null 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.

    • 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
      • layer

        protected Layer layer
      • 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()
      • 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 interface java.awt.event.MouseListener
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent mouseEvent)
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent mouseEvent)
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent mouseEvent)
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent mouseEvent)
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent mouseEvent)
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent mouseEvent)
        Specified by:
        mouseMoved in interface java.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.
      • selectObjects

        protected void selectObjects​(java.util.List<?> list)