NASA World Wind

gov.nasa.worldwind.render
Class ScreenRelativeAnnotation

java.lang.Object
  extended by gov.nasa.worldwind.avlist.AVListImpl
      extended by gov.nasa.worldwind.render.AbstractAnnotation
          extended by gov.nasa.worldwind.render.ScreenAnnotation
              extended by gov.nasa.worldwind.render.ScreenRelativeAnnotation
All Implemented Interfaces:
AVList, Disposable, Annotation, Renderable, Restorable

public class ScreenRelativeAnnotation
extends ScreenAnnotation

Provides a screen annotation positioned relatively to the window rather than absolutely. The annotation's position is specified as fractional locations along the window's X and Y axes. When the window is resized the annotation is repositioned according to its relative coordinates.

The annotation can be forced to remain fully visible even if its relative position would place a portion of it outside the window. X and Y margins can be specified to ensure distance between the annotation's edges and the window edges.


Nested Class Summary
 
Nested classes/interfaces inherited from class gov.nasa.worldwind.render.AbstractAnnotation
AbstractAnnotation.TextCacheKey
 
Field Summary
 
Fields inherited from class gov.nasa.worldwind.render.AbstractAnnotation
alwaysOnTop, attributes, childList, delegateOwner, layoutManager, maxActiveAltitude, minActiveAltitude, pickEnabled, pickSupport, text, textBoundsMap, vertexBuffer, wrappedTextMap
 
Fields inherited from interface gov.nasa.worldwind.render.Annotation
ANTIALIAS_DONT_CARE, ANTIALIAS_FASTEST, ANTIALIAS_NICEST
 
Constructor Summary
ScreenRelativeAnnotation(String text, double xFraction, double yFraction)
          Create an annotation with spedified text and relative position.
 
Method Summary
 String getRestorableState()
          Returns an XML state document String describing the public attributes of this ScreenAnnotation.
protected  Point getScreenPoint(DrawContext dc)
          Computes and returns the screen point in pixels corresponding to the annotation's relative position coordinates and the current window size.
 double getXFraction()
          Returns the annotation's relative X position.
 int getXMargin()
          Returns the annotation's X margin.
 double getYFraction()
          Returns the annotation's relative Y position.
 int getYMargin()
          Returns the annotation's Y margin.
 boolean isKeepFullyVisible()
          Indicates whether the annotation is kept fully visible in the window.
 void restoreState(String stateInXml)
          Restores publicly settable attribute values found in the specified XML state document String.
 void setKeepFullyVisible(boolean keepFullyVisible)
          Specifies whether to adjust the annotation's position so that it is always fully visible when the window has sufficient area to display it, even if it would be fully or partially obscured when placed according to its relative coordinates.
 void setXFraction(double xFraction)
          Specifies the annotation's relative X position.
 void setXMargin(int xMargin)
          Specifies the annotation's X margin, the minimum distance to maintain between the annotation's leading and trailing edges and the respective window edge.
 void setYFraction(double yFraction)
          Specifies the annotation's relative Y position.
 void setYMargin(int yMargin)
          Specifies the annotation's Y margin, the minimum distance to maintain between the annotation's top and bottom edges and the respective window edge.
 
Methods inherited from class gov.nasa.worldwind.render.ScreenAnnotation
computeBounds, computeOffset, computeSize, doRenderNow, getScreenPoint, setScreenPoint
 
Methods inherited from class gov.nasa.worldwind.render.AbstractAnnotation
addChild, adjustSizeToChildren, adjustSizeToText, applyBackgroundTextureState, applyColor, applyScreenTransform, beginDraw, beginDrawChildren, bindPickableObject, computeBoundingRectangle, computeFreeBounds, computeInsetBounds, computeOpacity, computeScale, computeTextBounds, dispose, doDraw, doDrawBackgroundTexture, doDrawChildren, draw, drawBackground, drawBackgroundImage, drawBorder, drawCallout, drawChildren, drawContent, drawHTML, drawPlainText, drawText, drawText, drawTopLevelAnnotation, endDraw, endDrawChildren, getAttributes, getBounds, getChildren, getDelegateOwner, getLayout, getMaxActiveAltitude, getMinActiveAltitude, getMultiLineTextRenderer, getPickSupport, getPreferredSize, getText, getTextBounds, getTextRenderer, getWrappedText, glPointFromAWTPoint, isAlwaysOnTop, isPickEnabled, modulateColorOpacity, pick, removeAllChildren, removeChild, render, renderNow, setAlwaysOnTop, setAttributes, setDelegateOwner, setLayout, setMaxActiveAltitude, setMinActiveAltitude, setPickEnabled, setPickSupport, setText, transformBackgroundImageCoordsToAnnotationCoords, transformByModelview, transformImageCoordsToBackgroundImageCoords, wrapText
 
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
 

