sartrackbuilder.java
来自「world wind java sdk 源码」· Java 代码 · 共 165 行
JAVA
165 行
/*Copyright (C) 2001, 2007 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.applications.sar;import gov.nasa.worldwind.WorldWindow;import gov.nasa.worldwind.event.*;import gov.nasa.worldwind.geom.Position;import java.awt.event.*;import java.awt.*;/** * @author tag * @version $Id: SARTrackBuilder.java 9630 2009-03-24 10:50:46Z dcollins $ */public class SARTrackBuilder{ private WorldWindow wwd; private SARTrack sarTrack; private boolean armed = false; private boolean active = false; private MouseAdapter mouseAdapter; private MouseMotionAdapter mouseMotionAdapter; private PositionListener positionListener; public SARTrackBuilder() { this.mouseAdapter = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { if (armed && sarTrack != null && mouseEvent.getButton() == MouseEvent.BUTTON1) { if (armed && (mouseEvent.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) { if (mouseEvent.isAltDown() && !mouseEvent.isControlDown()) { active = true; addPosition(); } } mouseEvent.consume(); } } public void mouseReleased(MouseEvent mouseEvent) { if (armed && sarTrack != null && mouseEvent.getButton() == MouseEvent.BUTTON1) { active = false; mouseEvent.consume(); } } public void mouseClicked(MouseEvent mouseEvent) { if (armed && sarTrack != null && mouseEvent.getButton() == MouseEvent.BUTTON1) { if (mouseEvent.isControlDown()) removeEndPosition(); mouseEvent.consume(); } } }; this.mouseMotionAdapter = new MouseMotionAdapter() { public void mouseDragged(MouseEvent mouseEvent) { if (armed && sarTrack != null && (mouseEvent.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) { // Don't update the track here because the wwd current cursor position will not // have been updated to reflect the current mouse position. Wait to update in the // position listener, but consume the event so the view doesn't respond to it. if (active) mouseEvent.consume(); } } }; this.positionListener = new PositionListener() { public void moved(PositionEvent event) { if (!active || sarTrack == null) return; replacePosition(); } }; } public void setWwd(WorldWindow wwd) { if (this.wwd == wwd) return; if (this.wwd != null) { this.wwd.getInputHandler().removeMouseListener(this.mouseAdapter); this.wwd.getInputHandler().removeMouseMotionListener(this.mouseMotionAdapter); this.wwd.removePositionListener(this.positionListener); } this.wwd = wwd; this.wwd.getInputHandler().addMouseListener(this.mouseAdapter); this.wwd.getInputHandler().addMouseMotionListener(this.mouseMotionAdapter); this.wwd.addPositionListener(this.positionListener); } public void setTrack(SARTrack track) { this.sarTrack = track; } public boolean isArmed() { return this.armed; } public void setArmed(boolean armed) { this.armed = armed; if (this.armed) ((Component) this.wwd).setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); else ((Component) this.wwd).setCursor(Cursor.getDefaultCursor()); } private void addPosition() { Position curPos = this.wwd != null ? this.wwd.getCurrentPosition() : null; if (curPos == null) return; this.sarTrack.appendPosition(new SARPosition(curPos)); } private void replacePosition() { Position curPos = this.wwd != null ? this.wwd.getCurrentPosition() : null; if (curPos == null) return; int index = this.sarTrack.size() - 1; if (index < 0) index = 0; this.sarTrack.set(index, new SARPosition(curPos)); } private void removeEndPosition() { if (this.sarTrack.size() == 0) return; this.sarTrack.removePosition(this.sarTrack.size() - 1); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?