viewcontrolsselectlistener.java
来自「world wind java sdk 源码」· Java 代码 · 共 524 行 · 第 1/2 页
JAVA
524 行
/*
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.layers;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.event.SelectEvent;
import gov.nasa.worldwind.event.SelectListener;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.globes.Globe;
import gov.nasa.worldwind.render.ScreenAnnotation;
import gov.nasa.worldwind.util.Logging;
import gov.nasa.worldwind.view.OrbitView;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Controller for onscreen view controls.
*
* @author Patrick Murris
* @version $Id: ViewControlsSelectListener.java 7253 2008-10-28 01:32:04Z patrickmurris $
* @see ViewControlsLayer
*/
public class ViewControlsSelectListener implements SelectListener
{
protected WorldWindow wwd;
protected ViewControlsLayer viewControlsLayer;
protected ScreenAnnotation pressedControl;
protected String pressedControlType;
protected Point lastPickPoint = null;
private Timer repeatTimer;
private int timerDelay = 50;
private double panStep = .6;
private double zoomStep = .8;
private double headingStep = 1;
private double pitchStep = 1;
private double fovStep = 1.05;
public ViewControlsSelectListener(WorldWindow wwd, ViewControlsLayer layer)
{
if (wwd == null)
{
String msg = Logging.getMessage("nullValue.WorldWindow");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
if (layer == null)
{
String msg = Logging.getMessage("nullValue.LayerIsNull");
Logging.logger().severe(msg);
throw new IllegalArgumentException(msg);
}
this.wwd = wwd;
this.viewControlsLayer = layer;
// Setup repeat timer
this.repeatTimer = new Timer(timerDelay, new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if (pressedControl != null)
updateView(pressedControl, pressedControlType);
}
});
this.repeatTimer.start();
}
/**
* Set the repeat timer delay in milliseconds.
* @param delay the repeat timer delay in milliseconds.
* @throws IllegalArgumentException
*/
public void setRepeatTimerDelay(int delay)
{
if (delay <= 0)
{
String message = Logging.getMessage("generic.ArgumentOutOfRange", delay);
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.repeatTimer.setDelay(delay);
}
/**
* Get the repeat timer delay in milliseconds.
* @return the repeat timer delay in milliseconds.
*/
public int getReapeatTimerDelay()
{
return this.repeatTimer.getDelay();
}
/**
* Set the panning distance factor. Doubling this value will double the panning speed. Negating it will reverse
* the panning direction. Default value is .6.
* @param value the panning distance factor.
*/
public void setPanIncrement(double value)
{
this.panStep = value;
}
/**
* Get the panning distance factor.
* @return the panning distance factor.
*/
public double getPanIncrement()
{
return this.panStep;
}
/**
* Set the zoom distance factor. Doubling this value will double the zooming speed. Negating it will reverse
* the zooming direction. Default value is .8.
* @param value the zooming distance factor.
*/
public void setZoomIncrement(double value)
{
this.zoomStep = value;
}
/**
* Get the zooming distance factor.
* @return the zooming distance factor.
*/
public double getZoomIncrement()
{
return this.zoomStep;
}
/**
* Set the heading increment value in decimal degrees. Doubling this value will double the heading change speed.
* Negating it will reverse the heading change direction. Default value is 1 degree.
* @param value the heading increment value in decimal degrees.
*/
public void setHeadingIncrement(double value)
{
this.headingStep = value;
}
/**
* Get the heading increment value in decimal degrees.
* @return the heading increment value in decimal degrees.
*/
public double getHeadingIncrement()
{
return this.headingStep;
}
/**
* Set the pitch increment value in decimal degrees. Doubling this value will double the pitch change speed.
* Must be positive. Default value is 1 degree.
* @param value the pitch increment value in decimal degrees.
* @throws IllegalArgumentException
*/
public void setPitchIncrement(double value)
{
if (value < 0)
{
String message = Logging.getMessage("generic.ArgumentOutOfRange", value);
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.pitchStep = value;
}
/**
* Get the pitch increment value in decimal degrees.
* @return the pitch increment value in decimal degrees.
*/
public double getPitchIncrement()
{
return this.pitchStep;
}
/**
* Set the field of view increment factor. At each iteration the current field of view will be multiplied
* or divided by this value. Must be greater then or equal to one. Default value is 1.05.
* @param value the field of view increment factor.
* @throws IllegalArgumentException
*/
public void setFovIncrement(double value)
{
if (value < 1)
{
String message = Logging.getMessage("generic.ArgumentOutOfRange", value);
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}
this.fovStep = value;
}
/**
* Get the field of view increment factor.
* @return the field of view increment factor.
*/
public double getFovIncrement()
{
return this.fovStep;
}
public void selected(SelectEvent event)
{
if (this.wwd == null)
return;
if (!(this.wwd.getView() instanceof OrbitView))
return;
OrbitView view = (OrbitView)this.wwd.getView();
this.viewControlsLayer.highlight(null);
if (event.getTopObject() == null || !(event.getTopObject() instanceof AVList))
return;
String controlType = ((AVList) event.getTopObject()).getStringValue(AVKey.VIEW_OPERATION);
if (controlType == null)
return;
ScreenAnnotation selectedObject = (ScreenAnnotation)event.getTopObject();
this.lastPickPoint = event.getPickPoint();
if (event.getEventAction().equals(SelectEvent.ROLLOVER))
{
// Highlight on rollover
this.viewControlsLayer.highlight(selectedObject);
this.wwd.redraw();
}
else if (event.getEventAction().equals(SelectEvent.LEFT_PRESS) ||
(event.getEventAction().equals(SelectEvent.DRAG) && controlType.equals(AVKey.VIEW_PAN)) ||
(event.getEventAction().equals(SelectEvent.DRAG) && controlType.equals(AVKey.VIEW_LOOK)))
{
// Handle left press on controls
this.pressedControl = selectedObject;
this.pressedControlType = controlType;
}
else if (event.getEventAction().equals(SelectEvent.LEFT_CLICK)
|| event.getEventAction().equals(SelectEvent.LEFT_DOUBLE_CLICK)
|| event.getEventAction().equals(SelectEvent.DRAG_END))
{
// Release pressed control
this.pressedControl = null;
resetOrbitView(view);
}
// Keep pressed control highlighted - overrides rollover non currently pressed controls
if (this.pressedControl != null)
{
this.viewControlsLayer.highlight(this.pressedControl);
this.wwd.redraw();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?