Class DragInteractor

    • Constructor Detail

      • DragInteractor

        public DragInteractor()
    • Method Detail

      • addLayerListener

        public void addLayerListener​(LayerListener l)
        Add the given layer listener to this interactor. Any event that is received by this interactor will be passed on to the listener after it is handled by this interactor.
        Parameters:
        l - The listener
      • appendConstraint

        public void appendConstraint​(PointConstraint constraint)
        Append a constraint to the list of constraints on this interactor.
        Parameters:
        constraint - The constraint.
      • constrainPoint

        public void constrainPoint​(java.awt.geom.Point2D p)
        Constrain a point using the current constraints. The given point will be modified according to the current constraints. This method does not trigger constraint events. The caller must be careful to make a copy of the passed point if it is not guaranteed that changing the point will not affect other objects with a reference to it.
        Parameters:
        p - The point
      • fireLayerEvent

        public void fireLayerEvent​(LayerEvent event)
        Fire a layer event.
        Parameters:
        event - The event
      • getSelectiveEnabled

        public boolean getSelectiveEnabled()
        Get the flag that says that the interactor responds only if the figure being moused on is selected. By default, this flag is false.
        Returns:
        True if selective is enabled.
        See Also:
        setSelectiveEnabled(boolean)
      • getTargetArray

        public java.lang.Object[] getTargetArray()
        Get the target array.
        Returns:
        the target array
        See Also:
        setTargetArray(Object[])
      • getX

        public double getX()
        Get the current value of the X coordinate.
        Returns:
        The x value
      • getY

        public double getY()
        Get the current value of the Y coordinate.
        Returns:
        the y value
      • mouseDragged

        public void mouseDragged​(LayerEvent e)
        Constrain the point and move the target if the mouse move. The target movement is done by the translate() method, which can be overridden to change the behaviour. Nothing happens if the interactor is not enabled, or if it is "selective enabled" but not in the selection.
        Specified by:
        mouseDragged in interface LayerListener
        Overrides:
        mouseDragged in class AbstractInteractor
        Parameters:
        e - the event
      • mousePressed

        public void mousePressed​(LayerEvent e)
        Handle a mouse press on a figure or layer. Set the target to be the figure contained in the event. Call the setup() method in case there is additional setup to do, then constrain the point and remember it. Nothing happens if the interactor is not enabled, or if it is "selective enabled" but not in the selection.
        Specified by:
        mousePressed in interface LayerListener
        Overrides:
        mousePressed in class AbstractInteractor
        Parameters:
        e - the event
      • mouseReleased

        public void mouseReleased​(LayerEvent e)
        Handle a mouse released event. Nothing happens if the interactor is not enabled, if if it is "selective enabled" but not in the selection.
        Specified by:
        mouseReleased in interface LayerListener
        Overrides:
        mouseReleased in class AbstractInteractor
        Parameters:
        e - The event
      • prependConstraint

        public void prependConstraint​(PointConstraint constraint)
        Prepend a constraint to the list of constraints on this interactor.
        Parameters:
        constraint - The constraint
      • removeLayerListener

        public void removeLayerListener​(LayerListener l)
        Remove the given layer listener from this interactor.
        Parameters:
        l - the listener
      • setSelectiveEnabled

        public boolean setSelectiveEnabled​(boolean s)
        Set the flag that says that the interactor responds only if the figure being moused on is selected. By default, this flag is false; if set true, then the mouse methods check that the figure is contained in the selection model of that figure's selection interactor (if it has one).
        Parameters:
        s - The value of selective enable
        Returns:
        The value of the selective enabled flag
        See Also:
        getSelectiveEnabled()
      • setTargetArray

        public void setTargetArray​(java.lang.Object[] arr)
        Set the target that the interactor operates on. By default, this will be the figure obtained from the event, but this method can be used to set it to something else.
        Parameters:
        arr - The array
        See Also:
        getTargetArray()
      • setup

        public void setup​(LayerEvent e)
        Initialize the interactor before a mouse-pressed event is processed. This default implementation does nothing, but clients can override to cause it to perform some action, such as setting up constraints.
        Parameters:
        e - The event
      • targets

        public java.util.Iterator targets()
        Get an iterator over the target figures.
        Returns:
        An iterator
      • translate

        public void translate​(LayerEvent e,
                              double x,
                              double y)
        Translate the target by the given distance. The first argument is the figure that was moused one. Any overriding methods should be aware that the interactor may in general be operating on multiple figures, and use the targets() method to get them.
        Parameters:
        e - The event
        x - the x distance
        y - the y distance