📄 sectorselector.java
字号:
if (!(event.getTopObject() instanceof Movable)) return; this.setCursor(this.determineAdjustmentSide((Movable) event.getTopObject(), this.getEdgeFactor())); } } protected int determineAdjustmentSide(Movable dragObject, double factor) { if (dragObject instanceof SurfaceSector) { SurfaceSector quad = (SurfaceSector) dragObject; Sector s = quad.getSector(); // TODO: go over all sectors Position p = this.getWwd().getCurrentPosition(); if (p == null) { return NONE; } double dN = abs(s.getMaxLatitude().subtract(p.getLatitude()).degrees); double dS = abs(s.getMinLatitude().subtract(p.getLatitude()).degrees); double dW = abs(s.getMinLongitude().subtract(p.getLongitude()).degrees); double dE = abs(s.getMaxLongitude().subtract(p.getLongitude()).degrees); double sLat = factor * s.getDeltaLatDegrees(); double sLon = factor * s.getDeltaLonDegrees(); if (dN < sLat && dW < sLon) return NORTHWEST; if (dN < sLat && dE < sLon) return NORTHEAST; if (dS < sLat && dW < sLon) return SOUTHWEST; if (dS < sLat && dE < sLon) return SOUTHEAST; if (dN < sLat) return NORTH; if (dS < sLat) return SOUTH; if (dW < sLon) return WEST; if (dE < sLon) return EAST; } return NONE; } protected Sector resizeShape(Movable dragObject, int side) { if (dragObject instanceof SurfaceSector) { SurfaceSector quad = (SurfaceSector) dragObject; Sector s = quad.getSector(); // TODO: go over all sectors Position p = this.getWwd().getCurrentPosition(); if (p == null || this.getPreviousPosition() == null) { return null; } Angle dLat = p.getLatitude().subtract(this.getPreviousPosition().getLatitude()); Angle dLon = p.getLongitude().subtract(this.getPreviousPosition().getLongitude()); Angle newMinLat = s.getMinLatitude(); Angle newMinLon = s.getMinLongitude(); Angle newMaxLat = s.getMaxLatitude(); Angle newMaxLon = s.getMaxLongitude(); if (side == NORTH) { newMaxLat = s.getMaxLatitude().add(dLat); } else if (side == SOUTH) { newMinLat = s.getMinLatitude().add(dLat); } else if (side == EAST) { newMaxLon = s.getMaxLongitude().add(dLon); } else if (side == WEST) { newMinLon = s.getMinLongitude().add(dLon); } else if (side == NORTHWEST) { newMaxLat = s.getMaxLatitude().add(dLat); newMinLon = s.getMinLongitude().add(dLon); } else if (side == NORTHEAST) { newMaxLat = s.getMaxLatitude().add(dLat); newMaxLon = s.getMaxLongitude().add(dLon); } else if (side == SOUTHWEST) { newMinLat = s.getMinLatitude().add(dLat); newMinLon = s.getMinLongitude().add(dLon); } else if (side == SOUTHEAST) { newMinLat = s.getMinLatitude().add(dLat); newMaxLon = s.getMaxLongitude().add(dLon); } return new Sector(newMinLat, newMaxLat, newMinLon, newMaxLon); } return null; } private static double abs(double a) { return a >= 0 ? a : -a; } protected void dragWholeShape(DragSelectEvent dragEvent, Movable dragObject) { View view = getWwd().getView(); EllipsoidalGlobe globe = (EllipsoidalGlobe) getWwd().getModel().getGlobe(); // Compute ref-point position in screen coordinates. Position refPos = dragObject.getReferencePosition(); Vec4 refPoint = globe.computePointFromPosition(refPos); Vec4 screenRefPoint = view.project(refPoint); // Compute screen-coord delta since last event. int dx = dragEvent.getPickPoint().x - dragEvent.getPreviousPickPoint().x; int dy = dragEvent.getPickPoint().y - dragEvent.getPreviousPickPoint().y; // Find intersection of screen coord ref-point with globe. double x = screenRefPoint.x + dx; double y = dragEvent.getMouseEvent().getComponent().getSize().height - screenRefPoint.y + dy - 1; Line ray = view.computeRayFromScreenPoint(x, y); Intersection inters[] = globe.intersect(ray, refPos.getElevation()); if (inters != null) { // Intersection with globe. Move reference point to the intersection point. Position p = globe.computePositionFromPoint(inters[0].getIntersectionPoint()); dragObject.moveTo(p); } } protected void setCursor(int sideName) { Cursor cursor = null; switch (sideName) { case NONE: cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); break; case NORTH: cursor = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR); break; case SOUTH: cursor = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR); break; case EAST: cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR); break; case WEST: cursor = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR); break; case NORTHWEST: cursor = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR); break; case NORTHEAST: cursor = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR); break; case SOUTHWEST: cursor = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR); break; case SOUTHEAST: cursor = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR); break; } this.setCursor(cursor); } protected void setCursor(Cursor cursor) { ((Component) this.getWwd()).setCursor(cursor != null ? cursor : Cursor.getDefaultCursor()); } protected static class RegionShape extends SurfaceSector { private boolean resizeable = false; private Position startPosition; private Position endPosition; private SurfaceSector borderShape; protected RegionShape(Sector sector) { super(sector); // Create the default border shape. this.setBorder(new SurfaceSector(sector)); // The edges of the region shape should be constant lines of latitude and longitude. this.setPathType(AVKey.LINEAR); this.getBorder().setPathType(AVKey.LINEAR); // Setup default interior rendering attributes. Note that the interior rendering attributes are // configured so only the SurfaceSector's interior is rendered. ShapeAttributes interiorAttrs = this.getAttributes(); interiorAttrs.setDrawOutline(false); interiorAttrs.setInteriorMaterial(new Material(Color.WHITE)); interiorAttrs.setInteriorOpacity(0.1); // Setup default border rendering attributes. Note that the border rendering attributes are configured // so that only the SurfaceSector's outline is rendered. ShapeAttributes borderAttrs = this.getBorder().getAttributes(); borderAttrs.setDrawInterior(false); borderAttrs.setOutlineMaterial(new Material(Color.RED)); borderAttrs.setOutlineOpacity(0.7); borderAttrs.setOutlineWidth(3); } public Color getInteriorColor() { return this.getAttributes().getInteriorMaterial().getDiffuse(); } public void setInteriorColor(Color color) { this.getAttributes().setInteriorMaterial(new Material(color)); } public Color getBorderColor() { return this.getBorder().getAttributes().getOutlineMaterial().getDiffuse(); } public void setBorderColor(Color color) { this.getBorder().getAttributes().setOutlineMaterial(new Material(color)); } public double getInteriorOpacity() { return this.getAttributes().getInteriorOpacity(); } public void setInteriorOpacity(double opacity) { this.getAttributes().setInteriorOpacity(opacity); } public double getBorderOpacity() { return this.getBorder().getAttributes().getOutlineOpacity(); } public void setBorderOpacity(double opacity) { this.getBorder().getAttributes().setOutlineOpacity(opacity); } public double getBorderWidth() { return this.getBorder().getAttributes().getOutlineWidth(); } public void setBorderWidth(double width) { this.getBorder().getAttributes().setOutlineWidth(width); } public void setSector(Sector sector) { super.setSector(sector); this.getBorder().setSector(sector); } protected boolean isResizeable() { return resizeable; } protected void setResizeable(boolean resizeable) { this.resizeable = resizeable; } protected Position getStartPosition() { return startPosition; } protected void setStartPosition(Position startPosition) { this.startPosition = startPosition; } protected Position getEndPosition() { return endPosition; } protected void setEndPosition(Position endPosition) { this.endPosition = endPosition; } protected SurfaceSector getBorder() { return borderShape; } protected void setBorder(SurfaceSector shape) { if (shape == null) { String message = Logging.getMessage("nullValue.Shape"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.borderShape = shape; } protected boolean hasSelection() { return getStartPosition() != null && getEndPosition() != null; } protected void clear() { this.setStartPosition(null); this.setEndPosition(null); this.setSector(Sector.EMPTY_SECTOR); } public void preRender(DrawContext dc) { this.doPreRender(dc); } @Override public void render(DrawContext dc) { if (dc.isPickingMode() && this.isResizeable()) return; if (!this.isResizeable()) { if (this.hasSelection()) { this.doRender(dc); } return; } PickedObjectList pos = dc.getPickedObjects(); PickedObject terrainObject = pos != null ? pos.getTerrainObject() : null; if (terrainObject == null) return; if (this.getStartPosition() != null) { Position end = terrainObject.getPosition(); if (!this.getStartPosition().equals(end)) { this.setEndPosition(end); this.setSector(Sector.boundingSector(this.getStartPosition(), this.getEndPosition())); this.doRender(dc); } } else { this.setStartPosition(pos.getTerrainObject().getPosition()); } } protected void doPreRender(DrawContext dc) { this.doPreRenderInterior(dc); this.doPreRenderBorder(dc); } protected void doPreRenderInterior(DrawContext dc) { super.preRender(dc); } protected void doPreRenderBorder(DrawContext dc) { this.getBorder().preRender(dc); } protected void doRender(DrawContext dc) { this.doRenderInterior(dc); this.doRenderBorder(dc); } protected void doRenderInterior(DrawContext dc) { super.render(dc); } protected void doRenderBorder(DrawContext dc) { this.getBorder().render(dc); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -