From 68d8fe0a2b03a41fab325d4fbc4d7f5ff019c4e8 Mon Sep 17 00:00:00 2001 From: Wiehann Matthysen Date: Thu, 19 Jan 2017 09:26:10 +0200 Subject: [PATCH] Terrain-profile adapter. Added a new class called TerrainProfileAdapter to allow a TerrainProfileLayer to be updated from the MeasurementTool. When a new control-point is added or an existing control-point is moved, the adapter will forward the list of points to the TerrainProfileLayer so that the new terrain-profile is displayed in the on-screen window. --- .../util/measure/TerrainProfileAdapter.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/gov/nasa/worldwind/util/measure/TerrainProfileAdapter.java diff --git a/src/gov/nasa/worldwind/util/measure/TerrainProfileAdapter.java b/src/gov/nasa/worldwind/util/measure/TerrainProfileAdapter.java new file mode 100644 index 0000000000..146cd16a95 --- /dev/null +++ b/src/gov/nasa/worldwind/util/measure/TerrainProfileAdapter.java @@ -0,0 +1,74 @@ +/* + * 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.measure; + +import gov.nasa.worldwind.WorldWindow; +import gov.nasa.worldwind.geom.LatLon; +import gov.nasa.worldwind.layers.TerrainProfileLayer; +import gov.nasa.worldwind.util.Logging; + +import java.beans.*; +import java.util.ArrayList; + +/** + * Adapter that forwards control-point position changes from a {@link MeasureTool} + * to a {@link TerrainProfileLayer} so that the height-data along the measured + * path can be visualized. + * + * @author Wiehann Matthysen + */ +public class TerrainProfileAdapter implements PropertyChangeListener +{ + protected WorldWindow wwd; + protected TerrainProfileLayer profileLayer; + + /** + * Construct an adapter for the specified WorldWindow and TerrainProfileLayer. + * + * @param wwd the WorldWindow the specified layer is associated with. + * @param layer the layer to forward control-point events to. + */ + public TerrainProfileAdapter(WorldWindow wwd, TerrainProfileLayer layer) + { + if (wwd == null) + { + String msg = Logging.getMessage("nullValue.WorldWindow"); + Logging.logger().severe(msg); + throw new IllegalArgumentException(msg); + } + if (layer == null) + { + String msg = Logging.getMessage("nullValue.LayerIsNull"); + Logging.logger().severe(msg); + throw new IllegalArgumentException(msg); + } + + this.wwd = wwd; + this.profileLayer = layer; + } + + @Override + public void propertyChange(PropertyChangeEvent event) + { + MeasureTool measureTool = (MeasureTool)event.getSource(); + // Measure shape position list changed - update terrain profile + if (event.getPropertyName().equals(MeasureTool.EVENT_POSITION_ADD) + || event.getPropertyName().equals(MeasureTool.EVENT_POSITION_REMOVE) + || event.getPropertyName().equals(MeasureTool.EVENT_POSITION_REPLACE)) + { + ArrayList positions = measureTool.getPositions(); + if (positions != null && positions.size() > 1) + { + this.profileLayer.setPathPositions(positions); + this.profileLayer.setEnabled(true); + } else + { + this.profileLayer.setEnabled(false); + } + this.wwd.redraw(); + } + } +}