⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 airspaces.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
Copyright (C) 2001, 2008 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.
*/
package gov.nasa.worldwind.examples;

import gov.nasa.worldwind.Configuration;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.event.*;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.globes.Globe;
import gov.nasa.worldwind.layers.*;
import gov.nasa.worldwind.pick.PickedObjectList;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.render.airspaces.*;
import gov.nasa.worldwind.render.airspaces.Box;
import gov.nasa.worldwind.render.airspaces.Polygon;
import gov.nasa.worldwind.util.Logging;
import gov.nasa.worldwind.view.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

/**
 * @author dcollins
 * @version $Id: Airspaces.java 10903 2009-05-06 07:15:47Z dcollins $
 */
public class Airspaces extends ApplicationTemplate
{
    public static final String ACTION_COMMAND_ANTIALIAS = "gov.nasa.worldwind.avkey.ActionCommandAntialias";
    public static final String ACTION_COMMAND_DEPTH_OFFSET = "gov.nasa.worldwind.avkey.ActionCommandDepthOffset";
    public static final String ACTION_COMMAND_DRAW_EXTENT = "gov.nasa.worldwind.avkey.ActionCommandDrawExtent";
    public static final String ACTION_COMMAND_DRAW_WIREFRAME = "gov.nasa.worldwind.avkey.ActionCommandDrawWireframe";
    public static final String ACTION_COMMAND_LOAD_DEMO_AIRSPACES = "ActionCommandLoadDemoAirspaces";
    public static final String ACTION_COMMAND_LOAD_INTERSECTING_AIRSPACES = "ActionCommandLoadIntersectingAirspaces";
    public static final String ACTION_COMMAND_ZOOM_TO_DEMO_AIRSPACES = "ActionCommandZoomToDemoAirspaces";
    public static final String ACTION_COMMAND_SAVE_AIRSPACES = "ActionCommandSaveAirspaces";
    public static final String ACTION_COMMAND_READ_AIRSPACES = "ActionCommandReadAirspaces";
    public static final String ACTION_COMMAND_VERTICAL_EXAGGERATION = "ActionCommandVerticalExaggeration";
    public static final String AIRSPACE_LAYER_NAME = "Airspaces";
    public static final String ANNOTATION_LAYER_NAME = "Annotations";
    public static final String DESCRIPTION = "Description";

    public static class AppFrame extends ApplicationTemplate.AppFrame
    {
        private AirspacesController controller;
        private LayerPanel layerPanel;

        public AppFrame()
        {
            // We add our own LayerPanel, but keep the StatusBar from ApplicationTemplate.
            super(true, false, false);
            this.controller = new AirspacesController(this.getWwd());
            this.controller.frame = this;
            this.makeComponents();

            //((FlatGlobe) this.getWwd().getModel().getGlobe()).setProjection(FlatGlobe.PROJECTION_MODIFIED_SINUSOIDAL);

            this.controller.actionPerformed(new ActionEvent(this, 0, ACTION_COMMAND_LOAD_DEMO_AIRSPACES));
            this.getLayerPanel().update(this.getWwd());

            this.pack();
        }

        public LayerPanel getLayerPanel()
        {
            return this.layerPanel;
        }

