public abstract class KMLAbstractBalloon extends Object implements Balloon, WebResourceResolver, PropertyChangeListener
Balloon
that applies a KMLBalloonStyle
to the balloon. Rather than fully
implementing the Balloon interface, this class provides a thin wrapper around another Balloon implementation and adds
the logic for styling the Balloon according to the KML style. All Balloon methods on this class pass through to the
contained Balloon.
To use KML Balloon, first create a Balloon of the desired type, and then create the KML Balloon. For example:
KMLPlacemark myPlacemark = ...;
Position placemarkPosition = ...;
// Create a BrowserBalloon for the placemark.
GlobeBalloon globeBalloon = new GlobeBrowserBalloon(myPlacemark.getName(), placemarkPosition);
// Create a KML Balloon to apply the placemark's KML BalloonStyle to the browser balloon.
KMLGlobeBalloonImpl kmlBalloon = new KMLGlobeBalloonImpl(globeBalloon, myPlacemark);
Modifier and Type | Field and Description |
---|---|
static String |
DISPLAY_MODE_DEFAULT |
static String |
DISPLAY_MODE_HIDE |
protected String |
displayMode |
protected boolean |
highlightAttributesResolved |
protected String |
highlightText
Text when balloon is highlighted.
|
protected boolean |
normalAttributesResolved |
protected String |
normalText
Text when balloon is not highlighted.
|
protected KMLAbstractFeature |
parent |
protected boolean |
usingDefaultText
Indicates that the balloon has default text loaded, rather than text supplied by the BalloonStyle.
|
Constructor and Description |
---|
KMLAbstractBalloon(KMLAbstractFeature feature)
Create a globe attached Balloon Impl object for a KML feature.
|
Modifier and Type | Method and Description |
---|---|
protected String |
addHyperlinks(String text)
Add hyperlink tags to URLs in the balloon text.
|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds the specified all-property property change listener that will be called for all list changes.
|
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds a property change listener for the specified key.
|
protected void |
assembleBalloonAttributes(KMLBalloonStyle style,
BalloonAttributes balloonAttributes)
Apply a KML BalloonStyle to the balloon attributes object.
|
AVList |
clearList()
.
|
AVList |
copy()
Returns a shallow copy of this
AVList instance: the keys and values themselves are not cloned. |
protected String |
createDefaultBalloonText()
Build a default balloon text string for the feature.
|
protected void |
createDefaultExtendedDataText(StringBuilder sb,
List<KMLData> data)
Build a default balloon text string for the feature's extended data.
|
protected void |
createDefaultSchemaDataText(StringBuilder sb,
List<KMLSchemaData> data)
Build a default balloon text string for the feature's schema data.
|
protected TextDecoder |
createTextDecoder(KMLAbstractFeature feature)
Create the text decoder that will process the text in the balloon.
|
protected void |
determineActiveText()
Determine the balloon text for this frame, depending on the balloon highlight state.
|
void |
firePropertyChange(PropertyChangeEvent propertyChangeEvent)
Calls all registered property change listeners with the specified property change event.
|
void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Calls all property change listeners associated with the specified key.
|
BalloonAttributes |
getAttributes()
Get the "normal" balloon attributes.
|
protected abstract Balloon |
getBalloon()
Get the Balloon object that is contained in the KMLBalloon object.
|
Rectangle |
getBounds(DrawContext dc)
Get the balloon bounding
Rectangle using OGL coordinates - bottom-left corner x and y relative
to the WorldWindow bottom-left corner, and the balloon callout width and height. |
Object |
getDelegateOwner()
Returns the delegate owner of the balloon.
|
String |
getDisplayMode()
Get the balloon display mode, either
DISPLAY_MODE_DEFAULT or DISPLAY_MODE_HIDE . |
Set<Map.Entry<String,Object>> |
getEntries()
.
|
BalloonAttributes |
getHighlightAttributes()
Get the highlight attributes.
|
protected BalloonAttributes |
getInitialBalloonAttributes()
Get the default attributes applied to the balloon.
|
double |
getMaxActiveAltitude()
Returns the maximum eye altitude, in meters, for which the balloon is displayed.
|
double |
getMinActiveAltitude()
Returns the minimum eye altitude, in meters, for which the balloon is displayed.
|
String |
getStringValue(String key)
Returns the value for a specified key.
|
String |
getText()
Get the balloon text.
|
TextDecoder |
getTextDecoder()
Get the text decoder that will process the balloon text.
|
Object |
getValue(String key)
Returns the value for a specified key.
|
Collection<Object> |
getValues()
.
|
boolean |
hasKey(String key)
Indicates whether a key is in the collection.
|
protected void |
initialize(Balloon balloon)
Initialize the object.
|
boolean |
isAlwaysOnTop()
Is the balloon always on top?
|
boolean |
isHighlighted()
Indicates whether to highlight the shape.
|
boolean |
isPickEnabled()
Is the balloon enabled for picking?
|
boolean |
isVisible()
Get whether the annotation is visible and should be rendered.
|
protected void |
makeAttributesCurrent(String attrType)
Update the balloon attributes to match the KML BalloonStyle.
|
protected boolean |
mustAddHyperlinks(String text)
Determines if URLs in the balloon text should be converted to hyperlinks.
|
void |
propertyChange(PropertyChangeEvent evt)
Forward property change events to the parent KMLRoot.
|
Object |
removeKey(String key)
Removes a specified key from the collection if the key exists, otherwise returns without affecting the
collection.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes the specified all-property property change listener.
|
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Removes a property change listener associated with the specified key.
|
void |
render(DrawContext dc)
Render the balloon.
|
URL |
resolve(String address)
This implementation resolves relative resource paths by calling
on the parent
KMLAbstractFeature's KMLDoc . |
void |
setAlwaysOnTop(boolean alwaysOnTop)
Set the balloon to always on top or not.
|
void |
setAttributes(BalloonAttributes attrs)
Set the "normal" balloon attributes.
|
void |
setDelegateOwner(Object owner)
Specifies the delegate owner of the balloon.
|
void |
setDisplayMode(String displayMode)
Set the balloon's display mode, either
DISPLAY_MODE_DEFAULT or DISPLAY_MODE_HIDE . |
void |
setHighlightAttributes(BalloonAttributes attrs)
Set the highlight attributes.
|
void |
setHighlighted(boolean highlighted)
Specifies whether to highlight the shape.
|
void |
setMaxActiveAltitude(double maxActiveAltitude)
Specifies the maximum eye altitude, in meters, for which the balloon is displayed.
|
void |
setMinActiveAltitude(double minActiveAltitude)
Specifies the minimum eye altitude, in meters, for which the balloon is displayed.
|
void |
setPickEnabled(boolean enable)
Set the balloon to be pick enabled or not.
|
void |
setText(String text)
Set the balloon text.
|
void |
setTextDecoder(TextDecoder decoder)
Set a text decoder to process the balloon text.
|
Object |
setValue(String key,
Object value)
Adds a key/value pair to the list.
|
AVList |
setValues(AVList avList)
Adds the contents of another attribute-value list to the list.
|
void |
setVisible(boolean visible)
Set whether the balloon is visible and should be rendered.
|
public static final String DISPLAY_MODE_DEFAULT
public static final String DISPLAY_MODE_HIDE
protected String displayMode
protected boolean highlightAttributesResolved
protected String highlightText
protected boolean normalAttributesResolved
protected String normalText
protected KMLAbstractFeature parent
protected boolean usingDefaultText
public KMLAbstractBalloon(KMLAbstractFeature feature)
feature
- Feature to create balloon annotation for.protected String addHyperlinks(String text)
text
- Text to process. Each URL in the text will be replaced with <a href="url" target="_blank"> url
</a>public void addPropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener
in interface AVList
listener
- the listener to call.PropertyChangeSupport
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
addPropertyChangeListener
in interface AVList
propertyName
- the key to associate the listener with.listener
- the listener to associate with the key.PropertyChangeSupport
protected void assembleBalloonAttributes(KMLBalloonStyle style, BalloonAttributes balloonAttributes)
style
- KML style to apply.balloonAttributes
- Attributes to modify.public AVList clearList()
public AVList copy()
AVList
instance: the keys and values themselves are not cloned.. This method passes through to the contained balloon.protected String createDefaultBalloonText()
protected void createDefaultExtendedDataText(StringBuilder sb, List<KMLData> data)
sb
- Extended data string will be appended to this StringBuilder.data
- The feature's extended data.protected void createDefaultSchemaDataText(StringBuilder sb, List<KMLSchemaData> data)
sb
- Extended data string will be appended to this StringBuilder.data
- The feature's schema data.protected TextDecoder createTextDecoder(KMLAbstractFeature feature)
feature
- Feature to decode text for.protected void determineActiveText()
public void firePropertyChange(PropertyChangeEvent propertyChangeEvent)
firePropertyChange
in interface AVList
propertyChangeEvent
- the eventPropertyChangeSupport
public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
odValue
and newValue
are equal and non-null.. This method passes through to the contained balloon.firePropertyChange
in interface AVList
propertyName
- the keyoldValue
- the value associated with the key before the even causing the firing.newValue
- the new value associated with the key.PropertyChangeSupport
public BalloonAttributes getAttributes()
getAttributes
in interface Balloon
protected abstract Balloon getBalloon()
public Rectangle getBounds(DrawContext dc)
Rectangle
using OGL coordinates - bottom-left corner x and y relative
to the WorldWindow
bottom-left corner, and the balloon callout width and height.
The balloon offset from it's reference point is factored in such that the callout leader shape and reference
point are included in the bounding rectangle.. This method passes through to the contained balloon.public Object getDelegateOwner()
getDelegateOwner
in interface Balloon
public String getDisplayMode()
DISPLAY_MODE_DEFAULT
or DISPLAY_MODE_HIDE
.setDisplayMode(String)
public Set<Map.Entry<String,Object>> getEntries()
getEntries
in interface AVList
public BalloonAttributes getHighlightAttributes()
getHighlightAttributes
in interface Balloon
protected BalloonAttributes getInitialBalloonAttributes()
assembleBalloonAttributes
to reflect the settings in the KML BalloonStyle.public double getMaxActiveAltitude()
getMaxActiveAltitude
in interface Balloon
Balloon.setMaxActiveAltitude(double)
,
Balloon.getMinActiveAltitude()
public double getMinActiveAltitude()
getMinActiveAltitude
in interface Balloon
Balloon.setMinActiveAltitude(double)
,
Balloon.getMaxActiveAltitude()
public String getStringValue(String key)
String
.. This method passes through to the contained balloon.getStringValue
in interface AVList
key
- the attribute name. May not be null
.null
.public String getText()
getText
in interface Balloon
Balloon.getTextDecoder()
,
Balloon.setTextDecoder(gov.nasa.worldwind.util.TextDecoder)
public TextDecoder getTextDecoder()
getTextDecoder
in interface Balloon
public Object getValue(String key)
public Collection<Object> getValues()
public boolean hasKey(String key)
protected void initialize(Balloon balloon)
balloon
- The balloon contained in this wrapper object.public boolean isAlwaysOnTop()
isAlwaysOnTop
in interface Balloon
public boolean isHighlighted()
isHighlighted
in interface Highlightable
public boolean isPickEnabled()
isPickEnabled
in interface Balloon
public boolean isVisible()
protected void makeAttributesCurrent(String attrType)
attrType
- Type of attributes to update. Either KMLConstants.NORMAL
or KMLConstants.HIGHLIGHT
.protected boolean mustAddHyperlinks(String text)
text
- Balloon text to process.public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
evt
- Event to forward.public Object removeKey(String key)
public void removePropertyChangeListener(PropertyChangeListener listener)
removePropertyChangeListener
in interface AVList
listener
- the listener to remove.PropertyChangeSupport
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
removePropertyChangeListener
in interface AVList
propertyName
- the key associated with the change listener.listener
- the listener to remove.PropertyChangeSupport
public void render(DrawContext dc)
render
in interface Renderable
dc
- Draw contextDrawContext
public URL resolve(String address)
KMLDoc.getSupportFilePath(String)
on the parent
KMLAbstractFeature's
KMLDoc
. This is necessary to correctly resolve relative references
in a KMZ archive.
This returns null
if the specified address
is null
.resolve
in interface WebResourceResolver
public void setAlwaysOnTop(boolean alwaysOnTop)
setAlwaysOnTop
in interface Balloon
alwaysOnTop
- True if the balloon should always render above other objects.public void setAttributes(BalloonAttributes attrs)
setAttributes
in interface Balloon
attrs
- New attributespublic void setDelegateOwner(Object owner)
setDelegateOwner
in interface Balloon
owner
- the object to use as the pickable object returned during picking, or null to return the balloon.public void setDisplayMode(String displayMode)
DISPLAY_MODE_DEFAULT
or DISPLAY_MODE_HIDE
. When the mode
is DISPLAY_MODE_HIDE
, the balloon will not be drawn.displayMode
- New display mode.getDisplayMode()
public void setHighlightAttributes(BalloonAttributes attrs)
setHighlightAttributes
in interface Balloon
attrs
- Attributes to use when the balloon is highlighted.public void setHighlighted(boolean highlighted)
setHighlighted
in interface Highlightable
highlighted
- true to highlight the shape, otherwise false.public void setMaxActiveAltitude(double maxActiveAltitude)
setMaxActiveAltitude
in interface Balloon
maxActiveAltitude
- the maximum altitude, in meters, for which the balloon is displayed.Balloon.getMaxActiveAltitude()
,
Balloon.setMinActiveAltitude(double)
public void setMinActiveAltitude(double minActiveAltitude)
setMinActiveAltitude
in interface Balloon
minActiveAltitude
- the minimum altitude, in meters, for which the balloon is displayed.Balloon.getMinActiveAltitude()
,
Balloon.setMaxActiveAltitude(double)
public void setPickEnabled(boolean enable)
setPickEnabled
in interface Balloon
enable
- True if the balloon can be picked, false if not.public void setText(String text)
public void setTextDecoder(TextDecoder decoder)
setTextDecoder
in interface Balloon
decoder
- New decoder.public Object setValue(String key, Object value)
setValue
in interface AVList
key
- the attribute name. May not be null
.value
- the attribute value. May be null
, in which case any existing value for the key is
removed from the collection.public AVList setValues(AVList avList)
public void setVisible(boolean visible)
setVisible
in interface Balloon
visible
- true if the balloon is visible and should be rendered.