org.apache.batik.refimpl.util
Class JSVGCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--org.apache.batik.refimpl.util.JSVGCanvas
All Implemented Interfaces:
ActionMap, DynamicRenderer.RepaintHandler, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, SelectionListener, java.io.Serializable

public class JSVGCanvas
extends javax.swing.JComponent
implements ActionMap, DynamicRenderer.RepaintHandler, SelectionListener

This class implements a JComponent which is able to display a SVG document.

See Also:
Serialized Form

Inner Class Summary
protected  class JSVGCanvas.CanvasListener
          To correctly resize the view.
protected  class JSVGCanvas.MouseListener
          To handle the mouse events.
protected  class JSVGCanvas.MutationListener
          To listener to the DOM mutation events.
protected  class JSVGCanvas.RepaintTimer
          Timer class which fires periodic repaint request while buffer is being painted.
protected  class JSVGCanvas.ThumbnailCanvas
          This class represents the thumbnail canvas.
 class JSVGCanvas.UnzoomAction
          To reset the zoom.
static interface JSVGCanvas.ZoomHandler
          Interface implemented by zoom handlers.
 class JSVGCanvas.ZoomInAction
          To zoom in the document.
 class JSVGCanvas.ZoomOutAction
          To zoom out the document.
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  java.awt.image.BufferedImage buffer
          The current offscreen buffer.
protected  boolean bufferNeedsRendering
          Must the buffer be updated?
protected  GVTBuilder builder
          The GVT builder.
protected  java.awt.Shape docBBox
          The pan bounding box.
protected  SVGDocument document
          The SVG document to render.
protected  boolean documentTransformed
          Whether or not the current document was transformed.
protected  java.awt.image.BufferedImage globalBuffer
          The global offscreen buffer.
protected  GraphicsNode gvtRoot
          Root of the GVT tree displayed by this viewer
protected  double initialScale
          The initial scale factor.
protected  boolean isLoadPending
          Is there a document load pending?
protected  java.util.Map listeners
          The map that contains the listeners
protected  java.lang.Object loadPendingLock
          An object used to synchronize access to loadPending flag.
protected  java.awt.geom.Line2D markerBottom
          The zoom marker bottom line.
protected  java.awt.geom.Line2D markerLeft
          The zoom marker left line.
protected  java.awt.geom.Line2D markerRight
          The zoom marker right line.
protected  java.awt.BasicStroke markerStroke
          Used to draw marker
protected  java.awt.geom.Line2D markerTop
          The zoom marker top line.
static java.awt.Cursor NORMAL_CURSOR
          The default cursor.
static java.awt.Cursor PAN_CURSOR
          The cursor for panning.
protected  java.awt.geom.AffineTransform panTransform
          The transform representing the pan tranlate.
protected  ParserFactory parserFactory
          The parser factory.
protected  java.awt.geom.AffineTransform previousRotateTransform
          The transform representing the previous rotation.
protected  boolean progressiveRenderingEnabled
          Fires periodic repaints while buffer is rendered
protected  RendererFactory rendererFactory
          The renderer factory.
 java.awt.Cursor requestedCursor
          The cursor which has been most recently requested by a background thread.
static java.awt.Cursor ROTATE_CURSOR
          The cursor for rotating.
protected  double rotateAngle
          The rotation angle
protected  double rotateCos
          The rotation cosinus
protected  java.awt.Shape rotateMarker
          The rotate marker.
protected  java.awt.geom.AffineTransform rotateTransform
          The transform representing the rotation.
protected  java.awt.Shape selectionHighlightShape
          The selection highlight shape.
protected static java.awt.Color selectionXORColor
          The color used for the XOR painting of the selection highlight.
static java.awt.Cursor TEXT_CURSOR
          The cursor indicating that a text selection operation is under way.
protected  Selector textSelector
          The text selector.
protected  JSVGCanvas.ThumbnailCanvas thumbnailCanvas
          The thumbnail canvas.
protected  java.awt.geom.AffineTransform transform
          The transform to apply to the graphics object.
static java.lang.String UNZOOM_ACTION
           
protected  UserAgent userAgent
          The user agent.
static java.awt.Cursor WAIT_CURSOR
          The cursor indicating that an operation is pending.
static java.awt.Cursor ZOOM_CURSOR
          The cursor for zooming.
static java.lang.String ZOOM_IN_ACTION
           
