sartrackextensiontool.java
来自「world wind java sdk 源码」· Java 代码 · 共 521 行 · 第 1/2 页
JAVA
521 行
/*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.*;import gov.nasa.worldwind.avlist.AVKey;import gov.nasa.worldwind.event.*;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.pick.PickedObject;import gov.nasa.worldwind.render.*;import java.awt.*;import java.awt.event.*;import java.beans.*;import java.util.Arrays;/** * @author tag * @version $Id: SARTrackExtensionTool.java 9634 2009-03-24 17:03:21Z dcollins $ */public class SARTrackExtensionTool implements MouseListener, PositionListener, PropertyChangeListener{ private boolean armed; private WorldWindow wwd; // Can be null. private SARTrack track; // Can be null. protected SARSegmentPlane segmentPlane; protected Position potentialNextPosition; protected boolean waitingForNextPosition = true; protected boolean ignoreTrackChangeEvents = false; protected boolean canInsertTrailingPoint = true; protected SegmentPlaneAttributes.GeometryAttributes segmentEndGeomAttribs; protected SegmentPlaneAttributes.LabelAttributes segmentEndLabelAttribs; public SARTrackExtensionTool() { this.segmentPlane = new SARSegmentPlane(); this.segmentPlane.addPropertyChangeListener(this); this.segmentEndGeomAttribs = this.segmentPlane.getAttributes().getGeometryAttributes(SegmentPlane.SEGMENT_END).copy(); this.segmentEndLabelAttribs = this.segmentPlane.getAttributes().getLabelAttributes(SegmentPlane.SEGMENT_END).copy(); } public boolean isArmed() { return this.armed; } public void setArmed(boolean armed) { boolean wasArmed = this.armed; this.armed = armed; this.segmentPlane.setArmed(armed); if (!wasArmed && this.armed) { this.start(); } else if (wasArmed && !this.armed) { this.stop(); } } public WorldWindow getWwd() { return this.wwd; } public void setWorldWindow(WorldWindow wwd) { if (this.wwd == wwd) return; if (this.wwd != null) { this.wwd.getInputHandler().removeMouseListener(this); this.wwd.removePositionListener(this); } this.wwd = wwd; this.segmentPlane.setWorldWindow(wwd); if (this.wwd != null) { this.wwd.getInputHandler().addMouseListener(this); this.wwd.addPositionListener(this); } } public SARTrack getTrack() { return this.track; } public void setTrack(SARTrack track) { if (this.track == track) return; if (this.track != null) { this.track.removePropertyChangeListener(this); } this.track = track; this.canInsertTrailingPoint = true; if (this.track != null) { this.track.addPropertyChangeListener(this); } } public boolean canMoveToNextTrackPoint() { return this.track != null && !this.waitingForNextPosition; } public void moveToNextTrackPoint() { if (this.track == null || this.waitingForNextPosition) return; this.start(); } public boolean canRemoveLastTrackPoint() { return this.track != null && this.track.size() != 0; } public void removeLastTrackPoint() { if (this.track == null || this.track.size() == 0) return; int lastIndex = this.track.size() - 1; this.track.removePosition(lastIndex); } protected void start() { if (this.track.size() >= 1) { this.snapPlaneToLastTrackPoint(); this.segmentPlane.setVisible(true); } else { this.segmentPlane.setVisible(false); } this.waitingForNextPosition = true; this.canInsertTrailingPoint = true; } protected void stop() { this.segmentPlane.setVisible(false); } protected void setNextPosition(Position position) { SARPosition trackPosition = this.positionToTrackPosition(position); this.ignoreTrackChangeEvents = true; try { this.track.appendPosition(trackPosition); } finally { this.ignoreTrackChangeEvents = false; } this.segmentPlane.getAttributes().setGeometryAttributes(SegmentPlane.SEGMENT_END, this.segmentEndGeomAttribs.copy()); this.segmentPlane.getAttributes().setLabelAttributes(SegmentPlane.SEGMENT_END, this.segmentEndLabelAttribs.copy()); this.snapPlaneToLastTrackSegment(); } protected void setPotentialNextPosition(Position position) { this.potentialNextPosition = position; if (this.potentialNextPosition != null) { Position[] segmentPositions = this.segmentPlane.getSegmentPositions(); this.segmentPlane.setSegmentPositions(segmentPositions[0], this.potentialNextPosition); this.segmentPlane.getAttributes().setGeometryAttributes(SegmentPlane.SEGMENT_END, this.createPotentialNextPositionGeomAttributes()); this.segmentPlane.getAttributes().setLabelAttributes(SegmentPlane.SEGMENT_END, this.createPotentialNextPositionLabelAttributes()); this.showSegmentEndPoint(true); } else { this.showSegmentEndPoint(false); } } protected PickedObject getTopPickedObject() { return (this.wwd.getSceneController().getPickedObjectList() != null) ? this.wwd.getSceneController().getPickedObjectList().getTopPickedObject() : null; } //**************************************************************// //******************** Mouse Events **************************// //**************************************************************// public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e == null || e.isConsumed()) { return; } if (!this.armed || this.wwd == null) { return; } if (e.getButton() == MouseEvent.BUTTON1) { if (this.waitingForNextPosition) { if (this.potentialNextPosition != null) { this.setNextPosition(this.potentialNextPosition); this.waitingForNextPosition = false; } } } } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?