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

📄 draggingconformingshapes.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (C) 2001, 2006 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples;import gov.nasa.worldwind.awt.WorldWindowGLCanvas;import gov.nasa.worldwind.event.SelectEvent;import gov.nasa.worldwind.event.SelectListener;import gov.nasa.worldwind.geom.Angle;import gov.nasa.worldwind.geom.LatLon;import gov.nasa.worldwind.geom.Position;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.layers.IconLayer;import gov.nasa.worldwind.layers.RenderableLayer;import gov.nasa.worldwind.pick.PickedObjectList;import gov.nasa.worldwind.render.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.font.*;import java.util.ArrayList;import java.util.HashMap;/** * @author tag * @version $Id: DraggingShapes.java 7478 2008-11-11 14:54:53Z jmiller $ */public class DraggingConformingShapes extends ApplicationTemplate{    private static class AppFrame extends ApplicationTemplate.AppFrame    {        private boolean	drawWireframeInterior = false, drawWireframeExterior = false;        private boolean buildConformingShapes = true;        private boolean drawShapeInterior = true, drawShapeBoundary = true;        private RenderableLayer rLayer;        private int numShapesInLayer = -1; // -1 indicates demo set should be built.        public AppFrame()        {            super(true,true,true);            rLayer = new RenderableLayer();            rebuildRenderableShapeLayer(this.getWwd().getModel().getGlobe());            insertBeforeCompass(this.getWwd(), rLayer);            insertBeforeCompass(this.getWwd(), this.buildIconLayer());            this.getLayerPanel().update(this.getWwd());            makeControlPanel(this.getLayerPanel());            this.getWwd().addSelectListener(new SelectListener()            {                private WWIcon lastToolTipIcon = null;                private BasicDragger dragger = new BasicDragger(getWwd());                public void selected(SelectEvent event)                {                    // Have hover selections show a picked icon's tool tip.                    if (event.getEventAction().equals(SelectEvent.HOVER))                    {                        // If a tool tip is already showing, undisplay it.                        if (lastToolTipIcon != null)                        {                            lastToolTipIcon.setShowToolTip(false);                            this.lastToolTipIcon = null;                            AppFrame.this.getWwd().repaint();                        }                        // If there's a selection, we're not dragging, and the selection is an icon, show tool tip.                        if (event.hasObjects() && !this.dragger.isDragging())                        {                            if (event.getTopObject() instanceof WWIcon)                            {                                this.lastToolTipIcon = (WWIcon) event.getTopObject();                                lastToolTipIcon.setShowToolTip(true);                                AppFrame.this.getWwd().repaint();                            }                            else if (event.getTopObject() instanceof ConformingPolygon)                            {                                ConformingPolygon cp = (ConformingPolygon)event.getTopObject();                                Globe g = AppFrame.this.getWwd().getModel().getGlobe();                                double length = cp.getLength(g);                                double area = cp.getArea(g);                                double perimeter = cp.getPerimeter(g);                                double width = cp.getWidth(g);                                double height = cp.getHeight(g);                                System.out.println("length = " + length + ", area = " + area + ", perimeter = " + perimeter);                                System.out.println("width = " + width + ", height = " + height);                            }                        }                    }                    // Have rollover events highlight the rolled-over object.                    else if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !this.dragger.isDragging())                    {                        AppFrame.this.highlight(event.getTopObject());                    }                    // Have drag events drag the selected object.                    else if (event.getEventAction().equals(SelectEvent.DRAG_END)                        || event.getEventAction().equals(SelectEvent.DRAG))                    {                        // Delegate dragging computations to a dragger.                        this.dragger.selected(event);                        // We missed any roll-over events while dragging, so highlight any under the cursor now,                        // or de-highlight the dragged shape if it's no longer under the cursor.                        if (event.getEventAction().equals(SelectEvent.DRAG_END))                        {                            PickedObjectList pol = getWwd().getObjectsAtCurrentPosition();                            if (pol != null)                            {                                AppFrame.this.highlight(pol.getTopObject());                                AppFrame.this.getWwd().repaint();                            }                        }                    }                }            });        }        WWIcon lastPickedIcon;        private void highlight(Object o)        {            // Manage highlighting of icons.            if (this.lastPickedIcon == o)                return; // same thing selected            // Turn off highlight if on.            if (this.lastPickedIcon != null)            {                this.lastPickedIcon.setHighlighted(false);                this.lastPickedIcon = null;            }            // Turn on highlight if object selected.            if (o != null && o instanceof WWIcon)            {                this.lastPickedIcon = (WWIcon) o;                this.lastPickedIcon.setHighlighted(true);            }        }        private IconLayer buildIconLayer()        {            IconLayer layer = new IconLayer();            Font font = this.makeToolTipFont();            // Distribute little NASA icons around the equator. Put a few at non-zero altitude.            for (double lat = 0; lat < 10; lat += 10)            {                for (double lon = -180; lon < 180; lon += 10)                {                    double alt = 0;                    if (lon % 90 == 0)                        alt = 2000000;                    WWIcon icon = new UserFacingIcon("images/32x32-icon-nasa.png",                        new Position(Angle.fromDegrees(lat), Angle.fromDegrees(lon), alt));                    icon.setHighlightScale(1.5);                    icon.setToolTipFont(font);                    icon.setToolTipText(icon.getImageSource().toString());                    icon.setToolTipTextColor(java.awt.Color.YELLOW);                    layer.addIcon(icon);                }            }            return layer;        }        private void makeControlPanel(LayerPanel lp)        {            JPanel controlPanel = new JPanel();            controlPanel.setLayout(new GridLayout(0,1));            String[] shapeChoices = { "Demo", "25", "50", "100", "200", "400", "800", "1600", "3200" };            JComboBox jcb = new JComboBox(shapeChoices);            jcb.setSelectedIndex(0);            jcb.addActionListener( new ActionListener()            {                private int[] num = { -1, 25, 50, 100, 200, 400, 800, 1600, 3200 };                public void actionPerformed(ActionEvent e)                {                    JComboBox theBox = (JComboBox)e.getSource();                    int which = theBox.getSelectedIndex();                    AppFrame.this.numShapesInLayer = num[which];                    AppFrame.this.rLayer.removeAllRenderables();                    AppFrame.this.rebuildRenderableShapeLayer(                            AppFrame.this.getWwd().getModel().getGlobe());                    AppFrame.this.getWwd().redraw();                }            });            controlPanel.add(jcb);            JCheckBox buildWhatCB = new JCheckBox("Build 'Conforming' Shapes", buildConformingShapes);            controlPanel.add(buildWhatCB);            buildWhatCB.addActionListener( new ActionListener() {                public void actionPerformed(ActionEvent e)                {                    buildConformingShapes = !buildConformingShapes;                    AppFrame.this.rLayer.removeAllRenderables();                    AppFrame.this.rebuildRenderableShapeLayer(                            AppFrame.this.getWwd().getModel().getGlobe());                    AppFrame.this.getWwd().redraw();                }} );            JCheckBox fillCB = new JCheckBox("Fill shape boundaries", drawShapeInterior);            controlPanel.add(fillCB);            fillCB.addActionListener( new ActionListener() {                public void actionPerformed(ActionEvent e)                {                    drawShapeInterior = !drawShapeInterior;                    for (Renderable r : rLayer.getRenderables())                        if (r instanceof ConformingShape)                            ((ConformingShape)r).setDrawInterior(drawShapeInterior);                        else                            ((AbstractSurfaceShape)r).getAttributes().setDrawOutline(drawShapeInterior);                    AppFrame.this.getWwd().redraw();

⌨️ 快捷键说明

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