static java.lang.String ZOOM_OUT_ACTION
           
protected  JSVGCanvas.ZoomHandler zoomHandler
          The zoom handler.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
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
JSVGCanvas()
          Creates a new SVG canvas.
JSVGCanvas(UserAgent ua)
          Creates a new SVG canvas, associating it with a UserAgent.
 
Method Summary
protected  void clearBuffer(java.awt.image.BufferedImage buffer, int w, int h)
          Clears a specific buffer.
protected  void clearBuffer(int w, int h)
          Clears the offscreen buffer.
protected  void clearBuffer(java.awt.Shape aoi)
          Clears the offscreen buffer.
protected  void computeTransform()
          Computes the value of the transform attribute.
protected  BridgeContext createBridgeContext(SVGDocument doc)
          Creates a new bridge context.
 javax.swing.Action getAction(java.lang.String key)
          Returns the action associated with the given string or null on error
protected  java.awt.Shape getAreaOfInterest(java.awt.Shape devAOI)
           
 java.awt.image.BufferedImage getBuffer()
          Returns the current buffer.
 RendererFactory getRendererFactory()
          Returns the current renderer factory.
protected  java.awt.Cursor getRequestedCursor()
          Gets the value of the requested cursor, but in a thread-safe way.
 javax.swing.JComponent getThumbnail()
          Returns the thumbnail.
 java.awt.geom.AffineTransform getTransform()
          Returns the current document-to-device space transform.
 void initSelectors(GraphicsNode treeRoot)
          Associate selectable elements in the current tree with Selector instances.
 boolean isLoadPending()
          Returns boolean indicating whether there is a document load pending.
 boolean isProgressiveRenderingEnabled()
          Returns boolean indicating whether progressive rendering is enabled.
 void notifyRepaintedRegion(java.awt.Shape oldAoi, java.awt.Shape newAoi, Renderer renderer)
          Notifies that the specified area of interest need to be repainted.
protected  void paintComponent(java.awt.Graphics g)
          Paints this component into a graphics context.
