NASA World Wind

gov.nasa.worldwind.examples.util
Class LayerManagerLayer

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.WWObjectImpl
          extended by gov.nasa.worldwind.layers.AbstractLayer
              extended by gov.nasa.worldwind.layers.RenderableLayer
                  extended by gov.nasa.worldwind.examples.util.LayerManagerLayer
All Implemented Interfaces:
AVList, Disposable, MessageListener, SelectListener, Layer, Restorable, WWObject, PropertyChangeListener, EventListener

public class LayerManagerLayer
extends RenderableLayer
implements SelectListener

Displays the layer list in a heads-up display in the viewport. Layers can be turned on and off by clicking the check box next to the layer name. The order of layers in the list can be changed by dragging the layer names.


Field Summary
protected  Color dragColor
           
protected  boolean draggingComponent
           
protected  boolean draggingLayer
           
protected  Point dragRefCursorPoint
           
protected  int dragRefIndex
           
protected  Point dragRefPoint
           
protected  Dimension size
           
protected  boolean update
           
protected  WorldWindow wwd
           
 
Fields inherited from class gov.nasa.worldwind.layers.RenderableLayer
pickSupport
 
Constructor Summary
LayerManagerLayer(WorldWindow wwd)
           
 
Method Summary
protected  Point computeLocation(Rectangle viewport)
          Compute the draw frame south-west corner screen location according to it's position - see setPosition(String), location offset - see setLocationOffset(Vec4), or location center - see setLocationCenter(Vec4), and border distance from the viewport edges - see setBorderWidth(int).
protected  void drag(SelectEvent event)
           
protected static String encodeHTMLColor(Color c)
           
 ScreenAnnotation getAnnotation()
          Get the ScreenAnnotation used to display the layer list.
 int getBorderWidth()
          Get the layer manager frame offset from the viewport borders.
 Color getColor()
          Get the Color used to draw the layer names and the frame border when they are not highlighted.
 Font getFont()
          Get the Font used to draw the layer list text.
 Color getHighlightColor()
          Get the Color used to draw the layer names and the frame border when they are highlighted.
 char getLayerDisabledSymbol()
          Get the character used to denote a disabled layer.
 char getLayerEnabledSymbol()
          Get the character used to denote an enabled layer.
 Vec4 getLocationCenter()
          Returns the current layer manager location.
 Vec4 getLocationOffset()
          Returns the current location offset.
 double getMaxOpacity()
          Get the opacity applied to the layer list when the cursor is inside it's frame.
 double getMinOpacity()
          Get the opacity applied to the layer list when the cursor is outside it's frame.
 String getPosition()
          Returns the current relative layer manager frame position.
 int getSelectedIndex()
          Get the selected layer index number in the current Model layer list.
protected  void highlight(boolean highlighted)
          Change the annotation appearance according to the given highlighted state.
protected  void initialize()
           
 boolean isComponentDragEnabled()
          Determines whether the layer list can be moved or dragged with the mouse cursor.
 boolean isEnabled()
          Indicates whether the layer is enabled for rendering and selection.
 boolean isLayerDragEnabled()
          Determines whether a layer can be moved or dragged within the list with the mouse cursor.
 boolean isMinimized()
          Determines whether the layer list frame is minimized.
 boolean isSnapToCorners()
          Determines whether the layer list snaps to the viewport sides and corners while being dragged.
protected  String makeAnnotationText(LayerList layers)
          Compose the annotation text from the given LayerList.
protected  void moveTo(Point targetPoint)
           
 void render(DrawContext dc)
          Cause the layer to draw its representation.
 void selected(SelectEvent event)
          SelectListener implementation.
 void setBorderWidth(int borderWidth)
          Sets the layer manager frame offset from the viewport borders.
 void setColor(Color color)
          Set the Color used to draw the layer names and the frame border when they are not highlighted.
 void setComponentDragEnabled(boolean enabled)
          Sets whether the layer list can be moved or dragged with the mouse cursor.
 void setEnabled(boolean enabled)
          Controls whether the layer is enabled for rendering and selection.
 void setFont(Font font)
          Set the Font used to draw the layer list text.
 void setHighlightColor(Color color)
          Set the Color used to draw the layer names and the frame border when they are highlighted.
 void setLayerDisabledSymbol(char c)
          Set the character used to denote a disabled layer.
 void setLayerDragEnabled(boolean enabled)
          Sets whether a layer can be moved or dragged within the list with the mouse cursor.
 void setLayerEnabledSymbol(char c)
          Set the character used to denote an enabled layer.
 void setLocationCenter(Vec4 locationCenter)
          Specifies the screen location of the layer manager, relative to it's frame center.
 void setLocationOffset(Vec4 locationOffset)
          Specifies a placement offset from the layer manager frame position on the screen.
 void setMaxOpacity(double opacity)
          Set the opacity applied to the layer list when the cursor is inside it's frame - zero to one, one is fully opaque.
 void setMinimized(boolean minimized)
          Set the layer list frame to be minimized.
 void setMinOpacity(double opacity)
          Set the opacity applied to the layer list when the cursor is outside it's frame - zero to one, one is fully opaque.
 void setPosition(String position)
          Sets the relative viewport location to display the layer manager.
 void setSelectedIndex(int index)
          Set the selected layer index number.
 void setSnapToCorners(boolean enabled)
          Sets whether the layer list snaps to the viewport sides and corners while being dragged.
