Class CanvasSelection


  • public class CanvasSelection
    extends Object
    This class represents the current state of the canvas selection. The default insets and handles are 6px. The default stroke is dashed
    Author:
    KIYUT
    • Constructor Detail

      • CanvasSelection

        public CanvasSelection()
        Creates a new instance of SelectionModel
    • Method Detail

      • paint

        public void paint​(Graphics2D g2d)
        Paint this CanvasSelection
        Parameters:
        g2d - Graphics2D
      • setVectorCanvas

        public void setVectorCanvas​(VectorCanvas canvas)
        Sets the canvas associated with this CanvasSelection.
        Parameters:
        canvas - the VectorCanvas
      • setSelectionTool

        public void setSelectionTool​(SelectionTool tool)
        Set the SelectionTool to be used as SelectionTool
        Parameters:
        tool - SelectionTool
      • getStrokePaint

        public Paint getStrokePaint()
        Return stroke paint used. The value returned is same with the preferences
        Returns:
        stroke Paint
        See Also:
        getStroke()
      • getStroke

        public Stroke getStroke()
        Return stroke. The value returned is same with the preferences
        Returns:
        Stroke
        See Also:
        getStrokePaint()
      • addSelectionListener

        public void addSelectionListener​(CanvasSelectionListener listener)
        Add CanvasSelectionListener for notification of any changes to the CanvasSelection.
        Parameters:
        listener - Listener to be added
      • removeSelectionListener

        public void removeSelectionListener​(CanvasSelectionListener listener)
        Remove CanvasSelectionListener for notification of any changes to the CanvasSelection.
        Parameters:
        listener - Listener to be removed
      • clearSelection

        public void clearSelection()
        clear the selection only, it doesn't change the DOM / document
      • resetBorder

        protected void resetBorder()
        Reset the Border and Handle to default or initial location
      • setBoundsVisible

        public void setBoundsVisible​(boolean boundsVisible)
        Set the visibility of selection bounds
        Parameters:
        boundsVisible - true or false
      • isBoundsVisible

        public boolean isBoundsVisible()
        Determines if the selection bounds is currently visible.
        Returns:
        true or false
      • setHandlesVisible

        public void setHandlesVisible​(boolean handlesVisible)
        set the visibility of selection handles
        Parameters:
        handlesVisible - true or false
      • isHandlessVisible

        public boolean isHandlessVisible()
        Determines if the selection handles is currently visible.
        Returns:
        true or false
      • setEnabled

        public void setEnabled​(boolean enabled)
        Sets whether or not this CanvasSelection is enabled. If enabled is false, it does not respond to user input eg: mouse and keyboard event
        Parameters:
        enabled - true or false
      • isEnabled

        public boolean isEnabled()
        Return true if enabled otherwise false
        Returns:
        true if enabled otherwise false
      • setEnabledVisible

        public void setEnabledVisible​(boolean enabled,
                                      boolean boundsVisible,
                                      boolean handleVisible)
        Convenience method to set enabled, boundsVisible, handleVisible in one method call
        Parameters:
        enabled - true or false
        boundsVisible - true or false
        handleVisible - true or false
      • setVisible

        public void setVisible​(boolean boundsVisible,
                               boolean handleVisible)
        Convenience method to set boundsVisible, handleVisible in one method call
        Parameters:
        boundsVisible - true or false
        handleVisible - true or false
      • getSelectionList

        public List<org.w3c.dom.svg.SVGElement> getSelectionList()
        Return selection list
        Returns:
        selection list
      • setSelectionList

        public void setSelectionList​(List<org.w3c.dom.svg.SVGElement> selectionList)
        Set the selectionList. If selectionList is null, this has the same effect as invoking clearSelection.
        Parameters:
        selectionList - List of SVGElement
        See Also:
        clearSelection()
      • getBorder

        public Map<String,​Rectangle2D> getBorder()
        Return selection border in the form of phone keypad format.
        [1 2 3]
        [4 5 6]
        [7 8 9]
        - key 0 as the bounds
        - 1 as top left handle or North West
        - 9 as bottom right handle or South East
        Returns:
        border
      • getSelectionBounds2D

        public Rectangle2D getSelectionBounds2D()
        Return Rectangle2D of selection bounds.
        Returns:
        Rectangle2D of selection bounds
      • getSelectionBounds2D

        @Deprecated
        public Rectangle2D getSelectionBounds2D​(boolean includeInsets)
        Deprecated.
        not to be used anymore, use #getSelectionBounds2D() instead. no more insets
        Return Rectangle2D of selection bounds include inset or not
        Parameters:
        includeInsets - true or false
        Returns:
        Rectangle2D of selection bounds
      • updateBorder

        public void updateBorder()
        Update the selection border
      • updateCanvasTool

        protected void updateCanvasTool​(Tool tool)