|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--org.apache.batik.swing.gvt.JGVTComponent | +--org.apache.batik.swing.svg.JSVGComponent
This class represents a swing component that can display SVG documents. This component also lets you translate, zoom and rotate the document being displayed. This is the fundamental class for rendering SVG documents in a swing application.
The rendering process can be broken down into three phases. Not all of those steps are required - depending on the method used to specify the SVG document to display, but basically the steps in the rendering process are:
If the loadSVGDocument(String)
method is used,
the SVG file is parsed and an SVG DOM Tree is built.
Once an SVGDocument is created (using the step 1 or if the
setSVGDocument(SVGDocument)
method has been used) - a GVT
tree is constructed. The GVT tree is the data structure used internally to
render an SVG document. see the org.apache.batik.gvt
package.
Then the GVT tree is rendered. see the org.apache.batik.gvt.renderer package.
Those steps are performed in a separate thread. To be notified to what
happens and eventually perform some operations - such as resizing the window
to the size of the document or get the SVGDocument built via a URI, three
different listeners are provided (one per step): SVGDocumentLoaderListener
, GVTTreeBuilderListener
, and
GVTTreeRendererListener
.
The following example shows how you can get the size of an SVG document. Note that due to how SVG is designed (units, percentages...), the size of an SVG document can be known only once the SVGDocument has been analyzed (ie. the GVT tree has been constructed).
final JSVGComponent svgComp = new JSVGComponent(); svgComp.loadSVGDocument("foo.svg"); svgComp.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() { public void gvtBuildCompleted(GVTTreeBuilderEvent evt) { Dimension2D size = svgComp.getSVGDocumentSize(); // ... } });
The second example shows how you can access to the DOM tree when a URI has been used to display an SVG document.
final JSVGComponent svgComp = new JSVGComponent(); svgComp.loadSVGDocument("foo.svg"); svgComp.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() { public void documentLoadingCompleted(SVGDocumentLoaderEvent evt) { SVGDocument svgDoc = svgComp.getSVGDocument(); //... } });
Conformed to the single thread rule of swing, the listeners are executed in the swing thread. The sequence of the method calls for a particular listener and the order of the listeners themselves are guaranteed.
The JSVGComponent can pick up some informations to a user
agent. The SVGUserAgent
provides a way to control the
resolution used to display an SVG document (controling the pixel to
millimeter conversion factor), perform an operation in respond to a click on
an hyperlink, control the default language to use, or specify a user
stylesheet, or how to display errors when an error occured while
building/rendering a document (invalid XML file, missing attributes...).
Inner Class Summary | |
protected class |
JSVGComponent.BridgeUserAgent
To hide the user-agent methods. |
protected class |
JSVGComponent.SVGListener
To hide the listener methods. |
Inner classes inherited from class org.apache.batik.swing.gvt.JGVTComponent |
JGVTComponent.Listener |
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 BridgeContext |
bridgeContext
The current bridge context. |
protected SVGDocumentLoader |
documentLoader
The document loader. |
protected static java.util.Set |
FEATURES
|
protected java.lang.String |
fragmentIdentifier
The current document fragment identifier. |
protected GVTTreeBuilder |
gvtTreeBuilder
The GVT tree builder. |
protected java.util.List |
gvtTreeBuilderListeners
The GVT tree builder listeners. |
protected java.util.List |
linkActivationListeners
The link activation listeners. |
protected DocumentLoader |
loader
The concrete bridge document loader. |
protected SVGDocumentLoader |
nextDocumentLoader
The next document loader to run. |
protected GVTTreeBuilder |
nextGVTTreeBuilder
The next GVT tree builder to run. |
protected SVGDocument |
svgDocument
The current SVG document. |
protected java.util.List |
svgDocumentLoaderListeners
The document loader listeners. |
protected SVGUserAgent |
svgUserAgent
The SVG user agent. |
protected UserAgent |
userAgent
The user agent. |
Fields inherited from class org.apache.batik.swing.gvt.JGVTComponent |
disableInteractions, doubleBufferedRendering, eventDispatcher, eventsEnabled, gvtRoot, gvtTreeRenderer, gvtTreeRendererListeners, image, initialTransform, interactor, interactors, listener, needRender, overlays, paintingTransform, progressivePaint, progressivePaintThread, renderer, rendererFactory, renderingTransform, selectableText, suspendInteractions, textSelectionManager |
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 | |
JSVGComponent()
Creates a new JSVGComponent. |
|
JSVGComponent(SVGUserAgent ua,
boolean eventsEnabled,
boolean selectableText)
Creates a new JSVGComponent. |
Method Summary | |
void |
addGVTTreeBuilderListener(GVTTreeBuilderListener l)
Adds a GVTTreeBuilderListener to this component. |
void |
addLinkActivationListener(LinkActivationListener l)
Adds a LinkActivationListener to this component. |
void |
addSVGDocumentLoaderListener(SVGDocumentLoaderListener l)
Adds a SVGDocumentLoaderListener to this component. |
protected void |
computeRenderingTransform()
Computes the transform used for rendering. |
protected BridgeContext |
createBridgeContext()
Creates a new bridge context. |
protected JGVTComponent.Listener |
createListener()
Creates an instance of Listener. |
protected UserAgent |
createUserAgent()
Creates a UserAgent. |
java.lang.String |
getFragmentIdentifier()
Returns the current's document fragment identifier. |
SVGDocument |
getSVGDocument()
Returns the current SVG document. |
java.awt.geom.Dimension2D |
getSVGDocumentSize()
Returns the size of the SVG document. |
protected void |
handleException(java.lang.Exception e)
Handles an exception. |
void |
loadSVGDocument(java.lang.String url)
Loads a SVG document from the given URL. |
void |
removeGVTTreeBuilderListener(GVTTreeBuilderListener l)
Removes a GVTTreeBuilderListener from this component. |
void |
removeLinkActivationListener(LinkActivationListener l)
Removes a LinkActivationListener from this component. |
void |
removeSVGDocumentLoaderListener(SVGDocumentLoaderListener l)
Removes a SVGDocumentLoaderListener from this component. |
void |
setFragmentIdentifier(java.lang.String fi)
Sets the current fragment identifier. |
void |
setSVGDocument(SVGDocument doc)
Sets the SVG document to display. |
void |
stopProcessing()
Stops the processing of the current document. |
protected void |
updateRenderingTransform()
Updates the value of the transform used for rendering. |
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 |
protected SVGDocumentLoader documentLoader
protected SVGDocumentLoader nextDocumentLoader
protected DocumentLoader loader
protected GVTTreeBuilder gvtTreeBuilder
protected GVTTreeBuilder nextGVTTreeBuilder
protected SVGDocument svgDocument
protected java.util.List svgDocumentLoaderListeners
protected java.util.List gvtTreeBuilderListeners
protected java.util.List linkActivationListeners
protected UserAgent userAgent
protected SVGUserAgent svgUserAgent
protected BridgeContext bridgeContext
protected java.lang.String fragmentIdentifier
protected static final java.util.Set FEATURES
Constructor Detail |
public JSVGComponent()
public JSVGComponent(SVGUserAgent ua, boolean eventsEnabled, boolean selectableText)
ua
- a SVGUserAgent instance or null.eventEnabled
- Whether the GVT tree should be reactive
to mouse and key events.selectableText
- Whether the text should be selectable.Method Detail |
public void stopProcessing()
stopProcessing
in class JGVTComponent
public void loadSVGDocument(java.lang.String url)
public void setSVGDocument(SVGDocument doc)
public SVGDocument getSVGDocument()
public java.awt.geom.Dimension2D getSVGDocumentSize()
public java.lang.String getFragmentIdentifier()
public void setFragmentIdentifier(java.lang.String fi)
protected BridgeContext createBridgeContext()
protected void computeRenderingTransform()
computeRenderingTransform
in class JGVTComponent
protected void updateRenderingTransform()
updateRenderingTransform
in class JGVTComponent
protected void handleException(java.lang.Exception e)
handleException
in class JGVTComponent
public void addSVGDocumentLoaderListener(SVGDocumentLoaderListener l)
public void removeSVGDocumentLoaderListener(SVGDocumentLoaderListener l)
public void addGVTTreeBuilderListener(GVTTreeBuilderListener l)
public void removeGVTTreeBuilderListener(GVTTreeBuilderListener l)
public void addLinkActivationListener(LinkActivationListener l)
public void removeLinkActivationListener(LinkActivationListener l)
protected JGVTComponent.Listener createListener()
createListener
in class JGVTComponent
protected UserAgent createUserAgent()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |