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 CanvasBackgroundcanvasBackgroundCanvasBackgroundprotected DefaultCanvasGridcanvasGridCanvasGridprotected CanvasSelectioncanvasSelectionCanvasSelectionprotected DimensioncanvasSizeCanvas Sizestatic StringDOCUMENT_PROPERTYIdentifies a change to the documentprotected EventListenerdomListenerDOM EventListenerprotected PointdropLocationDrop Locationprotected NodeFilteremptyTextNodeFilterEmpty or Whitespace Text node filterprotected BufferedImageimageCanvas Bufferprotected CanvasModelmodelCanvasModelprotected ToolpreviousToolPrevious Canvas Toolprotected org.apache.batik.gvt.renderer.ImageRendererrendererCanvas Rendererprotected booleansnapToGridSnap To Gridprotected TextEditortextEditorTextEditorprotected TooltoolCanvas Toolstatic StringTOOL_PROPERTYIdentifies a change to the toolprotected DOMUndoManagerundoManagerDOMUndoManagerprotected doublezoomFactorZoom 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 VectorCanvasVectorCanvas(TextEditor textEditor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeleteSelection()Delete the selection, update DOMvoiddispose()disposeorg.apache.batik.bridge.SVGAnimationEnginegetAnimationEngine()Returns theSVGAnimationEnginefor the document or null.CanvasBackgroundgetCanvasBackground()Return CanvasBackgroundCanvasGridgetCanvasGrid()Return CanvasGridCanvasSelectiongetCanvasSelection()Return CanvasSelectionPointgetDropLocation()Returns the position of the mouse pointer in this Component's coordinate space during DND operation, otherwise returns null.EditorUserAgentgetEditorUserAgent()ReturnEditorUserAgentCanvasModelgetModel()Return CanvasModelColorgetPixelColor(int x, int y)Returns the color of a pixel at the given coordinates.ToolgetPreviousTool()Return previous Toolorg.w3c.dom.svg.SVGDocumentgetSVGDocument()Return SVGDocumentTextEditorgetTextEditor()Return TextEditorToolgetTool()Return current ToolAffineTransformgetTransform()Return copy of canvas transform.AffineTransformgetTransform(boolean includeRootDocTransform)Return copy of canvas transform.DOMUndoManagergetUndoManager()Return DOMUndoManagerdoublegetZoomFactor()Return zoomFactor.voidgroupSelection()Group Canvas Selection into single SVGGElement.booleanisGridVisible()Return true or false, it is just convenience methodsbooleanisSnapToGrid()Return true or falsevoidmoveBottomRootSelection()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 topmostvoidmoveBottomSelection()It move in the same level.voidmoveDownSelection()It move in the same level.voidmoveTopRootSelection()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.voidmoveTopSelection()It move in the same level.voidmoveUpSelection()It move in the same level.voidpaintComponent(Graphics g)voidrefresh()Refresh whole canvasvoidrefresh(Shape shape)refresh canvas only the specified area of interest.voidrefreshSelection()Convenience method to refresh CanvasSelectionprotected voidresetCanvasSelection()Reset Canvas Selection State enabled, boundsVisible, handlesVisiblevoidsetGridVisible(boolean visible)Set Grid Visible property, it is just convenience methodsvoidsetSnapToGrid(boolean snapToGrid)Set Snap to Grid propertyvoidsetSVGDocument(org.w3c.dom.svg.SVGDocument doc)Set SVGDocumentvoidsetTool(Tool tool)Set Current ToolvoidsetZoomFactor(double zoomFactor)Set zoom factorvoidungroupSelection()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
-
-
-
-
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:
paintComponentin classJComponent
-
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()
ReturnEditorUserAgent- 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 theSVGAnimationEnginefor the document or null. Just convenience method to wrap model.getAnimationEngine- Returns:
SVGAnimationEngineor 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 pixely- 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 CanvasExceptionGroup 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.
-
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.
-
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
-
-