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

📄 measuretoolpanel.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            c.getGreen() / 255f * .5f, c.getBlue() / 255f * .5f, .5f);
                    measureTool.setFillColor(fill);
                }
            }
        });
        colorPanel.add(lineColorButton);
        lineColorButton.setBackground(measureTool.getLineColor());

        pointColorButton = new JButton("Points");
        pointColorButton.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.getControlPointsAttributes().setBackgroundColor(c);
                }
            }
        });
        colorPanel.add(pointColorButton);
        pointColorButton.setBackground(measureTool.getControlPointsAttributes().getBackgroundColor());

        annotationColorButton = new JButton("Tooltip");
        annotationColorButton.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.getAnnotationAttributes().setTextColor(c);
                }
            }
        });
        annotationColorButton.setBackground(measureTool.getAnnotationAttributes().getTextColor());
        colorPanel.add(annotationColorButton);

        // Action buttons
        JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 5, 5));
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
        newButton = new JButton("New");
        newButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent actionEvent)
            {
                measureTool.clear();
                measureTool.setArmed(true);
            }
        });
        buttonPanel.add(newButton);
        newButton.setEnabled(true);

        pauseButton = new JButton("Pause");
        pauseButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent actionEvent)
            {
                measureTool.setArmed(!measureTool.isArmed());
                pauseButton.setText(!measureTool.isArmed() ? "Resume" : "Pause");
                pauseButton.setEnabled(true);
                ((Component) wwd).setCursor(!measureTool.isArmed() ? Cursor.getDefaultCursor()
                        : Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
            }
        });
        buttonPanel.add(pauseButton);
        pauseButton.setEnabled(false);

        endButton = new JButton("End");
        endButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent actionEvent)
            {
                measureTool.setArmed(false);
            }
        });
        buttonPanel.add(endButton);
        endButton.setEnabled(false);

        // Preset buttons
        JPanel presetPanel = new JPanel(new GridLayout(1, 2, 5, 5));
        presetPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
        JButton bt = new JButton("Polyline");
        bt.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent actionEvent)
            {
                shapeCombo.setSelectedIndex(1);
                measureTool.setMeasureShape(new Polyline(PATH));
            }
        });
        presetPanel.add(bt);
        bt = new JButton("Surf. Quad");
        bt.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent actionEvent)
            {
                shapeCombo.setSelectedIndex(6);
                measureTool.setMeasureShape(new SurfaceQuad(Position.fromDegrees(44, 7, 0), 100e3, 50e3, Angle.fromDegrees(30)));
            }
        });
        presetPanel.add(bt);
        bt = new JButton("Polygon");
        bt.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent actionEvent)
            {
                shapeCombo.setSelectedIndex(2);
                measureTool.setMeasureShape(new SurfacePolygon(POLYGON));
            }
        });
        presetPanel.add(bt);


        // Point list
        JPanel pointPanel = new JPanel(new GridLayout(0, 1, 0, 4));
        pointPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

        this.pointLabels = new JLabel[100];
        for (int i = 0; i < this.pointLabels.length; i++)
        {
            this.pointLabels[i] = new JLabel("");
            pointPanel.add(this.pointLabels[i]);
        }

        // Put the point panel in a container to prevent scroll panel from stretching the vertical spacing.
        JPanel dummyPanel = new JPanel(new BorderLayout());
        dummyPanel.add(pointPanel, BorderLayout.NORTH);

        // Put the point panel in a scroll bar.
        JScrollPane scrollPane = new JScrollPane(dummyPanel);
        scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        if (size != null)
            scrollPane.setPreferredSize(size);

        // Metric
        JPanel metricPanel = new JPanel(new GridLayout(0, 2, 0, 4));
        metricPanel.setBorder( new CompoundBorder(
                new TitledBorder("Metric"), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
        metricPanel.add(new JLabel("Length:"));
        lengthLabel = new JLabel();
        metricPanel.add(lengthLabel);
        metricPanel.add(new JLabel("Area:"));
        areaLabel = new JLabel();
        metricPanel.add(areaLabel);
        metricPanel.add(new JLabel("Width:"));
        widthLabel = new JLabel();
        metricPanel.add(widthLabel);
        metricPanel.add(new JLabel("Height:"));
        heightLabel = new JLabel();
        metricPanel.add(heightLabel);
        metricPanel.add(new JLabel("Heading:"));
        headingLabel = new JLabel();
        metricPanel.add(headingLabel);
        metricPanel.add(new JLabel("Center:"));
        centerLabel = new JLabel();
        metricPanel.add(centerLabel);


        // Add all the panels to a titled panel
        JPanel outerPanel = new JPanel();
        outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));
        outerPanel.setBorder(
            new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Measure")));
        outerPanel.setToolTipText("Measure tool control and info");
        outerPanel.add(colorPanel);
        outerPanel.add(shapePanel);
        outerPanel.add(pathTypePanel);
        outerPanel.add(checkPanel);
        outerPanel.add(buttonPanel);
        //outerPanel.add(presetPanel);
        outerPanel.add(metricPanel);
        outerPanel.add(scrollPane);

        this.add(outerPanel, BorderLayout.NORTH);
    }

    private void fillPointsPanel()
    {
        int i = 0;
        if (measureTool.getPositions() != null)
        {
            for (LatLon pos : measureTool.getPositions())
            {
                if (i == this.pointLabels.length)
                    break;

                String las = String.format("Lat %7.4f\u00B0", pos.getLatitude().getDegrees());
                String los = String.format("Lon %7.4f\u00B0", pos.getLongitude().getDegrees());
                pointLabels[i++].setText(las + "  " + los);
            }
        }
        // Clear remaining labels
        for (; i < this.pointLabels.length; i++)
            pointLabels[i].setText("");

    }

    private void updateMetric()
    {
        // Update length label
        double value = measureTool.getLength();
        String s;
        if (value <= 0)
            s = "na";
        else if(value < 1000)
            s = String.format("%,7.1f m", value);
        else
            s = String.format("%,7.3f km", value / 1000);
        lengthLabel.setText(s);

        // Update area label
        value = measureTool.getArea();
        if (value < 0)
            s = "na";
        else if(value < 1e6)
            s = String.format("%,7.1f m2", value);
        else
            s = String.format("%,7.3f km2", value / 1e6);
        areaLabel.setText(s);

        // Update width label
        value = measureTool.getWidth();
        if (value < 0)
            s = "na";
        else if(value < 1000)
            s = String.format("%,7.1f m", value);
        else
            s = String.format("%,7.3f km", value / 1000);
        widthLabel.setText(s);

        // Update height label
        value = measureTool.getHeight();
        if (value < 0)
            s = "na";
        else if(value < 1000)
            s = String.format("%,7.1f m", value);
        else
            s = String.format("%,7.3f km", value / 1000);
        heightLabel.setText(s);

        // Update heading label
        Angle angle = measureTool.getOrientation();
        if(angle != null)
            s = String.format("%,6.2f\u00B0", angle.degrees);
        else
            s = "na";
        headingLabel.setText(s);

        // Update center label
        Position center = measureTool.getCenterPosition();
        if(center != null)
            s = String.format("%,7.4f\u00B0 %,7.4f\u00B0", center.getLatitude().degrees, center.getLongitude().degrees);
        else
            s = "na";
        centerLabel.setText(s);
    }
}

⌨️ 快捷键说明

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