Class SurfaceText
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.render.AbstractSurfaceObject
-
- gov.nasa.worldwind.render.SurfaceText
-
- All Implemented Interfaces:
AVList
,Draggable
,MessageListener
,Movable
,GeographicText
,OrderedRenderable
,PreRenderable
,Renderable
,SurfaceObject
,SurfaceRenderable
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
public class SurfaceText extends AbstractSurfaceObject implements GeographicText, Movable, Draggable
Renders a string of text on the surface of the globe. The text will appear draped over terrain. Surface text is drawn at a constant geographic size: it will appear larger when the view zooms in on the text and smaller when the view zooms out.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class gov.nasa.worldwind.render.AbstractSurfaceObject
AbstractSurfaceObject.CacheEntry, AbstractSurfaceObject.SurfaceObjectStateKey
-
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.Color
bgColor
Background color for the text.protected java.awt.Color
color
Color to use to draw the text.static java.awt.Color
DEFAULT_COLOR
Default text color.static java.awt.Font
DEFAULT_FONT
Default font.static Offset
DEFAULT_OFFSET
Default offset.static double
DEFAULT_TEXT_SIZE_IN_METERS
Default text size.protected boolean
dragEnabled
Dragging Supportprotected DraggableSupport
draggableSupport
protected LatLon
drawLocation
The lower-left location of the text box after applying offset.protected java.awt.Font
font
Font to use to draw the text.protected Position
location
Location at which to draw the text.protected Offset
offset
Offset that specifies where to place the text in relation to it's geographic position.protected double
pixelSizeInMeters
Geographic size of a pixel.protected double
priority
Text priority.protected double
scale
Scaling factor applied to the text to maintain a constant geographic size.protected boolean
spansAntimeridian
Indicates whether this text spans the dateline.protected java.lang.CharSequence
text
The text to draw.protected java.awt.geom.Rectangle2D
textBounds
Bounds of the text in pixels.protected double
textSizeInMeters
The height of the text in meters.-
Fields inherited from class gov.nasa.worldwind.render.AbstractSurfaceObject
delegateOwner, drawBoundingSectors, enableBatchPicking, extentCache, lastModifiedTime, nextUniqueId, pickLayer, pickSupport, pickTileBuilder, uniqueId, visible
-
-
Constructor Summary
Constructors Constructor Description SurfaceText(java.lang.String text, Position position)
Create a new surface text object.SurfaceText(java.lang.String text, Position position, java.awt.Font font, java.awt.Color color)
Create a new surface text object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyDrawTransform(DrawContext dc, SurfaceTileDrawContext sdc)
Apply a transform to the GL state to draw the text at the proper location and scale.protected java.awt.Color
computeBackgroundColor(java.awt.Color color)
Compute a background color that contrasts with the text color.protected void
computeGeometry(DrawContext dc, SurfaceTileDrawContext sdc)
Compute the text size and position.protected double
computePixelSize(DrawContext dc, SurfaceTileDrawContext sdc)
Compute the size of a pixel in the surface tile.protected Sector[]
computeSector(DrawContext dc)
Compute the sector covered by this surface text.protected java.awt.Color
determineBackgroundColor(java.awt.Color color)
Determine the text background color.protected void
doDrag(DragContext dragContext)
void
drag(DragContext dragContext)
Drag the object given the providedDragContext
.protected void
drawGeographic(DrawContext dc, SurfaceTileDrawContext sdc)
Causes the SurfaceObject to render itself to the specified region in geographic coordinates.protected void
drawText(DrawContext dc)
Draw the text.java.awt.Color
getBackgroundColor()
Indicates the background color used to draw the text.java.awt.Color
getColor()
Indicates the color used to draw the text.java.awt.Font
getFont()
Indicates the font used to draw the text.Offset
getOffset()
Returns the text offset.Position
getPosition()
Indicates the geographic position of the text.double
getPriority()
Indicates the text priority.Position
getReferencePosition()
A position associated with the object that indicates its aggregate geographic position.java.util.List<Sector>
getSectors(DrawContext dc)
Returns a list of sectors indicating the geographic region that bounds this renderable for the specified draw context.java.lang.CharSequence
getText()
Indicates the text contained in this object.protected TextRenderer
getTextRenderer(DrawContext dc)
Get the text renderer to use to draw text.double
getTextSize()
boolean
isDragEnabled()
Indicates whether the object is enabled for dragging.protected boolean
isSmall()
Determine if the text is too small to draw.void
move(Position position)
Shift the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.void
moveTo(Position position)
Move the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.void
preRender(DrawContext dc)
Causes the surface object to prepare a representation of itself which can be drawn on the surface terrain, using the provided draw context.void
setBackgroundColor(java.awt.Color background)
Specifies the background color used to draw the text.void
setColor(java.awt.Color color)
Specifies the color used to draw the text.void
setDragEnabled(boolean enabled)
Controls whether the object is enabled for dragging.void
setFont(java.awt.Font font)
Specifies the font used to draw the text.void
setOffset(Offset offset)
Specifies a location relative to the label position at which to align the label.void
setPosition(Position position)
Specifies the geographic position of the text.void
setPriority(double priority)
Specifies the text priority.void
setText(java.lang.CharSequence text)
Specifies the text.void
setTextSize(double meters)
protected void
updateTextBounds(DrawContext dc)
Determine the text bounds.-
Methods inherited from class gov.nasa.worldwind.render.AbstractSurfaceObject
buildPickRepresentation, clearCaches, computeExtent, computeExtent, createPickedObject, createPickTileBuilder, drawBoundingSectors, drawOrderedRenderable, drawPickRepresentation, getDelegateOwner, getDistanceFromEye, getExtent, getStateKey, getUniqueId, intersectsFrustum, intersectsPickFrustum, intersectsVisibleSector, isDrawBoundingSectors, isEnableBatchPicking, isVisible, makeOrderedPreRenderable, makeOrderedRenderable, nextUniqueId, onShapeChanged, pick, pickBatched, pickOrderedRenderable, render, setDelegateOwner, setDrawBoundingSectors, setEnableBatchPicking, setVisible, updateModifiedTime
-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.render.GeographicText
isVisible, setVisible
-
-
-
-
Field Detail
-
DEFAULT_TEXT_SIZE_IN_METERS
public static final double DEFAULT_TEXT_SIZE_IN_METERS
Default text size.- See Also:
- Constant Field Values
-
DEFAULT_FONT
public static final java.awt.Font DEFAULT_FONT
Default font.
-
DEFAULT_COLOR
public static final java.awt.Color DEFAULT_COLOR
Default text color.
-
DEFAULT_OFFSET
public static final Offset DEFAULT_OFFSET
Default offset. The default offset centers the text on its geographic position both horizontally and vertically.
-
text
protected java.lang.CharSequence text
The text to draw.
-
location
protected Position location
Location at which to draw the text.
-
textSizeInMeters
protected double textSizeInMeters
The height of the text in meters.
-
dragEnabled
protected boolean dragEnabled
Dragging Support
-
draggableSupport
protected DraggableSupport draggableSupport
-
font
protected java.awt.Font font
Font to use to draw the text. Defaults toDEFAULT_FONT
.
-
color
protected java.awt.Color color
Color to use to draw the text. Defaults toDEFAULT_COLOR
.
-
bgColor
protected java.awt.Color bgColor
Background color for the text. By default color will be generated to contrast with the text color.
-
priority
protected double priority
Text priority. Can be used to implement text culling.
-
offset
protected Offset offset
Offset that specifies where to place the text in relation to it's geographic position.
-
textBounds
protected java.awt.geom.Rectangle2D textBounds
Bounds of the text in pixels.
-
pixelSizeInMeters
protected double pixelSizeInMeters
Geographic size of a pixel.
-
scale
protected double scale
Scaling factor applied to the text to maintain a constant geographic size.
-
drawLocation
protected LatLon drawLocation
The lower-left location of the text box after applying offset.
-
spansAntimeridian
protected boolean spansAntimeridian
Indicates whether this text spans the dateline.
-
-
Constructor Detail
-
SurfaceText
public SurfaceText(java.lang.String text, Position position)
Create a new surface text object.- Parameters:
text
- Text to draw.position
- Geographic location at which to draw the text.
-
SurfaceText
public SurfaceText(java.lang.String text, Position position, java.awt.Font font, java.awt.Color color)
Create a new surface text object.- Parameters:
text
- Text to draw.position
- Geographic location at which to draw the text.font
- Font to use when drawing text.color
- Color to use when drawing text.
-
-
Method Detail
-
getText
public java.lang.CharSequence getText()
Indicates the text contained in this object.- Specified by:
getText
in interfaceGeographicText
- Returns:
- The current text.
-
setText
public void setText(java.lang.CharSequence text)
Specifies the text.- Specified by:
setText
in interfaceGeographicText
- Parameters:
text
- New text.
-
getPosition
public Position getPosition()
Indicates the geographic position of the text.- Specified by:
getPosition
in interfaceGeographicText
- Returns:
- The text position.
-
setPosition
public void setPosition(Position position)
Specifies the geographic position of the text.The offset determines how the text is placed relative to this position. The default offset centers the text on the position both horizontally and vertically.
- Specified by:
setPosition
in interfaceGeographicText
- Parameters:
position
- New text position.- See Also:
setOffset(Offset)
-
getFont
public java.awt.Font getFont()
Indicates the font used to draw the text.- Specified by:
getFont
in interfaceGeographicText
- Returns:
- Current font.
-
setFont
public void setFont(java.awt.Font font)
Specifies the font used to draw the text.- Specified by:
setFont
in interfaceGeographicText
- Parameters:
font
- New font.
-
getColor
public java.awt.Color getColor()
Indicates the color used to draw the text.- Specified by:
getColor
in interfaceGeographicText
- Returns:
- Current text color.
-
setColor
public void setColor(java.awt.Color color)
Specifies the color used to draw the text.- Specified by:
setColor
in interfaceGeographicText
- Parameters:
color
- New color.
-
getBackgroundColor
public java.awt.Color getBackgroundColor()
Indicates the background color used to draw the text.- Specified by:
getBackgroundColor
in interfaceGeographicText
- Returns:
- Current background color.
-
setBackgroundColor
public void setBackgroundColor(java.awt.Color background)
Specifies the background color used to draw the text.- Specified by:
setBackgroundColor
in interfaceGeographicText
- Parameters:
background
- New background color.
-
setPriority
public void setPriority(double priority)
Specifies the text priority. The priority can be used to implement text culling.- Specified by:
setPriority
in interfaceGeographicText
- Parameters:
priority
- New priority.
-
getPriority
public double getPriority()
Indicates the text priority. The priority can be used to implement text culling.- Specified by:
getPriority
in interfaceGeographicText
- Returns:
- The text priority.
-
getOffset
public Offset getOffset()
Returns the text offset. The offset determines how to position the text relative to its geographic position.- Returns:
- the text offset.
- See Also:
setOffset(Offset)
-
setOffset
public void setOffset(Offset offset)
Specifies a location relative to the label position at which to align the label. The label text begins at the point indicated by the offset. An offset of (0, 0) aligns the left baseline of the text with the position. An offset of (-0.5, -0.5) fraction aligns the center of the text with the position.A pixel based offset is interpreted based on the geographic size of the text. For example, if the text rendered "normally" in two dimensions would be 20 pixels tall, and the geographic text is 100 meters tall, then each pixel of text corresponds to 5 meters. So an offset of 2 pixels would correspond to a geographic offset of 10 meters.
- Parameters:
offset
- Offset that controls where to position the label relative to its geographic location.
-
getTextSize
public double getTextSize()
-
setTextSize
public void setTextSize(double meters)
-
preRender
public void preRender(DrawContext dc)
Causes the surface object to prepare a representation of itself which can be drawn on the surface terrain, using the provided draw context.- Specified by:
preRender
in interfacePreRenderable
- Specified by:
preRender
in interfaceSurfaceObject
- Overrides:
preRender
in classAbstractSurfaceObject
- Parameters:
dc
- the current draw context.
-
getReferencePosition
public Position getReferencePosition()
A position associated with the object that indicates its aggregate geographic position. The chosen position varies among implementers of this interface. For objects defined by a list of positions, the reference position is typically the first position in the list. For symmetric objects the reference position is often the center of the object. In many cases the object's reference position may be explicitly specified by the application.- Specified by:
getReferencePosition
in interfaceMovable
- Returns:
- the object's reference position, or null if no reference position is available.
-
move
public void move(Position position)
Shift the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.
-
moveTo
public void moveTo(Position position)
Move the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.
-
isDragEnabled
public boolean isDragEnabled()
Description copied from interface:Draggable
Indicates whether the object is enabled for dragging.- Specified by:
isDragEnabled
in interfaceDraggable
- Returns:
- true if the object is enabled, else false.
-
setDragEnabled
public void setDragEnabled(boolean enabled)
Description copied from interface:Draggable
Controls whether the object is enabled for dragging.- Specified by:
setDragEnabled
in interfaceDraggable
- Parameters:
enabled
-true
if the object is enabled, elsefalse
.
-
drag
public void drag(DragContext dragContext)
Description copied from interface:Draggable
Drag the object given the providedDragContext
.- Specified by:
drag
in interfaceDraggable
- Parameters:
dragContext
- theDragContext
of this dragging event.
-
doDrag
protected void doDrag(DragContext dragContext)
-
getSectors
public java.util.List<Sector> getSectors(DrawContext dc)
Returns a list of sectors indicating the geographic region that bounds this renderable for the specified draw context.The returned list typically contains one sector that bounds this renderable in geographic coordinates. When this renderable spans the anti-meridian - the +/- 180 degree meridian - the returned list contains two sectors, one on either side of the anti-meridian.
- Specified by:
getSectors
in interfaceSurfaceRenderable
- Parameters:
dc
- the draw context for which to determine this renderable's geographic bounds.- Returns:
- a list of one or two sectors that bound this renderable.
-
drawGeographic
protected void drawGeographic(DrawContext dc, SurfaceTileDrawContext sdc)
Causes the SurfaceObject to render itself to the specified region in geographic coordinates. The specified viewport denotes the geographic region and its corresponding screen viewport.- Specified by:
drawGeographic
in classAbstractSurfaceObject
- Parameters:
dc
- the current draw context.sdc
- the context containing a geographic region and screen viewport corresponding to a surface tile.
-
drawText
protected void drawText(DrawContext dc)
Draw the text.- Parameters:
dc
- Current draw context.
-
computeGeometry
protected void computeGeometry(DrawContext dc, SurfaceTileDrawContext sdc)
Compute the text size and position.- Parameters:
dc
- Current draw context.sdc
- Current surface tile draw context.
-
applyDrawTransform
protected void applyDrawTransform(DrawContext dc, SurfaceTileDrawContext sdc)
Apply a transform to the GL state to draw the text at the proper location and scale.- Parameters:
dc
- Current draw context.sdc
- Current surface tile draw context.
-
isSmall
protected boolean isSmall()
Determine if the text is too small to draw.- Returns:
true
if the height of the text is less than one pixel.
-
computePixelSize
protected double computePixelSize(DrawContext dc, SurfaceTileDrawContext sdc)
Compute the size of a pixel in the surface tile.- Parameters:
dc
- Current draw context.sdc
- Current surface tile draw context.- Returns:
- The size of a tile pixel in meters.
-
determineBackgroundColor
protected java.awt.Color determineBackgroundColor(java.awt.Color color)
Determine the text background color. This method returns the user specified background color, or a computed default color if the user has not set a background color.- Parameters:
color
- text color.- Returns:
- the user specified background color, or a default color that contrasts with the text color.
-
computeBackgroundColor
protected java.awt.Color computeBackgroundColor(java.awt.Color color)
Compute a background color that contrasts with the text color.- Parameters:
color
- text color.- Returns:
- a color that contrasts with the text color.
-
computeSector
protected Sector[] computeSector(DrawContext dc)
Compute the sector covered by this surface text.- Parameters:
dc
- Current draw context.- Returns:
- The sector covered by the surface text.
-
getTextRenderer
protected TextRenderer getTextRenderer(DrawContext dc)
Get the text renderer to use to draw text.- Parameters:
dc
- Current draw context.- Returns:
- The text renderer that will be used to draw the surface text.
-
updateTextBounds
protected void updateTextBounds(DrawContext dc)
Determine the text bounds.- Parameters:
dc
- Current draw context.
-
-