NASA World Wind

gov.nasa.worldwindx.examples.util
Class ScreenSelector

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwindx.examples.util.ScreenSelector
All Implemented Interfaces:
AVList, MessageListener, SelectListener, WWObject, MouseListener, MouseMotionListener, PropertyChangeListener, EventListener

public class ScreenSelector
extends WWObjectImpl
implements MouseListener, 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.


Nested Class Summary
protected static class ScreenSelector.SelectionRectangle
           
 
Field Summary
protected  boolean armed
           
protected  Layer layer
           
protected  List<MessageListener> messageListeners
           
protected  List<Object> selectedObjects
           
static String SELECTION_CHANGED
          Message type indicating that the list of selected objects has changed.
static String SELECTION_ENDED
          Message type indicating that the user has completed their selection.
static String SELECTION_STARTED
          Message type indicating that the user has started their selection.
protected  ScreenSelector.SelectionRectangle selectionRect
           
protected  WorldWindow wwd
           
 
Constructor Summary
ScreenSelector(WorldWindow worldWindow)
           
 
Method Summary
 void addMessageListener(MessageListener listener)
           
protected  Layer createLayer()
           
protected  ScreenSelector.SelectionRectangle createSelectionRectangle()
           
 void disable()
           
 void enable()
           
 Color getBorderColor()
           
 Color getInteriorColor()
           
 Layer getLayer()
           
 List<?> getSelectedObjects()
           
 WorldWindow getWwd()
           
protected  Point limitPointToWorldWindow(Point point)
          Limits the specified point's x and y coordinates to the World Window's viewport, and returns a new point with the limited coordinates.
 void mouseClicked(MouseEvent mouseEvent)
           
 void mouseDragged(MouseEvent mouseEvent)
           
 void mouseEntered(MouseEvent mouseEvent)
           
 void mouseExited(MouseEvent mouseEvent)
           
 void mouseMoved(MouseEvent mouseEvent)
           
 void mousePressed(MouseEvent mouseEvent)
           
 void mouseReleased(MouseEvent mouseEvent)
           
 void removeMessageListener(MessageListener listener)
           
 void selected(SelectEvent event)
           
protected  void selectionChanged(MouseEvent mouseEvent)
           
protected  void selectionEnded(MouseEvent mouseEvent)
           
protected  void selectionStarted(MouseEvent mouseEvent)
           
protected  void selectObjects(List<?> list)
           
protected  void sendMessage(Message message)
           
 void setBorderColor(Color color)
           
 void setInteriorColor(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, finalize, 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

armed

protected boolean armed

layer

protected Layer layer

messageListeners

protected List<MessageListener> messageListeners

selectedObjects

protected List<Object> selectedObjects

SELECTION_CHANGED

public static final 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 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

SELECTION_STARTED

public static final 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

selectionRect

protected ScreenSelector.SelectionRectangle selectionRect

wwd

protected WorldWindow wwd
Constructor Detail

ScreenSelector

public ScreenSelector(WorldWindow worldWindow)
Method Detail

addMessageListener

public void addMessageListener(MessageListener listener)

createLayer

protected Layer createLayer()

createSelectionRectangle

protected ScreenSelector.SelectionRectangle createSelectionRectangle()

disable

public void disable()

enable

public void enable()

getBorderColor

public Color getBorderColor()

getInteriorColor

public Color getInteriorColor()

getLayer

public Layer getLayer()

getSelectedObjects

public List<?> getSelectedObjects()

getWwd

public WorldWindow getWwd()

limitPointToWorldWindow

protected Point limitPointToWorldWindow(Point point)
Limits the specified point's x and y coordinates to the World Window's viewport, and returns a new point with the limited coordinates. For example, if the World Window'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 World Window'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 World Window's viewport rectangle.

mouseClicked

public void mouseClicked(MouseEvent mouseEvent)
Specified by:
mouseClicked in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent mouseEvent)
Specified by:
mouseDragged in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent mouseEvent)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent mouseEvent)
Specified by:
mouseExited in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent mouseEvent)
Specified by:
mouseMoved in interface MouseMotionListener

mousePressed

public void mousePressed(MouseEvent mouseEvent)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent mouseEvent)
Specified by:
mouseReleased in interface MouseListener

removeMessageListener

public void removeMessageListener(MessageListener listener)

selected

public void selected(SelectEvent event)
Specified by:
selected in interface SelectListener

selectionChanged

protected void selectionChanged(MouseEvent mouseEvent)

selectionEnded

protected void selectionEnded(MouseEvent mouseEvent)

selectionStarted

protected void selectionStarted(MouseEvent mouseEvent)

selectObjects

protected void selectObjects(List<?> list)

sendMessage

protected void sendMessage(Message message)

setBorderColor

public void setBorderColor(Color color)

setInteriorColor

public void setInteriorColor(Color color)

NASA World Wind