public abstract class AbstractAnnotation extends AVListImpl implements Annotation
Annotation
represent a text label and its rendering attributes. Annotations must be attached either to a
globe Position
(GlobeAnnotation
) or a viewport Point
(ScreenAnnotation).
GlobeAnnotation 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.
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
interface 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 referring 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 series 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 inheritance 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 referring 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.
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(AVKey.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. Background images are specified by setting the Annotation attribute
AnnotationAttributes.setImageSource(Object)
.
The source can be either a path to a valid image file, or a BufferedImage
. By default,
background images are aligned with the annotation as follows: the image's upper left corner is aligned with the
annotation's upper left corner, and the image's lower right corner is aligned with a point (imageWidth,
imageHeight)
pixels right and down from the annotation's upper left corner. Thus the background image
coordinate system has its origin at the annotation's upper left corner, has the +X axis pointing to the right, and
has the +Y axis pointing down. Units are in image pixels, where one image pixel corresponds to one screen pixel. The
background image may be translated or scaled by setting the attributes AnnotationAttributes.setImageOffset(java.awt.Point)
and AnnotationAttributes.setImageScale(double)
, respectively. The offset attribute
defines an offset right and down in background image coordinates. The scale attribute is unitless, and defines the
background image's magnification or minification factor relative to the annotation. For example, a scale of
0.5
indicates the image should be 1/2 its original size relative to the annotation, while a scale of
2.0
indicates the image should be 2x its original size.
Warning: For compatibility across the myriad of graphics hardware, background images must have
power-of-two dimensions. Non-power-of-two images are handled inconsistently by graphics hardware. Not all hardware
supports them, and many that do lack full support for the features available when using power-of-two images. Proper
conversion from a non-power-of-two image to a power-of-two image depends on the image's intended use. However, the
following two step solution works for most applications: WWMath.powerOfTwoCeiling(int)
is useful for
computing power-of-two dimensions:
int newWidth = WWMath.powerOfTwoCeiling(originalWidth);
int
newHeight = WWMath.powerOfTwoCeiling(originalHeight);
BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = newImage.createGraphics();
try
{
g2d.drawImage(originalImage, 0, 0,
null);
}
finally
{
g2d.dispose();
}
AnnotationAttributes
,
AnnotationRenderer
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractAnnotation.TextCacheKey |
Modifier and Type | Field and Description |
---|---|
protected boolean |
alwaysOnTop |
protected AnnotationAttributes |
attributes |
protected List<Annotation> |
childList |
protected Object |
delegateOwner |
protected AnnotationLayoutManager |
layoutManager |
protected double |
maxActiveAltitude |
protected double |
minActiveAltitude |
protected boolean |
pickEnabled |
protected PickSupport |
pickSupport |
protected String |
text |
protected Map<Object,Rectangle> |
textBoundsMap |
protected static DoubleBuffer |
vertexBuffer |
protected Map<Object,String> |
wrappedTextMap |
ANTIALIAS_DONT_CARE, ANTIALIAS_FASTEST, ANTIALIAS_NICEST
Modifier | Constructor and Description |
---|---|
protected |
AbstractAnnotation() |
Modifier and Type | Method and Description |
---|---|
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,
WWTexture texture) |
protected void |
applyColor(DrawContext dc,
Color color,
double opacity,
boolean premultiplyColors) |
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 |
computeBoundingRectangle(Rectangle rect,
int px,
int py) |
protected abstract Rectangle |
computeBounds(DrawContext dc) |
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,
String align) |
void |
dispose()
Disposes of any internal resources allocated by the object.
|
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,
WWTexture 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) |
AnnotationAttributes |
getAttributes() |
Rectangle |
getBounds(DrawContext dc)
Get the annotation bounding
Rectangle using OGL coordinates - bottom-left corner x and y
relative to the WorldWindow bottom-left corner, and the annotation callout width and height. |
List<? extends Annotation> |
getChildren() |
Object |
getDelegateOwner() |
AnnotationLayoutManager |
getLayout() |
double |
getMaxActiveAltitude()
Returns the maximum eye altitude, in meters, for which the annotation is displayed.
|
double |
getMinActiveAltitude()
Returns the minimum eye altitude, in meters, for which the annotation is displayed.
|
protected MultiLineTextRenderer |
getMultiLineTextRenderer(DrawContext dc,
Font font,
String 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,
String align) |
protected TextRenderer |
getTextRenderer(DrawContext dc,
Font font) |
protected String |
getWrappedText(DrawContext dc,
int width,
int height,
String text,
Font font,
String 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 immediately 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) |
void |
setDelegateOwner(Object delegateOwner) |
void |
setLayout(AnnotationLayoutManager layoutManager) |
void |
setMaxActiveAltitude(double maxActiveAltitude)
Specifies the maximum eye altitude, in meters, for which the annotation is displayed.
|
void |
setMinActiveAltitude(double minActiveAltitude)
Specifies the minimum eye altitude, in meters, for which the annotation is displayed.
|
void |
setPickEnabled(boolean enable) |
void |
setPickSupport(PickSupport pickSupport) |
void |
setText(String text) |
protected void |
transformBackgroundImageCoordsToAnnotationCoords(DrawContext dc,
int width,
int height,
WWTexture texture)
Transforms texture coordinates from Annotation background image coordinates to Annotation geometry coordinates
(in screen pixels), and applies the Annotation's image scale and image offset attributes.
|
protected Rectangle |
transformByModelview(DrawContext dc,
Rectangle rectangle) |
protected void |
transformImageCoordsToBackgroundImageCoords(DrawContext dc,
WWTexture texture)
Transforms texture coordinates from standard GL image coordinates to Annotation background image coordinates.
|
protected String |
wrapText(DrawContext dc,
int width,
int height,
String text,
Font font,
String align) |
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
protected boolean alwaysOnTop
protected AnnotationAttributes attributes
protected List<Annotation> childList
protected Object delegateOwner
protected AnnotationLayoutManager layoutManager
protected double maxActiveAltitude
protected double minActiveAltitude
protected boolean pickEnabled
protected PickSupport pickSupport
protected String text
protected static DoubleBuffer vertexBuffer
public void addChild(Annotation annotation)
addChild
in interface 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, WWTexture texture)
protected void applyColor(DrawContext dc, Color color, double opacity, boolean premultiplyColors)
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 computeBoundingRectangle(Rectangle rect, int px, int py)
protected abstract Rectangle computeBounds(DrawContext dc)
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, String align)
public void dispose()
Disposable
dispose
in interface Disposable
protected void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
dc
- current DrawContext.width
- annotation callout widthheight
- annotation callout heightopacity
- opacity to applypickPosition
- Position
that will be associated with any PickedObject
produced
during picking.protected void doDrawBackgroundTexture(DrawContext dc, int width, int height, double opacity, Position pickPosition, WWTexture texture)
protected void doDrawChildren(DrawContext dc, Rectangle bounds, double opacity, Position pickPosition)
protected abstract void doRenderNow(DrawContext dc)
public void draw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
Annotation
draw
in interface Annotation
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.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)
public AnnotationAttributes getAttributes()
getAttributes
in interface Annotation
public Rectangle getBounds(DrawContext dc)
Rectangle
using OGL coordinates - bottom-left corner x and y
relative to the WorldWindow
bottom-left corner, and the annotation callout width and height.
The annotation offset from it's reference point is factored in such that the callout leader shape and reference
point are included in the bounding rectangle.getBounds
in interface Annotation
dc
- the current DrawContext.Rectangle
using OGL viewport coordinates.IllegalArgumentException
- if dc
is null.public List<? extends Annotation> getChildren()
getChildren
in interface Annotation
public Object getDelegateOwner()
getDelegateOwner
in interface Annotation
public AnnotationLayoutManager getLayout()
getLayout
in interface Annotation
public double getMaxActiveAltitude()
Annotation
getMaxActiveAltitude
in interface Annotation
Annotation.setMaxActiveAltitude(double)
,
Annotation.getMinActiveAltitude()
public double getMinActiveAltitude()
Annotation
getMinActiveAltitude
in interface Annotation
Annotation.setMinActiveAltitude(double)
,
Annotation.getMaxActiveAltitude()
protected MultiLineTextRenderer getMultiLineTextRenderer(DrawContext dc, Font font, String align)
public PickSupport getPickSupport()
getPickSupport
in interface Annotation
public Dimension getPreferredSize(DrawContext dc)
getPreferredSize
in interface Annotation
public String getRestorableState()
getRestorableState
in interface Restorable
public String getText()
getText
in interface Annotation
protected Rectangle getTextBounds(DrawContext dc, String text, Font font, String align)
protected TextRenderer getTextRenderer(DrawContext dc, Font font)
protected String getWrappedText(DrawContext dc, int width, int height, String text, Font font, String align)
protected Point glPointFromAWTPoint(DrawContext dc, Point awtPoint)
public boolean isAlwaysOnTop()
isAlwaysOnTop
in interface Annotation
public boolean isPickEnabled()
isPickEnabled
in interface Annotation
public void pick(DrawContext dc, Point pickPoint)
dc
- the current DrawContext.pickPoint
- the screen coordinate point.public void removeAllChildren()
removeAllChildren
in interface Annotation
public boolean removeChild(Annotation annotation)
removeChild
in interface Annotation
public void render(DrawContext dc)
render
in interface Renderable
dc
- the current DrawContext.DrawContext
public void renderNow(DrawContext dc)
Annotation
renderNow
in interface Annotation
dc
- the current DrawContext.public void restoreState(String stateInXml)
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.restoreState
in interface Restorable
stateInXml
- an XML document String describing an AbstractAnnotation.IllegalArgumentException
- If stateInXml
is null, or if stateInXml
is not a well
formed XML document String.public void setAlwaysOnTop(boolean alwaysOnTop)
setAlwaysOnTop
in interface Annotation
public void setAttributes(AnnotationAttributes attributes)
setAttributes
in interface Annotation
public void setDelegateOwner(Object delegateOwner)
setDelegateOwner
in interface Annotation
public void setLayout(AnnotationLayoutManager layoutManager)
setLayout
in interface Annotation
public void setMaxActiveAltitude(double maxActiveAltitude)
Annotation
setMaxActiveAltitude
in interface Annotation
maxActiveAltitude
- the maximum altitude, in meters, for which the annotation is displayed.Annotation.getMaxActiveAltitude()
,
Annotation.setMinActiveAltitude(double)
public void setMinActiveAltitude(double minActiveAltitude)
Annotation
setMinActiveAltitude
in interface Annotation
minActiveAltitude
- the minimum altitude, in meters, for which the annotation is displayed.Annotation.getMinActiveAltitude()
,
Annotation.setMaxActiveAltitude(double)
public void setPickEnabled(boolean enable)
setPickEnabled
in interface Annotation
public void setPickSupport(PickSupport pickSupport)
setPickSupport
in interface Annotation
public void setText(String text)
setText
in interface Annotation
protected void transformBackgroundImageCoordsToAnnotationCoords(DrawContext dc, int width, int height, WWTexture texture)
(0, 0)
maps to the image's upper left corner, and (imageWidth,
imageHeight)
maps to the image's lower right corner. In Annotation geometry coordinates (0,
0)
maps to the Annotation geometry's lower left corner (ignoring any leader geometry), and (width,
height)
maps to the Annotation's upper right corner in window coordinates (screen pixels). This assumes
the current OGL matrix mode is GL_TEXTURE
.dc
- the DrawContext to receive the texture coordinate transform.width
- the Annotation's width, in window coordinates (screen pixels).height
- the Annotation's height, in window coordinates (screen pixels).texture
- the texture to transform from Annotation background image coordinates to Annotation geometry
coordinates.protected Rectangle transformByModelview(DrawContext dc, Rectangle rectangle)
protected void transformImageCoordsToBackgroundImageCoords(DrawContext dc, WWTexture texture)
(0, 0)
maps to the image's lower left corner, and (1, 1)
maps to the image's upper right corner. In Annotation background image coordinates (0, 0)
maps to
the image's upper left corner, and (imageWidth, imageHeight)
maps to the image's lower right corner.
This assumes the current OGL matrix mode is GL_TEXTURE
.dc
- the DrawContext to receive the texture coordinate transform.texture
- the texture to transform from standard GL image coordinates to Annotation background image
coordinates.protected String wrapText(DrawContext dc, int width, int height, String text, Font font, String align)