public abstract class KMLAbstractBalloon extends java.lang.Object implements Balloon, WebResourceResolver, java.beans.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 java.lang.String |
DISPLAY_MODE_DEFAULT |
static java.lang.String |
DISPLAY_MODE_HIDE |
protected java.lang.String |
displayMode |
protected boolean |
highlightAttributesResolved |
protected java.lang.String |
highlightText
Text when balloon is highlighted.
|
protected boolean |
normalAttributesResolved |
protected java.lang.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 java.lang.String |
addHyperlinks(java.lang.String text)
Add hyperlink tags to URLs in the balloon text.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds the specified all-property property change listener that will be called for all list changes.
|
void |
addPropertyChangeListener(java.lang.String propertyName,
java.beans.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 java.lang.String |
createDefaultBalloonText()
Build a default balloon text string for the feature.
|
protected void |
createDefaultExtendedDataText(java.lang.StringBuilder sb,
java.util.List<KMLData> data)
Build a default balloon text string for the feature's extended data.
|
protected void |
createDefaultSchemaDataText(java.lang.StringBuilder sb,
java.util.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(java.beans.PropertyChangeEvent propertyChangeEvent)
Calls all registered property change listeners with the specified property change event.
|
void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.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.
|
java.awt.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. |
java.lang.Object |
getDelegateOwner()
Returns the delegate owner of the balloon.
|
java.lang.String |
getDisplayMode()
Get the balloon display mode, either
DISPLAY_MODE_DEFAULT or DISPLAY_MODE_HIDE . |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.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.
|
java.lang.String |
getStringValue(java.lang.String key)
Returns the value for a specified key.
|
java.lang.String |
getText()
Get the balloon text.
|
TextDecoder |
getTextDecoder()
Get the text decoder that will process the balloon text.
|
java.lang.Object |
getValue(java.lang.String key)
Returns the value for a specified key.
|
java.util.Collection<java.lang.Object> |
getValues()
.
|
boolean |
hasKey(java.lang.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(java.lang.String attrType)
Update the balloon attributes to match the KML BalloonStyle.
|
protected boolean |
mustAddHyperlinks(java.lang.String text)
Determines if URLs in the balloon text should be converted to hyperlinks.
|
void |
propertyChange(java.beans.PropertyChangeEvent evt)
Forward property change events to the parent KMLRoot.
|
java.lang.Object |
removeKey(java.lang.String key)
Removes a specified key from the collection if the key exists, otherwise returns without affecting the
collection.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the specified all-property property change listener.
|
void |
removePropertyChangeListener(java.lang.String propertyName,
java.beans.PropertyChangeListener listener)
Removes a property change listener associated with the specified key.
|
void |
render(DrawContext dc)
Render the balloon.
|
java.net.URL |
resolve(java.lang.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(java.lang.Object owner)
Specifies the delegate owner of the balloon.
|
void |
setDisplayMode(java.lang.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(java.lang.String text)
Set the balloon text.
|
void |
setTextDecoder(TextDecoder decoder)
Set a text decoder to process the balloon text.
|
java.lang.Object |
setValue(java.lang.String key,
java.lang.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 java.lang.String DISPLAY_MODE_DEFAULT
public static final java.lang.String DISPLAY_MODE_HIDE
protected java.lang.String displayMode
protected boolean highlightAttributesResolved
protected java.lang.String highlightText
protected boolean normalAttributesResolved
protected java.lang.String normalText
protected KMLAbstractFeature parent
protected boolean usingDefaultText
public KMLAbstractBalloon(KMLAbstractFeature feature)
feature
- Feature to create balloon annotation for.protected java.lang.String addHyperlinks(java.lang.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(java.beans.PropertyChangeListener listener)
addPropertyChangeListener
in interface AVList
listener
- the listener to call.PropertyChangeSupport
public void addPropertyChangeListener(java.lang.String propertyName, java.beans.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 java.lang.String createDefaultBalloonText()
protected void createDefaultExtendedDataText(java.lang.StringBuilder sb, java.util.List<KMLData> data)
sb
- Extended data string will be appended to this StringBuilder.data
- The feature's extended data.protected void createDefaultSchemaDataText(java.lang.StringBuilder sb, java.util.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(java.beans.PropertyChangeEvent propertyChangeEvent)
firePropertyChange
in interface AVList
propertyChangeEvent
- the eventPropertyChangeSupport
public void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.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 java.awt.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 java.lang.Object getDelegateOwner()
getDelegateOwner
in interface Balloon
public java.lang.String getDisplayMode()
DISPLAY_MODE_DEFAULT
or DISPLAY_MODE_HIDE
.setDisplayMode(String)
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.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 java.lang.String getStringValue(java.lang.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 java.lang.String getText()
getText
in interface Balloon
Balloon.getTextDecoder()
,
Balloon.setTextDecoder(gov.nasa.worldwind.util.TextDecoder)
public TextDecoder getTextDecoder()
getTextDecoder
in interface Balloon
public java.lang.Object getValue(java.lang.String key)
public java.util.Collection<java.lang.Object> getValues()
public boolean hasKey(java.lang.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(java.lang.String attrType)
attrType
- Type of attributes to update. Either KMLConstants.NORMAL
or KMLConstants.HIGHLIGHT
.protected boolean mustAddHyperlinks(java.lang.String text)
text
- Balloon text to process.public void propertyChange(java.beans.PropertyChangeEvent evt)
propertyChange
in interface java.beans.PropertyChangeListener
evt
- Event to forward.public java.lang.Object removeKey(java.lang.String key)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
removePropertyChangeListener
in interface AVList
listener
- the listener to remove.PropertyChangeSupport
public void removePropertyChangeListener(java.lang.String propertyName, java.beans.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 java.net.URL resolve(java.lang.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(java.lang.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(java.lang.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(java.lang.String text)
public void setTextDecoder(TextDecoder decoder)
setTextDecoder
in interface Balloon
decoder
- New decoder.public java.lang.Object setValue(java.lang.String key, java.lang.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.