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

📄 measuretoolpanel.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
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.WorldWindow;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.util.measure.MeasureTool;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.ArrayList;

/**
* Control panel for the MeasureTool.
*
* @author Patrick Murris
* @version $Id: MeasureToolPanel.java 9992 2009-04-08 04:38:54Z dcollins $
* @see gov.nasa.worldwind.util.measure.MeasureTool
*/
public class MeasureToolPanel extends JPanel
{
    private final WorldWindow wwd;
    private final MeasureTool measureTool;

    private JComboBox shapeCombo;
    private JComboBox pathTypeCombo;
    private JButton lineColorButton;
    private JButton pointColorButton;
    private JButton annotationColorButton;
    private JCheckBox followCheck;
    private JCheckBox showControlsCheck;
    private JCheckBox showAnnotationCheck;
    private JCheckBox rubberBandCheck;
    private JCheckBox freeHandCheck;
    private JButton newButton;
    private JButton pauseButton;
    private JButton endButton;
    private JLabel[] pointLabels;
    private JLabel lengthLabel;
    private JLabel areaLabel;
    private JLabel widthLabel;
    private JLabel heightLabel;
    private JLabel headingLabel;
    private JLabel centerLabel;

    private static ArrayList<Position> LINE = new ArrayList<Position>();
    private static ArrayList<Position> PATH = new ArrayList<Position>();
    private static ArrayList<Position> POLYGON = new ArrayList<Position>();
    static
    {
        LINE.add(Position.fromDegrees(44, 7, 0));
        LINE.add(Position.fromDegrees(45, 8, 0));

        PATH.addAll(LINE);
        PATH.add(Position.fromDegrees(46, 6, 0));
        PATH.add(Position.fromDegrees(47, 5, 0));
        PATH.add(Position.fromDegrees(45, 6, 0));

        POLYGON.addAll(PATH);
        POLYGON.add(Position.fromDegrees(44, 7, 0));
    }

    public MeasureToolPanel(WorldWindow wwdObject, MeasureTool measureToolObject)
    {
        super(new BorderLayout());
        this.wwd = wwdObject;
        this.measureTool = measureToolObject;
        this.makePanel(new Dimension(200, 300));

        // Handle measure tool events
        measureTool.addPropertyChangeListener(new PropertyChangeListener()
        {
            public void propertyChange(PropertyChangeEvent event)
            {
                // Add, remove or change positions
                if (event.getPropertyName().equals(MeasureTool.EVENT_POSITION_ADD)
                        || event.getPropertyName().equals(MeasureTool.EVENT_POSITION_REMOVE)
                        || event.getPropertyName().equals(MeasureTool.EVENT_POSITION_REPLACE))
                    fillPointsPanel();    // Update position list when changed

                // The tool was armed / disarmed
                else if(event.getPropertyName().equals(MeasureTool.EVENT_ARMED))
                {
                    if (measureTool.isArmed())
                    {
                        newButton.setEnabled(false);
                        pauseButton.setText("Pause");
                        pauseButton.setEnabled(true);
                        endButton.setEnabled(true);
                        ((Component) wwd).setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
                    }
                    else
                    {
                        newButton.setEnabled(true);
                        pauseButton.setText("Pause");
                        pauseButton.setEnabled(false);
                        endButton.setEnabled(false);
                        ((Component) wwd).setCursor(Cursor.getDefaultCursor());
                    }

                }

                // Metric changed - sent after each render frame
                else if(event.getPropertyName().equals(MeasureTool.EVENT_METRIC_CHANGED))
                {
                    updateMetric();
                }

            }
        });
    }

    public MeasureTool getMeasureTool()
    {
        return this.measureTool;
    }

