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

📄 viewinputhandler.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        View view = this.getView();        if (view == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (view instanceof OrbitView)        {            Angle newHeading = BasicOrbitViewLimits.limitHeading(Angle.ZERO, ((OrbitView) view).getOrbitViewLimits());            view.applyStateIterator(ScheduledOrbitViewStateIterator.createHeadingIterator(                ((OrbitView) view).getHeading(), newHeading));        }    }    protected void onResetHeadingAndPitch()    {        View view = this.getView();        if (view == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (view instanceof OrbitView)        {            Angle newHeading = BasicOrbitViewLimits.limitHeading(Angle.ZERO, ((OrbitView) view).getOrbitViewLimits());            Angle newPitch = BasicOrbitViewLimits.limitPitch(Angle.ZERO, ((OrbitView) view).getOrbitViewLimits());            view.applyStateIterator(ScheduledOrbitViewStateIterator.createHeadingPitchIterator(                ((OrbitView) view).getHeading(), newHeading, ((OrbitView) view).getPitch(), newPitch));        }    }    protected void onRotateView(Angle headingChange, Angle pitchChange,        ViewInputAttributes.ActionAttributes actionAttribs)    {        View view = this.getView();        if (view == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (view instanceof OrbitView)        {            if (!headingChange.equals(Angle.ZERO))                this.changeHeading((OrbitView) view, headingChange, actionAttribs);            if (!pitchChange.equals(Angle.ZERO))                this.changePitch((OrbitView) view, pitchChange, actionAttribs);        }    }    protected void onStopView()    {        View view = this.getView();        if (view == null) // include this test to ensure any derived implementation performs it        {            return;        }        view.stopMovement();    }    protected void onZoomView(double zoomChange, ViewInputAttributes.ActionAttributes actionAttribs)    {        View view = this.getView();        if (view == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (zoomChange == 0)        {            return;        }        if (view instanceof OrbitView)        {            this.changeZoom((OrbitView) view, zoomChange, actionAttribs);        }    }    //**************************************************************//    //********************  Key Events  ****************************//    //**************************************************************//    public void keyTyped(KeyEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.keyEventState.keyTyped(e);    }    public void keyPressed(KeyEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.keyEventState.keyPressed(e);        this.handleKeyPressed(e);    }    public void keyReleased(KeyEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.keyEventState.keyReleased(e);    }    protected void handleKeyPressed(KeyEvent e)    {        if (e.getKeyCode() == KeyEvent.VK_N)        {            this.onResetHeading();        }        else if (e.getKeyCode() == KeyEvent.VK_R)        {            this.onResetHeadingAndPitch();        }        else if (e.getKeyCode() == KeyEvent.VK_SPACE)        {            this.onStopView();        }        else        {            // Determine whether or not the current key state would have generated a view change event.            // If so, issue a repaint event to give the per-frame input a chance to run.            if (this.handlePerFrameKeyState(this.keyEventState, QUERY_EVENTS))            {                View view = this.getView();                if (view != null)                {                    view.firePropertyChange(AVKey.VIEW, null, view);                }            }        }    }    //**************************************************************//    //********************  Mouse Events  **************************//    //**************************************************************//    public void mouseClicked(MouseEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.handleMouseClicked(e);    }    public void mousePressed(MouseEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.updateMousePoint(e);        this.setSelectedPosition(this.computeSelectedPosition());    }    public void mouseReleased(MouseEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.updateMousePoint(e);        this.setSelectedPosition(null);    }    public void mouseEntered(MouseEvent e)    {       if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            //noinspection UnnecessaryReturnStatement            return;        }    }    public void mouseExited(MouseEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            //noinspection UnnecessaryReturnStatement            return;        }    }    protected void handleMouseClicked(MouseEvent e)    {        if (MouseEvent.BUTTON1 == e.getButton())        {            this.handleMouseFocus(e);        }    }    @SuppressWarnings({"UnusedDeclaration"})    protected void handleMouseFocus(MouseEvent e)    {        Position pos = this.computeSelectedPosition();        if (pos == null)            return;        ViewInputAttributes.ActionAttributes actionAttributes = this.attributes.getActionAttributes(            ViewInputAttributes.DEVICE_MOUSE, ViewInputAttributes.VIEW_FOCUS);        this.onFocusView(pos, actionAttributes);    }    //**************************************************************//    //********************  Mouse Motion Events  *******************//    //**************************************************************//    public void mouseDragged(MouseEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            return;        }        this.updateMousePoint(e);        this.handleMouseDragged(e);    }    public void mouseMoved(MouseEvent e)    {        if (this.wwd == null) // include this test to ensure any derived implementation performs it        {            return;        }        if (e == null) // include this test to ensure any derived implementation performs it        {            //noinspection UnnecessaryReturnStatement            return;        }        this.updateMousePoint(e);    }        protected void handleMouseDragged(MouseEvent e)    {        // If the rotate modifier is down, or if the rotate button is down, then invoke rotate commands.        if ((e.getModifiersEx() & (MouseEvent.CTRL_DOWN_MASK | MouseEvent.META_DOWN_MASK)) != 0            || (e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) != 0)        {            if ((e.getModifiersEx() & (MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK)) != 0)            {                this.handleMouseRotate(e);            }        }        // Otherwise, if the zoom button is down, then invoke zoom commands.        else if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) != 0)        {            this.handleMouseZoom(e);        }        // Otherwise, if the pan button is down, then invoke pan commands.        else if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0)        {            this.handleMousePan(e);        }    }    @SuppressWarnings({"UnusedDeclaration"})    protected void handleMousePan(MouseEvent e)    {        Point point = constrainToSourceBounds(this.getMousePoint(), this.wwd);        Point lastPoint = constrainToSourceBounds(this.getLastMousePoint(), this.wwd);        if (point == null || lastPoint == null)        {            return;        }        if (this.getSelectedPosition() == null)        {            // Compute the current selected position if none exists. This happens if the user starts dragging when            // the cursor is off the globe, then drags the cursor onto the globe.            this.setSelectedPosition(this.computeSelectedPosition());        }        else if (this.computeSelectedPosition() == null)        {            // User dragged the cursor off the globe. Clear the selected position to ensure a new one will be            // computed if the user drags the cursor back to the globe.            this.setSelectedPosition(null);        }        else if (this.computeSelectedPointAt(point) == null || this.computeSelectedPointAt(lastPoint) == null)        {            // User selected a position that is won't work for dragging. Probably the selected elevation is above the            // eye elevation, in which case dragging becomes unpredictable. Clear the selected position to ensure            // a new one will be computed if the user drags the cursor to a valid position.            this.setSelectedPosition(null);        }        Vec4 vec = this.computeSelectedPointAt(point);        Vec4 lastVec = this.computeSelectedPointAt(lastPoint);        // Cursor is on the globe, pan between the two positions.        if (vec != null && lastVec != null)        {            ViewInputAttributes.ActionAttributes actionAttributes =                this.attributes.getActionAttributes(ViewInputAttributes.DEVICE_MOUSE,                    ViewInputAttributes.VIEW_PAN);            // Compute the change in view location given two screen points and corresponding world vectors.            LatLon latlon = this.getChangeInLocation(lastPoint, point, lastVec, vec);            this.onPanViewAbsolute(latlon.getLatitude(), latlon.getLongitude(),  actionAttributes);        }        // Cursor is off the globe, we potentially want to simulate globe dragging.        else        {            Point movement = subtract(point, lastPoint);            int forwardInput = movement.y;            int sideInput = -movement.x;            ViewInputAttributes.DeviceAttributes deviceAttributes =                this.attributes.getDeviceAttributes(ViewInputAttributes.DEVICE_MOUSE);            ViewInputAttributes.ActionAttributes actionAttributes =                this.attributes.getActionAttributes(ViewInputAttributes.DEVICE_MOUSE,                    ViewInputAttributes.VIEW_PAN);            Angle forwardChange = Angle.fromDegrees(                this.rawInputToChangeInValue(forwardInput, deviceAttributes, actionAttributes, SCALE_FUNC_ZOOM));            Angle sideChange = Angle.fromDegrees(                this.rawInputToChangeInValue(sideInput, deviceAttributes, actionAttributes, SCALE_FUNC_ZOOM));            this.onPanViewRelative(forwardChange, sideChange, actionAttributes);        }    }    @SuppressWarnings({"UnusedDeclaration"})    protected void handleMouseRotate(MouseEvent e)

⌨️ 快捷键说明

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