Package gov.nasa.worldwind.render
Class ScreenRelativeAnnotation
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.render.AbstractAnnotation
-
- gov.nasa.worldwind.render.ScreenAnnotation
-
- 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.ScreenAnnotation
position, screenPoint
-
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
Constructors Constructor Description ScreenRelativeAnnotation(java.lang.String text, double xFraction, double yFraction)
Create an annotation with spedified text and relative position.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getRestorableState()
Returns an XML state document String describing the public attributes of this ScreenAnnotation.protected java.awt.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(java.lang.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
computeAnnotationPosition, computeBounds, computeOffset, computeSize, doRenderNow, getPosition, getScreenPoint, setPosition, 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
-
-
-
-
Constructor Detail
-
ScreenRelativeAnnotation
public ScreenRelativeAnnotation(java.lang.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:
java.lang.IllegalArgumentException
- if the text string is null.
-
-
Method Detail
-
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.
-
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.
-
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)
.
-
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.
-
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)
.
-
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.
-
getXMargin
public int getXMargin()
Returns the annotation's X margin.- Returns:
- the annotation's X margin, in pixels.
-
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 thekeepFullyVisible
flag is true.- Parameters:
xMargin
- the X margin, in pixels.
-
getYMargin
public int getYMargin()
Returns the annotation's Y margin.- Returns:
- the annotation's Y margin, in pixels.
-
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 thekeepFullyVisible
flag is true.- Parameters:
yMargin
- the Y margin, in pixels.
-
getScreenPoint
protected java.awt.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 classScreenAnnotation
- 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.
-
getRestorableState
public java.lang.String getRestorableState()
Returns an XML state document String describing the public attributes of this ScreenAnnotation.- Specified by:
getRestorableState
in interfaceRestorable
- Overrides:
getRestorableState
in classScreenAnnotation
- Returns:
- XML state document string describing this ScreenAnnotation.
-
restoreState
public void restoreState(java.lang.String stateInXml)
Restores publicly settable attribute values found in the specified XML state document String. The document specified bystateInXml
must be a well formed XML document String, or this will throw an IllegalArgumentException. Unknown structures instateInXml
are benign, because they will simply be ignored.- Specified by:
restoreState
in interfaceRestorable
- Overrides:
restoreState
in classScreenAnnotation
- Parameters:
stateInXml
- an XML document String describing a ScreenAnnotation.- Throws:
java.lang.IllegalArgumentException
- IfstateInXml
is null, or ifstateInXml
is not a well formed XML document String.
-
-