analysispanel.java

来自「world wind java sdk 源码」· Java 代码 · 共 718 行 · 第 1/2 页

JAVA
718
字号
/*Copyright (C) 2001, 2007 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.applications.sar;import gov.nasa.worldwind.WorldWindow;import gov.nasa.worldwind.avlist.AVKey;import gov.nasa.worldwind.event.*;import gov.nasa.worldwind.examples.ApplicationTemplate;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.layers.*;import gov.nasa.worldwind.view.*;import javax.swing.*;import java.awt.*;import java.beans.*;/** * @author tag * @version $Id: AnalysisPanel.java 8959 2009-02-23 15:44:34Z patrickmurris $ */public class AnalysisPanel extends JPanel{    private WorldWindow wwd;    private SARTrack currentTrack;    private TrackViewPanel trackViewPanel;    private TerrainProfilePanel terrainProfilePanel;    private CloudCeilingPanel cloudCeilingPanel;    private JFrame cloudCeilingFrame;    private CrosshairLayer crosshairLayer;    private boolean crosshairNeedsUpdate = false;    private RenderableLayer planeModelLayer;    private PlaneModel planeModel;    private final PropertyChangeListener propertyChangeListener = new PropertyChangeListener()    {        @SuppressWarnings({"StringEquality"})        public void propertyChange(PropertyChangeEvent propertyChangeEvent)        {            if (propertyChangeEvent.getPropertyName() == TrackViewPanel.VIEW_CHANGE)            {                // When the view mode has changed, update the view parameters gradually.                updateView(true);            }            else if (propertyChangeEvent.getPropertyName() == TrackViewPanel.POSITION_CHANGE)            {                // When the track position has changed, update the view parameters immediately.                updateView(false);            }            else if (propertyChangeEvent.getPropertyName() == TrackController.TRACK_MODIFY)            {                // When the track has changed, update the view parameters immediately                updateView(false);                // Update the terrain profile path and cloud ceiling too.                terrainProfilePanel.updatePath(currentTrack.getPositions());                cloudCeilingPanel.setTrack(currentTrack);            }            else if (propertyChangeEvent.getPropertyName() == AVKey.ELEVATION_MODEL                && trackViewPanel.isExamineViewMode() && !wwd.getView().hasStateIterator())            {                // When the elevation model changes, and the view is examining the terrain beneath the track                // (but has not active state iterators), update the view parameters immediately.                updateView(false);            }            else if (propertyChangeEvent.getPropertyName() == SAR2.ELEVATION_UNIT)            {                updateElevationUnit(propertyChangeEvent.getNewValue());            }            else if (propertyChangeEvent.getPropertyName() == SAR2.ANGLE_FORMAT)            {                updateAngleFormat(propertyChangeEvent.getNewValue());            }            else if (propertyChangeEvent.getPropertyName() == CloudCeilingPanel.CLOUD_CEILING_OPEN)            {                cloudCeilingFrame.setVisible(true);            }            else if (propertyChangeEvent.getPropertyName() == CloudCeilingPanel.CLOUD_CEILING_CHANGE)            {                wwd.redraw();            }            if ((propertyChangeEvent.getPropertyName() == AVKey.VIEW                || propertyChangeEvent.getPropertyName() == AVKey.VIEW_QUIET)                && trackViewPanel.isFollowViewMode())            {                doUpdateCrosshair();            }        }    };    private final RenderingListener renderingListener = new RenderingListener()    {        public void stageChanged(RenderingEvent event)        {            if (crosshairNeedsUpdate && event.getStage().equals(RenderingEvent.AFTER_BUFFER_SWAP))            {                doUpdateCrosshair();            }        }    };    public AnalysisPanel()    {        initComponents();        // Init plane model layer        this.planeModel = new PlaneModel(100d, 100d, Color.YELLOW);        this.planeModel.setShadowScale(0.1);        this.planeModel.setShadowColor(new Color(255, 255, 0, 192));        this.planeModelLayer = new RenderableLayer();        this.planeModelLayer.setName("Aircraft Location");        this.planeModelLayer.addRenderable(this.planeModel);        //Init crosshair layer        this.crosshairLayer = new CrosshairLayer("images/64x64-crosshair.png");        this.crosshairLayer.setOpacity(0.4);        this.crosshairLayer.setEnabled(false);        // Init cloud ceiling panel and frame        this.cloudCeilingPanel = new CloudCeilingPanel();        this.cloudCeilingFrame = new JFrame("Cloud Contour");        this.cloudCeilingFrame.setResizable(false);        this.cloudCeilingFrame.setAlwaysOnTop(true);        this.cloudCeilingFrame.add(this.cloudCeilingPanel);        this.cloudCeilingFrame.pack();        SAR2.centerWindowInDesktop(this.cloudCeilingFrame);        // Listen to track view panel and cloud ceiling panel        this.trackViewPanel.addPropertyChangeListener(this.propertyChangeListener);        this.cloudCeilingPanel.addPropertyChangeListener(this.propertyChangeListener);    }    public void setWwd(WorldWindow wwd)    {        if (this.wwd != null)        {            this.wwd.removePropertyChangeListener(this.propertyChangeListener);//            this.wwd.getModel().getGlobe().getElevationModel().removePropertyChangeListener(this.propertyChangeListener);            this.wwd.getView().removePropertyChangeListener(this.propertyChangeListener);            this.wwd.removeRenderingListener(this.renderingListener);        }        this.wwd = wwd;        this.terrainProfilePanel.setWwd(wwd);        if (this.wwd != null)        {            this.wwd.addPropertyChangeListener(this.propertyChangeListener);//            this.wwd.getModel().getGlobe().getElevationModel().addPropertyChangeListener(this.propertyChangeListener);            this.wwd.getView().addPropertyChangeListener(this.propertyChangeListener);            this.wwd.addRenderingListener(this.renderingListener);            ApplicationTemplate.insertBeforeCompass(wwd, this.planeModelLayer);            ApplicationTemplate.insertBeforeCompass(wwd, this.crosshairLayer);            // Init cloud ceiling            this.cloudCeilingPanel.setCloudCeiling(new CloudCeiling(this.wwd));        }    }    public void setCurrentTrack(SARTrack currentTrack)    {        if (this.currentTrack != null)            this.currentTrack.removePropertyChangeListener(this.propertyChangeListener);        this.currentTrack = currentTrack;        this.trackViewPanel.setCurrentTrack(currentTrack);                if (this.currentTrack != null)        {            this.currentTrack.addPropertyChangeListener(this.propertyChangeListener);            this.terrainProfilePanel.updatePath(currentTrack.getPositions());            this.cloudCeilingPanel.setTrack(this.currentTrack);        }    }    private void updateElevationUnit(Object newValue)    {        if (newValue != null)        {            this.trackViewPanel.setElevationUnit(newValue.toString());            this.trackViewPanel.updateReadout(this.getPositionAlongSegment());            this.cloudCeilingPanel.setElevationUnit(newValue.toString());        }    }    private void updateAngleFormat(Object newValue)    {        if (newValue != null)        {            this.trackViewPanel.setAngleFormat(newValue.toString());            this.trackViewPanel.updateReadout(this.getPositionAlongSegment());        }    }    private Angle getControlHeading()    {        return Angle.ZERO;    }    @SuppressWarnings({"UnusedDeclaration"})    private Angle getControlPitch()    {        return Angle.fromDegrees(80);    }    private Angle getControlFOV()    {        return Angle.fromDegrees(45);    }    private void updateView(boolean goSmoothly)    {        OrbitView view = (OrbitView) this.wwd.getView();        view.setFieldOfView(this.getControlFOV());        if (this.trackViewPanel.isOverrideClipDistance())        {            view.setNearClipDistance(this.trackViewPanel.getClipDistance());            view.setDetectCollisions(false);        }        else        {            view.setNearClipDistance(-1); // Tells View to auto-compute the near clip distance.            view.setDetectCollisions(!trackViewPanel.isSubsurfaceOkay());        }        Position pos = this.getPositionAlongSegment();        if (pos != null)        {            Angle heading = this.getHeading().add(this.getControlHeading());            this.terrainProfilePanel.updatePosition(pos, heading);            this.planeModel.setPosition(pos);            this.planeModel.setHeading(heading);            if (this.trackViewPanel.isExamineViewMode())            {                this.crosshairLayer.setEnabled(false);  // Turn off crosshair                this.terrainProfilePanel.setFollowObject();                // Set the view center point to the current track position on the ground - spheroid.                // This gets the eye looking at the cross section.                Position groundPos = getSmoothedGroundPositionAlongSegment();                if (groundPos == null)                    groundPos = getGroundPositionAlongSegment();                if (goSmoothly)                {                    Angle initialPitch = Angle.fromDegrees(Math.min(60, view.getPitch().degrees));                    double initialZoom = 10000;                    // If the player is active, set initial parameters immediately.                    // Otherwise, set initial parameters gradually.                    if (this.trackViewPanel.isPlayerActive())                    {                        view.setCenterPosition(groundPos);                        view.setZoom(initialZoom);                        view.setPitch(initialPitch);                    }                    else                    {                        view.applyStateIterator(FlyToOrbitViewStateIterator.createPanToIterator(                            view, this.wwd.getModel().getGlobe(),                            groundPos, view.getHeading(), initialPitch, initialZoom, true));                    }                }                else                {                    // Stop any state iterators, and center movement only.                    view.stopStateIterators();                    view.stopMovementOnCenter();                    // Set the view to center on the track position,                    // while keeping the eye altitude constant.                    try                    {                        Position eyePos = view.getCurrentEyePosition();                        // New eye lat/lon will follow the ground position.                        LatLon newEyeLatLon = eyePos.add(groundPos.subtract(view.getCenterPosition()));                        // Eye elevation will not change unless it is below the ground position elevation.                        double newEyeElev = eyePos.getElevation() < groundPos.getElevation() ?                                groundPos.getElevation() : eyePos.getElevation();                        Position newEyePos = new Position(newEyeLatLon, newEyeElev);                        view.setOrientation(newEyePos, groundPos);                    }                    // Fallback to setting center position.                    catch (Exception e)                    {                        view.setCenterPosition(groundPos);                        // View/OrbitView will have logged the exception, no need to log it here.                    }                }            }            else if (this.trackViewPanel.isFollowViewMode())            {                Angle pitch = Angle.POS90;                double zoom = 0;                heading = getSmoothedHeading(.1); // smooth heading on first and last 10% of segment                this.terrainProfilePanel.setFollowObject();                // Place the eye at the track current lat-lon and altitude, with the proper heading                // and pitch from slider. Intended to simulate the view from the plane.                if (goSmoothly)                {                    // If the player is active, set initial parameters immediately.                    // Otherwise, set initial parameters gradually.                    if (this.trackViewPanel.isPlayerActive())                    {                        view.setCenterPosition(pos);                        view.setHeading(heading);                        view.setPitch(pitch);                        view.setZoom(zoom);                    }                    else                    {                        view.applyStateIterator(FlyToOrbitViewStateIterator.createPanToIterator(                            view, this.wwd.getModel().getGlobe(),                            pos, heading, pitch, zoom));                    }                }                else                {                    // Stop any state iterators, and any view movement.                    view.stopStateIterators();                    view.stopMovement();                    // Set the view values to follow the track.                    view.setCenterPosition(pos);                    view.setHeading(heading);                    view.setPitch(pitch);                    view.setZoom(zoom);                }                // Update crosshair position                this.updateCrosshair();            }            else if (this.trackViewPanel.isFreeViewMode())            {                this.crosshairLayer.setEnabled(false);  // Turn off crosshair                if (goSmoothly)                {                    // Stop any state iterators, and any view movement.                    view.stopStateIterators();                    view.stopMovement();                    // Set the view's center position to a point on the ground (without moving the eye).                    // This is needed to ensure normal interactions immediately.                    try                    {                        view.focusOnViewportCenter();                    }                    catch (Exception e)                    {                        // View/OrbitView will have logged the exception, no need to log it here.                    }                }            }        }        this.trackViewPanel.updateReadout(pos);        this.wwd.redraw();    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?