        private void makeComponents()
        {
            this.getWwd().setPreferredSize(new Dimension(1024, 768));

            JPanel panel = new JPanel(new BorderLayout());
            {
                panel.setBorder(new EmptyBorder(10, 0, 10, 0));

                JPanel controlPanel = new JPanel(new BorderLayout(0, 10));
                controlPanel.setBorder(new EmptyBorder(20, 10, 20, 10));

                JPanel btnPanel = new JPanel(new GridLayout(5, 1, 0, 5));
                {
                    JButton btn = new JButton("Load Demo Airspaces");
                    btn.setActionCommand(ACTION_COMMAND_LOAD_DEMO_AIRSPACES);
                    btn.addActionListener(this.controller);
                    btnPanel.add(btn);

                    btn = new JButton("Load Intersecting Airspaces");
                    btn.setActionCommand(ACTION_COMMAND_LOAD_INTERSECTING_AIRSPACES);
                    btn.addActionListener(this.controller);
                    btnPanel.add(btn);

                    btn = new JButton("Zoom to Demo Airspaces");
                    btn.setActionCommand(ACTION_COMMAND_ZOOM_TO_DEMO_AIRSPACES);
                    btn.addActionListener(this.controller);
                    btnPanel.add(btn);

                    btn = new JButton("Save Airspaces");
                    btn.setActionCommand(ACTION_COMMAND_SAVE_AIRSPACES);
                    btn.addActionListener(this.controller);
                    btnPanel.add(btn);
                    controller.saveButton = btn;

                    btn = new JButton("Read Airspaces");
                    btn.setActionCommand(ACTION_COMMAND_READ_AIRSPACES);
                    btn.addActionListener(this.controller);
                    btnPanel.add(btn);
                    controller.readButton = btn;
                }
                controlPanel.add(btnPanel, BorderLayout.NORTH);

                JComponent box = javax.swing.Box.createVerticalBox();
                {
                    JCheckBox cb = new JCheckBox("Antialias", this.controller.airspaceLayer.isEnableAntialiasing());
                    cb.setActionCommand(ACTION_COMMAND_ANTIALIAS);
                    cb.addActionListener(this.controller);
                    box.add(cb);

                    cb = new JCheckBox("Fix Z-Fighting", this.controller.airspaceLayer.isEnableDepthOffset());
                    cb.setActionCommand(ACTION_COMMAND_DEPTH_OFFSET);
                    cb.addActionListener(this.controller);
                    box.add(cb);

                    cb = new JCheckBox("Show Wireframe", this.controller.airspaceLayer.isDrawWireframe());
                    cb.setActionCommand(ACTION_COMMAND_DRAW_WIREFRAME);
                    cb.addActionListener(this.controller);
                    box.add(cb);

                    cb = new JCheckBox("Show Bounds", this.controller.airspaceLayer.isDrawExtents());
                    cb.setActionCommand(ACTION_COMMAND_DRAW_EXTENT);
                    cb.addActionListener(this.controller);
                    box.add(cb);
                }
                controlPanel.add(box, BorderLayout.CENTER);

                JPanel vePanel = new JPanel(new BorderLayout(0, 5));
                {
                    JLabel label = new JLabel("Vertical Exaggeration");
                    vePanel.add(label, BorderLayout.NORTH);

                    int MIN_VE = 1;
                    int MAX_VE = 8;
                    int curVe = (int) this.getWwd().getSceneController().getVerticalExaggeration();
                    curVe = curVe < MIN_VE ? MIN_VE : (curVe > MAX_VE ? MAX_VE : curVe);
                    JSlider slider = new JSlider(MIN_VE, MAX_VE, curVe);
                    slider.setMajorTickSpacing(1);
                    slider.setPaintTicks(true);
                    slider.setSnapToTicks(true);
                    Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
                    labelTable.put(1, new JLabel("1x"));
                    labelTable.put(2, new JLabel("2x"));
                    labelTable.put(4, new JLabel("4x"));
                    labelTable.put(8, new JLabel("8x"));
                    slider.setLabelTable(labelTable);
                    slider.setPaintLabels(true);
                    slider.addChangeListener(new ChangeListener()
                    {
                        public void stateChanged(ChangeEvent e)
                        {
                            double ve = ((JSlider) e.getSource()).getValue();
                            ActionEvent ae = new ActionEvent(ve, 0, ACTION_COMMAND_VERTICAL_EXAGGERATION);
                            controller.actionPerformed(ae);
                        }
                    });
                    vePanel.add(slider, BorderLayout.SOUTH);
                }
                controlPanel.add(vePanel, BorderLayout.SOUTH);

                panel.add(controlPanel, BorderLayout.SOUTH);

                this.layerPanel = new LayerPanel(this.getWwd(), null);
                panel.add(this.layerPanel, BorderLayout.CENTER);
            }
            getContentPane().add(panel, BorderLayout.WEST);
        }
    }