Constructor Detail

ScreenRelativeAnnotation

public ScreenRelativeAnnotation(String text,
                                double xFraction,
                                double yFraction)
Create an annotation with spedified text and relative position.

Parameters:
text - the text to display in the annotation.
xFraction - the relative X position of the annotation. A value of 0 indicates the window's left edge, a value of 1 indicates its right edge. The annotation is centered horizontally on this position prior to applying any X offest specified in the annotation's attributes.
yFraction - the relative Y position of the annotation. A value of 0 indicates the window's bottom edge, a value of 1 indicates the window's top edge. The annotation's lower edge is justified to this position prior to applying any Y offset specified in the annotation's attributes.
Throws:
IllegalArgumentException - if the text string is null.
Method Detail

getRestorableState

public String getRestorableState()
Returns an XML state document String describing the public attributes of this ScreenAnnotation.

Specified by:
getRestorableState in interface Restorable
Overrides:
getRestorableState in class ScreenAnnotation
Returns:
XML state document string describing this ScreenAnnotation.

getScreenPoint

protected Point getScreenPoint(DrawContext dc)
Computes and returns the screen point in pixels corresponding to the annotation's relative position coordinates and the current window size.

Overrides:
getScreenPoint in class ScreenAnnotation
Parameters:
dc - the current draw context.
Returns:
the pixel coordinates corresponding to the annotation's relative coordinates. The pixel coordinate origin is the lower left of the window.

getXFraction

public double getXFraction()
Returns the annotation's relative X position.

Returns:
the annotation's relative X position, as specified to the constructor or setXFraction(double).

getXMargin

public int getXMargin()
Returns the annotation's X margin.

Returns:
the annotation's X margin, in pixels.

getYFraction

public double getYFraction()
Returns the annotation's relative Y position.

Returns:
the annotation's relative Y position, as specified to the constructor or setYFraction(double).

getYMargin

public int getYMargin()
Returns the annotation's Y margin.

Returns:
the annotation's Y margin, in pixels.

isKeepFullyVisible

public boolean isKeepFullyVisible()
Indicates whether the annotation is kept fully visible in the window.

Returns:
true if annotation is kept fully visible, otherwise false.

restoreState

public void restoreState(String stateInXml)
Restores publicly settable attribute values found in the specified XML state document String. The document specified by stateInXml must be a well formed XML document String, or this will throw an IllegalArgumentException. Unknown structures in stateInXml are benign, because they will simply be ignored.

Specified by:
restoreState in interface Restorable
Overrides:
restoreState in class ScreenAnnotation
Parameters:
stateInXml - an XML document String describing a ScreenAnnotation.
Throws:
IllegalArgumentException - If stateInXml is null, or if stateInXml is not a well formed XML document String.

setKeepFullyVisible

public void setKeepFullyVisible(boolean keepFullyVisible)
Specifies whether to adjust the annotation's position so that it is always fully visible when the window has sufficient area to display it, even if it would be fully or partially obscured when placed according to its relative coordinates.

Parameters:
keepFullyVisible - true to keep the annotation fully visible, otherwise false.

setXFraction

public void setXFraction(double xFraction)
Specifies the annotation's relative X position. A value of 0 indicates the window's left edge, a value of 1 indicates its right edge.

Parameters:
xFraction - the annotation's relative X position.

setXMargin

public void setXMargin(int xMargin)
Specifies the annotation's X margin, the minimum distance to maintain between the annotation's leading and trailing edges and the respective window edge. Used only when the keepFullyVisible flag is true.

Parameters:
xMargin - the X margin, in pixels.

setYFraction

public void setYFraction(double yFraction)
Specifies the annotation's relative Y position. A value of 0 indicates the window's lower edge, a value of 1 indicates its top edge.

Parameters:
yFraction - the annotation's relative Y position.

setYMargin

public void setYMargin(int yMargin)
Specifies the annotation's Y margin, the minimum distance to maintain between the annotation's top and bottom edges and the respective window edge. Used only when the keepFullyVisible flag is true.

Parameters:
yMargin - the Y margin, in pixels.

NASA World Wind