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

📄 airspacebuilder.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* Copyright (C) 2001, 2008 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples;import gov.nasa.worldwind.*;import gov.nasa.worldwind.avlist.AVKey;import gov.nasa.worldwind.examples.util.ShapeUtils;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.layers.AirspaceLayer;import gov.nasa.worldwind.pick.PickedObjectList;import gov.nasa.worldwind.render.Material;import gov.nasa.worldwind.render.airspaces.*;import gov.nasa.worldwind.render.airspaces.Polygon;import gov.nasa.worldwind.render.airspaces.editor.*;import gov.nasa.worldwind.util.WWIO;import gov.nasa.worldwind.view.*;import javax.swing.*;import javax.swing.Box;import javax.swing.event.*;import javax.swing.table.*;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.io.*;import java.net.URL;import java.util.*;import java.util.zip.*;/** * @author dcollins * @version $Id: AirspaceBuilder.java 9428 2009-03-17 07:05:09Z tgaskins $ */public class AirspaceBuilder extends ApplicationTemplate{    protected static final String AIRSPACE_LAYER_NAME = "Airspace Shapes";    protected static final String CLEAR_SELECTION = "AirspaceBuilder.ClearSelection";    protected static final String SIZE_NEW_SHAPES_TO_VIEWPORT = "AirspaceBuilder.SizeNewShapesToViewport";    protected static final String ENABLE_EDIT = "AirspaceBuilder.EnableEdit";    protected static final String OPEN = "AirspaceBuilder.Open";    protected static final String OPEN_URL = "AirspaceBuilder.OpenUrl";    protected static final String OPEN_DEMO_AIRSPACES = "AirspaceBuilder.OpenDemoAirspaces";    protected static final String NEW_AIRSPACE = "AirspaceBuilder.NewAirspace";    protected static final String REMOVE_SELECTED = "AirspaceBuilder.RemoveSelected";    protected static final String SAVE = "AirspaceBuilder.Save";    protected static final String SELECTION_CHANGED = "AirspaceBuilder.SelectionChanged";    protected static final String DEMO_AIRSPACES_URL = "http://worldwind.arc.nasa.gov/java/demos/data/AirspaceBuilder-DemoShapes.zip";    //**************************************************************//    //********************  Airspace Builder Model  ****************//    //**************************************************************//    protected static class AirspaceEntry extends WWObjectImpl    {        private Airspace airspace;        private AirspaceEditor editor;        private AirspaceAttributes attributes;        private boolean editing = false;        private boolean selected = false;        private boolean intersecting = false;        public AirspaceEntry(Airspace airspace, AirspaceEditor editor)        {            this.airspace = airspace;            this.editor = editor;            this.attributes = this.airspace.getAttributes();        }        public boolean isEditing()        {            return this.editing;        }        public void setEditing(boolean editing)        {            this.editing = editing;            this.updateAttributes();        }        public boolean isSelected()        {            return this.selected;        }        public void setSelected(boolean selected)        {            this.selected = selected;            this.updateAttributes();        }        public boolean isIntersecting()        {            return this.intersecting;        }        public void setIntersecting(boolean intersecting)        {            this.intersecting = intersecting;            this.updateAttributes();        }        public String getName()        {            return this.getStringValue(AVKey.DISPLAY_NAME);        }        public void setName(String name)        {            this.setValue(AVKey.DISPLAY_NAME, name);        }        public Airspace getAirspace()        {            return airspace;        }        public AirspaceEditor getEditor()        {            return editor;        }        public AirspaceAttributes getAttributes()        {            return this.attributes;        }        public String toString()        {            return this.getName();        }        public Object getValue(String key)        {            Object value = super.getValue(key);            if (value == null)            {                value = this.airspace.getValue(key);            }            return value;        }        public Object setValue(String key, Object value)        {            //noinspection StringEquality            if (key == AVKey.DISPLAY_NAME)            {                return this.airspace.setValue(key, value);            }            else            {                return super.setValue(key, value);            }        }        protected void updateAttributes()        {            if (this.isSelected() && this.isIntersecting())            {                this.airspace.setAttributes(getSelectionAndIntersectionAttributes());            }            else if (this.isSelected())            {                this.airspace.setAttributes(getSelectionAttributes());            }            else if (this.isIntersecting())            {                this.airspace.setAttributes(getIntersectionAttributes());            }            else            {                this.airspace.setAttributes(this.getAttributes());            }        }    }    protected static class AirspaceBuilderModel extends AbstractTableModel    {        private static String[] columnName = {"Name"};        private static Class[] columnClass = {String.class};        private static String[] columnAttribute = {AVKey.DISPLAY_NAME};        private ArrayList<AirspaceEntry> entryList = new ArrayList<AirspaceEntry>();        public AirspaceBuilderModel()        {        }        public String getColumnName(int columnIndex)        {            return columnName[columnIndex];        }        public Class<?> getColumnClass(int columnIndex)        {            return columnClass[columnIndex];        }        public int getRowCount()        {            return this.entryList.size();        }        public int getColumnCount()        {            return 1;        }        public boolean isCellEditable(int rowIndex, int columnIndex)        {            return true;        }        public Object getValueAt(int rowIndex, int columnIndex)        {            AirspaceEntry entry = this.entryList.get(rowIndex);            return entry.getValue(columnAttribute[columnIndex]);        }        public void setValueAt(Object aObject, int rowIndex, int columnIndex)        {            AirspaceEntry entry = this.entryList.get(rowIndex);            String key = columnAttribute[columnIndex];            entry.setValue(key, aObject);        }        public java.util.List<AirspaceEntry> getEntries()        {            return Collections.unmodifiableList(this.entryList);        }        public void setEntries(Iterable<? extends AirspaceEntry> entries)        {            this.entryList.clear();            if (entries != null)            {                for (AirspaceEntry entry : entries)                {                    this.entryList.add(entry);                }            }            this.fireTableDataChanged();        }        public void addEntry(AirspaceEntry entry)        {            this.entryList.add(entry);            int index = this.entryList.size() - 1;            this.fireTableRowsInserted(index, index);        }        public void removeEntry(AirspaceEntry entry)        {            int index = this.entryList.indexOf(entry);            if (index != -1)            {                this.entryList.remove(entry);                this.fireTableRowsDeleted(index, index);            }        }        public void removeAllEntries()        {            this.entryList.clear();            this.fireTableDataChanged();        }        public AirspaceEntry getEntry(int index)        {            return this.entryList.get(index);        }        public AirspaceEntry setEntry(int index, AirspaceEntry entry)        {            return this.entryList.set(index, entry);        }        public int getIndexForEntry(AirspaceEntry entry)        {            return this.entryList.indexOf(entry);        }    }    protected static AirspaceFactory[] defaultAirspaceFactories = new AirspaceFactory[]    {        new PolygonAirspaceFactory(),        new SphereAirspaceFactory()    };    protected static final double DEFAULT_SHAPE_SIZE_METERS = 200000.0; // 200 km    protected interface AirspaceFactory    {        Airspace createAirspace(WorldWindow wwd, boolean fitShapeToViewport);        AirspaceEditor createEditor(Airspace airspace);    }    protected static class PolygonAirspaceFactory implements AirspaceFactory    {        public PolygonAirspaceFactory()        {        }        public Airspace createAirspace(WorldWindow wwd, boolean fitShapeToViewport)        {            Polygon poly = new Polygon();            poly.setAttributes(getDefaultAttributes());            poly.setValue(AVKey.DISPLAY_NAME, getNextName(toString()));            poly.setAltitudes(0.0, 0.0);            poly.setTerrainConforming(true, false);            this.initializePolygon(wwd, poly, fitShapeToViewport);            return poly;        }        public AirspaceEditor createEditor(Airspace airspace)        {            PolygonEditor editor = new PolygonEditor();            editor.setPolygon((Polygon) airspace);            setEditorAttributes(editor);            return editor;        }        protected void initializePolygon(WorldWindow wwd, Polygon polygon, boolean fitShapeToViewport)        {            // Creates a rectangle in the center of the viewport. Attempts to guess at a reasonable size and height.            Position position = ShapeUtils.getNewShapePosition(wwd);            Angle heading = ShapeUtils.getNewShapeHeading(wwd, true);            double sizeInMeters = fitShapeToViewport ?                ShapeUtils.getViewportScaleFactor(wwd) : DEFAULT_SHAPE_SIZE_METERS;            java.util.List<LatLon> locations = ShapeUtils.createSquareInViewport(wwd, position, heading, sizeInMeters);            double maxElevation = -Double.MAX_VALUE;            Globe globe = wwd.getModel().getGlobe();            for (LatLon ll : locations)            {                double e = globe.getElevation(ll.getLatitude(), ll.getLongitude());                if (e > maxElevation)                    maxElevation = e;            }            polygon.setAltitudes(0.0, maxElevation + sizeInMeters);            polygon.setTerrainConforming(true, false);            polygon.setLocations(locations);        }        public String toString()        {            return "Polygon";        }    }    protected static class SphereAirspaceFactory implements AirspaceFactory    {        public SphereAirspaceFactory()        {        }        public Airspace createAirspace(WorldWindow wwd, boolean fitShapeToViewport)

⌨️ 快捷键说明

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