Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrain-profile adapter #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/gov/nasa/worldwind/util/measure/TerrainProfileAdapter.java
Original file line number Diff line number Diff line change
@@ -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 <code>WorldWindow</code> and <code>TerrainProfileLayer</code>.
*
* @param wwd the <code>WorldWindow</code> 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<? extends LatLon> 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();
}
}
}