protected  void snapToCorners()
           
 String toString()
           
 void update()
          Schedule the layer list for redrawing before the next render pass.
 void updateNow(DrawContext dc)
          Force the layer list to redraw itself from the current Model with the current highlighted state and selected layer colors and opacity.
 
Methods inherited from class gov.nasa.worldwind.layers.RenderableLayer
addRenderable, addRenderables, clearRenderables, dispose, disposeRenderables, doPick, doPick, doPreRender, doPreRender, doRender, doRender, getActiveRenderables, getNumRenderables, getOpacity, getRenderables, onMessage, removeAllRenderables, removeRenderable, setOpacity, setRenderables
 
Methods inherited from class gov.nasa.worldwind.layers.AbstractLayer
createLayerConfigElements, getDataFileStore, getExpiryTime, getLayerConfigParams, getMaxActiveAltitude, getMaxEffectiveAltitude, getMinActiveAltitude, getMinEffectiveAltitude, getName, getRestorableState, getScale, getScreenCredit, isAtMaxResolution, isLayerActive, isLayerConfigDocument, isLayerInView, isMultiResolution, isNetworkRetrievalEnabled, isPickEnabled, pick, preRender, restoreState, setDataFileStore, setExpiryTime, setMaxActiveAltitude, setMinActiveAltitude, setName, setNetworkRetrievalEnabled, setPickEnabled, setScreenCredit
 
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
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, 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
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 

Field Detail

dragColor

protected Color dragColor

draggingComponent

protected boolean draggingComponent

draggingLayer

protected boolean draggingLayer

dragRefCursorPoint

protected Point dragRefCursorPoint

dragRefIndex

protected int dragRefIndex

dragRefPoint

protected Point dragRefPoint

size

protected Dimension size

update

protected boolean update

wwd

protected WorldWindow wwd
Constructor Detail

LayerManagerLayer

public LayerManagerLayer(WorldWindow wwd)
Method Detail

computeLocation

protected Point computeLocation(Rectangle viewport)
Compute the draw frame south-west corner screen location according to it's position - see setPosition(String), location offset - see setLocationOffset(Vec4), or location center - see setLocationCenter(Vec4), and border distance from the viewport edges - see setBorderWidth(int).

Parameters:
viewport - the current Viewport rectangle.
Returns:
the draw frame south-west corner screen location.

drag

protected void drag(SelectEvent event)

encodeHTMLColor

protected static String encodeHTMLColor(Color c)

getAnnotation

public ScreenAnnotation getAnnotation()
Get the ScreenAnnotation used to display the layer list.

Returns:
the ScreenAnnotation used to display the layer list.

getBorderWidth

public int getBorderWidth()
Get the layer manager frame offset from the viewport borders.

Returns:
the number of pixels to offset the layer manager frame from the borders indicated by setPosition(String).

getColor

public Color getColor()
Get the Color used to draw the layer names and the frame border when they are not highlighted.

Returns:
the Color used to draw the layer names and the frame border when they are not highlighted.

getFont

public Font getFont()
Get the Font used to draw the layer list text.

Returns:
the Font used to draw the layer list text.

getHighlightColor

public Color getHighlightColor()
Get the Color used to draw the layer names and the frame border when they are highlighted.

Returns:
the Color used to draw the layer names and the frame border when they are highlighted.

getLayerDisabledSymbol

public char getLayerDisabledSymbol()
Get the character used to denote a disabled layer.

Returns:
the character used to denote a disabled layer.

getLayerEnabledSymbol

public char getLayerEnabledSymbol()
Get the character used to denote an enabled layer.

