terrainprofilepanel.java

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

JAVA
660
字号
/*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.examples.ApplicationTemplate;import gov.nasa.worldwind.geom.Angle;import gov.nasa.worldwind.geom.LatLon;import gov.nasa.worldwind.geom.Position;import gov.nasa.worldwind.layers.Layer;import gov.nasa.worldwind.layers.ScalebarLayer;import gov.nasa.worldwind.layers.TerrainProfileLayer;import gov.nasa.worldwind.render.Polyline;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import java.util.ArrayList;import java.util.HashMap;/** * @author tag * @version $Id: TerrainProfilePanel.java 8336 2009-01-05 23:43:09Z patrickmurris $ */@SuppressWarnings({"FieldCanBeLocal"})public class TerrainProfilePanel extends JPanel{    private final TerrainProfileController controller;    private static final String GRAPH_SIZE_SMALL_TEXT = "Small Graph";    private static final String GRAPH_SIZE_MEDIUM_TEXT = "Medium Graph";    private static final String GRAPH_SIZE_LARGE_TEXT = "Large Graph";    private static final String FOLLOW_VIEW_TEXT   = "Profile At Screen Center";    private static final String FOLLOW_CURSOR_TEXT = "Profile Under Cursor";    //private static final String FOLLOW_EYE_TEXT    = "Profile Under Eye";    private static final String FOLLOW_OBJECT_TEXT = "Profile Under Aircraft";    private static final String FOLLOW_NONE_TEXT   = "No Profile";    public TerrainProfilePanel()    {        initComponents();//        this.followComboBox.setModel(new DefaultComboBoxModel(TerrainProfileController.getFollowKeys()));//        this.followComboBox.setSelectedIndex(0);//        this.sizeComboBox.setModel(new DefaultComboBoxModel(TerrainProfileController.getSizeKeys()));//        this.sizeComboBox.setSelectedIndex(0);        this.controller = new TerrainProfileController();//        this.matchProfileToPanel();    }    public WorldWindow getWwd()    {        return this.controller.getWwd();    }    public void setWwd(WorldWindow wwd)    {        this.controller.setWwd(wwd);        this.matchProfileToPanel();    }    private void matchProfileToPanel()    {        this.setFollow();        this.controller.setProfileSize((String) this.sizeComboBox.getSelectedItem());        this.controller.setKeepProportions(this.proportionalCheckBox.isSelected());        this.controller.setShowEyePosition(this.showEyeCheckBox.isSelected());        this.controller.setZeroBased(this.zeroBaseCheckBox.isSelected());        this.controller.setProfileWidthFactor(            Double.parseDouble(((String)this.profileWidthSpinner.getValue()).replace("x", "")));        this.controller.setProfileLengthFactor(            Double.parseDouble(((String)this.profileLengthSpinner.getValue()).replace("x", "")));    }    @SuppressWarnings({"UnusedDeclaration"})    private void sizeComboBoxActionPerformed(ActionEvent e)    {        this.controller.setProfileSize((String) this.sizeComboBox.getSelectedItem());    }    @SuppressWarnings({"UnusedDeclaration"})    private void followComboBoxActionPerformed(ActionEvent e)    {        this.setFollow();    }    //public void setFollowEye()    //{    //    this.followComboBox.getModel().setSelectedItem(FOLLOW_EYE_TEXT);    //}/    public void setFollowObject()    {        this.followComboBox.getModel().setSelectedItem(FOLLOW_OBJECT_TEXT);    }    @SuppressWarnings({"StringEquality"})    private void setFollow()    {        this.controller.setFollow((String) this.followComboBox.getSelectedItem());        String follow = this.controller.getFollow();        if (follow == TerrainProfileLayer.FOLLOW_VIEW)        {            if (this.showEyeCheckBox.isEnabled())                this.showEyeCheckBox.setEnabled(false);            if (!this.profileWidthSpinner.isEnabled())                this.profileWidthSpinner.setEnabled(true);            if (this.profileLengthSpinner.isEnabled())                this.profileLengthSpinner.setEnabled(false);        }        else if (follow == TerrainProfileLayer.FOLLOW_CURSOR)        {            if (this.showEyeCheckBox.isEnabled())                this.showEyeCheckBox.setEnabled(false);            if (!this.profileWidthSpinner.isEnabled())                this.profileWidthSpinner.setEnabled(true);            if (this.profileLengthSpinner.isEnabled())                this.profileLengthSpinner.setEnabled(false);        }        //else if (follow == TerrainProfileLayer.FOLLOW_EYE)        //{        //    if (!this.showEyeCheckBox.isEnabled())        //        this.showEyeCheckBox.setEnabled(true);        //    if (!this.profileWidthSlider.isEnabled())        //        this.profileWidthSlider.setEnabled(true);        //    if (!this.profileLengthSlider.isEnabled())        //        this.profileLengthSlider.setEnabled(true);        //}        else if (follow == TerrainProfileLayer.FOLLOW_OBJECT)        {            if (!this.showEyeCheckBox.isEnabled())                this.showEyeCheckBox.setEnabled(true);            if (!this.profileWidthSpinner.isEnabled())                this.profileWidthSpinner.setEnabled(true);            if (!this.profileLengthSpinner.isEnabled())                this.profileLengthSpinner.setEnabled(true);        }        else if (follow == TerrainProfileLayer.FOLLOW_NONE)        {            if (this.showEyeCheckBox.isEnabled())                this.showEyeCheckBox.setEnabled(false);            if (this.profileWidthSpinner.isEnabled())                this.profileWidthSpinner.setEnabled(false);            if (this.profileLengthSpinner.isEnabled())                this.profileLengthSpinner.setEnabled(false);        }    }    private void proportionalCheckBoxItemStateChanged(ItemEvent e)    {        this.controller.setKeepProportions(((JCheckBox) e.getSource()).isSelected());    }    private void showEyeCheckBoxItemStateChanged(ItemEvent e)    {        this.controller.setShowEyePosition(((JCheckBox) e.getSource()).isSelected());    }    private void zeroBaseCheckBoxItemStateChanged(ItemEvent e)    {        this.controller.setZeroBased(((JCheckBox) e.getSource()).isSelected());    }    private void profileWidthSpinnerStateChanged(ChangeEvent e)    {        String value = (String)((JSpinner) e.getSource()).getValue();        value = value.replace("x", "");        this.controller.setProfileWidthFactor(Double.parseDouble(value));        if (this.profilesSameSize.isSelected())            this.profileLengthSpinner.setValue(this.profileWidthSpinner.getValue());    }    private void profileLengthSpinnerStateChanged(ChangeEvent e)    {        String value = (String)((JSpinner) e.getSource()).getValue();        value = value.replace("x", "");        this.controller.setProfileLengthFactor(Double.parseDouble(value));        if (this.profilesSameSize.isSelected())            this.profileWidthSpinner.setValue(this.profileLengthSpinner.getValue());    }    public void profilesSameSizeStateChanged(ChangeEvent e)    {        if (((JCheckBox)e.getSource()).isSelected())            this.profileLengthSpinner.setValue(this.profileWidthSpinner.getValue());    }    public void profileFollowPathStateChanged(ChangeEvent e)    {        this.controller.setWholeTrackLength(((JCheckBox)e.getSource()).isSelected());    }    public void updatePosition(Position position, Angle heading)    {        this.controller.updatePosition(position, heading);    }    public void updatePath(ArrayList<? extends LatLon> positions)    {        this.controller.updatePath(positions);    }    public String getFollow()    {        return this.controller.getFollow();    }    private void initComponents()    {        this.panel1 = new JPanel();        this.panel2 = new JPanel();        this.panel6 = new JPanel();        this.panel5 = new JPanel();        this.sizeComboBox = new JComboBox();        this.panel7 = new JPanel();        this.followComboBox = new JComboBox();        this.panel3 = new JPanel();        this.proportionalCheckBox = new JCheckBox();        this.showEyeCheckBox = new JCheckBox();        this.zeroBaseCheckBox = new JCheckBox();        this.panel4 = new JPanel();        this.profileWidthSpinner = new JSpinner();        this.profileWidthLabel = new JLabel();        this.panel8 = new JPanel();        this.panel4b = new JPanel();        this.profileLengthSpinner = new JSpinner();        this.profileLengthLabel = new JLabel();        this.panel4c = new JPanel();        this.profilesSameSize = new JCheckBox();        this.panel4d = new JPanel();        this.profileFollowPath = new JCheckBox();        //======== this ========        setBorder(new CompoundBorder(            new TitledBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY), "Terrain Profile"),            new EmptyBorder(5, 5, 5, 5)));        setLayout(new BorderLayout(20, 20));        //======== panel1 ========        {        	this.panel1.setLayout(new BorderLayout(20, 20));        	//======== panel2 ========        	{        		this.panel2.setLayout(new GridLayout(1, 2, 20, 10));        		//======== panel6 ========        		{        			this.panel6.setLayout(new GridLayout(1, 2, 20, 10));        			//======== panel5 ========        			{        				this.panel5.setLayout(new BorderLayout(5, 5));        				//---- sizeComboBox ----        				this.sizeComboBox.setModel(new DefaultComboBoxModel(new String[] {                                GRAPH_SIZE_SMALL_TEXT,                                GRAPH_SIZE_MEDIUM_TEXT,                                GRAPH_SIZE_LARGE_TEXT        				}));        				this.sizeComboBox.setToolTipText("Size of profile graph");        				this.sizeComboBox.addActionListener(new ActionListener() {        					public void actionPerformed(ActionEvent e) {        						sizeComboBoxActionPerformed(e);        					}        				});        				this.panel5.add(this.sizeComboBox, BorderLayout.CENTER);        			}        			this.panel6.add(this.panel5);        			//======== panel7 ========        			{        				this.panel7.setLayout(new BorderLayout(5, 5));        				//---- followComboBox ----        				this.followComboBox.setModel(new DefaultComboBoxModel(new String[] {        					FOLLOW_VIEW_TEXT,        					FOLLOW_CURSOR_TEXT,        					//FOLLOW_EYE_TEXT,        					FOLLOW_OBJECT_TEXT,                            FOLLOW_NONE_TEXT                        }));        				this.followComboBox.setToolTipText("Set profile behavior");        				this.followComboBox.addActionListener(new ActionListener() {        					public void actionPerformed(ActionEvent e) {        						followComboBoxActionPerformed(e);        					}        				});        				this.panel7.add(this.followComboBox, BorderLayout.CENTER);        			}        			this.panel6.add(this.panel7);        		}        		this.panel2.add(this.panel6);        	}        	this.panel1.add(this.panel2, BorderLayout.NORTH);        	//======== panel3 ========        	{        		this.panel3.setLayout(new GridLayout(1, 3, 10, 10));        		//---- proportionalCheckBox ----        		this.proportionalCheckBox.setText("Proportional");        		this.proportionalCheckBox.setToolTipText("Maintain 1:1 profile dimensions");        		this.proportionalCheckBox.setAlignmentX(0.5F);        		this.proportionalCheckBox.addItemListener(new ItemListener() {        			public void itemStateChanged(ItemEvent e) {        				proportionalCheckBoxItemStateChanged(e);        			}        		});        		this.panel3.add(this.proportionalCheckBox);        		//---- showEyeCheckBox ----        		this.showEyeCheckBox.setText("Show A/C Position");        		this.showEyeCheckBox.setToolTipText("Show aircraft position in profile graph");        		this.showEyeCheckBox.setAlignmentX(0.5F);        		this.showEyeCheckBox.setHorizontalAlignment(SwingConstants.CENTER);        		this.showEyeCheckBox.setSelected(true);        		this.showEyeCheckBox.addItemListener(new ItemListener() {        			public void itemStateChanged(ItemEvent e) {        				showEyeCheckBoxItemStateChanged(e);        			}

⌨️ 快捷键说明

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