Class DraggableSupport


  • public class DraggableSupport
    extends java.lang.Object
    Utility functions which support dragging operations on objects implementing the Movable or Movable2 interface.
    • Field Detail

      • DEFAULT_CONVERGENCE_THRESHOLD

        public static final double DEFAULT_CONVERGENCE_THRESHOLD
        The computeRelativePoint(Line, Globe, SceneController, double) method uses a numeric search method to determine the coordinates of the desired position. The numeric solver will stop at a defined threshold or step limit. The default threshold is provided here. This value is utilized when using the static drag functions provided by this class.
        See Also:
        Constant Field Values
      • DEFAULT_STEP_LIMIT

        public static final int DEFAULT_STEP_LIMIT
        The computeRelativePoint(Line, Globe, SceneController, double) method uses a numeric search method to determine the coordinates of the desired position. The numeric solver will stop at a defined threshold or step limit. The default step limit is provided here. This value is utilized when using the static drag functions provided by this class.
        See Also:
        Constant Field Values
      • initialScreenPointOffset

        protected Vec4 initialScreenPointOffset
        Initial drag operation offset in x and y screen coordinates, between the object reference position and the screen point. Used for screen size constant drag operations.
      • initialEllipsoidalReferencePoint

        protected Vec4 initialEllipsoidalReferencePoint
        Initial drag operation cartesian coordinates of the objects reference position. Used for globe size constant drag operations.
      • initialEllipsoidalScreenPoint

        protected Vec4 initialEllipsoidalScreenPoint
        Initial drag operation cartesian coordinates of the initial screen point.
      • stepLimit

        protected int stepLimit
        This instances step limit when using the solver to determine the position of objects using the WorldWind.RELATIVE_TO_GROUND altitude mode. Increasing this value will increase solver runtime and may cause the event loop to hang. If the solver exceeds the number of steps specified here, it will fall back to using a position calculated by intersection with the ellipsoid.
      • convergenceThreshold

        protected double convergenceThreshold
        This instances convergence threshold for the solver used to determine the position of objects using the WorldWind.RELATIVE_TO_GROUND altitude mode. Decreasing this value will increase solver runtime and may cause the event loop to hang. If the solver does not converge to the threshold specified here, it will fall back to using a position calculated by intersection with the ellipsoid.
      • dragObject

        protected final java.lang.Object dragObject
        The object that will be subject to the drag operations. This object should implement Movable or Movable2.
      • altitudeMode

        protected int altitudeMode
        The altitude mode of the object to be dragged.
    • Constructor Detail

      • DraggableSupport

        public DraggableSupport​(java.lang.Object dragObject,
                                int altitudeMode)
        Provides persistence of initial values of a drag operation to increase dragging precision and provide better dragging behavior.
        Parameters:
        dragObject - the object to be dragged.
        altitudeMode - the altitude mode.
        Throws:
        java.lang.IllegalArgumentException - if the object is null.
    • Method Detail

      • dragScreenSizeConstant

        public void dragScreenSizeConstant​(DragContext dragContext)
        Converts the screen position inputs to geographic movement information. Uses the information provided by the DragContext object and attempts to move the object using the Movable2 or Movable interface. This method maintains a constant screen offset from the cursor to the reference point of the object being dragged. It is suited for objects maintaining a constant screen size presentation like, TacticalSymbols or PointPlacemark.
        Parameters:
        dragContext - the current DragContext for this object.
        Throws:
        java.lang.IllegalArgumentException - if the DragContext is null.
      • dragGlobeSizeConstant

        public void dragGlobeSizeConstant​(DragContext dragContext)
        Converts the screen position inputs to geographic movement information. Uses the information provided by the DragContext object and attempts to move the object using the Movable2 or Movable interface. This method maintains a constant geographic distance between the cursor and the reference point of the object being dragged. It is suited for objects which maintain a constant model space or geographic size.
        Parameters:
        dragContext - the current DragContext for this object.
        Throws:
        java.lang.IllegalArgumentException - if the DragContext is null.
      • getStepLimit

        public int getStepLimit()
        Returns the step limit used by the position solver method for objects using a screen size constant drag approach and a WorldWind.RELATIVE_TO_GROUND altitude mode. If the solver exceeds this value it will utilize an intersection with the ellipsoid at the specified altitude.
        Returns:
        the step limit.
      • setStepLimit

        public void setStepLimit​(int stepLimit)
        Sets the step limit to use for the position solver. The position solver is only used for screen size constant objects with a WorldWind.RELATIVE_TO_GROUND altitude mode. The step limit is the maximum steps the solver will attempt before using an intersection with the ellipsoid at the specified altitude. Set this value in coordination with the convergence threshold.
        Parameters:
        stepLimit - the step limit to set for the solver method.
      • getConvergenceThreshold

        public double getConvergenceThreshold()
        Returns the convergence threshold used by the solver when an a screen size constant object using a WorldWind.RELATIVE_TO_GROUND altitude mode needs to determine a position. When the solver finds an altitude within the convergence threshold to the desired altitude, the solver will stop and return the cartesian position.
        Returns:
        the convergence threshold.
      • setConvergenceThreshold

        public void setConvergenceThreshold​(double convergenceThreshold)
        Sets the convergence threshold for the screen size constant object using a WorldWind.RELATIVE_TO_GROUND altitude mode. The solver will test each iterations solution altitude with the desired altitude and if it is found to be within the convergence threshold, the cartesian solution will be returned. Set this value in coordination with the step limit.
        Parameters:
        convergenceThreshold - the convergence threshold to use for the solver.
      • getAltitudeMode

        public int getAltitudeMode()
        Returns the current altitude mode being used by the dragging calculations.
        Returns:
        the altitude mode.
      • setAltitudeMode

        public void setAltitudeMode​(int altitudeMode)
        Sets the altitude mode to be used during dragging calculations.
        Parameters:
        altitudeMode - the altitude mode to use for dragging calculations.
      • computeEllipsoidalPointFromScreen

        protected Vec4 computeEllipsoidalPointFromScreen​(DragContext dragContext,
                                                         java.awt.Point screenPoint,
                                                         double altitude,
                                                         boolean utilizeSearchMethod)
        Determines the cartesian coordinate of a screen point given the altitude mode.
        Parameters:
        dragContext - the current DragContext of the dragging event.
        screenPoint - the Point of the screen to determine the position.
        altitude - the altitude in meters.
        utilizeSearchMethod - if the altitude mode is WorldWind.RELATIVE_TO_GROUND, this determines if the search method will be used to determine the position, please see the computeRelativePoint(Line, Globe, SceneController, double) for more information.
        Returns:
        the cartesian coordinates using an ellipsoidal globe, or null if a position could not be determined.
      • computeScreenOffsetFromReferencePosition

        protected Vec4 computeScreenOffsetFromReferencePosition​(Position dragObjectReferencePosition,
                                                                DragContext dragContext)
        Determines the offset in screen coordinates from the previous screen point (DragContext.getInitialPoint() and the objects Movable.getReferencePosition() or Movable2.getReferencePosition() methods. If the object doesn't implement either of the interfaces, or there is an error determining the offset, this function will return null.
        Parameters:
        dragObjectReferencePosition - the Movable or Movable2 reference position Position.
        dragContext - the current DragContext of this drag event.
        Returns:
        a Vec4 containing the x and y offsets in screen coordinates from the reference position and the previous screen point.
      • computeGlobeIntersection

        protected Vec4 computeGlobeIntersection​(Line ray,
                                                double altitude,
                                                boolean useSearchMethod,
                                                Globe globe,
                                                SceneController sceneController)
        Computes the intersection of the provided Line with the Globe while accounting for the altitude mode. If a Globe2D is specified, then the intersection is calculated using the globe objects method.
        Parameters:
        ray - the Line to calculate the intersection of the Globe.
        altitude - the altitude mode for the intersection calculation.
        useSearchMethod - if the altitude mode is WorldWind.RELATIVE_TO_GROUND, this determines if the search method will be used to determine the position, please see the computeRelativePoint(Line, Globe, SceneController, double) for more information.
        globe - the Globe to intersect.
        sceneController - if an altitude mode other than WorldWind.ABSOLUTE is specified, the SceneController which will provide terrain information.
        Returns:
        the cartesian coordinates of the intersection based on the Globes coordinate system or null if the intersection couldn't be calculated.
      • computeRelativePoint

        protected Vec4 computeRelativePoint​(Line ray,
                                            Globe globe,
                                            SceneController sceneController,
                                            double altitude)
        Attempts to find a position with the altitude specified for objects which are WorldWind.RELATIVE_TO_GROUND. Using the provided Line, conducts a bisectional search along the Line for a Position which is within the convergenceThreshold of the requested altitude provided. The stepLimit limits the number of bisections the function will attempt. If the search does not find a position within the stepLimit or within the convergenceThreshold it will provide an intersection with the ellipsoid at the provided altitude.
        Parameters:
        ray - the Line from the eye point and direction in globe coordinates.
        globe - the current Globe.
        sceneController - the current SceneController.
        altitude - the target altitude.
        Returns:
        a Vec4 of the point in globe coordinates.