All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.gov.nasa.worldwind.util.layertree.KMLNetworkLinkTreeNode Maven / Gradle / Ivy

Go to download

World Wind is a collection of components that interactively display 3D geographic information within Java applications or applets.

There is a newer version: 2.0.0-986
Show newest version
/*
 * Copyright (C) 2012 United States Government as represented by the Administrator of the
 * National Aeronautics and Space Administration.
 * All Rights Reserved.
 */
package gov.nasa.worldwind.util.layertree;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.ogc.kml.*;

import javax.swing.*;
import java.beans.*;

/**
 * A KMLFeatureTreeNode that represents a KML network link defined by a {@link
 * gov.nasa.worldwind.ogc.kml.KMLNetworkLink}.
 * 

* KMLNetworkLinkTreeNode automatically repopulates its hierarchy when its KMLNetworkLink is * refreshed, and notifies its listeners when this happens. * * @author dcollins * @version $Id: KMLNetworkLinkTreeNode.java 1171 2013-02-11 21:45:02Z dcollins $ */ public class KMLNetworkLinkTreeNode extends KMLContainerTreeNode { /** * Creates a new KMLNetworkLinkTreeNode from the specified networkLink. The node's name is * set to the network link's name, and the node's hierarchy is populated from the network link's KML features. * * @param networkLink the KML network link this node represents. * * @throws IllegalArgumentException if the networkLink is null. */ public KMLNetworkLinkTreeNode(KMLNetworkLink networkLink) { super(networkLink); } /** * Indicates the KML network link this node represents. * * @return this node's KML network link. */ @Override public KMLNetworkLink getFeature() { return (KMLNetworkLink) super.getFeature(); } /** * {@inheritDoc} *

* Additionally, this node's hierarchy is populated from the KML features in its KMLNetworkLink, and * this registers a RETRIEVAL_STATE_SUCCESSFUL property change listener on the * KMLNetworkLink. */ @Override protected void initialize() { super.initialize(); // Add a property change listener to the KMLRoot. Upon receiving an RETRIEVAL_STATE_SUCCESSFUL event, // repopulate this node's hierarchy with the KML features in its KMLNetworkLink and fire a // RETRIEVAL_STATE_SUCCESSFUL to this nodes listeners. this.getFeature().getRoot().addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { if (AVKey.RETRIEVAL_STATE_SUCCESSFUL.equals(propertyChangeEvent.getPropertyName()) && KMLNetworkLinkTreeNode.this.getFeature() == propertyChangeEvent.getNewValue()) { // Ensure that the node list is manipulated on the EDT if (SwingUtilities.isEventDispatchThread()) { refresh(); KMLNetworkLinkTreeNode.this.firePropertyChange(AVKey.RETRIEVAL_STATE_SUCCESSFUL, null, this); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { refresh(); KMLNetworkLinkTreeNode.this.firePropertyChange(AVKey.RETRIEVAL_STATE_SUCCESSFUL, null, this); } }); } } } }); } /** * Called when this node's KMLNetworkLink refreshes. Clears this node's hierarchy by removing its * children, then adds a new KMLFeatureTreeNode to this node for each KML feature in the * KMLNetworkLink. *

* If the KMLNetworkLink's top level feature is a KMLDocument, this method ignores the * document and adds its children directly to this node. Creating a node for the document adds an extra level to the * tree node that doesn't provide any meaningful grouping. */ @Override protected void refresh() { // Call super to add features contained by the NetworkLink. super.refresh(); // Now add the network resource. KMLRoot kmlRoot = this.getFeature().getNetworkResource(); if (kmlRoot == null || kmlRoot.getFeature() == null) return; // A KML document has only one top-level feature. Except for very simple files, this top level is typically a // Document. In this case we skip the top level document, and attach tree nodes for the features beneath that // document. Attaching the document as a tree node would add an extra level to the tree that doesn't provide any // meaningful grouping. if (kmlRoot.getFeature() instanceof KMLDocument) { KMLDocument doc = (KMLDocument) kmlRoot.getFeature(); for (KMLAbstractFeature child : doc.getFeatures()) { if (child != null) this.addFeatureNode(child); } } else { this.addFeatureNode(kmlRoot.getFeature()); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy