trackviewpanel.java

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

JAVA
783
字号
/*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.geom.Position;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.beans.*;/** * @author tag * @version $Id: TrackViewPanel.java 8957 2009-02-23 14:33:26Z patrickmurris $ */public class TrackViewPanel extends JPanel{    // SAR logical components.    private AnalysisPanel analysisPanel;    private SARTrack sarTrack;    private String elevationUnit;    private String angleFormat;    // "View" panel components    private JCheckBox subsurfaceButton;    private JRadioButton examineButton;    private JRadioButton followButton;    private JRadioButton freeButton;    private JCheckBox overrideClipDistanceButton;    private JSlider clipDistanceSlider;    // "Position" panel components    private boolean suspendPositionEvents = false;    private double positionDelta = 0;    private JLabel latLabel;    private JLabel lonLabel;    private JLabel altLabel;    private JLabel latReadout;    private JLabel lonReadout;    private JLabel altReadout;    private JSpinner positionSpinner;    private JSlider positionSlider;    private JButton fastReverseButton;    private JButton reverseButton;    private JButton stopButton;    private JButton forwardButton;    private JButton fastForwardButton;    private JLabel speedLabel;    private JSpinner speedSpinner;    private JSpinner speedFactorSpinner;    // "Player" logical components.    private static final int PLAY_FORWARD = 1;    private static final int PLAY_BACKWARD = -1;    private static final int PLAY_STOP = 0;    private int playMode = PLAY_STOP;    private Timer player;    private long previousStepTime = -1;    public static final String POSITION_CHANGE = "TrackViewPanel.PositionChange";    public static final String VIEW_CHANGE = "TrackViewPanel.ViewChange";    public TrackViewPanel(AnalysisPanel analysisPanel)    {        this.analysisPanel = analysisPanel;        initComponents();        this.updateEnabledState();    }    public void setCurrentTrack(SARTrack sarTrack)    {        this.sarTrack = sarTrack;        if (this.sarTrack != null)        {            this.sarTrack.addPropertyChangeListener(new PropertyChangeListener()            {                public void propertyChange(PropertyChangeEvent propertyChangeEvent)                {                    updatePositionList(false);                }            });        }        this.updatePositionList(true);        this.updateEnabledState();    }    public String getElevationUnit()    {        return this.elevationUnit;    }    public void setElevationUnit(String elevationUnit)    {        this.elevationUnit = elevationUnit;    }    public String getAngleFormat()    {        return this.angleFormat;    }    public void setAngleFormat(String format)    {        this.angleFormat = format;    }    private void updatePositionList(boolean resetPosition)    {        String[] strings = new String[this.sarTrack != null ? this.sarTrack.size() : 0];        for (int i = 0; i < strings.length; i++)            strings[i] = String.format("%,4d", i);        if (strings.length == 0)            strings = new String[] {"   0"};        Object currentSpinnerValue = this.positionSpinner.getValue();        int currentSliderValue = this.positionSlider.getValue();        this.positionSpinner.setModel(new SpinnerListModel(strings));        this.positionSpinner.setValue(resetPosition ? strings[0] : currentSpinnerValue);        this.positionSlider.setValue(resetPosition ? 0 : currentSliderValue);    }    private void setPositionSpinnerNumber(int n)    {        this.positionSpinner.setValue(String.format("%,4d", n));    }    private void updateEnabledState()    {        boolean state = this.sarTrack != null;        this.examineButton.setEnabled(state);        this.followButton.setEnabled(state);        this.positionSpinner.setEnabled(state);        this.positionSlider.setEnabled(state);        this.latLabel.setEnabled(state);        this.lonLabel.setEnabled(state);        this.altLabel.setEnabled(state);        this.fastReverseButton.setEnabled(state);        this.reverseButton.setEnabled(state);//        this.stopButton.setEnabled(state);        this.forwardButton.setEnabled(state);        this.fastForwardButton.setEnabled(state);        this.speedLabel.setEnabled(state);        this.speedSpinner.setEnabled(state);        this.speedFactorSpinner.setEnabled(state);        this.updateReadout(this.sarTrack != null && sarTrack.size() > 0 ? sarTrack.get(0) : null);    }    private void positionSpinnerStateChanged()    {        if (!this.suspendPositionEvents)        {            setPositionDelta(getCurrentPositionNumber(), 0);            this.firePropertyChange(POSITION_CHANGE, -1, 0);        }    }    private void positionSliderStateChanged()    {        if (!this.suspendPositionEvents)        {            updatePositionDelta();            this.firePropertyChange(POSITION_CHANGE, -1, 0);        }    }    private void examineButtonItemStateChanged()    {        this.subsurfaceButton.setSelected(false);        this.firePropertyChange(VIEW_CHANGE, -1, 0);    }    private void followButtonItemStateChanged()    {        this.subsurfaceButton.setSelected(true);        this.firePropertyChange(VIEW_CHANGE, -1, 0);    }    private void freeButtonItemStateChanged()    {        this.subsurfaceButton.setSelected(false);        this.firePropertyChange(VIEW_CHANGE, -1, 0);    }    private void subsurfaceButtonItemStateChanged()    {        this.firePropertyChange(VIEW_CHANGE, -1, 0);    }    private void overrideClipDistanceButtonStateChanged()    {        this.subsurfaceButton.setEnabled(!this.overrideClipDistanceButton.isSelected());        this.firePropertyChange(POSITION_CHANGE, -1, 0);    }    private void clipDistanceStateChanged()    {        this.firePropertyChange(POSITION_CHANGE, -1, 0);    }    public int getCurrentPositionNumber()    {        Object o = this.positionSpinner.getValue();        if (o == null)            return -1;        return Integer.parseInt(o.toString().trim().replaceAll(",", ""));    }    private boolean isLastPosition(int n)    {        return n >= this.sarTrack.size() - 1;    }    public double getPositionDelta()    {        // Portion of the current segment 0.0 .. 1.0        return this.positionDelta;    }    private void updatePositionDelta()    {        // From UI control        int i = this.positionSlider.getValue();        int min = this.positionSlider.getMinimum();        int max = this.positionSlider.getMaximum();        this.positionDelta = (double) i / ((double) max - (double) min);    }    private void setPositionDelta(int positionNumber, double positionDelta)    {        // Update UI controls without firing events        this.suspendPositionEvents = true;        {            setPositionSpinnerNumber(positionNumber);            int min = this.positionSlider.getMinimum();            int max = this.positionSlider.getMaximum();            int value = (int)(min + (double)(max - min) * positionDelta);            this.positionSlider.setValue(value);        }        this.suspendPositionEvents = false;        this.positionDelta = positionDelta;    }    public boolean isSubsurfaceOkay()    {        return this.subsurfaceButton.isSelected();    }    public boolean isExamineViewMode()    {        return this.examineButton.isSelected();    }    public boolean isFollowViewMode()    {        return this.followButton.isSelected();    }    public boolean isFreeViewMode()    {        return this.freeButton.isSelected();    }    public boolean isOverrideClipDistance()    {        return this.overrideClipDistanceButton.isSelected();    }    public double getClipDistance()    {        return this.clipDistanceSlider.getValue();    }    public void updateReadout(Position pos)    {        this.latReadout.setText(pos == null ? "" : SAR2.formatAngle(angleFormat, pos.getLatitude()));        this.lonReadout.setText(pos == null ? "" : SAR2.formatAngle(angleFormat, pos.getLongitude()));        if (SAR2.UNIT_IMPERIAL.equals(this.elevationUnit))            this.altReadout.setText(pos == null ? "" : String.format("% 8.0f ft", SAR2.metersToFeet(pos.getElevation())));        else // Default to metric units.           this.altReadout.setText(pos == null ? "" : String.format("% 8.0f m", pos.getElevation()));        this.speedLabel.setText(SAR2.UNIT_IMPERIAL.equals(this.elevationUnit) ? "MPH: " : "KMH: ");    }    public double getSpeedKMH()    {        String speedValue = (String)this.speedSpinner.getValue();        String speedFactor = ((String)this.speedFactorSpinner.getValue()).replace("x", "");        double speed = Double.parseDouble(speedValue) * Double.parseDouble(speedFactor);        if (SAR2.UNIT_IMPERIAL.equals(this.elevationUnit))            speed *= 1.609344; // mph to kmh        return speed;    }    // Player Controls    private void fastReverseButtonActionPerformed()    {        if (this.getCurrentPositionNumber() > 0)            setPositionSpinnerNumber(this.getCurrentPositionNumber() - 1);    }    private void reverseButtonActionPerformed()    {        setPlayMode(PLAY_BACKWARD);    }    private void stopButtonActionPerformed()    {        setPlayMode(PLAY_STOP);    }    private void forwardButtonActionPerformed()    {        setPlayMode(PLAY_FORWARD);    }    private void fastForwardButtonActionPerformed()    {        if (!isLastPosition(this.getCurrentPositionNumber()))            setPositionSpinnerNumber(this.getCurrentPositionNumber() + 1);    }    public boolean isPlayerActive()    {        return this.playMode != PLAY_STOP;    }    private void setPlayMode(int mode)    {        this.playMode = mode;        if (player == null)            initPlayer();        player.start();    }    private void initPlayer()    {        if (player != null)            return;        player = new Timer(50, new ActionListener()        {            // Animate the view motion by controlling the positionSpinner and positionDelta            public void actionPerformed(ActionEvent actionEvent)            {                runPlayer();                }        });    }    private void runPlayer()    {        int positionNumber = getCurrentPositionNumber();        double curDelta = getPositionDelta();        double speedKMH = getSpeedKMH();        if (this.playMode == PLAY_STOP)        {            this.stopButton.setEnabled(false);            this.player.stop();            this.previousStepTime = -1;        }        else if (this.playMode == PLAY_FORWARD)        {            this.stopButton.setEnabled(true);            if (positionNumber >= (this.sarTrack.size() - 1))            {                setPositionDelta(this.sarTrack.size() - 1, 0);                this.playMode = PLAY_STOP;            }            else            {                double distanceToGo = computeDistanceToGo(speedKMH);                while (distanceToGo > 0)                {                    double segmentLength = this.analysisPanel.getSegmentLength(positionNumber);                    if (segmentLength * curDelta + distanceToGo <= segmentLength)                    {

⌨️ 快捷键说明

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