Package kiyut.sketsa.canvas

## Class CanvasSelection

- java.lang.Object
- - kiyut.sketsa.canvas.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 Summary

    Constructors
    Constructor | Description
    --- | ---
    `CanvasSelection()` | Creates a new instance of SelectionModel

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addSelectionListener​(CanvasSelectionListener listener)` | Add CanvasSelectionListener for notification of any changes to the CanvasSelection.
    `void` | `clearSelection()` | clear the selection only, it doesn't change the DOM / document
    `Map<String,​Rectangle2D>` | `getBorder()` | Return selection border in the form of phone keypad format.
    `Rectangle2D` | `getSelectionBounds2D()` | Return Rectangle2D of selection bounds.
    `Rectangle2D` | `getSelectionBounds2D​(boolean includeInsets)` | Deprecated. not to be used anymore, use #getSelectionBounds2D() instead.
    `List<org.w3c.dom.svg.SVGElement>` | `getSelectionList()` | Return selection list
    `SelectionTool` | `getSelectionTool()` |
    `Stroke` | `getStroke()` | Return stroke.
    `Paint` | `getStrokePaint()` | Return stroke paint used.
    `VectorCanvas` | `getVectorCanvas()` | Return the `VectorCanvas` that this associated with.
    `boolean` | `isBoundsVisible()` | Determines if the selection bounds is currently visible.
    `boolean` | `isEnabled()` | Return true if enabled otherwise false
    `boolean` | `isHandlessVisible()` | Determines if the selection handles is currently visible.
    `void` | `keyPressed​(KeyEvent evt)` | Invoked when a key has been pressed.
    `void` | `keyReleased​(KeyEvent evt)` | Invoked when a key has been released.
    `void` | `keyTyped​(KeyEvent evt)` | Invoked when a key has been typed.
    `void` | `mouseClicked​(MouseEvent evt)` | Invoked when the mouse button has been clicked (pressed and released) on a component.
    `void` | `mouseDragged​(MouseEvent evt)` | Invoked when a mouse button is pressed on a component and then dragged.
    `void` | `mouseEntered​(MouseEvent evt)` | Invoked when the mouse enters a component.
    `void` | `mouseExited​(MouseEvent evt)` | Invoked when the mouse exits a component.
    `void` | `mouseMoved​(MouseEvent evt)` | Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.
    `void` | `mousePressed​(MouseEvent evt)` | Invoked when a mouse button has been pressed on a component.
    `void` | `mouseReleased​(MouseEvent evt)` | Invoked when a mouse button has been released on a component.
    `void` | `paint​(Graphics2D g2d)` | Paint this CanvasSelection
    `void` | `removeSelectionListener​(CanvasSelectionListener listener)` | Remove CanvasSelectionListener for notification of any changes to the CanvasSelection.
    `protected void` | `resetBorder()` | Reset the Border and Handle to default or initial location
    `void` | `setBoundsVisible​(boolean boundsVisible)` | Set the visibility of selection bounds
    `void` | `setEnabled​(boolean enabled)` | Sets whether or not this CanvasSelection is enabled.
    `void` | `setEnabledVisible​(boolean enabled, boolean visible)` | Deprecated. replaced by `setEnabledVisible(boolean,boolean,boolean)`
    `void` | `setEnabledVisible​(boolean enabled, boolean boundsVisible, boolean handleVisible)` | Convenience method to set enabled, boundsVisible, handleVisible in one method call
    `void` | `setHandlesVisible​(boolean handlesVisible)` | set the visibility of selection handles
    `void` | `setSelectionList​(List<org.w3c.dom.svg.SVGElement> selectionList)` | Set the selectionList.
    `void` | `setSelectionTool​(SelectionTool tool)` | Set the `SelectionTool` to be used as `SelectionTool`
    `void` | `setVectorCanvas​(VectorCanvas canvas)` | Sets the canvas associated with this CanvasSelection.
    `void` | `setVisible​(boolean boundsVisible, boolean handleVisible)` | Convenience method to set boundsVisible, handleVisible in one method call
    `void` | `updateBorder()` | Update the selection border
    `protected void` | `updateCanvasTool​(Tool tool)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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`

    - #### getVectorCanvas

          public VectorCanvas getVectorCanvas()

      Return the `VectorCanvas` that this associated with.
      Returns:
        `VectorCanvas`
      See Also:
        `setVectorCanvas(VectorCanvas)`

    - #### setSelectionTool

          public void setSelectionTool​(SelectionTool tool)

      Set the `SelectionTool` to be used as `SelectionTool`
      Parameters:
        `tool` - `SelectionTool`

    - #### getSelectionTool

          public SelectionTool getSelectionTool()

    - #### 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

          @Deprecated
          public void setEnabledVisible​(boolean enabled,
                                        boolean visible)

      Deprecated.
      replaced by `setEnabledVisible(boolean,boolean,boolean)`
      Parameters:
        `enabled` - true or false
        `visible` - true or false
      See Also:
        `setEnabledVisible(boolean,boolean,boolean)`

    - #### 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)

    - #### keyPressed

          public void keyPressed​(KeyEvent evt)

      Invoked when a key has been pressed. See the class description for `KeyEvent` for a definition of a key pressed event.
      Parameters:
        `evt` - the KeyEvent
      See Also:
        `KeyListener.keyPressed(java.awt.event.KeyEvent)`

    - #### keyReleased

          public void keyReleased​(KeyEvent evt)

      Invoked when a key has been released. See the class description for `KeyEvent` for a definition of a key released event.
      Parameters:
        `evt` - the KeyEvent
      See Also:
        `KeyListener.keyReleased(java.awt.event.KeyEvent)`

    - #### keyTyped

          public void keyTyped​(KeyEvent evt)

      Invoked when a key has been typed. See the class description for `KeyEvent` for a definition of a key typed event.
      Parameters:
        `evt` - the KeyEvent
      See Also:
        `KeyListener.keyTyped(java.awt.event.KeyEvent)`

    - #### mouseClicked

          public void mouseClicked​(MouseEvent evt)

      Invoked when the mouse button has been clicked (pressed and released) on a component.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseListener.mouseClicked(java.awt.event.MouseEvent)`

    - #### mouseDragged

          public void mouseDragged​(MouseEvent evt)

      Invoked when a mouse button is pressed on a component and then dragged.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseMotionListener.mouseDragged(java.awt.event.MouseEvent)`

    - #### mouseEntered

          public void mouseEntered​(MouseEvent evt)

      Invoked when the mouse enters a component.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseListener.mouseEntered(java.awt.event.MouseEvent)`

    - #### mouseExited

          public void mouseExited​(MouseEvent evt)

      Invoked when the mouse exits a component.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseListener.mouseExited(java.awt.event.MouseEvent)`

    - #### mouseMoved

          public void mouseMoved​(MouseEvent evt)

      Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseMotionListener.mouseMoved(java.awt.event.MouseEvent)`

    - #### mousePressed

          public void mousePressed​(MouseEvent evt)

      Invoked when a mouse button has been pressed on a component.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseListener.mousePressed(java.awt.event.MouseEvent)`

    - #### mouseReleased

          public void mouseReleased​(MouseEvent evt)

      Invoked when a mouse button has been released on a component.
      Parameters:
        `evt` - the MouseEvent
      See Also:
        `MouseListener.mouseReleased(java.awt.event.MouseEvent)`