airspacebuilder.java
来自「world wind java sdk 源码」· Java 代码 · 共 1,830 行 · 第 1/5 页
JAVA
1,830 行
if (!this.isEnabled()) { return; } //noinspection StringEquality if (e.getActionCommand() == NEW_AIRSPACE) { this.createNewEntry(this.getView().getSelectedFactory()); } else //noinspection StringEquality if (e.getActionCommand() == CLEAR_SELECTION) { this.selectEntry(null, true); } else //noinspection StringEquality if (e.getActionCommand() == SIZE_NEW_SHAPES_TO_VIEWPORT) { if (e.getSource() instanceof AbstractButton) { boolean selected = ((AbstractButton) e.getSource()).isSelected(); this.setResizeNewShapesToViewport(selected); } } else //noinspection StringEquality if (e.getActionCommand() == ENABLE_EDIT) { if (e.getSource() instanceof AbstractButton) { boolean selected = ((AbstractButton) e.getSource()).isSelected(); this.setEnableEdit(selected); } } else //noinspection StringEquality if (e.getActionCommand() == OPEN) { this.openFromFile(); } else //noinspection StringEquality if (e.getActionCommand() == OPEN_URL) { this.openFromURL(); } else //noinspection StringEquality if (e.getActionCommand() == OPEN_DEMO_AIRSPACES) { URL url = null; try { url = new URL(DEMO_AIRSPACES_URL); } catch (IOException ex) { ex.printStackTrace(); } if (url != null) { this.openFromURL(url); this.zoomTo(LatLon.fromDegrees(47.6584074779224, -122.3059199579634), Angle.fromDegrees(-152), Angle.fromDegrees(75), 750); } } else //noinspection StringEquality if (e.getActionCommand() == REMOVE_SELECTED) { this.removeEntries(Arrays.asList(this.getSelectedEntries())); } else //noinspection StringEquality if (e.getActionCommand() == SAVE) { this.saveToFile(); } else //noinspection StringEquality if (e.getActionCommand() == SELECTION_CHANGED) { this.viewSelectionChanged(); } } public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e == null || e.isConsumed()) { return; } if (!this.isEnabled()) { return; } //noinspection StringEquality if (e.getButton() == MouseEvent.BUTTON1) { this.handleSelect(); } } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void airspaceMoved(AirspaceEditEvent e) { this.updateShapeIntersection(); } public void airspaceResized(AirspaceEditEvent e) { this.updateShapeIntersection(); } public void controlPointAdded(AirspaceEditEvent e) { } public void controlPointRemoved(AirspaceEditEvent e) { } public void controlPointChanged(AirspaceEditEvent e) { } protected void handleSelect() { // If the picked object is null or something other than an airspace, then ignore the mouse click. If we // deselect the current entry at this point, the user cannot easily navigate without loosing the selection. PickedObjectList pickedObjects = this.getApp().getWwd().getObjectsAtCurrentPosition(); Object topObject = pickedObjects.getTopObject(); if (!(topObject instanceof Airspace)) return; AirspaceEntry pickedEntry = this.getEntryFor((Airspace) topObject); if (pickedEntry == null) return; if (this.getSelectedEntry() != pickedEntry) { this.selectEntry(pickedEntry, true); } } //protected void handleSelectHover(SelectEvent e) //{ // ToolTip toolTip = this.getApp().getWorldWindToolTip(); // if (toolTip != null) // { // this.getApp().setWorldWindToolTip(null); // this.getApp().getWwd().redraw(); // } // // // Don't show any tool tips if the editor controller is engaged in some action. // if (this.getModel().getEditorController().isActive()) // return; // // if (e.hasObjects()) // { // toolTip = this.createToolTip(e.getTopObject(), e.getPickPoint()); // this.getApp().setWorldWindToolTip(toolTip); // this.getApp().getWwd().redraw(); // } //} protected void handleEnableEdit(boolean enable) { if (this.getSelectedEntry() == null) return; if (this.isSelectionEditing() != enable) this.setSelectionEditing(enable); } protected void updateShapeIntersection() { AirspaceEntry selected = this.getSelectedEntry(); if (selected != null) { boolean hasIntersection = false; for (AirspaceEntry entry : this.getModel().getEntries()) { if (entry != selected) { boolean intersecting = this.areShapesIntersecting(entry.getAirspace(), selected.getAirspace()); if (intersecting) hasIntersection = true; entry.setIntersecting(intersecting); } } selected.setIntersecting(hasIntersection); } else { for (AirspaceEntry entry : this.getModel().getEntries()) { entry.setIntersecting(false); } } } protected boolean areShapesIntersecting(Airspace a1, Airspace a2) { if ((a1 instanceof SphereAirspace) && (a2 instanceof SphereAirspace)) { SphereAirspace s1 = (SphereAirspace) a1; SphereAirspace s2 = (SphereAirspace) a2; LatLon location1 = s1.getLocation(); LatLon location2 = s2.getLocation(); double altitude1 = s1.getAltitudes()[0]; double altitude2 = s2.getAltitudes()[0]; boolean terrainConforming1 = s1.isTerrainConforming()[0]; boolean terrainConforming2 = s2.isTerrainConforming()[0]; // We have to compute the 3D coordinates of the sphere's center ourselves here. Vec4 p1 = terrainConforming1 ? this.getSurfacePoint(location1, altitude1) : this.getPoint(location1, altitude1); Vec4 p2 = terrainConforming2 ? this.getSurfacePoint(location2, altitude2) : this.getPoint(location2, altitude2); double r1 = s1.getRadius(); double r2 = s2.getRadius(); double d = p1.distanceTo3(p2); return d <= (r1 + r2); } return false; } protected Vec4 getSurfacePoint(LatLon latlon, double elevation) { Vec4 point = null; SceneController sc = this.getApp().getWwd().getSceneController(); Globe globe = this.getApp().getWwd().getModel().getGlobe(); if (sc.getTerrain() != null) { point = sc.getTerrain().getSurfacePoint( latlon.getLatitude(), latlon.getLongitude(), elevation * sc.getVerticalExaggeration()); } if (point == null) { double e = globe.getElevation(latlon.getLatitude(), latlon.getLongitude()); point = globe.computePointFromPosition( latlon.getLatitude(), latlon.getLongitude(), (e + elevation) * sc.getVerticalExaggeration()); } return point; } protected Vec4 getPoint(LatLon latlon, double elevation) { SceneController sc = this.getApp().getWwd().getSceneController(); Globe globe = this.getApp().getWwd().getModel().getGlobe(); double e = globe.getElevation(latlon.getLatitude(), latlon.getLongitude()); return globe.computePointFromPosition( latlon.getLatitude(), latlon.getLongitude(), (e + elevation) * sc.getVerticalExaggeration()); } public void createNewEntry(AirspaceFactory factory) { Airspace airspace = factory.createAirspace(this.getApp().getWwd(), this.isResizeNewShapesToViewport()); AirspaceEditor editor = factory.createEditor(airspace); AirspaceEntry entry = new AirspaceEntry(airspace, editor); this.addEntry(entry); this.selectEntry(entry, true); } public void removeEntries(Iterable<? extends AirspaceEntry> entries) { if (entries != null) { for (AirspaceEntry entry : entries) { this.removeEntry(entry); } } } public void addEntry(AirspaceEntry entry) { entry.getEditor().addEditListener(this); this.getModel().addEntry(entry); this.updateShapeIntersection(); this.getApp().getAirspaceLayer().addAirspace(entry.getAirspace()); this.getApp().getWwd().redraw(); } public void removeEntry(AirspaceEntry entry) { entry.getEditor().removeEditListener(this); if (this.getSelectedEntry() == entry) { this.selectEntry(null, true); } this.getModel().removeEntry(entry); this.updateShapeIntersection(); this.getApp().getAirspaceLayer().removeAirspace(entry.getAirspace()); this.getApp().getWwd().redraw(); } public AirspaceEntry getSelectedEntry() { return this.selectedEntry; } public void selectEntry(AirspaceEntry entry, boolean updateView) { this.setSelectedEntry(entry); if (updateView) { if (entry != null) { int index = this.getModel().getIndexForEntry(entry); this.getView().setSelectedIndices(new int[] {index}); } else { this.getView().setSelectedIndices(new int[0]); } } if (this.isEnableEdit()) { if (this.getSelectedEntry() != null && !this.isSelectionEditing()) { this.setSelectionEditing(true); } } this.updateShapeIntersection(); this.getApp().getWwd().redraw(); } protected void setSelectedEntry(AirspaceEntry entry) { if (this.selectedEntry != null) { if (this.selectedEntry != entry && this.selectedEntry.isEditing()) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?