Returns:
the character used to denote an enabled layer.

getLocationCenter

public Vec4 getLocationCenter()
Returns the current layer manager location.

Returns:
the current location center. May be null.

getLocationOffset

public Vec4 getLocationOffset()
Returns the current location offset. See #setLocationOffset for a description of the offset and its values.

Returns:
the location offset. Will be null if no offset has been specified.

getMaxOpacity

public double getMaxOpacity()
Get the opacity applied to the layer list when the cursor is inside it's frame.

Returns:
the opacity applied to the layer list when the cursor is inside it's frame.

getMinOpacity

public double getMinOpacity()
Get the opacity applied to the layer list when the cursor is outside it's frame.

Returns:
the opacity applied to the layer list when the cursor is outside it's frame.

getPosition

public String getPosition()
Returns the current relative layer manager frame position.

Returns:
the current layer manager frame position

getSelectedIndex

public int getSelectedIndex()
Get the selected layer index number in the current Model layer list. A layer is selected when the cursor is over it in the list. Returns -1 if no layer is currently selected.

Returns:
the selected layer index number or -1 if none is selected.

highlight

protected void highlight(boolean highlighted)
Change the annotation appearance according to the given highlighted state.

Parameters:
highlighted - true if the annotation should appear highlighted.

initialize

protected void initialize()

isComponentDragEnabled

public boolean isComponentDragEnabled()
Determines whether the layer list can be moved or dragged with the mouse cursor.

If enabled, dragging the frame will result in a change to it's location offset - setLocationOffset(Vec4). If the list is also set to snap to corners - setSnapToCorners(boolean), the frame position may change so as to be attached to the nearest corner - see setPosition(String).

Returns:
true if the layer list can be moved or dragged with the mouse cursor.

isEnabled

public boolean isEnabled()
Description copied from interface: Layer
Indicates whether the layer is enabled for rendering and selection.

Specified by:
isEnabled in interface Layer
Overrides:
isEnabled in class AbstractLayer
Returns:
true if the layer is enabled, else false.

isLayerDragEnabled

public boolean isLayerDragEnabled()
Determines whether a layer can be moved or dragged within the list with the mouse cursor. If enabled, layers can be moved up and down the list.

Returns:
true if a layer can be moved or dragged within the list.

isMinimized

public boolean isMinimized()
Determines whether the layer list frame is minimized. When minimized, the layer list only contains itself as the only item, and thus shrinks toward it's corner position.

Returns:
true if the layer list frame is minimized.

isSnapToCorners

public boolean isSnapToCorners()
Determines whether the layer list snaps to the viewport sides and corners while being dragged.

Dragging the layer list frame will result in a change to it's location offset - setLocationOffset(Vec4). If the list is also set to snap to corners - setSnapToCorners(boolean), the frame position may change so as to be attached to the nearest corner - see setPosition(String).

Returns:
true if the layer list snaps to the viewport sides and corners while being dragged.

makeAnnotationText

protected String makeAnnotationText(LayerList layers)
Compose the annotation text from the given LayerList.

Parameters:
layers - the LayerList to draw names from.
Returns:
the annotation text to be displayed.

moveTo

protected void moveTo(Point targetPoint)

render

public void render(DrawContext dc)
Description copied from interface: Layer
Cause the layer to draw its representation.

Specified by:
render in interface Layer
Overrides:
render in class AbstractLayer
Parameters:
dc - the current draw context

selected

public void selected(SelectEvent event)
SelectListener implementation.

Specified by:
selected in interface SelectListener
Parameters:
event - the current SelectEvent

setBorderWidth

public void setBorderWidth(int borderWidth)
Sets the layer manager frame offset from the viewport borders.

Parameters:
borderWidth - the number of pixels to offset the layer manager frame from the borders indicated by setPosition(String).

setColor

public void setColor(Color color)
Set the Color used to draw the layer names and the frame border when they are not highlighted.

Parameters:
color - the Color used to draw the layer names and the frame border when they are not highlighted.

setComponentDragEnabled

public void setComponentDragEnabled(boolean enabled)
Sets whether the layer list can be moved or dragged with the mouse cursor.

If enabled, dragging the frame will result in a change to it's location offset - setLocationOffset(Vec4). If the list is also set to snap to corners - setSnapToCorners(boolean), the frame position may change so as to be attached to the nearest corner - see setPosition(String).

Parameters:
enabled - true if the layer list can be moved or dragged with the mouse cursor.

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: Layer
Controls whether the layer is enabled for rendering and selection.

