Class 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
    • Field Detail

      • renderer

        protected org.apache.batik.gvt.renderer.ImageRenderer renderer
        Canvas Renderer
      • canvasSelection

        protected CanvasSelection canvasSelection
        CanvasSelection
      • 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
      • 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

      • 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()
      • 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()
      • 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
      • 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
      • 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