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

📄 mgrsattributespanel.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (C) 2001, 2007 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.avlist.AVKey;import gov.nasa.worldwind.layers.Earth.MGRSGraticuleLayer;import gov.nasa.worldwind.layers.Earth.UTMGraticuleLayer;import gov.nasa.worldwind.util.Logging;import javax.swing.*;import javax.swing.border.EmptyBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.awt.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.net.URL;import java.util.HashMap;import java.util.Map;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.io.FileWriter;/** * @author dcollins * @version $Id: MGRSAttributesPanel.java 5232 2008-04-30 20:25:04Z dcollins $ */public class MGRSAttributesPanel extends JPanel{    // Logical components.    private final MGRSGraticuleLayer layer;    // UI components.    private JList itemList;    private JComboBox maxResolutionComboBox;    private JButton saveStateButton;    private JButton loadStateButton;    private JPanel cardPanel;    private CardLayout cardLayout;    private Map<String, Component> graticuleAttribPanelMap = new HashMap<String, Component>();    // Helper properties.    private boolean ignoreLayerEvents = false;    private boolean ignoreUIEvents = false;    private String[] ALL_GRATICULE_TYPES = new String[] {        UTMGraticuleLayer.GRATICULE_UTM,        MGRSGraticuleLayer.GRATICULE_UTM_GRID,        MGRSGraticuleLayer.GRATICULE_100000M,        MGRSGraticuleLayer.GRATICULE_10000M,        MGRSGraticuleLayer.GRATICULE_1000M,        MGRSGraticuleLayer.GRATICULE_100M,        MGRSGraticuleLayer.GRATICULE_10M,        MGRSGraticuleLayer.GRATICULE_1M    };    private String[] MGRS_GRATICULE_TYPES = new String[] {        MGRSGraticuleLayer.GRATICULE_UTM_GRID,        MGRSGraticuleLayer.GRATICULE_100000M,        MGRSGraticuleLayer.GRATICULE_10000M,        MGRSGraticuleLayer.GRATICULE_1000M,        MGRSGraticuleLayer.GRATICULE_100M,        MGRSGraticuleLayer.GRATICULE_10M,        MGRSGraticuleLayer.GRATICULE_1M    };    public MGRSAttributesPanel(MGRSGraticuleLayer mgrsGraticuleLayer)    {        if (mgrsGraticuleLayer == null)        {            String message = Logging.getMessage("nullValue.LayerIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        this.layer = mgrsGraticuleLayer;        this.layer.addPropertyChangeListener(new PropertyChangeListener() {            public void propertyChange(PropertyChangeEvent event) {                onLayerPropertyChanged(event);            }        });        init();    }    private void init()    {        // Initialize UI components.        makeComponents();        // Initialize UI layout.        layoutComponents();        // Update UI state to reflect the current layer state.        updateComponents();        String selectedType = MGRSGraticuleLayer.GRATICULE_UTM_GRID;        this.itemList.setSelectedValue(selectedType, true);        this.cardLayout.show(this.cardPanel, selectedType);    }    public final MGRSGraticuleLayer getLayer()    {        return this.layer;    }    public static JDialog showDialog(Component component, String title, MGRSGraticuleLayer mgrsGraticuleLayer)    {        if (mgrsGraticuleLayer == null)        {            String message = Logging.getMessage("nullValue.LayerIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        JDialog dialog;        if (component != null && component instanceof Dialog)        {            dialog = new JDialog((Dialog) component);        }        else if (component != null && component instanceof Frame)        {            dialog = new JDialog((Frame) component);        }        else        {            dialog = new JDialog();        }        if (title != null)        {            dialog.setTitle(title);        }        MGRSAttributesPanel panel = new MGRSAttributesPanel(mgrsGraticuleLayer);        dialog.getContentPane().setLayout(new BorderLayout());        dialog.getContentPane().add(panel, BorderLayout.CENTER);        dialog.pack();        dialog.setVisible(true);        return dialog;    }    public String getSelectedGraticule()    {        Object selectedValue = this.itemList.getSelectedValue();        return selectedValue != null ? selectedValue.toString() : null;    }    public void setSelectedGraticule(String graticuleType)    {        if (graticuleType == null)        {            String message = Logging.getMessage("nullValue.StringIsNull");            Logging.logger().severe(message);            throw new IllegalArgumentException(message);        }        this.itemList.setSelectedValue(graticuleType, true);        this.cardLayout.show(this.cardPanel, graticuleType);    }    private void onListSelectionChanged(ListSelectionEvent event)    {        if (event != null)        {            Object selectedValue = this.itemList.getSelectedValue();            this.cardLayout.show(this.cardPanel, selectedValue.toString());        }    }    private void onMaxResolutionChanged(ActionEvent event)    {        if (event != null)        {            if (!this.ignoreUIEvents)            {                updateLayer();            }        }    }    private void onSaveStatePressed(ActionEvent event)    {        if (event == null)            return;        JFileChooser fc = new JFileChooser();        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);        int resultVal = fc.showSaveDialog(this);        if (resultVal != JFileChooser.APPROVE_OPTION)            return;        File file = fc.getSelectedFile();        if (file == null)            return;        try        {            String stateInXml = this.layer.getRestorableState();            saveString(stateInXml, file);        }        catch (Exception e)        {            e.printStackTrace();        }    }    private void onLoadStatePressed(ActionEvent event)    {        if (event == null)            return;        JFileChooser fc = new JFileChooser();        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);        int resultVal = fc.showOpenDialog(this);        if (resultVal != JFileChooser.APPROVE_OPTION)            return;        File file = fc.getSelectedFile();        if (file == null)            return;        try        {            String stateInXml = loadString(file);            this.layer.restoreState(stateInXml);            this.layer.firePropertyChange(AVKey.LAYER, null, this.layer);        }        catch (Exception e)        {            e.printStackTrace();        }    }    private void onPanelStateChanged(PropertyChangeEvent event, String graticuleType)    {        if (event != null && graticuleType != null)        {            if (!this.ignoreUIEvents)            {                if (//event.getPropertyName().equals(GraticuleAttributesPanel.LINE_ENABLED_PROPERTY)                    event.getPropertyName().equals(GraticuleAttributesPanel.LINE_COLOR_PROPERTY)                    || event.getPropertyName().equals(GraticuleAttributesPanel.LINE_WIDTH_PROPERTY)                    || event.getPropertyName().equals(GraticuleAttributesPanel.LINE_STYLE_PROPERTY)                    || event.getPropertyName().equals(GraticuleAttributesPanel.LABEL_ENABLED_PROPERTY)                    || event.getPropertyName().equals(GraticuleAttributesPanel.LABEL_COLOR_PROPERTY)                    || event.getPropertyName().equals(GraticuleAttributesPanel.LABEL_FONT_PROPERTY))                {                    updateLayer();                }            }        }    }    private void updateLayer()    {        this.ignoreLayerEvents = true;        try        {            if (this.layer != null)            {                this.layer.setMaximumGraticuleResolution(this.maxResolutionComboBox.getSelectedItem().toString());                for (Map.Entry<String, Component> entry : this.graticuleAttribPanelMap.entrySet())                {                    if (entry.getKey() != null && entry.getValue() != null)                    {                        if (entry.getValue() instanceof GraticuleAttributesPanel)                        {                            updateLayerState((GraticuleAttributesPanel) entry.getValue(), entry.getKey());                        }                    }                }            }        }        finally        {            this.ignoreLayerEvents = false;        }    }    private void updateLayerState(GraticuleAttributesPanel attributesPanel, String graticuleType)    {        if (this.layer != null && attributesPanel != null && graticuleType != null)        {            //this.layer.setDrawGraticule(attributesPanel.isLineEnableSelected(), graticuleType);            this.layer.setGraticuleLineColor(attributesPanel.getSelectedLineColor(), graticuleType);            this.layer.setGraticuleLineWidth(attributesPanel.getSelectedLineWidth(), graticuleType);            this.layer.setGraticuleLineStyle(attributesPanel.getSelectedLineStyle(), graticuleType);            this.layer.setDrawLabels(attributesPanel.isLabelEnableSelected(), graticuleType);            this.layer.setLabelColor(attributesPanel.getSelectedLabelColor(), graticuleType);            this.layer.setLabelFont(attributesPanel.getSelectedLabelFont(), graticuleType);            this.layer.firePropertyChange(AVKey.LAYER, null, this.layer);        }    }

⌨️ 快捷键说明

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