Package kiyut.sketsa.canvas

## Class VectorCanvas

- java.lang.Object
- - java.awt.Component
  - - java.awt.Container
    - - javax.swing.JComponent
      - - javax.swing.JPanel
        - - kiyut.sketsa.canvas.VectorCanvas

- All Implemented Interfaces:
    `ImageObserver`, `MenuContainer`, `Serializable`, `Accessible`

      public class VectorCanvas
      extends JPanel

  A Vector Canvas component which represents a blank rectangular area of the screen onto which the application can draw or from which the component can trap input events from the user.
  Author:
    Kiyut
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class javax.swing.JPanel

      `JPanel.AccessibleJPanel`

    - ### Nested classes/interfaces inherited from class javax.swing.JComponent

      `JComponent.AccessibleJComponent`

    - ### Nested classes/interfaces inherited from class java.awt.Container

      `Container.AccessibleAWTContainer`

    - ### Nested classes/interfaces inherited from class java.awt.Component

      `Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected CanvasBackground` | `canvasBackground` | CanvasBackground
    `protected DefaultCanvasGrid` | `canvasGrid` | CanvasGrid
    `protected CanvasSelection` | `canvasSelection` | CanvasSelection
    `protected Dimension` | `canvasSize` | Canvas Size
    `static String` | `DOCUMENT_PROPERTY` | Identifies a change to the document
    `protected EventListener` | `domListener` | DOM EventListener
    `protected Point` | `dropLocation` | Drop Location
    `protected NodeFilter` | `emptyTextNodeFilter` | Empty or Whitespace Text node filter
    `protected BufferedImage` | `image` | Canvas Buffer
    `protected CanvasModel` | `model` | CanvasModel
    `protected Tool` | `previousTool` | Previous Canvas Tool
    `protected org.apache.batik.gvt.renderer.ImageRenderer` | `renderer` | Canvas Renderer
    `protected boolean` | `snapToGrid` | Snap To Grid
    `protected TextEditor` | `textEditor` | TextEditor
    `protected Tool` | `tool` | Canvas Tool
    `static String` | `TOOL_PROPERTY` | Identifies a change to the tool
    `protected DOMUndoManager` | `undoManager` | DOMUndoManager
    `protected double` | `zoomFactor` | Zoom Factor

    - ### Fields inherited from class javax.swing.JComponent

      `listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW`

    - ### Fields inherited from class java.awt.Component

      `accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT`

    - ### Fields inherited from interface java.awt.image.ImageObserver

      `ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `VectorCanvas()` | Creates a new instance of VectorCanvas
    `VectorCanvas​(TextEditor textEditor)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `deleteSelection()` | Delete the selection, update DOM
    `void` | `dispose()` | dispose
    `org.apache.batik.bridge.SVGAnimationEngine` | `getAnimationEngine()` | Returns the `SVGAnimationEngine` for the document or null.
    `CanvasBackground` | `getCanvasBackground()` | Return CanvasBackground
    `CanvasGrid` | `getCanvasGrid()` | Return CanvasGrid
    `CanvasSelection` | `getCanvasSelection()` | Return CanvasSelection
    `Point` | `getDropLocation()` | Returns the position of the mouse pointer in this Component's coordinate space during DND operation, otherwise returns null.
    `EditorUserAgent` | `getEditorUserAgent()` | Return `EditorUserAgent`
    `CanvasModel` | `getModel()` | Return CanvasModel
    `Color` | `getPixelColor​(int x, int y)` | Returns the color of a pixel at the given coordinates.
    `Tool` | `getPreviousTool()` | Return previous Tool
    `org.w3c.dom.svg.SVGDocument` | `getSVGDocument()` | Return SVGDocument
    `TextEditor` | `getTextEditor()` | Return TextEditor
    `Tool` | `getTool()` | Return current Tool
    `AffineTransform` | `getTransform()` | Return copy of canvas transform.
    `AffineTransform` | `getTransform​(boolean includeRootDocTransform)` | Return copy of canvas transform.
    `DOMUndoManager` | `getUndoManager()` | Return DOMUndoManager
    `double` | `getZoomFactor()` | Return zoomFactor.
    `void` | `groupSelection()` | Group Canvas Selection into single SVGGElement.
    `boolean` | `isGridVisible()` | Return true or false, it is just convenience methods
    `boolean` | `isSnapToGrid()` | Return true or false
    `void` | `moveBottomRootSelection()` | First it moveDown then move the parent down level top in root level Note:It is based on z-order, means put the Element in the topmost
    `void` | `moveBottomSelection()` | It move in the same level.
    `void` | `moveDownSelection()` | It move in the same level.
    `void` | `moveTopRootSelection()` | First it moveUp then move the parent up level top in root level Note: It is based on z-order, means put the Element in the bottomost.
    `void` | `moveTopSelection()` | It move in the same level.
    `void` | `moveUpSelection()` | It move in the same level.
    `void` | `paintComponent​(Graphics g)` |
    `void` | `refresh()` | Refresh whole canvas
    `void` | `refresh​(Shape shape)` | refresh canvas only the specified area of interest.
    `void` | `refreshSelection()` | Convenience method to refresh CanvasSelection
    `protected void` | `resetCanvasSelection()` | Reset Canvas Selection State enabled, boundsVisible, handlesVisible
    `void` | `setGridVisible​(boolean visible)` | Set Grid Visible property, it is just convenience methods
    `void` | `setSnapToGrid​(boolean snapToGrid)` | Set Snap to Grid property
    `void` | `setSVGDocument​(org.w3c.dom.svg.SVGDocument doc)` | Set SVGDocument
    `void` | `setTool​(Tool tool)` | Set Current Tool
    `void` | `setZoomFactor​(double zoomFactor)` | Set zoom factor
    `void` | `ungroupSelection()` | UnGroup Canvas Selection.

    - ### Methods inherited from class javax.swing.JPanel

      `getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI`

    - ### Methods inherited from class javax.swing.JComponent

      `addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update`

    - ### Methods inherited from class java.awt.Container

      `add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree`

    - ### Methods inherited from class java.awt.Component

      `action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle`

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

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

