NASA World Wind

gov.nasa.worldwind.render
Class AbstractAnnotation

java.lang.Object
  extended by gov.nasa.worldwind.render.AbstractAnnotation
All Implemented Interfaces:
Disposable, Pickable, Annotation, Renderable
Direct Known Subclasses:
GlobeAnnotation, ScreenAnnotation

public abstract class AbstractAnnotation
extends Object
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:
 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

Field Summary
protected  double alphaFactor
           
protected  AnnotationAttributes attributes
           
protected  Rectangle drawRectangle
           
protected  Rectangle freeRectangle
           
protected  gov.nasa.worldwind.render.AbstractAnnotation.RenderInfo renderInfo
           
protected  double scaleFactor
          Values used for drawing.
protected  String text
           
 
Fields inherited from interface gov.nasa.worldwind.render.Annotation
ANTIALIAS_DONT_CARE, ANTIALIAS_FASTEST, ANTIALIAS_NICEST, IMAGE_REPEAT_NONE, IMAGE_REPEAT_X, IMAGE_REPEAT_XY, IMAGE_REPEAT_Y, SIZE_FIT_TEXT, SIZE_FIXED
 
Constructor Summary
AbstractAnnotation()
           
 
Method Summary
protected  void cacheRenderInfo(Annotation annotation, gov.nasa.worldwind.render.AbstractAnnotation.RenderInfo renderInfo)
           
protected  double computeLookAtDistance(DrawContext dc)
           
 void dispose()
           
protected abstract  void doDraw(DrawContext dc)
           
 void draw(DrawContext dc)
          Draw the annotation.
protected  void drawAnnotation(DrawContext dc, Point screenPoint, double drawScale, double drawAlpha, Position pickPosition)
          Draws an annotation at a screen point.
 AnnotationAttributes getAttributes()
           
 PickSupport getPickSupport()
           
protected  Rectangle getRectangleInViewportCoordinates(DrawContext dc, Rectangle r, Point screenPoint, double scaleFactor)
           
protected  gov.nasa.worldwind.render.AbstractAnnotation.RenderInfo getRenderInfo(DrawContext dc, Annotation annotation)
           
 String getText()
           
protected  TextRenderer getTextRenderer(DrawContext dc, Font font)
           
protected  Texture initializeTexture(DrawContext dc, Annotation annotation)
           
 void pick(DrawContext dc, Point pickPoint)
          Pick at the annotation.
 void render(DrawContext dc)
          Render the annotation.
 void setAttributes(AnnotationAttributes attrs)
           
protected  void setDepthFunc(DrawContext dc, Vec4 screenPoint)
           
protected  void setDrawColor(DrawContext dc, Color color)
           
protected  void setDrawColor(DrawContext dc, float r, float g, float b, float a)
           
 void setPickSupport(PickSupport pickSupport)
           
 void setText(String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alphaFactor

protected double alphaFactor

attributes

protected AnnotationAttributes attributes

drawRectangle

protected Rectangle drawRectangle

freeRectangle

protected Rectangle freeRectangle

renderInfo

protected gov.nasa.worldwind.render.AbstractAnnotation.RenderInfo renderInfo

scaleFactor

protected double scaleFactor
Values used for drawing.

Should be used by post drawing code.


text

protected String text
Constructor Detail

AbstractAnnotation

public AbstractAnnotation()
Method Detail

cacheRenderInfo

protected void cacheRenderInfo(Annotation annotation,
                               gov.nasa.worldwind.render.AbstractAnnotation.RenderInfo renderInfo)

computeLookAtDistance

protected double computeLookAtDistance(DrawContext dc)

dispose

public void dispose()
Specified by:
dispose in interface Disposable

doDraw

protected abstract void doDraw(DrawContext dc)

draw

public void draw(DrawContext dc)
Draw the annotation. Called as an Annotation by an AnnotationRenderer while batch rendering. The gl context is ready to draw with the model view set as an identity ortho projection.

Specified by:
draw in interface Annotation
Parameters:
dc - the current DrawContext.

drawAnnotation

protected void drawAnnotation(DrawContext dc,
                              Point screenPoint,
                              double drawScale,
                              double drawAlpha,
                              Position pickPosition)
Draws an annotation at a screen point. Current GL state has ortho identity model view active with origin at the screen point.

Parameters:
dc - the current DrawContext.
screenPoint - the annotation position projected location on the viewport.
pickPosition - the Position that will be associated with any PickedObject produced during picking.

getAttributes

public AnnotationAttributes getAttributes()
Specified by:
getAttributes in interface Annotation

getPickSupport

public PickSupport getPickSupport()

getRectangleInViewportCoordinates

protected Rectangle getRectangleInViewportCoordinates(DrawContext dc,
                                                      Rectangle r,
                                                      Point screenPoint,
                                                      double scaleFactor)

getRenderInfo

protected gov.nasa.worldwind.render.AbstractAnnotation.RenderInfo getRenderInfo(DrawContext dc,
                                                                                Annotation annotation)

getText

public String getText()
Specified by:
getText in interface Annotation

getTextRenderer

protected TextRenderer getTextRenderer(DrawContext dc,
                                       Font font)

initializeTexture

protected Texture initializeTexture(DrawContext dc,
                                    Annotation annotation)

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.

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

setAttributes

public void setAttributes(AnnotationAttributes attrs)
Specified by:
setAttributes in interface Annotation

setDepthFunc

protected void setDepthFunc(DrawContext dc,
                            Vec4 screenPoint)

setDrawColor

protected void setDrawColor(DrawContext dc,
                            Color color)

setDrawColor

protected void setDrawColor(DrawContext dc,
                            float r,
                            float g,
                            float b,
                            float a)

setPickSupport

public void setPickSupport(PickSupport pickSupport)
Specified by:
setPickSupport in interface Annotation

setText

public void setText(String text)
Specified by:
setText in interface Annotation

NASA World Wind