Specified by:
setEnabled in interface Layer
Overrides:
setEnabled in class AbstractLayer
Parameters:
enabled - true if the layer is enabled, else false.

setFont

public void setFont(Font font)
Set the Font used to draw the layer list text.

Parameters:
font - the Font used to draw the layer list text.

setHighlightColor

public void setHighlightColor(Color color)
Set the Color used to draw the layer names and the frame border when they are highlighted.

Parameters:
color - the Color used to draw the layer names and the frame border when they are highlighted.

setLayerDisabledSymbol

public void setLayerDisabledSymbol(char c)
Set the character used to denote a disabled layer.

Parameters:
c - the character used to denote a disabled layer.

setLayerDragEnabled

public void setLayerDragEnabled(boolean enabled)
Sets whether a layer can be moved or dragged within the list with the mouse cursor. If enabled, layers can be moved up and down the list.

Parameters:
enabled - true if a layer can be moved or dragged within the list.

setLayerEnabledSymbol

public void setLayerEnabledSymbol(char c)
Set the character used to denote an enabled layer.

Parameters:
c - the character used to denote an enabled layer.

setLocationCenter

public void setLocationCenter(Vec4 locationCenter)
Specifies the screen location of the layer manager, relative to it's frame center. May be null. If this value is non-null, it overrides the position specified by #setPosition. The location is specified in pixels. The origin is the window's lower left corner. Positive X values are to the right of the origin, positive Y values are upwards from the origin. The final frame location will be affected by the currently specified location offset if a non-null location offset has been specified (see setLocationOffset(Vec4)).

Parameters:
locationCenter - the location center. May be null.
See Also:
setPosition(String), setLocationOffset(gov.nasa.worldwind.geom.Vec4)

setLocationOffset

public void setLocationOffset(Vec4 locationOffset)
Specifies a placement offset from the layer manager frame position on the screen.

Parameters:
locationOffset - the number of pixels to shift the layer manager frame from its specified screen position. A positive X value shifts the frame to the right. A positive Y value shifts the frame up. If null, no offset is applied. The default offset is null.
See Also:
setLocationCenter(gov.nasa.worldwind.geom.Vec4), setPosition(String)

setMaxOpacity

public void setMaxOpacity(double opacity)
Set the opacity applied to the layer list when the cursor is inside it's frame - zero to one, one is fully opaque.

Parameters:
opacity - the opacity applied to the layer list when the cursor is inside it's frame.

setMinimized

public void setMinimized(boolean minimized)
Set the layer list frame to be minimized. When minimized, the layer list only contains itself as the only item, and thus shrinks toward it's corner position.

Parameters:
minimized - true if the layer list frame sould be minimized.

setMinOpacity

public void setMinOpacity(double opacity)
Set the opacity applied to the layer list when the cursor is outside it's frame - zero to one, one is fully opaque.

Parameters:
opacity - the opacity applied to the layer list when the cursor is outside it's frame.

setPosition

public void setPosition(String position)
Sets the relative viewport location to display the layer manager. Can be one of AVKey.NORTHEAST (the default), AVKey.NORTHWEST, AVKey.SOUTHEAST, or AVKey.SOUTHWEST. These indicate the corner of the viewport to place the frame.

Parameters:
position - the desired layer manager position

setSelectedIndex

public void setSelectedIndex(int index)
Set the selected layer index number. When selected a layer is highlighted in the list - this usually happens when the cursor is over it.

Parameters:
index - the selected layer index number.

setSnapToCorners

public void setSnapToCorners(boolean enabled)
Sets whether the layer list snaps to the viewport sides and corners while being dragged.

Dragging the layer list frame will result in a change to it's location offset - setLocationOffset(Vec4). If the list is also set to snap to corners the frame position may change so as to be attached to the nearest corner - see setPosition(String).

Parameters:
enabled - true if the layer list should snaps to the viewport sides and corners while being dragged.

snapToCorners

protected void snapToCorners()

toString

public String toString()
Overrides:
toString in class RenderableLayer

update

public void update()
Schedule the layer list for redrawing before the next render pass.


updateNow

public void updateNow(DrawContext dc)
Force the layer list to redraw itself from the current Model with the current highlighted state and selected layer colors and opacity.

Parameters:
dc - the current DrawContext.
See Also:
setMinOpacity(double), setMaxOpacity(double), setColor(java.awt.Color), setHighlightColor(java.awt.Color)

NASA World Wind