sar2.java

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

JAVA
990
字号
/*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.*;import gov.nasa.worldwind.geom.Angle;import gov.nasa.worldwind.layers.Earth.*;import gov.nasa.worldwind.layers.Layer;import gov.nasa.worldwind.util.WWIO;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.nio.ByteBuffer;/** * @author tag * @version $Id: SAR2.java 10985 2009-05-07 22:11:23Z patrickmurris $ */public class SAR2 extends JFrame{    // Track and WWJ components.    private TrackController trackController;    private SARAnnotationSupport annotationSupport;    @SuppressWarnings({"FieldCanBeLocal"})    private ScalebarHint scalebarHint;    private WorldWindow wwd;    // Timer components.    @SuppressWarnings({"FieldCanBeLocal"})    private Timer redrawTimer;    private static final int REDRAW_TIMER_DELAY = 1000;  // 1 sec    // UI components.    private ControlPanel controlPanel;    private WWPanel wwPanel;    private LayerMenu layerMenu;    private ViewMenu viewLayerMenu;    private JCheckBoxMenuItem feetMenuItem;    private JCheckBoxMenuItem metersMenuItem;    private JCheckBoxMenuItem angleDDMenuItem;    private JCheckBoxMenuItem angleDMSMenuItem;    private HelpFrame helpFrame;    private JFileChooser openFileChooser;    private SaveTrackDialog saveTrackDialog;    private BulkDownloadFrame bulkDownloadFrame;    private static final int OK = 0;    private static final int CANCELLED = 2;    private static final int ERROR = 4;    // Unit constants.    private String elevationUnit;    public static final String ELEVATION_UNIT = "SAR2.ElevationUnit";    public static final String UNIT_IMPERIAL = "Imperial";    public static final String UNIT_METRIC = "Metric";    private final static double METER_TO_FEET = 3.280839895;    // Angle format    private String angleFormat;    public static final String ANGLE_FORMAT = "SAR2.AngleFormat";    public SAR2()    {        JPopupMenu.setDefaultLightWeightPopupEnabled(false);        ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);        initComponents();        this.setTitle(SARApp.APP_NAME_AND_VERSION);        this.wwd = this.wwPanel.getWwd();        for (Layer layer : this.wwd.getModel().getLayers())        {            if (layer instanceof USGSDigitalOrtho)            {                layer.setOpacity(0.5);                layer.setEnabled(false);            }            else if (layer instanceof USGSTopographicMaps)            {                layer.setEnabled(false);                layer.setOpacity(0.5);            }            else if (layer instanceof USGSUrbanAreaOrtho)            {                layer.setEnabled(false);            }        }        this.getAnalysisPanel().setWwd(this.wwd);        trackController = new TrackController();        this.trackController.setWwd(this.wwd);        this.trackController.setTracksPanel(this.getTracksPanel());        this.trackController.setAnalysisPanel(this.getAnalysisPanel());        this.layerMenu.setWwd(this.wwd);        this.viewLayerMenu.setWwd(this.wwd);        this.annotationSupport = new SARAnnotationSupport();        this.annotationSupport.setWwd(this.wwd);        this.scalebarHint = new ScalebarHint();        this.scalebarHint.setWwd(this.wwd);        setElevationUnit(UNIT_IMPERIAL);        setAngleFormat(Angle.ANGLE_FORMAT_DD);        // Setup and start redraw timer - to force downloads to completion without user interaction        this.redrawTimer = new Timer(REDRAW_TIMER_DELAY, new ActionListener()   // 1 sec        {            public void actionPerformed(ActionEvent event)            {                wwd.redraw();            }        });        this.redrawTimer.start();    }    public static void centerWindowInDesktop(Window window)    {        if (window != null)        {            int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;            int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;            Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration());            int desktopWidth = screenWidth - screenInsets.left - screenInsets.right;            int desktopHeight = screenHeight - screenInsets.bottom - screenInsets.top;            int frameWidth = window.getSize().width;            int frameHeight = window.getSize().height;            if (frameWidth > desktopWidth)                frameWidth = Math.min(frameWidth, desktopWidth);            if (frameHeight > desktopHeight)                frameHeight = Math.min(frameHeight, desktopHeight);            window.setPreferredSize(new Dimension(                frameWidth,                frameHeight));            window.pack();            window.setLocation(                (desktopWidth - frameWidth) / 2 + screenInsets.left,                (desktopHeight - frameHeight) / 2 + screenInsets.top);        }    }    public static double metersToFeet(double meters)    {        return meters * METER_TO_FEET;    }    public static double feetToMeters(double feet)    {        return feet / METER_TO_FEET;    }    public String getElevationUnit()    {        return this.elevationUnit;    }    public void setElevationUnit(String unit)    {        String oldValue = this.elevationUnit;        this.elevationUnit = unit;        elevationUnitChanged(oldValue, this.elevationUnit);    }    private void elevationUnitChanged(String oldValue, String newValue)    {        // Update unit menu selection.        if (UNIT_IMPERIAL.equals(newValue))            this.feetMenuItem.setSelected(true);        else if (UNIT_METRIC.equals(newValue))            this.metersMenuItem.setSelected(true);        // The TracksPanel doesn't listen to the WorldWindow. Handle it as a special case.        getTracksPanel().setElevationUnit(newValue);        // Use the WorldWindow as a vehicle for communicating the value change.        // Components that need to know the current unit will listen on this WorldWindow        // for a change with the name ELEVATION_UNIT.        this.wwd.setValue(ELEVATION_UNIT, newValue);        this.wwd.firePropertyChange(ELEVATION_UNIT, oldValue, newValue);        this.wwd.redraw();    }    public String getAngleFormat()    {        return this.angleFormat;    }    public void setAngleFormat(String format)    {        String oldValue = this.angleFormat;        this.angleFormat = format;        angleFormatChanged(oldValue, this.angleFormat);    }    private void angleFormatChanged(String oldValue, String newValue)    {        // Update angle format menu selection.        if (Angle.ANGLE_FORMAT_DD.equals(newValue))            this.angleDDMenuItem.setSelected(true);        else if (Angle.ANGLE_FORMAT_DMS.equals(newValue))            this.angleDMSMenuItem.setSelected(true);        // The TracksPanel doesn't listen to the WorldWindow. Handle it as a special case.        getTracksPanel().setAngleFormat(newValue);        // Use the WorldWindow as a vehicle for communicating the value change.        // Components that need to know the current angle format will listen on this WorldWindow        // for a change with the name ANGLE_FORMAT.        this.wwd.setValue(ANGLE_FORMAT, newValue);        this.wwd.firePropertyChange(ANGLE_FORMAT, oldValue, newValue);        this.wwd.redraw();    }    public SARTrack getCurrentTrack()    {        return getTracksPanel().getCurrentTrack();    }    public TracksPanel getTracksPanel()    {        return controlPanel.getTracksPanel();    }    public AnalysisPanel getAnalysisPanel()    {        return controlPanel.getAnalysisPanel1();    }    private void newTrack(String name)    {        Object inputValue = JOptionPane.showInputDialog(this, "Enter a new track name", "Add New Track",            JOptionPane.QUESTION_MESSAGE, null, null, name);        if (inputValue == null)            return;        name = inputValue.toString();                SARTrack st = new SARTrack(name);        trackController.addTrack(st);        st.clearDirtyBit();            }    private void newTrackFromFile(String filePath, String name)    {        if (filePath == null)        {            File file = showOpenDialog("Choose a track file");            if (file != null)                filePath = file.getPath();        }        if (filePath == null)            return;        SARTrack track = null;        try        {            track = SARTrack.fromFile(filePath);        }        catch (Exception e)        {            e.printStackTrace();        }        if (track == null)            return;        if (name != null)            track.setName(name);                trackController.addTrack(track);        try        {            String annotationFilePath = getAnnotationsPath(filePath);            this.annotationSupport.readAnnotations(annotationFilePath, track);        }        catch (Exception e)        {            e.printStackTrace();        }        track.clearDirtyBit();    }    private File showOpenDialog(String title)    {        if (this.openFileChooser == null)            this.openFileChooser = new JFileChooser();        if (title == null)            title = "Open Track";        this.openFileChooser.setDialogTitle(title);        this.openFileChooser.setMultiSelectionEnabled(false);        int state = this.openFileChooser.showOpenDialog(this);        return (state == JFileChooser.APPROVE_OPTION) ? this.openFileChooser.getSelectedFile() : null;    }    private void newTrackFromURL(String urlString, String name)    {        if (urlString == null)        {            Object input = JOptionPane.showInputDialog(SAR2.this, "Enter a track URL", "Add New Track",                JOptionPane.QUESTION_MESSAGE, null, null, null);            if (input != null)                urlString = input.toString();        }        if (urlString == null)            return;        URL url = makeURL(urlString);        if (url == null)            return;        SARTrack track = null;        try        {            ByteBuffer bb = WWIO.readURLContentToBuffer(url);            File file = WWIO.saveBufferToTempFile(bb, ".xml");            track = SARTrack.fromFile(file.getPath());

⌨️ 快捷键说明

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