- - ### Field Detail

    - #### TOOL_PROPERTY

          public static final String TOOL_PROPERTY

      Identifies a change to the tool
      See Also:
        Constant Field Values

    - #### DOCUMENT_PROPERTY

          public static final String DOCUMENT_PROPERTY

      Identifies a change to the document
      See Also:
        Constant Field Values

    - #### renderer

          protected org.apache.batik.gvt.renderer.ImageRenderer renderer

      Canvas Renderer

    - #### image

          protected BufferedImage image

      Canvas Buffer

    - #### model

          protected CanvasModel model

      CanvasModel

    - #### canvasSelection

          protected CanvasSelection canvasSelection

      CanvasSelection

    - #### canvasGrid

          protected DefaultCanvasGrid canvasGrid

      CanvasGrid

    - #### canvasBackground

          protected CanvasBackground canvasBackground

      CanvasBackground

    - #### textEditor

          protected TextEditor textEditor

      TextEditor

    - #### zoomFactor

          protected double zoomFactor

      Zoom Factor

    - #### canvasSize

          protected Dimension canvasSize

      Canvas Size

    - #### tool

          protected Tool tool

      Canvas Tool

    - #### previousTool

          protected Tool previousTool

      Previous Canvas Tool

    - #### dropLocation

          protected Point dropLocation

      Drop Location

    - #### domListener

          protected EventListener domListener

      DOM EventListener

    - #### snapToGrid

          protected boolean snapToGrid

      Snap To Grid

    - #### undoManager

          protected DOMUndoManager undoManager

      DOMUndoManager

    - #### emptyTextNodeFilter

          protected NodeFilter emptyTextNodeFilter

      Empty or Whitespace Text node filter

  - ### Constructor Detail

    - #### VectorCanvas

          public VectorCanvas()

      Creates a new instance of VectorCanvas

    - #### VectorCanvas

          public VectorCanvas​(TextEditor textEditor)

  - ### Method Detail

    - #### paintComponent

          public void paintComponent​(Graphics g)

      Overrides:
        `paintComponent` in class `JComponent`

    - #### dispose

          public void dispose()

      dispose

    - #### setSVGDocument

          public void setSVGDocument​(org.w3c.dom.svg.SVGDocument doc)

      Set SVGDocument
      Parameters:
        `doc` - `SVGDocument`
      See Also:
        `getSVGDocument()`

    - #### getSVGDocument

          public org.w3c.dom.svg.SVGDocument getSVGDocument()

      Return SVGDocument
      Returns:
        SVGDocument
      See Also:
        `setSVGDocument(SVGDocument)`

    - #### getEditorUserAgent

          public EditorUserAgent getEditorUserAgent()

      Return `EditorUserAgent`
      Returns:
        `EditorUserAgent`

    - #### getUndoManager

          public DOMUndoManager getUndoManager()

      Return DOMUndoManager
      Returns:
        DOMUndoManager

    - #### getCanvasBackground

          public CanvasBackground getCanvasBackground()

      Return CanvasBackground
      Returns:
        CanvasBackground

    - #### getCanvasGrid

          public CanvasGrid getCanvasGrid()

      Return CanvasGrid
      Returns:
        CanvasGrid

    - #### setGridVisible

          public void setGridVisible​(boolean visible)

      Set Grid Visible property, it is just convenience methods
      Parameters:
        `visible` - true or false
      See Also:
        `isGridVisible()`, `getCanvasGrid()`

    - #### isGridVisible

          public boolean isGridVisible()

      Return true or false, it is just convenience methods
      Returns:
        true or false
      See Also:
        `setGridVisible(boolean)`, `getCanvasGrid()`

    - #### setSnapToGrid

          public void setSnapToGrid​(boolean snapToGrid)

      Set Snap to Grid property
      Parameters:
        `snapToGrid` - true or false
      See Also:
        `isSnapToGrid()`

    - #### isSnapToGrid

          public boolean isSnapToGrid()

      Return true or false
      Returns:
        true or false
      See Also:
        `setSnapToGrid(boolean)`

    - #### getAnimationEngine

          public org.apache.batik.bridge.SVGAnimationEngine getAnimationEngine()

      Returns the `SVGAnimationEngine` for the document or null. Just convenience method to wrap model.getAnimationEngine
      Returns:
        `SVGAnimationEngine` or null

    - #### setZoomFactor

          public void setZoomFactor​(double zoomFactor)

      Set zoom factor
      Parameters:
        `zoomFactor` - the zoom factor
      See Also:
        `getZoomFactor()`

    - #### getZoomFactor

          public double getZoomFactor()

      Return zoomFactor.
      Returns:
        zoomFactor

    - #### getTransform

          public AffineTransform getTransform()

      Return copy of canvas transform. This method only return the canvas transform not including Root Document transform (eg: viewbox, etc). It is equivalent with calling getTransform(false)
      Returns:
        copy of canvas transform
      See Also:
        `getTransform(boolean)`

    - #### getTransform

          public AffineTransform getTransform​(boolean includeRootDocTransform)

      Return copy of canvas transform. If the parameter is true, it will include Root Document Transform as well (eg: viewbox, etc).
      Parameters:
        `includeRootDocTransform` - true or false
      Returns:
        copy of canvas transform

    - #### refresh

          public void refresh()

      Refresh whole canvas
      See Also:
        `refresh(Shape)`

    - #### refresh

          public void refresh​(Shape shape)

      refresh canvas only the specified area of interest.
      Parameters:
        `shape` - The area of interest
      See Also:
        `refresh()`

    - #### refreshSelection

          public void refreshSelection()

      Convenience method to refresh CanvasSelection
      See Also:
        `CanvasSelection.updateBorder()`

    - #### getPixelColor

          public Color getPixelColor​(int x,
                                     int y)

      Returns the color of a pixel at the given coordinates.
      Parameters:
        `x` - X position of pixel
        `y` - Y position of pixel
      Returns:
        Color of the pixel

    - #### getModel

          public CanvasModel getModel()

      Return CanvasModel
      Returns:
        CanvasModel

    - #### getCanvasSelection

          public CanvasSelection getCanvasSelection()

      Return CanvasSelection
      Returns:
        CanvasSelection

    - #### getTextEditor

          public TextEditor getTextEditor()

      Return TextEditor
      Returns:
        TextEditor

    - #### resetCanvasSelection

          protected void resetCanvasSelection()

      Reset Canvas Selection State enabled, boundsVisible, handlesVisible

    - #### setTool

          public void setTool​(Tool tool)

      Set Current Tool
      Parameters:
        `tool` - Canvas Tool
      See Also:
        `getTool()`, `getPreviousTool()`

    - #### getTool

          public Tool getTool()

      Return current Tool
      Returns:
        current Tool
      See Also:
        `setTool(Tool)`, `getPreviousTool()`

    - #### getPreviousTool

          public Tool getPreviousTool()

      Return previous Tool
      Returns:
        previous Tool
      See Also:
        `getTool()`, `setTool(Tool)`

    - #### getDropLocation

          public Point getDropLocation()

      Returns the position of the mouse pointer in this Component's coordinate space during DND operation, otherwise returns null. For Java 1.5 or higher it is preferable to use getMousePosition(). It is provided because Java 1.4 doesn't have getMousePosition() method.
      Returns:
        mouse coordinates relative to this Component, or null

    - #### deleteSelection

          public void deleteSelection()

      Delete the selection, update DOM

    - #### groupSelection

          public void groupSelection()
                              throws CanvasException

      Group Canvas Selection into single SVGGElement. Note:It will change canvas selection into the new created SVGGElement
      Throws:
        `CanvasException` - if one or more Object is not in the same level

    - #### ungroupSelection

          public void ungroupSelection()

      UnGroup Canvas Selection. Note:It will change canvas selection into break down Element

    - #### moveUpSelection

          public void moveUpSelection()

      It move in the same level. Note:It is based on z-order, means put the Element one node after.
      See Also:
        `moveDownSelection()`, `moveTopSelection()`, `moveBottomSelection()`

    - #### moveDownSelection

          public void moveDownSelection()

      It move in the same level. Note: It is based on z-order, means put the Element one node before.
      See Also:
        `moveUpSelection()`, `moveTopSelection()`, `moveBottomSelection()`

    - #### moveTopSelection

          public void moveTopSelection()

      It move in the same level. Note: It is based on z-order, means put the Element in the bottom most.
      See Also:
        `moveUpSelection()`, `moveDownSelection()`, `moveBottomSelection()`

    - #### moveBottomSelection

          public void moveBottomSelection()

      It move in the same level. Note: It is based on z-order, means put the Element in the topmost.
      See Also:
        `moveUpSelection()`, `moveDownSelection()`, `moveTopSelection()`

    - #### moveTopRootSelection

          public void moveTopRootSelection()

      First it moveUp then move the parent up level top in root level Note: It is based on z-order, means put the Element in the bottomost.

    - #### moveBottomRootSelection

          public void moveBottomRootSelection()

      First it moveDown then move the parent down level top in root level Note:It is based on z-order, means put the Element in the topmost