protected  void paintOverlays(java.awt.Graphics g)
          Paints the canvas "overlay" primitives (rotation box, zoom AOI box, highlight [not yet implemented], etc.
protected  void paintPanRegions(java.awt.Graphics2D g2d, int tx, int ty, int w, int h)
          Repaints the pan blank regions.
protected  void repaintAOI(Renderer renderer, java.awt.Dimension size, java.awt.image.BufferedImage buffer)
          Initiates the repainting of the offscreen buffer in a background thread.
protected  void requestCursor(java.awt.Cursor newCursor)
          Sets the value of the requested cursor, but in a thread-safe way.
 void selectionChanged(SelectionEvent e)
          Invoked when a selection has changed
 void setIsLoadPending(boolean value)
          Sets the value of a flag indicating whether there is a load pending:
 void setProgressiveRenderingEnabled(boolean value)
          Sets the value of the progressive rendering flag: true enables progressive rendering, false disables it.
 void setRendererFactory(RendererFactory rf)
          Sets the renderer factory to use to create the renderer.
 void setRootNode(GraphicsNode root, BridgeContext bridgeContext, SVGDocument document)
          Sets the root node adn current document, notifies the document that it has been installed, and issues necessary notifications and repaints to this JSVGCanvas.
 void setSVGDocument(SVGDocument doc)
          Sets the SVG document to display.
 void setZoomHandler(JSVGCanvas.ZoomHandler h)
          Sets the zoom handler.
protected  void updateBaseTransform()
          Updates the document bounding box, selection highlight and event dispatcher coordinate system based on the new value of the transform attribute.
protected  void updateBuffer(int w, int h)
          Updates the offscreen buffer.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNZOOM_ACTION

public static final java.lang.String UNZOOM_ACTION

ZOOM_IN_ACTION

public static final java.lang.String ZOOM_IN_ACTION

ZOOM_OUT_ACTION

public static final java.lang.String ZOOM_OUT_ACTION

PAN_CURSOR

public static final java.awt.Cursor PAN_CURSOR
The cursor for panning.

ZOOM_CURSOR

public static final java.awt.Cursor ZOOM_CURSOR
The cursor for zooming.

ROTATE_CURSOR

public static final java.awt.Cursor ROTATE_CURSOR
The cursor for rotating.

NORMAL_CURSOR

public static final java.awt.Cursor NORMAL_CURSOR
The default cursor.

WAIT_CURSOR

public static final java.awt.Cursor WAIT_CURSOR
The cursor indicating that an operation is pending.

TEXT_CURSOR

public static final java.awt.Cursor TEXT_CURSOR
The cursor indicating that a text selection operation is under way.

requestedCursor

public java.awt.Cursor requestedCursor
The cursor which has been most recently requested by a background thread.

globalBuffer

protected java.awt.image.BufferedImage globalBuffer
The global offscreen buffer.

buffer

protected java.awt.image.BufferedImage buffer
The current offscreen buffer.

gvtRoot

protected GraphicsNode gvtRoot
Root of the GVT tree displayed by this viewer

rendererFactory

protected RendererFactory rendererFactory
The renderer factory.

builder

protected GVTBuilder builder
The GVT builder.

document

protected SVGDocument document
The SVG document to render.

bufferNeedsRendering

protected boolean bufferNeedsRendering
Must the buffer be updated?

isLoadPending

protected boolean isLoadPending
Is there a document load pending?

userAgent

protected UserAgent userAgent
The user agent.

transform

protected java.awt.geom.AffineTransform transform
The transform to apply to the graphics object.

panTransform

protected java.awt.geom.AffineTransform panTransform
The transform representing the pan tranlate.

rotateTransform

protected java.awt.geom.AffineTransform rotateTransform
The transform representing the rotation.

previousRotateTransform

protected java.awt.geom.AffineTransform previousRotateTransform
The transform representing the previous rotation.

docBBox

protected java.awt.Shape docBBox
The pan bounding box.

markerTop

protected java.awt.geom.Line2D markerTop
The zoom marker top line.

markerLeft

protected java.awt.geom.Line2D markerLeft
The zoom marker left line.

markerBottom

protected java.awt.geom.Line2D markerBottom
The zoom marker bottom line.

markerRight

protected java.awt.geom.Line2D markerRight
The zoom marker right line.

rotateMarker

protected java.awt.Shape rotateMarker
The rotate marker.

selectionHighlightShape

protected java.awt.Shape selectionHighlightShape
The selection highlight shape.

thumbnailCanvas

protected JSVGCanvas.ThumbnailCanvas thumbnailCanvas
The thumbnail canvas.

parserFactory

protected ParserFactory parserFactory
The parser factory.

textSelector

protected Selector textSelector
The text selector.

zoomHandler

protected JSVGCanvas.ZoomHandler zoomHandler
The zoom handler.

rotateAngle

protected double rotateAngle
The rotation angle

rotateCos

protected double rotateCos
The rotation cosinus

initialScale

protected double initialScale
The initial scale factor.

progressiveRenderingEnabled

protected boolean progressiveRenderingEnabled
Fires periodic repaints while buffer is rendered

documentTransformed

protected boolean documentTransformed
Whether or not the current document was transformed.

markerStroke

protected java.awt.BasicStroke markerStroke
Used to draw marker

loadPendingLock

protected java.lang.Object loadPendingLock
An object used to synchronize access to loadPending flag.

listeners

protected java.util.Map listeners
The map that contains the listeners

selectionXORColor

protected static java.awt.Color selectionXORColor
The color used for the XOR painting of the selection highlight.
Constructor Detail

JSVGCanvas

public JSVGCanvas()
Creates a new SVG canvas.

JSVGCanvas

public JSVGCanvas(UserAgent ua)
Creates a new SVG canvas, associating it with a UserAgent.
Method Detail

setRendererFactory

public void setRendererFactory(RendererFactory rf)
Sets the renderer factory to use to create the renderer.

setProgressiveRenderingEnabled

public void setProgressiveRenderingEnabled(boolean value)
Sets the value of the progressive rendering flag: true enables progressive rendering, false disables it.

isProgressiveRenderingEnabled

public boolean isProgressiveRenderingEnabled()
Returns boolean indicating whether progressive rendering is enabled.

setIsLoadPending

public void setIsLoadPending(boolean value)
Sets the value of a flag indicating whether there is a load pending:

isLoadPending

public boolean isLoadPending()
Returns boolean indicating whether there is a document load pending.

setZoomHandler

public void setZoomHandler(JSVGCanvas.ZoomHandler h)
Sets the zoom handler.

getRendererFactory

public RendererFactory getRendererFactory()
Returns the current renderer factory.

setSVGDocument

public void setSVGDocument(SVGDocument doc)
Sets the SVG document to display.
Parameters:
doc - if null, clears the canvas.

setRootNode

public void setRootNode(GraphicsNode root,
                        BridgeContext bridgeContext,
                        SVGDocument document)
Sets the root node adn current document, notifies the document that it has been installed, and issues necessary notifications and repaints to this JSVGCanvas.

notifyRepaintedRegion

public void notifyRepaintedRegion(java.awt.Shape oldAoi,
                                  java.awt.Shape newAoi,
                                  Renderer renderer)
Notifies that the specified area of interest need to be repainted. If the current thread is interrupted while repainting this method will return silently.
Specified by:
notifyRepaintedRegion in interface DynamicRenderer.RepaintHandler
Parameters:
oldAoi - the previous area of interest
newAoi - the new area of interest to repaint
renderer - the Renderer instance which does the repainting Note: this function has not yet been modified to allow background rendering into the offscreen buffer, so it will block the AWT event thread.

requestCursor

protected void requestCursor(java.awt.Cursor newCursor)
Sets the value of the requested cursor, but in a thread-safe way. The requested cursor will be set during the next call to paintComponent.

getRequestedCursor

protected java.awt.Cursor getRequestedCursor()
Gets the value of the requested cursor, but in a thread-safe way. The requested cursor will be set during the next call to paintComponent.

createBridgeContext

protected BridgeContext createBridgeContext(SVGDocument doc)
Creates a new bridge context.

getThumbnail

public javax.swing.JComponent getThumbnail()
Returns the thumbnail.

initSelectors

public void initSelectors(GraphicsNode treeRoot)
Associate selectable elements in the current tree with Selector instances.

selectionChanged

public void selectionChanged(SelectionEvent e)
Description copied from interface: SelectionListener
Invoked when a selection has changed
Specified by:
selectionChanged in interface SelectionListener
Following copied from interface: org.apache.batik.gvt.event.SelectionListener
Parameters:
evt - the selection change event
See Also:
Selector, SelectionEvent, Selectable

getAction

public javax.swing.Action getAction(java.lang.String key)
                             throws MissingListenerException
Returns the action associated with the given string or null on error
Specified by:
getAction in interface ActionMap
Parameters:
key - the key mapped with the action to get
Throws:
MissingListenerException - if the action is not found

clearBuffer

protected void clearBuffer(int w,
                           int h)
Clears the offscreen buffer.

clearBuffer

protected void clearBuffer(java.awt.Shape aoi)
Clears the offscreen buffer.

clearBuffer

protected void clearBuffer(java.awt.image.BufferedImage buffer,
                           int w,
                           int h)
Clears a specific buffer.

getAreaOfInterest

protected java.awt.Shape getAreaOfInterest(java.awt.Shape devAOI)
Returns:
the area of interest displayed in the viewer, in usr space.

paintComponent

protected void paintComponent(java.awt.Graphics g)
Paints this component into a graphics context. Note that if the offscreen buffer has been marked for re-rendering, this method will initiate a background rendering thread and cue another repaint. Otherwise, it simply repaints the offscreen buffer and overlays.
Overrides:
paintComponent in class javax.swing.JComponent

paintOverlays

protected void paintOverlays(java.awt.Graphics g)
Paints the canvas "overlay" primitives (rotation box, zoom AOI box, highlight [not yet implemented], etc.

paintPanRegions

protected void paintPanRegions(java.awt.Graphics2D g2d,
                               int tx,
                               int ty,
                               int w,
                               int h)
Repaints the pan blank regions.

updateBuffer

protected void updateBuffer(int w,
                            int h)
Updates the offscreen buffer.
Parameters:
w h - The size of the component.

getBuffer

public java.awt.image.BufferedImage getBuffer()
Returns the current buffer.

computeTransform

protected void computeTransform()
Computes the value of the transform attribute.

updateBaseTransform

protected void updateBaseTransform()
Updates the document bounding box, selection highlight and event dispatcher coordinate system based on the new value of the transform attribute.

getTransform

public java.awt.geom.AffineTransform getTransform()
Returns the current document-to-device space transform.

repaintAOI

protected void repaintAOI(Renderer renderer,
                          java.awt.Dimension size,
                          java.awt.image.BufferedImage buffer)
Initiates the repainting of the offscreen buffer in a background thread.


Copyright © 2000 Apache Software Foundation. All Rights Reserved.