gov.nasa.worldwind.render
Class AbstractAnnotation
java.lang.Object
gov.nasa.worldwind.avlist.AVListImpl
gov.nasa.worldwind.render.AbstractAnnotation
- All Implemented Interfaces:
- AVList, Disposable, Pickable, Annotation, Renderable, Restorable
- Direct Known Subclasses:
- GlobeAnnotation, ScreenAnnotation
public abstract class AbstractAnnotation - extends AVListImpl
- implements Annotation
An Annotation represent a text label and its rendering attributes. Annotations must be attached either to
a globe Position (GlobeAnnotation) or a viewport Point (ScreenAnnotation).
GlobaAnnotation ga = new GlobeAnnotation("Lat-Lon zero", Position.fromDegrees(0, 0, 0)));
ScreenAnnotation sa = new ScreenAnnotation("Message...", new Point(10,10));
Each Annotation refers to an AnnotationAttributes object which defines how the text will be rendered.
Rendering attributes allow to set:
- the size of the bounding rectangle into which the text will be displayed
- its frame shape, border color, width and stippling pattern
- the text font, size, style and color
- the background color or image
- how much an annotation scales and fades with distance
ga.getAttributes().setTextColor(Color.WHITE);
ga.getAttributes().setFont(Font.decode("Arial-BOLD-24");
...
Annotations are usually handled by an AnnotationLayer. Although they also implement the Renderable
and Pickable interfaces and thus can be handled by a RenderableLayer too.
AnnotationLayer layer = new AnnotationLayer();
layer.addAnnotation(new GlobeAnnotation("Text...", Position.fromDegrees(0, 0, 0)));
Each Annotation starts its life with a fresh attribute set that can be altered to produce the desired effect.
However, AnnotationAttributes can be set and shared between annotations allowing to control the rendering attributes
of many annotations from a single AnnotationAttributes object.
AnnotationAttributes attr = new AnnotationAttributes();
attr.setTextColor(Color.WHITE);
attr.setFont(Font.decode("Arial-BOLD-24");
ga.setAttributes(attr);
In the above example changing the text color of the attributes set will affect all annotations refering it. However,
changing the text color of one of those annotations will also affect all others since it will in fact change the
common attributes set.
To use an attributes object only as default values for a serie of annotations use:
ga.getAttributes()setDefaults(attr);
which can also be done in the Annotation constructor:
GlobeAnnotation ga = new GlobeAnnotation(text, position, attr);
Finer control over attributes inheritence can be achieved using default or fallback attributes set.
Most attributes can be set to a 'use default' value which is minus one for numeric values and null for attributes
refering objects (colors, dimensions, insets..). In such a case the value of an attribute will be that of the
default attribute set. New annotations have all their attributes set to use default values.
Each AnnotationAttributes object points to a default static attributes set which is the fallback source for
attributes with null or -1 values. This default attributes set can be set to any attributes object other than the
static one.
AnnotationAttributes geoFeature = new AnnotationAttributes();
geoFeature.setFrameShape(FrameFactory.SHAPE_ELLIPSE);
geoFeature.setInsets(new Insets(12, 12, 12, 12));
AnnotationAttributes waterBody = new AnnotationAttributes();
waterBody.setTextColor(Color.BLUE);
waterBoby.setDefaults(geoFeature);
AnnotationAttributes mountain = new AnnotationAttributes();
mountain.setTextColor(Color.GREEN);
mountain.setDefaults(geoFeature);
layer.addAnnotation(new GlobeAnnotation("Spirit Lake", Position.fromDegrees(46.26, -122.15), waterBody);
layer.addAnnotation(new GlobeAnnotation("Mt St-Helens", Position.fromDegrees(46.20, -122.19), mountain);
In the above example all geographic features have an ellipse shape, water bodies and mountains use that attributes
set has defaults and have their own text colors. They are in turn used as defaults by the two annotations. Mount
Saint Helens attributes could be changed without affecting other mountains. However, changes on the geoFeatures
attributes would affect all mountains and lakes.
- See Also:
AnnotationAttributes,
AnnotationRenderer
|
Method Summary |
void |
addChild(Annotation annotation)
|
protected Dimension |
adjustSizeToChildren(DrawContext dc,
int width,
int height)
|
protected Dimension |
adjustSizeToText(DrawContext dc,
int width,
int height)
|
protected void |
applyBackgroundTextureState(DrawContext dc,
int width,
int height,
double opacity,
AnnotationTexture texture)
|
protected void |
applyBackgroundTextureTransform(DrawContext dc,
int width,
int height,
AnnotationTexture texture)
|
protected void |
applyScreenTransform(DrawContext dc,
int x,
int y,
int width,
int height,
double scale)
|
protected void |
beginDraw(DrawContext dc,
OGLStackHandler stackHandler)
|
protected void |
beginDrawChildren(DrawContext dc,
Rectangle bounds)
|
protected void |
bindPickableObject(DrawContext dc,
Position position)
|
protected Rectangle |
computeFreeBounds(DrawContext dc,
int width,
int height)
|
protected Rectangle |
computeInsetBounds(int width,
int height)
|
protected double |
computeOpacity(DrawContext dc)
|
protected double |
computeScale(DrawContext dc)
|
protected Rectangle |
computeTextBounds(DrawContext dc,
String text,
Font font,
int align)
|
void |
dispose()
|
protected void |
doDraw(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
Draws an annotation with the given dimensions and opacity. |
protected void |
doDrawBackgroundTexture(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition,
AnnotationTexture texture)
|
protected void |
doDrawChildren(DrawContext dc,
Rectangle bounds,
double opacity,
Position pickPosition)
|
protected abstract void |
doRenderNow(DrawContext dc)
|
void |
draw(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
Draws the annotation without transforming to its screen position, or applying any scaling. |
protected void |
drawBackground(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
|
protected void |
drawBackgroundImage(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
|
protected void |
drawBorder(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
|
protected void |
drawCallout(DrawContext dc,
int mode,
int width,
int height,
boolean useTexCoords)
|
protected void |
drawChildren(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
|
protected void |
drawContent(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
|
protected void |
drawHTML(DrawContext dc,
int x,
int y,
int lineHeight,
double opacity,
Object pickObject,
Position pickPosition,
String text)
|
protected void |
drawPlainText(DrawContext dc,
int x,
int y,
int lineHeight,
double opacity,
Object pickObject,
Position pickPosition,
String text)
|
protected void |
drawText(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
|
protected void |
drawText(DrawContext dc,
int x,
int y,
int lineHeight,
double opacity,
Object pickObject,
Position pickPosition,
String text)
|
protected void |
drawTopLevelAnnotation(DrawContext dc,
int x,
int y,
int width,
int height,
double scale,
double opacity,
Position pickPosition)
|
protected void |
endDraw(DrawContext dc,
OGLStackHandler stackHandler)
|
protected void |
endDrawChildren(DrawContext dc)
|
protected AnnotationTexture |
getAnnotationTexture(Object imageSource)
|
AnnotationAttributes |
getAttributes()
|
protected AnnotationTexture |
getCachedImage(Object source)
|
List<? extends Annotation> |
getChildren()
|
Object |
getDelegateOwner()
|
AnnotationLayoutManager |
getLayout()
|
protected MultiLineTextRenderer |
getMultiLineTextRenderer(DrawContext dc,
Font font,
int align)
|
PickSupport |
getPickSupport()
|
Dimension |
getPreferredSize(DrawContext dc)
|
String |
getRestorableState()
Returns an XML state document String describing the public attributes of this AbstractAnnotation. |
String |
getText()
|
protected Rectangle |
getTextBounds(DrawContext dc,
String text,
Font font,
int align)
|
protected com.sun.opengl.util.j2d.TextRenderer |
getTextRenderer(DrawContext dc,
Font font)
|
protected String |
getWrappedText(DrawContext dc,
int width,
int height,
String text,
Font font,
int align)
|
protected Point |
glPointFromAWTPoint(DrawContext dc,
Point awtPoint)
|
boolean |
isAlwaysOnTop()
|
boolean |
isPickEnabled()
|
protected Color |
modulateColorOpacity(Color color,
double opacity)
|
void |
pick(DrawContext dc,
Point pickPoint)
Pick at the annotation. |
void |
removeAllChildren()
|
boolean |
removeChild(Annotation annotation)
|
void |
render(DrawContext dc)
Render the annotation. |
void |
renderNow(DrawContext dc)
Draws the annotation immedately on the specified DrawContext. |
void |
restoreState(String stateInXml)
Restores publicly settable attribute values found in the specified XML state document String. |
void |
setAlwaysOnTop(boolean alwaysOnTop)
|
void |
setAttributes(AnnotationAttributes attributes)
|
protected void |
setCachedImage(Object source,
AnnotationTexture texture)
|
void |
setDelegateOwner(Object delegateOwner)
|
protected void |
setDrawColor(DrawContext dc,
Color color,
double opacity,
String colorMode)
|
void |
setLayout(AnnotationLayoutManager layoutManager)
|
void |
setPickEnabled(boolean enable)
|
void |
setPickSupport(PickSupport pickSupport)
|
void |
setText(String text)
|
protected Rectangle |
transformByModelview(DrawContext dc,
Rectangle rectangle)
|
protected String |
wrapText(DrawContext dc,
int width,
int height,
String text,
Font font,
int align)
|
| Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl |
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, 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 |
attributes
protected AnnotationAttributes attributes
childList
protected List<Annotation> childList
delegateOwner
protected Object delegateOwner
layoutManager
protected AnnotationLayoutManager layoutManager
text
protected String text
textBoundsMap
protected Map<Object,Rectangle> textBoundsMap
wrappedTextMap
protected Map<Object,String> wrappedTextMap
AbstractAnnotation
protected AbstractAnnotation()
addChild
public void addChild(Annotation annotation)
- Specified by:
addChild in interface Annotation
adjustSizeToChildren
protected Dimension adjustSizeToChildren(DrawContext dc,
int width,
int height)
adjustSizeToText
protected Dimension adjustSizeToText(DrawContext dc,
int width,
int height)
applyBackgroundTextureState
protected void applyBackgroundTextureState(DrawContext dc,
int width,
int height,
double opacity,
AnnotationTexture texture)
applyBackgroundTextureTransform
protected void applyBackgroundTextureTransform(DrawContext dc,
int width,
int height,
AnnotationTexture texture)
applyScreenTransform
protected void applyScreenTransform(DrawContext dc,
int x,
int y,
int width,
int height,
double scale)
beginDraw
protected void beginDraw(DrawContext dc,
OGLStackHandler stackHandler)
beginDrawChildren
protected void beginDrawChildren(DrawContext dc,
Rectangle bounds)
bindPickableObject
protected void bindPickableObject(DrawContext dc,
Position position)
computeFreeBounds
protected Rectangle computeFreeBounds(DrawContext dc,
int width,
int height)
computeInsetBounds
protected Rectangle computeInsetBounds(int width,
int height)
computeOpacity
protected double computeOpacity(DrawContext dc)
computeScale
protected double computeScale(DrawContext dc)
computeTextBounds
protected Rectangle computeTextBounds(DrawContext dc,
String text,
Font font,
int align)
dispose
public void dispose()
- Specified by:
dispose in interface Disposable
doDraw
protected void doDraw(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
- Draws an annotation with the given dimensions and opacity. Current GL state has ortho identity model
view active with origin at the screen point.
- Parameters:
dc - current DrawContext.width - annotation callout widthheight - annotation callout heightopacity - opacity to applypickPosition - Position that will be associated with any PickedObject
produced during picking.
doDrawBackgroundTexture
protected void doDrawBackgroundTexture(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition,
AnnotationTexture texture)
doDrawChildren
protected void doDrawChildren(DrawContext dc,
Rectangle bounds,
double opacity,
Position pickPosition)
doRenderNow
protected abstract void doRenderNow(DrawContext dc)
draw
public void draw(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
- Description copied from interface:
Annotation
- Draws the annotation without transforming to its screen position, or applying any scaling. This Annotation is
draw with the specified width, height, and opacity. The GL should have its model view set to whatever
transformation is desired.
- Specified by:
draw in interface Annotation
- Parameters:
dc - the current DrawContext.width - the width of the Annotation.height - the height of the Annotation.opacity - the opacity of the Annotation.pickPosition - the picked Position assigned to the Annotation, if picking is enabled.
drawBackground
protected void drawBackground(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
drawBackgroundImage
protected void drawBackgroundImage(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
drawBorder
protected void drawBorder(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
drawCallout
protected void drawCallout(DrawContext dc,
int mode,
int width,
int height,
boolean useTexCoords)
drawChildren
protected void drawChildren(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
drawContent
protected void drawContent(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
drawHTML
protected void drawHTML(DrawContext dc,
int x,
int y,
int lineHeight,
double opacity,
Object pickObject,
Position pickPosition,
String text)
drawPlainText
protected void drawPlainText(DrawContext dc,
int x,
int y,
int lineHeight,
double opacity,
Object pickObject,
Position pickPosition,
String text)
drawText
protected void drawText(DrawContext dc,
int width,
int height,
double opacity,
Position pickPosition)
drawText
protected void drawText(DrawContext dc,
int x,
int y,
int lineHeight,
double opacity,
Object pickObject,
Position pickPosition,
String text)
drawTopLevelAnnotation
protected void drawTopLevelAnnotation(DrawContext dc,
int x,
int y,
int width,
int height,
double scale,
double opacity,
Position pickPosition)
endDraw
protected void endDraw(DrawContext dc,
OGLStackHandler stackHandler)
endDrawChildren
protected void endDrawChildren(DrawContext dc)
getAnnotationTexture
protected AnnotationTexture getAnnotationTexture(Object imageSource)
getAttributes
public AnnotationAttributes getAttributes()
- Specified by:
getAttributes in interface Annotation
getCachedImage
protected AnnotationTexture getCachedImage(Object source)
getChildren
public List<? extends Annotation> getChildren()
- Specified by:
getChildren in interface Annotation
getDelegateOwner
public Object getDelegateOwner()
- Specified by:
getDelegateOwner in interface Annotation
getLayout
public AnnotationLayoutManager getLayout()
- Specified by:
getLayout in interface Annotation
getMultiLineTextRenderer
protected MultiLineTextRenderer getMultiLineTextRenderer(DrawContext dc,
Font font,
int align)
getPickSupport
public PickSupport getPickSupport()
- Specified by:
getPickSupport in interface Annotation
getPreferredSize
public Dimension getPreferredSize(DrawContext dc)
- Specified by:
getPreferredSize in interface Annotation
getRestorableState
public String getRestorableState()
- Returns an XML state document String describing the public attributes of this AbstractAnnotation.
- Specified by:
getRestorableState in interface Restorable
- Returns:
- XML state document string describing this AbstractAnnotation.
getText
public String getText()
- Specified by:
getText in interface Annotation
getTextBounds
protected Rectangle getTextBounds(DrawContext dc,
String text,
Font font,
int align)
getTextRenderer
protected com.sun.opengl.util.j2d.TextRenderer getTextRenderer(DrawContext dc,
Font font)
getWrappedText
protected String getWrappedText(DrawContext dc,
int width,
int height,
String text,
Font font,
int align)
glPointFromAWTPoint
protected Point glPointFromAWTPoint(DrawContext dc,
Point awtPoint)
isAlwaysOnTop
public boolean isAlwaysOnTop()
- Specified by:
isAlwaysOnTop in interface Annotation
isPickEnabled
public boolean isPickEnabled()
- Specified by:
isPickEnabled in interface Annotation
modulateColorOpacity
protected Color modulateColorOpacity(Color color,
double opacity)
pick
public void pick(DrawContext dc,
Point pickPoint)
- Pick at the annotation. Called as a Pickable.
- Specified by:
pick in interface Pickable
- Parameters:
dc - the current DrawContext.
removeAllChildren
public void removeAllChildren()
- Specified by:
removeAllChildren in interface Annotation
removeChild
public boolean removeChild(Annotation annotation)
- Specified by:
removeChild in interface Annotation
render
public void render(DrawContext dc)
- Render the annotation. Called as a Renderable.
- Specified by:
render in interface Renderable
- Parameters:
dc - the current DrawContext.- See Also:
DrawContext
renderNow
public void renderNow(DrawContext dc)
- Description copied from interface:
Annotation
- Draws the annotation immedately on the specified DrawContext. Rendering is not be delayed by use of the
DrawContext's ordered mechanism, or any other delayed rendering mechanism. This is typically called by an
AnnotationRenderer while batch rendering. The GL should have its model view set to the identity matrix.
- Specified by:
renderNow in interface Annotation
- Parameters:
dc - the current DrawContext.
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
- Parameters:
stateInXml - an XML document String describing an AbstractAnnotation.
- Throws:
IllegalArgumentException - If stateInXml is null, or if stateInXml is not
a well formed XML document String.
setAlwaysOnTop
public void setAlwaysOnTop(boolean alwaysOnTop)
- Specified by:
setAlwaysOnTop in interface Annotation
setAttributes
public void setAttributes(AnnotationAttributes attributes)
- Specified by:
setAttributes in interface Annotation
setCachedImage
protected void setCachedImage(Object source,
AnnotationTexture texture)
setDelegateOwner
public void setDelegateOwner(Object delegateOwner)
- Specified by:
setDelegateOwner in interface Annotation
setDrawColor
protected void setDrawColor(DrawContext dc,
Color color,
double opacity,
String colorMode)
setLayout
public void setLayout(AnnotationLayoutManager layoutManager)
- Specified by:
setLayout in interface Annotation
setPickEnabled
public void setPickEnabled(boolean enable)
- Specified by:
setPickEnabled in interface Annotation
setPickSupport
public void setPickSupport(PickSupport pickSupport)
- Specified by:
setPickSupport in interface Annotation
setText
public void setText(String text)
- Specified by:
setText in interface Annotation
transformByModelview
protected Rectangle transformByModelview(DrawContext dc,
Rectangle rectangle)
wrapText
protected String wrapText(DrawContext dc,
int width,
int height,
String text,
Font font,
int align)
|
|