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

📄 sectorselector.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (C) 2001, 2009 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples.util;import gov.nasa.worldwind.*;import gov.nasa.worldwind.avlist.AVKey;import gov.nasa.worldwind.event.*;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.globes.EllipsoidalGlobe;import gov.nasa.worldwind.layers.*;import gov.nasa.worldwind.pick.*;import gov.nasa.worldwind.render.*;import gov.nasa.worldwind.util.Logging;import java.awt.*;import java.awt.event.*;/** * Provides an interactive region selector. To use, construct and call enable/disable. Register a property listener to * receive changes to the sector as they occur, or just wait until the user is done and then query the result via {@link * #getSector()}. * * @author tag * @version $Id: SectorSelector.java 10902 2009-05-06 04:03:03Z dcollins $ */public class SectorSelector extends WWObjectImpl        implements SelectListener, MouseListener, MouseMotionListener, RenderingListener{    public final static String SECTOR_PROPERTY = "gov.nasa.worldwind.SectorSelector";    protected static final int NONE = 0;    protected static final int MOVING = 1;    protected static final int SIZING = 2;    protected static final int NORTH = 1;    protected static final int SOUTH = 2;    protected static final int EAST = 4;    protected static final int WEST = 8;    protected static final int NORTHWEST = NORTH + WEST;    protected static final int NORTHEAST = NORTH + EAST;    protected static final int SOUTHWEST = SOUTH + WEST;    protected static final int SOUTHEAST = SOUTH + EAST;    private final WorldWindow wwd;    private final Layer layer;    private final RegionShape shape;    private double edgeFactor = 0.10;    // state tracking fields    private boolean armed = false;    private int operation = NONE;    private int side = NONE;    private Position previousPosition = null;    private Sector previousSector = null;    public SectorSelector(WorldWindow worldWindow)    {        if (worldWindow == null)        {            String msg = Logging.getMessage("nullValue.WorldWindow");            Logging.logger().log(java.util.logging.Level.SEVERE, msg);            throw new IllegalArgumentException(msg);        }        this.wwd = worldWindow;        this.layer = new RenderableLayer();        this.shape = new RegionShape(Sector.EMPTY_SECTOR);        ((RenderableLayer) this.layer).addRenderable(this.shape);    }    protected SectorSelector(WorldWindow worldWindow, RegionShape shape, RenderableLayer rLayer)    {        if (worldWindow == null)        {            String msg = Logging.getMessage("nullValue.WorldWindow");            Logging.logger().log(java.util.logging.Level.SEVERE, msg);            throw new IllegalArgumentException(msg);        }        if (shape == null)        {            String msg = Logging.getMessage("nullValue.Shape");            Logging.logger().log(java.util.logging.Level.SEVERE, msg);            throw new IllegalArgumentException(msg);        }        if (rLayer == null)        {            String msg = Logging.getMessage("nullValue.Layer");            Logging.logger().log(java.util.logging.Level.SEVERE, msg);            throw new IllegalArgumentException(msg);        }        this.wwd = worldWindow;        this.shape = shape;        this.layer = rLayer;        rLayer.addRenderable(this.shape);    }    public WorldWindow getWwd()    {        return wwd;    }    public Layer getLayer()    {        return layer;    }    public void enable()    {        this.getShape().setStartPosition(null);        LayerList layers = this.getWwd().getModel().getLayers();        if (!layers.contains(this.getLayer()))            layers.add(this.getLayer());        if (!this.getLayer().isEnabled())            this.getLayer().setEnabled(true);        this.setArmed(true);        this.getWwd().addRenderingListener(this);        this.getWwd().addSelectListener(this);        this.getWwd().getInputHandler().addMouseListener(this);        this.getWwd().getInputHandler().addMouseMotionListener(this);        this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));    }    public void disable()    {        this.getWwd().removeRenderingListener(this);        this.getWwd().removeSelectListener(this);        this.getWwd().getInputHandler().removeMouseListener(this);        this.getWwd().getInputHandler().removeMouseMotionListener(this);        this.getWwd().getModel().getLayers().remove(this.getLayer());        this.getShape().clear();    }    public Sector getSector()    {        return this.getShape().hasSelection() ? this.getShape().getSector() : null;        // TODO: Determine how to handle date-line spanning sectors.    }    public Color getInteriorColor()    {        return this.getShape().getInteriorColor();    }    public void setInteriorColor(Color color)    {        this.getShape().setInteriorColor(color);    }    public Color getBorderColor()    {        return this.getShape().getBorderColor();    }    public void setBorderColor(Color color)    {        this.getShape().setBorderColor(color);    }    public double getInteriorOpacity()    {        return this.getShape().getInteriorOpacity();    }    public void setInteriorOpacity(double opacity)    {        this.getShape().setInteriorOpacity(opacity);    }    public double getBorderOpacity()    {        return this.getShape().getBorderOpacity();    }    public void setBorderOpacity(double opacity)    {        this.getShape().setBorderOpacity(opacity);    }    public double getBorderWidth()    {        return this.getShape().getBorderWidth();    }    public void setBorderWidth(double width)    {        this.getShape().setBorderWidth(width);    }    protected RegionShape getShape()    {        return shape;    }    protected boolean isArmed()    {        return armed;    }    protected void setArmed(boolean armed)    {        this.armed = armed;    }    protected int getOperation()    {        return operation;    }    protected void setOperation(int operation)    {        this.operation = operation;    }    protected int getSide()    {        return side;    }    protected void setSide(int side)    {        this.side = side;    }    protected Position getPreviousPosition()    {        return previousPosition;    }    protected void setPreviousPosition(Position previousPosition)    {        this.previousPosition = previousPosition;    }    protected double getEdgeFactor()    {        return edgeFactor;    }    protected void setEdgeFactor(double edgeFactor)    {        this.edgeFactor = edgeFactor;    }    public void stageChanged(RenderingEvent event)    {        if (!event.getStage().equals(RenderingEvent.AFTER_BUFFER_SWAP))            return;        // We notify of changes during this rendering stage because the sector is updated within the region shape's        // render method.        this.notifySectorChanged();    }    protected void notifySectorChanged()    {        if (this.getShape().hasSelection() && this.getSector() != null && !this.getSector().equals(this.previousSector))        {            this.firePropertyChange(SECTOR_PROPERTY, this.previousSector, this.getShape().getSector());            this.previousSector = this.getSector();        }    }//    // Mouse events are used to initiate and track initial drawing of the region. When the selector is enabled it is    // "armed", meaning that the next mouse press on the globe will initiate the region selection and display. The    // selector is then disarmed so that subsequent mouse presses either size or move the region when they occur on    // the region, or move the globe if they occur outside the region.    //    public void mousePressed(MouseEvent mouseEvent)    {        if (MouseEvent.BUTTON1_DOWN_MASK != mouseEvent.getModifiersEx())            return;        if (!this.isArmed())            return;        this.getShape().setResizeable(true);        this.getShape().setStartPosition(null);        this.setArmed(false);        mouseEvent.consume();    }    public void mouseReleased(MouseEvent mouseEvent)    {        if (MouseEvent.BUTTON1 != mouseEvent.getButton())            return;        if (this.getShape().isResizeable())            this.setCursor(null);        this.getShape().setResizeable(false);        mouseEvent.consume(); // prevent view operations    }    public void mouseDragged(MouseEvent mouseEvent)    {        if (MouseEvent.BUTTON1_DOWN_MASK != mouseEvent.getModifiersEx())            return;        if (this.getShape().isResizeable())            mouseEvent.consume(); // prevent view operations    }    public void mouseClicked(MouseEvent e)    {    }    public void mouseEntered(MouseEvent e)    {    }    public void mouseExited(MouseEvent e)    {    }    public void mouseMoved(MouseEvent e)    {    }    //    // Selection events are used to resize and move the region    //    public void selected(SelectEvent event)    {        if (event == null)        {            String msg = Logging.getMessage("nullValue.EventIsNull");            Logging.logger().log(java.util.logging.Level.FINE, msg);            throw new IllegalArgumentException(msg);        }        if (event.getTopObject() != null && !(event.getTopObject() instanceof RegionShape))        {            this.setCursor(null);            return;        }        if (event.getEventAction().equals(SelectEvent.LEFT_PRESS))        {            this.setPreviousPosition(this.getWwd().getCurrentPosition());        }        else if (event.getEventAction().equals(SelectEvent.DRAG))        {            DragSelectEvent dragEvent = (DragSelectEvent) event;            Object topObject = dragEvent.getTopObject();            if (topObject == null)                return;            RegionShape dragObject = (RegionShape) topObject;            if (this.getOperation() == SIZING)            {                Sector newSector = this.resizeShape(dragObject, this.getSide());                if (newSector != null)                    dragObject.setSector(newSector);            }            else            {                this.setSide(this.determineAdjustmentSide(dragObject, this.getEdgeFactor()));                if (this.getSide() == NONE || this.getOperation() == MOVING)                {                    this.setOperation(MOVING);                    this.dragWholeShape(dragEvent, dragObject);                }                else                {                    Sector newSector = this.resizeShape(dragObject, this.getSide());                    if (newSector != null)                        dragObject.setSector(newSector);                    this.setOperation(SIZING);                }            }            this.setPreviousPosition(this.getWwd().getCurrentPosition());            this.notifySectorChanged();        }        else if (event.getEventAction().equals(SelectEvent.DRAG_END))        {            this.setOperation(NONE);            this.setPreviousPosition(null);        }        else if (event.getEventAction().equals(SelectEvent.ROLLOVER))        {            if (!(this.getWwd() instanceof Component))                return;            if (event.getTopObject() == null || event.getTopPickedObject().isTerrain())            {                this.setCursor(null);                return;            }

⌨️ 快捷键说明

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