    public static class AirspacesController implements ActionListener
    {
        // AWT/Swing stuff.
        private JFileChooser fileChooser;
        private JButton readButton;
        private JButton saveButton;
        private Airspaces.AppFrame frame;
        // World Wind stuff.
        private WorldWindowGLCanvas wwd;
        private AirspaceLayer airspaceLayer;
        private AnnotationLayer annotationLayer;
        private Airspace lastHighlit;
        private Airspace lastToolTip;
        private AirspaceAttributes lastAttrs;
        private Annotation lastAnnotation;
        private BasicDragger dragger;

        public AirspacesController(WorldWindowGLCanvas wwd)
        {
            this.wwd = wwd;

            // Construct a layer that will hold the airspaces and annotations.
            this.airspaceLayer = new AirspaceLayer();
            this.annotationLayer = new AnnotationLayer();
            this.airspaceLayer.setName(AIRSPACE_LAYER_NAME);
            this.annotationLayer.setName(ANNOTATION_LAYER_NAME);
            insertBeforePlacenames(this.wwd, this.airspaceLayer);
            insertBeforePlacenames(this.wwd, this.annotationLayer);

            this.initializeSelectionMonitoring();
        }

        public void actionPerformed(ActionEvent e)
        {
            if (ACTION_COMMAND_LOAD_DEMO_AIRSPACES.equalsIgnoreCase(e.getActionCommand()))
            {
                this.airspaceLayer.removeAllAirspaces();
                this.doLoadDemoAirspaces();
            }
            else if (ACTION_COMMAND_LOAD_INTERSECTING_AIRSPACES.equalsIgnoreCase(e.getActionCommand()))
            {
                this.airspaceLayer.removeAllAirspaces();
                this.doLoadIntersectingAirspaces();
            }
            else if (ACTION_COMMAND_ZOOM_TO_DEMO_AIRSPACES.equalsIgnoreCase(e.getActionCommand()))
            {
                this.doZoomToAirspaces();
            }
            else if (ACTION_COMMAND_SAVE_AIRSPACES.equalsIgnoreCase(e.getActionCommand()))
            {
                this.doSaveAirspaces();
            }
            else if (ACTION_COMMAND_READ_AIRSPACES.equalsIgnoreCase(e.getActionCommand()))
            {
                this.doReadAirspaces();
            }
            else if (ACTION_COMMAND_VERTICAL_EXAGGERATION.equalsIgnoreCase(e.getActionCommand()))
            {
                Double ve = (Double) e.getSource();
                this.doSetVerticalExaggeration(ve);
                this.wwd.redraw();
            }
            else if (ACTION_COMMAND_ANTIALIAS.equalsIgnoreCase(e.getActionCommand()))
            {
                JCheckBox cb = (JCheckBox) e.getSource();
                this.airspaceLayer.setEnableAntialiasing(cb.isSelected());
                this.wwd.redraw();
            }
            else if (ACTION_COMMAND_DEPTH_OFFSET.equalsIgnoreCase(e.getActionCommand()))
            {
                JCheckBox cb = (JCheckBox) e.getSource();
                this.airspaceLayer.setEnableDepthOffset(cb.isSelected());
                this.wwd.redraw();
            }
            else if (ACTION_COMMAND_DRAW_WIREFRAME.equalsIgnoreCase(e.getActionCommand()))
            {
                JCheckBox cb = (JCheckBox) e.getSource();
                this.airspaceLayer.setDrawWireframe(cb.isSelected());
                this.wwd.redraw();
            }
            else if (ACTION_COMMAND_DRAW_EXTENT.equalsIgnoreCase(e.getActionCommand()))
            {
                JCheckBox cb = (JCheckBox) e.getSource();

⌨️ 快捷键说明

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