    private void makePanel(Dimension size)
    {
        // Shape combo
        JPanel shapePanel = new JPanel(new GridLayout(1, 2, 5, 5));
        shapePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
        shapePanel.add(new JLabel("Shape:"));
        shapeCombo = new JComboBox(new String[] {"Line", "Path", "Polygon", "Circle", "Ellipse", "Square", "Rectangle"});
        shapeCombo.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                String item = (String)((JComboBox)event.getSource()).getSelectedItem();
                if (item.equals("Line") )
                    measureTool.setMeasureShape(MeasureTool.SHAPE_LINE);
                else if (item.equals("Path"))
                    measureTool.setMeasureShape(MeasureTool.SHAPE_PATH);
                else if (item.equals("Polygon"))
                    measureTool.setMeasureShape(MeasureTool.SHAPE_POLYGON);
                else if (item.equals("Circle"))
                    measureTool.setMeasureShape(MeasureTool.SHAPE_CIRCLE);
                else if (item.equals("Ellipse"))
                    measureTool.setMeasureShape(MeasureTool.SHAPE_ELLIPSE);
                else if (item.equals("Square"))
                    measureTool.setMeasureShape(MeasureTool.SHAPE_SQUARE);
                else if (item.equals("Rectangle"))
                    measureTool.setMeasureShape(MeasureTool.SHAPE_QUAD);

            }
        });
        shapePanel.add(shapeCombo);

        // Path type combo
        JPanel pathTypePanel = new JPanel(new GridLayout(1, 2, 5, 5));
        pathTypePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
        pathTypePanel.add(new JLabel("Path type:"));
        pathTypeCombo = new JComboBox(new String[] {"Linear", "Rhumb", "Great circle"});
        pathTypeCombo.setSelectedIndex(2);
        pathTypeCombo.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                String item = (String)((JComboBox)event.getSource()).getSelectedItem();
                if (item.equals("Linear") )
                    measureTool.setPathType(AVKey.LINEAR);
                else if (item.equals("Rhumb"))
                    measureTool.setPathType(AVKey.RHUMB_LINE);
                else if (item.equals("Great circle"))
                    measureTool.setPathType(AVKey.GREAT_CIRCLE);
            }
        });
        pathTypePanel.add(pathTypeCombo);

        // Check boxes panel
        JPanel checkPanel = new JPanel(new GridLayout(3, 2, 5, 5));
        checkPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

        followCheck = new JCheckBox("Follow terrain");
        followCheck.setSelected(measureTool.isFollowTerrain());
        followCheck.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                JCheckBox cb = (JCheckBox)event.getSource();
                measureTool.setFollowTerrain(cb.isSelected());
                wwd.redraw();
            }
        });
        checkPanel.add(followCheck);

        showControlsCheck = new JCheckBox("Control points");
        showControlsCheck.setSelected(measureTool.isShowControlPoints());
        showControlsCheck.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                JCheckBox cb = (JCheckBox)event.getSource();
                measureTool.setShowControlPoints(cb.isSelected());
                wwd.redraw();
            }
        });
        checkPanel.add(showControlsCheck);

        rubberBandCheck = new JCheckBox("Rubber band");
        rubberBandCheck.setSelected(measureTool.getController().isUseRubberBand());
        rubberBandCheck.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                JCheckBox cb = (JCheckBox)event.getSource();
                measureTool.getController().setUseRubberBand(cb.isSelected());
                freeHandCheck.setEnabled(cb.isSelected());
                wwd.redraw();
            }
        });
        checkPanel.add(rubberBandCheck);

        freeHandCheck = new JCheckBox("Free Hand");
        freeHandCheck.setSelected(measureTool.getController().isFreeHand());
        freeHandCheck.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                JCheckBox cb = (JCheckBox)event.getSource();
                measureTool.getController().setFreeHand(cb.isSelected());
                wwd.redraw();
            }
        });
        checkPanel.add(freeHandCheck);

        showAnnotationCheck = new JCheckBox("Tooltip");
        showAnnotationCheck.setSelected(measureTool.isShowAnnotation());
        showAnnotationCheck.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                JCheckBox cb = (JCheckBox)event.getSource();
                measureTool.setShowAnnotation(cb.isSelected());
                wwd.redraw();
            }
        });
        checkPanel.add(showAnnotationCheck);

        // Color buttons
        final JPanel colorPanel = new JPanel(new GridLayout(1, 2, 5, 5));
        colorPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
        lineColorButton = new JButton("Line");
        lineColorButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                Color c = JColorChooser.showDialog(colorPanel,
                        "Choose a color...", ((JButton)event.getSource()).getBackground());
                if (c != null)
                {
                    ((JButton)event.getSource()).setBackground(c);
                    measureTool.setLineColor(c);
                    Color fill = new Color(c.getRed() / 255f * .5f, 

⌨️ 快捷键说明

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