Class KMLAbstractBalloon

  • All Implemented Interfaces:
    AVList, Balloon, Highlightable, Renderable, gov.nasa.worldwind.util.webview.WebResourceResolver, java.beans.PropertyChangeListener, java.util.EventListener
    Direct Known Subclasses:
    KMLGlobeBalloonImpl, KMLScreenBalloonImpl

    public abstract class KMLAbstractBalloon
    extends java.lang.Object
    implements Balloon, gov.nasa.worldwind.util.webview.WebResourceResolver, java.beans.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 Detail

      • DISPLAY_MODE_HIDE

        public static final java.lang.String DISPLAY_MODE_HIDE
        See Also:
        Constant Field Values
      • DISPLAY_MODE_DEFAULT

        public static final java.lang.String DISPLAY_MODE_DEFAULT
        See Also:
        Constant Field Values
      • displayMode

        protected java.lang.String displayMode
      • usingDefaultText

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

        protected boolean normalAttributesResolved
      • highlightAttributesResolved

        protected boolean highlightAttributesResolved
      • normalText

        protected java.lang.String normalText
        Text when balloon is not highlighted.
      • highlightText

        protected java.lang.String highlightText
        Text when balloon is highlighted.
    • 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

      • initialize

        protected void initialize​(Balloon balloon)
        Initialize the object.
        Parameters:
        balloon - The balloon contained in this wrapper object.
      • getBalloon

        protected abstract Balloon getBalloon()
        Get the Balloon object that is contained in the KMLBalloon object.
        Returns:
        The balloon contained by this object.
      • 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
      • determineActiveText

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

        protected void makeAttributesCurrent​(java.lang.String attrType)
        Update the balloon attributes to match the KML BalloonStyle.
        Parameters:
        attrType - Type of attributes to update. Either KMLConstants.NORMAL or KMLConstants.HIGHLIGHT.
      • createDefaultBalloonText

        protected java.lang.String createDefaultBalloonText()
        Build a default balloon text string for the feature.
        Returns:
        Default balloon text.
      • createDefaultExtendedDataText

        protected void createDefaultExtendedDataText​(java.lang.StringBuilder sb,
                                                     java.util.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​(java.lang.StringBuilder sb,
                                                   java.util.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.
      • mustAddHyperlinks

        protected boolean mustAddHyperlinks​(java.lang.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.
      • addHyperlinks

        protected java.lang.String addHyperlinks​(java.lang.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.
      • 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.
      • 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.
      • 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.
      • resolve

        public java.net.URL resolve​(java.lang.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 gov.nasa.worldwind.util.webview.WebResourceResolver
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Forward property change events to the parent KMLRoot.
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        Parameters:
        evt - Event to forward.
      • 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.
      • 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.
      • 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.
      • 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.
      • 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.
      • 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​(java.lang.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.
      • 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.
      • 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
      • 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.
      • 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.
      • 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.
      • 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.
      • getDelegateOwner

        public java.lang.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.
      • setDelegateOwner

        public void setDelegateOwner​(java.lang.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.
      • 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.
      • 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.
      • getBounds

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

        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.
      • setValue

        public java.lang.Object setValue​(java.lang.String key,
                                         java.lang.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.
      • getValue

        public java.lang.Object getValue​(java.lang.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 java.util.Collection<java.lang.Object> getValues()
        . This method passes through to the contained balloon.
        Specified by:
        getValues in interface AVList
      • getStringValue

        public java.lang.String getStringValue​(java.lang.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.
      • getEntries

        public java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.Object>> getEntries()
        . This method passes through to the contained balloon.
        Specified by:
        getEntries in interface AVList
      • hasKey

        public boolean hasKey​(java.lang.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.
      • removeKey

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

        public void addPropertyChangeListener​(java.lang.String propertyName,
                                              java.beans.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
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.lang.String propertyName,
                                                 java.beans.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
      • addPropertyChangeListener

        public void addPropertyChangeListener​(java.beans.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
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.beans.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
      • firePropertyChange

        public void firePropertyChange​(java.lang.String propertyName,
                                       java.lang.Object oldValue,
                                       java.lang.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
      • firePropertyChange

        public void firePropertyChange​(java.beans.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
      • 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.
      • clearList

        public AVList clearList()
        . This method passes through to the contained balloon.
        Specified by:
        clearList in interface AVList