Class ShapeEditor

  • All Implemented Interfaces:
    SelectListener, java.beans.PropertyChangeListener, java.util.EventListener
    Direct Known Subclasses:
    ShapeEditingExtension.ShapeEditorExtension

    public class ShapeEditor
    extends java.lang.Object
    implements SelectListener, java.beans.PropertyChangeListener
    Provides a user interface for editing a shape and performs editing. Depending on the shape type, the shape is shown with control points for vertex locations and size. All shapes are shown with a handle that provides rotation.

    Left-drag on the shape's body moves the whole shape. Left-drag on a control point performs the action associated with that control point. The editor provides vertex insertion and removal for airspace Polygon, Curtain, Route and Track shapes, and SurfacePolygon and SurfacePolyline. Shift-left-click when the cursor is over the shape inserts a control point at the cursor's position. Alt-left-click when the cursor is over a control point removes that control point. Control points are added to the ends of airspace Polygon, Curtain, Route and Track, and SurfacePolyline by shift-left-click on the first or last control point of the shape.

    This editor supports airspaces other than Cake and all surface shapes except SurfaceMultiPolygon and SurfaceImage.

    • Field Detail

      • ANNOTATION

        protected static java.lang.String ANNOTATION
        Indicates that a control point is associated with annotation.
      • LOCATION

        protected static java.lang.String LOCATION
        Indicates a control point is associated with a location.
      • ROTATION

        protected static java.lang.String ROTATION
        Indicates that a control point is associated with whole-shape rotation.
      • WIDTH

        protected static java.lang.String WIDTH
        Indicates that a control point is associated with width change.
      • HEIGHT

        protected static java.lang.String HEIGHT
        Indicates that a control point is associated with height change.
      • LEFT_WIDTH

        protected static java.lang.String LEFT_WIDTH
        Indicates that a control point is associated with the left width of a shape.
      • RIGHT_WIDTH

        protected static java.lang.String RIGHT_WIDTH
        Indicates that a control point is associated with the right width of a shape.
      • INNER_RADIUS

        protected static java.lang.String INNER_RADIUS
        Indicates that a control point is associated with the inner radius of a shape.
      • OUTER_RADIUS

        protected static java.lang.String OUTER_RADIUS
        Indicates that a control point is associated with the outer radius of a shape.
      • INNER_MINOR_RADIUS

        protected static java.lang.String INNER_MINOR_RADIUS
        Indicates that a control point is associated with the inner minor radius of a shape.
      • OUTER_MINOR_RADIUS

        protected static java.lang.String OUTER_MINOR_RADIUS
        Indicates that a control point is associated with the outer minor radius of a shape.
      • INNER_MAJOR_RADIUS

        protected static java.lang.String INNER_MAJOR_RADIUS
        Indicates that a control point is associated with the inner major radius of a shape.
      • OUTER_MAJOR_RADIUS

        protected static java.lang.String OUTER_MAJOR_RADIUS
        Indicates that a control point is associated with the outer major radius of a shape.
      • LEFT_AZIMUTH

        protected static java.lang.String LEFT_AZIMUTH
        Indicates that a control point is associated with the left azimuth of a shape.
      • RIGHT_AZIMUTH

        protected static java.lang.String RIGHT_AZIMUTH
        Indicates that a control point is associated with the right azimuth of a shape.
      • NONE

        protected static final int NONE
        Editor state indicating that the shape is not being resized or moved.
        See Also:
        Constant Field Values
      • MOVING

        protected static final int MOVING
        Editor state indicating that the shape is being moved.
        See Also:
        Constant Field Values
      • SIZING

        protected static final int SIZING
        Editor state indicating that the shape is being sized or otherwise respecified.
        See Also:
        Constant Field Values
      • shape

        protected Renderable shape
        The shape associated with the editor. Specified at construction and not subsequently modifiable.
      • controlPointLayer

        protected MarkerLayer controlPointLayer
        The layer holding the editor's control points.
      • accessoryLayer

        protected RenderableLayer accessoryLayer
        The layer holding the rotation line and perhaps other affordances.
      • annotationLayer

        protected RenderableLayer annotationLayer
        The layer holding the control point's annotation.
      • shadowLayer

        protected RenderableLayer shadowLayer
        The layer holding a shadow copy of the shape while the shape is being moved or sized.
      • annotation

        protected EditorAnnotation annotation
        The control point annotation.
      • unitsFormat

        protected UnitsFormat unitsFormat
        The units formatter to use when creating control point annotations.
      • armed

        protected boolean armed
        Indicates whether the editor is ready for editing.
      • active

        protected boolean active
        Indicates whether the editor is in the midst of an editing operation.
      • activeOperation

        protected int activeOperation
        Indicates the current editing operation, one of NONE, MOVING or SIZING.
      • previousPosition

        protected Position previousPosition
        The terrain position associated with the cursor during the just previous drag event.
      • originalAttributes

        protected ShapeAttributes originalAttributes
        The attributes associated with the shape when the editor is constructed. These are swapped out during editing operations in order to make the shape semi-transparent.
      • originalHighlightAttributes

        protected ShapeAttributes originalHighlightAttributes
        The highlight attributes associated with the shape when the editor is constructed. These are swapped out during editing operations in order to make the shape semi-transparent.
      • currentEvent

        protected SelectEvent currentEvent
        The event most recently recieved by the selection method.
      • currentHeading

        protected Angle currentHeading
        For shapes without an inherent heading, the current heading established by the editor for the shape.
      • trackAdjacencyList

        protected java.util.List<Box> trackAdjacencyList
        Indicates track legs that are adjacent to their previous leg in the track.
      • locationControlPointAttributes

        protected MarkerAttributes locationControlPointAttributes
        Attributes used to represent shape vertices.
      • sizeControlPointAttributes

        protected MarkerAttributes sizeControlPointAttributes
        Attributes used to represent shape size.
      • angleControlPointAttributes

        protected MarkerAttributes angleControlPointAttributes
        Attributes used to represent shape rotation and other angular features.
      • extensionEnabled

        protected boolean extensionEnabled
        Indicates whether shapes with sub-segments such as Route and Track may be edited to add and remove legs.
    • Constructor Detail

      • ShapeEditor

        public ShapeEditor​(WorldWindow wwd,
                           Renderable originalShape)
        Constructs an editor for a specified shape. Once constructed, the editor must be armed to operate. See setArmed(boolean).
        Parameters:
        wwd - the WorldWindow associated with the specified shape.
        originalShape - the shape to edit.
        Throws:
        java.lang.IllegalArgumentException - if either the specified WorldWindow or shape is null.
    • Method Detail

      • makeControlPointAttributes

        protected void makeControlPointAttributes()
      • getUnitsFormat

        public UnitsFormat getUnitsFormat()
        Indicates the units formatter associated with this editor.
        Returns:
        the units formatter associated with this editor.
      • setUnitsFormat

        public void setUnitsFormat​(UnitsFormat unitsFormat)
        Specifies the units formatter to use when creating editor annotations.
        Parameters:
        unitsFormat - the units formatter to use. A default is created if null is specified.
      • getWwd

        public WorldWindow getWwd()
        Indicates the WorldWindow associated with this editor.
        Returns:
        the WorldWindow associated with this editor.
      • getShape

        public Renderable getShape()
        Indicates the shape associated with this editor.
        Returns:
        the shape associated with this editor.
      • getControlPointLayer

        public MarkerLayer getControlPointLayer()
        Indicates the control point layer used by this editor.
        Returns:
        the control point layer used by this editor.
      • getAccessoryLayer

        public RenderableLayer getAccessoryLayer()
        Indicates the accessory layer used by this editor.
        Returns:
        the accessory layer used by this editor.
      • getAnnotationLayer

        public RenderableLayer getAnnotationLayer()
        Indicates the annotation layer used by this editor.
        Returns:
        the annotation layer used by this editor.
      • getShadowLayer

        public RenderableLayer getShadowLayer()
        Indicates the shadow layer used by this editor.
        Returns:
        the shadow layer used by this editor.
      • getAnnotation

        public EditorAnnotation getAnnotation()
        Indicates the annotation used to show locations and measurements.
        Returns:
        the annotation used to show shape locations and measurements.
      • isActive

        public boolean isActive()
        Indicates whether an editing operation is currently underway. Operations are SIZING and MOVING.
        Returns:
        true if an operation is underway, otherwise false.
      • getActiveOperation

        public int getActiveOperation()
        Indicates the current operation being performed, either SIZING, MOVING or NONE.
        Returns:
        the current operation underway.
      • getPreviousPosition

        public Position getPreviousPosition()
        Returns the geographic position associated with the previous select event.
        Returns:
        the geographic position associated with the previous select event.
      • getCurrentSizingMarker

        public ShapeEditor.ControlPointMarker getCurrentSizingMarker()
        Indicates the control point currently used in the operation underway.
        Returns:
        the control point used in the operation currently underway.
      • getOriginalAttributes

        public ShapeAttributes getOriginalAttributes()
        Indicates the attributes associated with the shape when the editor was created.
        Returns:
        the attributes associated with the shape when the editor was created.
      • getOriginalHighlightAttributes

        public ShapeAttributes getOriginalHighlightAttributes()
        Indicates the highlight attributes associated with the shape prior to their being changed to achieve shape transparency.
        Returns:
        the original highlight attributes.
      • getCurrentHeading

        public Angle getCurrentHeading()
        Indicates the current rotation heading. This is updated as shapes are rotated.
        Returns:
        the current rotation heading.
      • getLocationControlPointAttributes

        public MarkerAttributes getLocationControlPointAttributes()
        Indicates the attributes associated with location control points.
        Returns:
        the attributes associated with location control points.
      • getSizeControlPointAttributes

        public MarkerAttributes getSizeControlPointAttributes()
        Indicates the attributes associated with size control points.
        Returns:
        the attributes associated with size control points.
      • getAngleControlPointAttributes

        public MarkerAttributes getAngleControlPointAttributes()
        Indicates the attributes associated with angle control points.
        Returns:
        the attributes associated with angle control points.
      • isExtensionEnabled

        public boolean isExtensionEnabled()
        Indicates whether multi-segment shapes such as Route and Track may be edited to add or remove segments.
        Returns:
        true if segment addition and deletion are enabled, otherwise false. The default is true.
      • setExtensionEnabled

        public void setExtensionEnabled​(boolean extensionEnabled)
        Specifies whether multi-segment shapes such as Route and Track may be edited to add or remove segments.
        Parameters:
        extensionEnabled - true to allow segment addition and removal, otherwise false.
      • getCurrentEvent

        public SelectEvent getCurrentEvent()
        Indicates the event most recently passed to the select handler.
        Returns:
        the event most recently passed to the select handler.
      • isArmed

        public boolean isArmed()
        Indicates whether this editor is armed.
        Returns:
        true if the editor is armed, otherwise false.
      • setArmed

        public void setArmed​(boolean armed)
        Arms or disarms the editor. When armed, the editor's shape is displayed with control points and other affordances that indicate possible editing operations.
        Parameters:
        armed - true to arm the editor, false to disarm it and remove the control points and other affordances. This method must be called when the editor is no longer needed so that the editor may remove the resources it created when it was armed.
      • enable

        protected void enable()
        Called by setArmed(boolean) to initialize this editor.
      • disable

        protected void disable()
        Called by setArmed(boolean) to remove resources no longer needed after editing.
      • determineTrackAdjacency

        protected void determineTrackAdjacency()
        Determines and stores internally the adjacency of successive track legs. Called during editor arming.
      • selected

        public void selected​(SelectEvent event)
        The select handler, the method called when the user selects (rolls over, left clicks, etc.) the shape or a control point. Does not necessarily indicate the shape associated with this editor.
        Specified by:
        selected in interface SelectListener
        Parameters:
        event - the select event indicating what was selected and the geographic location under the cursor.
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent event)
        The property change listener, the method called when a property of the Scene Controller changes (vertical exaggeration, etc.). Does not necessarily indicate a property associated with this editor.
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        Parameters:
        event - the property change event indicating the property name and its associated value.
      • makeShadowShape

        protected void makeShadowShape()
        Creates the shape that will remain at the same location and is the same size as the shape to be edited.
      • removeShadowShape

        protected void removeShadowShape()
        Remove the shadow shape.
      • doMakeShadowShape

        protected Renderable doMakeShadowShape()
        Creates and returns the stationary shape displayed during editing operations. Subclasses should override this method to create shadow shapes appropriate to the editor's shape.
        Returns:
        the new shadow shape created, or null if the shape type is not recognized.
      • adjustShape

        protected void adjustShape()
        Performs shape-specific minor modifications to shapes after editing operation are performed. Some editing operations cause positions that are originally identical to become slightly different and thereby disrupt the original connectivity of the shape. This is the case for track-airspace legs, for instance. This method is called just after editing operations are performed in order to give the editor a chance to reform connectivity or otherwise modify the shape to retain its original properties. Subclasses should override this method if they are aware of shapes other than those recognized by default and those shapes need such adjustment during editing.
      • dragWholeShape

        protected void dragWholeShape​(DragSelectEvent dragEvent)
        Moves the entire shape according to a specified drag event.
        Parameters:
        dragEvent - the event initiating the move.
      • reshapeShape

        protected void reshapeShape​(ShapeEditor.ControlPointMarker controlPoint)
        Modifies the shape's locations, size or rotation. This method is called when a control point is dragged.
        Parameters:
        controlPoint - the control point selected.
      • doReshapeShape

        protected void doReshapeShape​(ShapeEditor.ControlPointMarker controlPoint,
                                      Position terrainPosition)
        Called by reshapeShape(ShapeEditor.ControlPointMarker) to perform the actual shape modification. Subclasses should override this method if they provide editing for shapes other than those supported by the basic editor.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updateControlPoints

        protected void updateControlPoints()
        Updates the control points to the locations of the currently edited shape. Called each time a modification to the shape is made. Subclasses should override this method to handle shape types not supported by the basic editor.
      • updateShapeAnnotation

        protected void updateShapeAnnotation()
        Updates the annotation indicating the edited shape's center. If the shape has no designated center, this method prevents the annotation from displaying.
      • getShapeCenter

        protected LatLon getShapeCenter()
        Returns the shape's center location, or null if it has no designated center.
        Returns:
        the shape's center location, or null if the shape has no designated center.
      • updateAnnotation

        protected void updateAnnotation​(ShapeEditor.ControlPointMarker controlPoint)
        Updates the annotation associated with a specified control point.
        Parameters:
        controlPoint - the control point.
      • updateOrientationLine

        protected void updateOrientationLine​(Position centerPosition,
                                             Position controlPoint)
        Updates the line designating the shape's central axis.
        Parameters:
        centerPosition - the shape's center location and altitude at which to place one of the line's end points.
        controlPoint - the shape orientation control point.
      • getControlPointAltitude

        protected double getControlPointAltitude​(LatLon location)
        Computes the appropriate absolute altitude at which to place a control point at a specified location.
        Parameters:
        location - the location of the control point.
        Returns:
        the appropriate altitude at which to place the control point.
      • doGetControlPointAltitude

        protected double doGetControlPointAltitude​(LatLon location,
                                                   Renderable shape)
      • getShapeAltitudeMode

        protected int getShapeAltitudeMode()
        Indicates the current shape's altitude mode if the shape has one.
        Returns:
        the shape's altitude mode if it has one, otherwise WorldWind.ABSOLUTE.
      • makeControlPoint

        protected ShapeEditor.ControlPointMarker makeControlPoint​(Position position,
                                                                  MarkerAttributes attributes,
                                                                  int id,
                                                                  java.lang.String purpose)
        Creates a control point.
        Parameters:
        position - the control point position.
        attributes - the control point attributes.
        id - the control point ID.
        purpose - the control point purpose.
        Returns:
        the new control point.
      • makeControlPoint

        protected ShapeEditor.ControlPointMarker makeControlPoint​(Position position,
                                                                  MarkerAttributes attributes,
                                                                  int id,
                                                                  int leg,
                                                                  java.lang.String purpose)
        Creates a control point.
        Parameters:
        position - the control point position.
        attributes - the control point attributes.
        id - the control point ID.
        leg - the control point leg.
        purpose - the control point purpose.
        Returns:
        the new control point.
      • computeControlPointDelta

        protected Vec4 computeControlPointDelta​(LatLon previousLocation,
                                                LatLon currentLocation)
        Computes the Cartesian difference between two control points.
        Parameters:
        previousLocation - the location nof the previous control point.
        currentLocation - the location of the current control point.
        Returns:
        the Cartesian difference between the two control points.
      • normalizedHeading

        protected Angle normalizedHeading​(Angle originalHeading,
                                          Angle deltaHeading)
        Add a specified increment to an angle and normalize the result to be between 0 and 360 degrees.
        Parameters:
        originalHeading - the base angle.
        deltaHeading - the increment to add prior to normalizing.
        Returns:
        the normalized angle.
      • computeEdgeLocation

        protected Position computeEdgeLocation​(LatLon center,
                                               LatLon location,
                                               double length)
        Computes a control point location at the edge of a shape.
        Parameters:
        center - the shape's center.
        location - a location that forms a line from the shape's center along the shape's axis. The returned location is on the edge indicated by the cross product of a vector normal to the surface at the specified center and a vector from the center to this location.
        length - the distance of the edge from the shape's center.
        Returns:
        a location at the shape's edge at the same location along the shape's axis as the specified center location.
      • computeRectangularEdgeLocation

        protected Position computeRectangularEdgeLocation​(LatLon begin,
                                                          LatLon end,
                                                          double width)
        Computes a control point location at the edge of a rectangular shape.
        Parameters:
        begin - the beginning of the shape's center.
        end - the end of the shape's center.
        width - the distance of the edge from the great circle arc between begin and end.
        Returns:
        a location centered along the edge parallel to the great circle arc between begin and end.
      • nearestPointOnSegment

        protected Vec4 nearestPointOnSegment​(Vec4 p1,
                                             Vec4 p2,
                                             Vec4 point)
        Computes the point on a specified line segment that is nearest a specified point.
        Parameters:
        p1 - the line's first point.
        p2 - the line's second point.
        point - the point for which to determine a nearest point on the line segment.
        Returns:
        the nearest point on the line segment.
      • addNearestLocation

        protected int addNearestLocation​(Position terrainPosition,
                                         double altitude,
                                         java.util.List<LatLon> locations)
        Inserts the location nearest to a specified position on an edge of a specified list of locations into the appropriate place in that list.
        Parameters:
        terrainPosition - the position to find a nearest point for.
        altitude - the altitude to use when determining the nearest point. Can be approximate and is not necessarily the altitude of the terrain position.
        locations - the list of locations. This list is modified by this method to contain the new location on an edge nearest the specified terrain position.
        Returns:
        the index at which the new location was inserted into the list.
      • appendLocation

        protected void appendLocation​(ShapeEditor.ControlPointMarker controlPoint,
                                      java.util.List<LatLon> locations)
        Adds a location to either the beginning or the end of a specified list of locations. Which end to add to is determined by a specified control point.
        Parameters:
        controlPoint - the control point of the shape's end. If the control point's ID is 0 the new location is inserted to the beginning of the list. If the control point ID corresponds to the last location in the list then the new location is appended to the list. Otherwise no operation occurs.
        locations - the shape's locations. This list is modified upon return to include the new location.
      • moveLocation

        protected void moveLocation​(ShapeEditor.ControlPointMarker controlPoint,
                                    Position terrainPosition,
                                    java.util.List<LatLon> locations)
        Moves a control point location.
        Parameters:
        controlPoint - the control point being moved.
        terrainPosition - the position selected by the user.
        locations - the list of locations for the shape.
      • rotateLocations

        protected void rotateLocations​(Position terrainPosition,
                                       java.util.List<LatLon> locations)
        Rotates a shape's locations.
        Parameters:
        terrainPosition - the position selected by the user.
        locations - the list of locations for the shape.
      • reshapePolygonAirspace

        protected void reshapePolygonAirspace​(Position terrainPosition,
                                              ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for Polygon shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updatePolygonAirspaceControlPoints

        protected void updatePolygonAirspaceControlPoints()
        Updates the control points and affordances for Polygon shapes.
      • reshapeCappedCylinder

        protected void reshapeCappedCylinder​(Position terrainPosition,
                                             ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for CappedCylinder shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updateCappedCylinderControlPoints

        protected void updateCappedCylinderControlPoints()
        Updates the control points and affordances for CappedCylinder shapes.
      • updatePartialCappedCylinderControlPoints

        protected void updatePartialCappedCylinderControlPoints()
        Updates the control points and affordances for PartialCappedCylinder shapes.
      • reshapeCappedEllipticalCylinder

        protected void reshapeCappedEllipticalCylinder​(Position terrainPosition,
                                                       ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for CappedCylinder shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • isRadiiValid

        protected static boolean isRadiiValid​(double innerRadius,
                                              double outerRadius)
      • updateCappedEllipticalCylinderControlPoints

        protected void updateCappedEllipticalCylinderControlPoints()
        Updates the control points and affordances for CappedCylinder shapes.
      • reshapeSphere

        protected void reshapeSphere​(Position terrainPosition,
                                     ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for SphereAirspace shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updateSphereControlPoints

        protected void updateSphereControlPoints()
        Updates the control points and affordances for SphereAirspace shapes.
      • reshapeOrbit

        protected void reshapeOrbit​(Position terrainPosition,
                                    ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for Orbit shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updateOrbitControlPoints

        protected void updateOrbitControlPoints()
        Updates the control points and affordances for Orbit shapes.
      • reshapeRoute

        protected void reshapeRoute​(Position terrainPosition,
                                    ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for Route shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updateRouteControlPoints

        protected void updateRouteControlPoints()
        Updates the control points and affordances for Route shapes.
      • reshapeTrack

        protected void reshapeTrack​(Position terrainPosition,
                                    ShapeEditor.ControlPointMarker controlPoint)
        Performs an edit for TrackAirspace shapes.
        Parameters:
        controlPoint - the control point selected.
        terrainPosition - the terrain position under the cursor.
      • updateTrackControlPoints

        protected void updateTrackControlPoints()
        Updates the control points and affordances for TrackAirspace shapes.
      • updateSurfacePolygonControlPoints

        protected void updateSurfacePolygonControlPoints()
      • updateSurfaceCircleControlPoints

        protected void updateSurfaceCircleControlPoints()
      • updateSurfaceSquareControlPoints

        protected void updateSurfaceSquareControlPoints()
      • updateSurfaceQuadControlPoints

        protected void updateSurfaceQuadControlPoints()
      • updateSurfaceEllipseControlPoints

        protected void updateSurfaceEllipseControlPoints()