NASA World Wind

gov.nasa.worldwind.ogc.kml.impl
Class KMLAbstractBalloon

java.lang.Object
  extended by gov.nasa.worldwind.ogc.kml.impl.KMLAbstractBalloon
All Implemented Interfaces:
AVList, Balloon, Highlightable, Renderable, WebResourceResolver, PropertyChangeListener, EventListener
Direct Known Subclasses:
KMLGlobeBalloonImpl, KMLScreenBalloonImpl

public abstract class KMLAbstractBalloon
extends Object
implements Balloon, WebResourceResolver, PropertyChangeListener

An implementation of 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);
 


Field Summary
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 Summary
KMLAbstractBalloon(KMLAbstractFeature feature)
          Create a globe attached Balloon Impl object for a KML feature.
 
Method Summary
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 KMLDoc.getSupportFilePath(String) 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISPLAY_MODE_DEFAULT

public static final String DISPLAY_MODE_DEFAULT
See Also:
Constant Field Values

DISPLAY_MODE_HIDE

public static final String DISPLAY_MODE_HIDE
See Also:
Constant Field Values

displayMode

protected String displayMode

highlightAttributesResolved

protected boolean highlightAttributesResolved

highlightText

protected String highlightText
Text when balloon is highlighted.


normalAttributesResolved

protected boolean normalAttributesResolved

normalText

protected String normalText
Text when balloon is not highlighted.


parent

protected KMLAbstractFeature parent

usingDefaultText

protected boolean usingDefaultText
Indicates that the balloon has default text loaded, rather than text supplied by the BalloonStyle.

Constructor Detail

KMLAbstractBalloon

public KMLAbstractBalloon(KMLAbstractFeature feature)
Create a globe attached Balloon Impl object for a KML feature.

Parameters:
feature - Feature to create balloon annotation for.
Method Detail

addHyperlinks

protected String addHyperlinks(String text)
Add hyperlink tags to URLs in the balloon text. The text may include some simple HTML markup. This method attempts to identify URLs in the text while not altering URLs that are already linked.

This method is conservative about what is identified as a URL, in order to avoid adding links to text that the user did not intend to be linked. Only HTTP and HTTPS URLs are recognised, as well as text that begins with www. (in which case a http:// prefix will be prepended). Some punctuation characters that are valid URL characters (such as parentheses) are not treated as URL characters here because users may expect the punctuation to separate the URL from text.

Parameters:
text - Text to process. Each URL in the text will be replaced with <a href="url" target="_blank"> url </a>
Returns:
Text with hyperlinks added.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds the specified all-property property change listener that will be called for all list changes.. This method passes through to the contained balloon.

Specified by:
addPropertyChangeListener in interface AVList
Parameters:
listener - the listener to call.
See Also:
PropertyChangeSupport

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Adds a property change listener for the specified key.. This method passes through to the contained balloon.

Specified by:
addPropertyChangeListener in interface AVList
Parameters:
propertyName - the key to associate the listener with.
listener - the listener to associate with the key.
See Also:
PropertyChangeSupport

assembleBalloonAttributes

protected void assembleBalloonAttributes(KMLBalloonStyle style,
                                         BalloonAttributes balloonAttributes)
Apply a KML BalloonStyle to the balloon attributes object.

Parameters:
style - KML style to apply.
balloonAttributes - Attributes to modify.

clearList

public AVList clearList()
. This method passes through to the contained balloon.

Specified by:
clearList in interface AVList

copy

public AVList copy()
Returns a shallow copy of this AVList instance: the keys and values themselves are not cloned.. This method passes through to the contained balloon.

Specified by:
copy in interface AVList
Returns:
a shallow copy of this AVList.

createDefaultBalloonText

protected String createDefaultBalloonText()
Build a default balloon text string for the feature.

Returns:
Default balloon text.

createDefaultExtendedDataText

protected void createDefaultExtendedDataText(StringBuilder sb,
                                             List<KMLData> data)
Build a default balloon text string for the feature's extended data. This implementation builds a simple data table.

Parameters:
sb - Extended data string will be appended to this StringBuilder.
data - The feature's extended data.

createDefaultSchemaDataText

protected void createDefaultSchemaDataText(StringBuilder sb,
                                           List<KMLSchemaData> data)
Build a default balloon text string for the feature's schema data. This implementation builds a simple data table.

Parameters:
sb - Extended data string will be appended to this StringBuilder.
data - The feature's schema data.

createTextDecoder

protected TextDecoder createTextDecoder(KMLAbstractFeature feature)
Create the text decoder that will process the text in the balloon.

Parameters:
feature - Feature to decode text for.
Returns:
New text decoder.

determineActiveText

protected void determineActiveText()
Determine the balloon text for this frame, depending on the balloon highlight state.


firePropertyChange

public void firePropertyChange(PropertyChangeEvent propertyChangeEvent)
Calls all registered property change listeners with the specified property change event.. This method passes through to the contained balloon.

Specified by:
firePropertyChange in interface AVList
Parameters:
propertyChangeEvent - the event
See Also:
PropertyChangeSupport

firePropertyChange

public void firePropertyChange(String propertyName,
                               Object oldValue,
                               Object newValue)
Calls all property change listeners associated with the specified key. No listeners are called if odValue and newValue are equal and non-null.. This method passes through to the contained balloon.

Specified by:
firePropertyChange in interface AVList
Parameters:
propertyName - the key
oldValue - the value associated with the key before the even causing the firing.
newValue - the new value associated with the key.
See Also:
PropertyChangeSupport

getAttributes

public BalloonAttributes getAttributes()
Get the "normal" balloon attributes.. This method passes through to the contained balloon.

Specified by:
getAttributes in interface Balloon
Returns:
Balloon attributes.

getBalloon

protected abstract Balloon getBalloon()
Get the Balloon object that is contained in the KMLBalloon object.

Returns:
The balloon contained by this object.

getBounds

public 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.

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.

Specified by:
getBounds in interface Balloon
Parameters:
dc - the current DrawContext.
Returns:
the balloon bounding Rectangle using OGL viewport coordinates.

getDelegateOwner

public Object getDelegateOwner()
Returns the delegate owner of the balloon. If non-null, the returned object replaces the balloon as the pickable object returned during picking. If null, the balloon itself is the pickable object returned during picking.. This method passes through to the contained balloon.

Specified by:
getDelegateOwner in interface Balloon
Returns:
the object used as the pickable object returned during picking, or null to indicate the the balloon is returned during picking.

getDisplayMode

public String getDisplayMode()
Get the balloon display mode, either DISPLAY_MODE_DEFAULT or DISPLAY_MODE_HIDE.

Returns:
The current display mode.
See Also:
setDisplayMode(String)

getEntries

public Set<Map.Entry<String,Object>> getEntries()
. This method passes through to the contained balloon.

Specified by:
getEntries in interface AVList

getHighlightAttributes

public BalloonAttributes getHighlightAttributes()
Get the highlight attributes.. This method passes through to the contained balloon.

Specified by:
getHighlightAttributes in interface Balloon
Returns:
Balloon's highlight attributes.

getInitialBalloonAttributes

protected BalloonAttributes getInitialBalloonAttributes()
Get the default attributes applied to the balloon. These attributes will be modified by assembleBalloonAttributes to reflect the settings in the KML BalloonStyle.

Returns:
Initial balloon attributes.

getMaxActiveAltitude

public double getMaxActiveAltitude()
Returns the maximum eye altitude, in meters, for which the balloon is displayed.. This method passes through to the contained balloon.

Specified by:
getMaxActiveAltitude in interface Balloon
Returns:
the maximum altitude, in meters, for which the balloon is displayed.
See Also:
Balloon.setMaxActiveAltitude(double), Balloon.getMinActiveAltitude()

getMinActiveAltitude

public double getMinActiveAltitude()
Returns the minimum eye altitude, in meters, for which the balloon is displayed.. This method passes through to the contained balloon.

Specified by:
getMinActiveAltitude in interface Balloon
Returns:
the minimum altitude, in meters, for which the balloon is displayed.
See Also:
Balloon.setMinActiveAltitude(double), Balloon.getMaxActiveAltitude()

getStringValue

public String getStringValue(String key)
Returns the value for a specified key. The value must be a String.. This method passes through to the contained balloon.

Specified by:
getStringValue in interface AVList
Parameters:
key - the attribute name. May not be null.
Returns:
the attribute value if one exists in the collection, otherwise null.

getText

public String getText()
Get the balloon text. The method returns the raw text, before decoding.. This method passes through to the contained balloon.

Specified by:
getText in interface Balloon
Returns:
The balloon text.
See Also:
Balloon.getTextDecoder(), Balloon.setTextDecoder(gov.nasa.worldwind.util.TextDecoder)

getTextDecoder

public TextDecoder getTextDecoder()
Get the text decoder that will process the balloon text.. This method passes through to the contained balloon.

Specified by:
getTextDecoder in interface Balloon
Returns:
Active text decoder.

getValue

public Object getValue(String key)
Returns the value for a specified key.. This method passes through to the contained balloon.

Specified by:
getValue in interface AVList
Parameters:
key - the attribute name. May not be null.
Returns:
the attribute value if one exists in the collection, otherwise null.

getValues

public Collection<Object> getValues()
. This method passes through to the contained balloon.

Specified by:
getValues in interface AVList

hasKey

public boolean hasKey(String key)
Indicates whether a key is in the collection.. This method passes through to the contained balloon.

Specified by:
hasKey in interface AVList
Parameters:
key - the attribute name. May not be null.
Returns:
true if the key exists in the collection, otherwise false.

initialize

protected void initialize(Balloon balloon)
Initialize the object.

Parameters:
balloon - The balloon contained in this wrapper object.

isAlwaysOnTop

public boolean isAlwaysOnTop()
Is the balloon always on top?. This method passes through to the contained balloon.

Specified by:
isAlwaysOnTop in interface Balloon
Returns:
True if the balloon will always render above other items.

isHighlighted

public boolean isHighlighted()
Indicates whether to highlight the shape.. This method passes through to the contained balloon.

Specified by:
isHighlighted in interface Highlightable
Returns:
true to highlight the shape, otherwise false.

isPickEnabled

public boolean isPickEnabled()
Is the balloon enabled for picking?. This method passes through to the contained balloon.

Specified by:
isPickEnabled in interface Balloon
Returns:
True if the balloon can be picked, false if not.

isVisible

public boolean isVisible()
Get whether the annotation is visible and should be rendered.. This method passes through to the contained balloon.

Specified by:
isVisible in interface Balloon
Returns:
true if the annotation is visible and should be rendered.

makeAttributesCurrent

protected void makeAttributesCurrent(String attrType)
Update the balloon attributes to match the KML BalloonStyle.

Parameters:
attrType - Type of attributes to update. Either KMLConstants.NORMAL or KMLConstants.HIGHLIGHT.

mustAddHyperlinks

protected boolean mustAddHyperlinks(String text)
Determines if URLs in the balloon text should be converted to hyperlinks. The Google KML specification states the GE will add hyperlinks to balloon text that does not contain HTML formatting. This method searches for a <html> tag in the content to determine if the content is HTML or plain text.

Parameters:
text - Balloon text to process.
Returns:
True if URLs should be converted links. Returns true if a <html> tag is found in the text.

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Forward property change events to the parent KMLRoot.

Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
evt - Event to forward.

removeKey

public Object removeKey(String key)
Removes a specified key from the collection if the key exists, otherwise returns without affecting the collection.. This method passes through to the contained balloon.

Specified by:
removeKey in interface AVList
Parameters:
key - the attribute name. May not be null.
Returns:
previous value associated with specified key, or null if there was no mapping for key.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes the specified all-property property change listener.. This method passes through to the contained balloon.

Specified by:
removePropertyChangeListener in interface AVList
Parameters:
listener - the listener to remove.
See Also:
PropertyChangeSupport

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Removes a property change listener associated with the specified key.. This method passes through to the contained balloon.

Specified by:
removePropertyChangeListener in interface AVList
Parameters:
propertyName - the key associated with the change listener.
listener - the listener to remove.
See Also:
PropertyChangeSupport

render

public void render(DrawContext dc)
Render the balloon. This method will attempt to resolve the balloon style, if it has not already been resolved.

Specified by:
render in interface Renderable
Parameters:
dc - Draw context
See Also:
DrawContext

resolve

public URL resolve(String address)

This implementation resolves relative resource paths by calling 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.

Specified by:
resolve in interface WebResourceResolver

setAlwaysOnTop

public void setAlwaysOnTop(boolean alwaysOnTop)
Set the balloon to always on top or not.. This method passes through to the contained balloon.

Specified by:
setAlwaysOnTop in interface Balloon
Parameters:
alwaysOnTop - True if the balloon should always render above other objects.

setAttributes

public void setAttributes(BalloonAttributes attrs)
Set the "normal" balloon attributes.. This method passes through to the contained balloon.

Specified by:
setAttributes in interface Balloon
Parameters:
attrs - New attributes

setDelegateOwner

public void setDelegateOwner(Object owner)
Specifies the delegate owner of the balloon. If non-null, the delegate owner replaces the balloon as the pickable object returned during picking. If null, the balloon itself is the pickable object returned during picking.. This method passes through to the contained balloon.

Specified by:
setDelegateOwner in interface Balloon
Parameters:
owner - the object to use as the pickable object returned during picking, or null to return the balloon.

setDisplayMode

public void setDisplayMode(String displayMode)
Set the balloon's display mode, either DISPLAY_MODE_DEFAULT or DISPLAY_MODE_HIDE. When the mode is DISPLAY_MODE_HIDE, the balloon will not be drawn.

Parameters:
displayMode - New display mode.
See Also:
getDisplayMode()

setHighlightAttributes

public void setHighlightAttributes(BalloonAttributes attrs)
Set the highlight attributes.. This method passes through to the contained balloon.

Specified by:
setHighlightAttributes in interface Balloon
Parameters:
attrs - Attributes to use when the balloon is highlighted.

setHighlighted

public void setHighlighted(boolean highlighted)
Specifies whether to highlight the shape.. This method passes through to the contained balloon.

Specified by:
setHighlighted in interface Highlightable
Parameters:
highlighted - true to highlight the shape, otherwise false.

setMaxActiveAltitude

public void setMaxActiveAltitude(double maxActiveAltitude)
Specifies the maximum eye altitude, in meters, for which the balloon is displayed.. This method passes through to the contained balloon.

Specified by:
setMaxActiveAltitude in interface Balloon
Parameters:
maxActiveAltitude - the maximum altitude, in meters, for which the balloon is displayed.
See Also:
Balloon.getMaxActiveAltitude(), Balloon.setMinActiveAltitude(double)

setMinActiveAltitude

public void setMinActiveAltitude(double minActiveAltitude)
Specifies the minimum eye altitude, in meters, for which the balloon is displayed.. This method passes through to the contained balloon.

Specified by:
setMinActiveAltitude in interface Balloon
Parameters:
minActiveAltitude - the minimum altitude, in meters, for which the balloon is displayed.
See Also:
Balloon.getMinActiveAltitude(), Balloon.setMaxActiveAltitude(double)

setPickEnabled

public void setPickEnabled(boolean enable)
Set the balloon to be pick enabled or not.. This method passes through to the contained balloon.

Specified by:
setPickEnabled in interface Balloon
Parameters:
enable - True if the balloon can be picked, false if not.

setText

public void setText(String text)
Set the balloon text.. This method passes through to the contained balloon.

Specified by:
setText in interface Balloon
Parameters:
text - New balloon text.

setTextDecoder

public void setTextDecoder(TextDecoder decoder)
Set a text decoder to process the balloon text.. This method passes through to the contained balloon.

Specified by:
setTextDecoder in interface Balloon
Parameters:
decoder - New decoder.

setValue

public Object setValue(String key,
                       Object value)
Adds a key/value pair to the list. Replaces an existing key/value pair if the list already contains the key.. This method passes through to the contained balloon.

Specified by:
setValue in interface AVList
Parameters:
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.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.

setValues

public AVList setValues(AVList avList)
Adds the contents of another attribute-value list to the list. Replaces an existing key/value pair if the list already contains the key.. This method passes through to the contained balloon.

Specified by:
setValues in interface AVList
Parameters:
avList - the list to copy. May not be null.
Returns:
this, a self reference.

setVisible

public void setVisible(boolean visible)
Set whether the balloon is visible and should be rendered.. This method passes through to the contained balloon.

Specified by:
setVisible in interface Balloon
Parameters:
visible - true if the balloon is visible and should be rendered.

NASA World Wind