yext.svg.io
Class SVGDOMEnhancer

java.lang.Object
  extended by y.view.DefaultGraph2DRenderer
      extended by yext.svg.io.SVGGraph2DRenderer
          extended by yext.svg.io.SVGDOMEnhancer
All Implemented Interfaces:
Graph2DRenderer, OrderRenderer

public class SVGDOMEnhancer
extends SVGGraph2DRenderer

A SVGGraph2DRenderer that allows to enhance the svg document while it gets generated by SVGIOHandler.

This renderer adds named group elements <g> around the SVG definition of each node and edge in the graph.

Additionally this renderer provides callback methods that will be invoked whenever a node label, a node, an edge, an edge label or a graph has been added to the document. Subclasses can override these methods to add to or modify the generated DOM structure.

As an example, one can hyperlink all graph nodes in the SVG document by overwriting method nodeAddedToDOM(y.base.Node yNode, org.w3c.dom.Element element) in the following way:

   protected void nodeAddedToDOM(y.base.Node yNode, org.w3c.dom.Element element) {
      org.w3c.dom.Element a = createElement("a");
      a.setAttribute("xlink:href", "http://www.yworks.com"); 
      insertNodeBelow(a, element);
   }
 

 

Field Summary
static byte LABEL_DETECTION_BY_RECONFIGURING
          Label detection strategy specifier.
static byte LABEL_DETECTION_BY_SEPARATE_RENDERING
          Label detection strategy specifier.
static byte LABEL_DETECTION_BY_TEXT_SEARCH
          Label detection strategy specifier.
static byte LABEL_DETECTION_BY_WRAPPING
          Label detection strategy specifier.
static byte LABEL_DETECTION_NONE
          Label detection strategy specifier.
 
Constructor Summary
SVGDOMEnhancer()
          Creates a new instance of SVGDOMEnhancer
 
Method Summary
protected  String createGroupID(Edge edge)
          Returns the group identifier assigned to the group element encapsulating the given edge in the SVG document.
protected  String createGroupID(Node node)
          Returns the group identifier assigned to the group element encapsulating the given node in the SVG document.
protected  void edgeAddedToDOM(Edge yEdge, Element element)
          Callback method that will be invoked whenever the given edge has been added to the SVG document.
protected  void edgeLabelAddedToDOM(EdgeLabel yEdgeLabel, Element element)
          Callback method that will be invoked whenever the given edge label has been added to the SVG document.
 byte getLabelDetectionStrategy()
          Returns the detection strategy used for DOM elements that enclose node and edge label graphics.
protected  void initializeDOM()
          Callback method that will be invoked just before the graph will be added to the SVG document.
protected  void nodeAddedToDOM(Node yNode, Element element)
          Callback method that will be invoked whenever the given node has been added to the SVG document.
protected  void nodeLabelAddedToDOM(NodeLabel yNodeLabel, Element element)
          Callback method that will be invoked whenever the given node label has been added to the SVG document.
protected  void onPaint(Graphics2D gfx, Graph2D graph, boolean sloppy)
          Notifies interested parties that the given graph is about to be painted.
protected  void onPainted(Graphics2D gfx, Graph2D graph, boolean sloppy)
          Notifies interested parties that the given graph has been painted.
 void paint(Graphics2D gfx, EdgeRealizer r)
           
protected  void paint(Graphics2D gfx, EdgeRealizer r, boolean sloppyMode)
          Renders the given edge realizer on the given graphics context.
 void paint(Graphics2D gfx, Graph2D graph)
          Renders the graph on the given graphics context.
 void paint(Graphics2D gfx, NodeRealizer r)
           
protected  void paint(Graphics2D gfx, NodeRealizer r, boolean sloppyMode)
          Renders the given node realizer on the given graphics context.
 void paintSloppy(Graphics2D gfx, EdgeRealizer r)
           
 void paintSloppy(Graphics2D gfx, Graph2D graph)
          Renders the graph sloppily on the given graphics context.
 void paintSloppy(Graphics2D gfx, NodeRealizer r)
           
 void setLabelDetectionStrategy(byte labelDetectionStrategy)
          Sets the detection strategy used for DOM elements that enclose node label and edge label graphics.
 
Methods inherited from class yext.svg.io.SVGGraph2DRenderer
addToSVGDefinition, createCDATASection, createElement, getSVGDocument, getSVGIOHandler, getTopLevelGroup, insertNodeAbove, insertNodeBelow, setSVGIOHandler, setTopLevelGroup, writeDocument
 
Methods inherited from class y.view.DefaultGraph2DRenderer
beginLayerPainting, endLayerPainting, getBridgeCalculator, getBridgeCalculator, getClipEnlargementValue, getDrawEdgesFirst, getEdgeLock, getGlobalLock, getLayer, getLayer, getNodeLock, getPaintOrder, getSloppyPaintOrder, intersects, intersects, isDrawSelectionOnTop, isHierarchicSloppyPaintOrderEnabled, isLayeredPainting, isNestedEdgeDrawingOrderEnabled, isSloppyNestedEdgeDrawingOrderEnabled, isSynchronizationEnabled, paintLayered, paintLayered, paintSloppyLayered, paintSloppyLayered, prepareBridgeCalculator, setBridgeCalculator, setClipEnlargementValue, setDrawEdgesFirst, setDrawSelectionOnTop, setGlobalLock, setHierarchicSloppyPaintOrderEnabled, setLayeredPainting, setNestedEdgeDrawingOrderEnabled, setSloppyNestedEdgeDrawingOrderEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LABEL_DETECTION_NONE

public static final byte LABEL_DETECTION_NONE
Label detection strategy specifier. No label detection will be done at all.

See Also:
Constant Field Values

LABEL_DETECTION_BY_TEXT_SEARCH

public static final byte LABEL_DETECTION_BY_TEXT_SEARCH
Label detection strategy specifier. Labels will be identified by <text> elements within the SVG representation of a node or edge. This strategy does not work if the label does not contain any text.

See Also:
Constant Field Values

LABEL_DETECTION_BY_SEPARATE_RENDERING

public static final byte LABEL_DETECTION_BY_SEPARATE_RENDERING
Label detection strategy specifier. Labels will be identified by rendering labels in a separate rendering pass. This way all XML elements that were generated during the rendition of a label will be enclosed by the DOM element passed to #nodeLabelAddedToDOM(y.view.NodeLabel, org.w3c.dom.Element) or #edgeLabelAddedToDOM(y.view.EdgeLabel, org.w3c.dom.Element).

See Also:
Constant Field Values

LABEL_DETECTION_BY_WRAPPING

public static final byte LABEL_DETECTION_BY_WRAPPING
Label detection strategy specifier. Labels will be temporarily wrapped in an internal implementation that handles DOM enhancement upon calls to YLabel.paint(java.awt.Graphics2D).

See Also:
Constant Field Values

LABEL_DETECTION_BY_RECONFIGURING

public static final byte LABEL_DETECTION_BY_RECONFIGURING
Label detection strategy specifier. Label configurations will be temporarily replaced with in an internal implementation that handles DOM enhancement upon calls to YLabel.paint(java.awt.Graphics2D).

See Also:
Constant Field Values
Constructor Detail

SVGDOMEnhancer

public SVGDOMEnhancer()
Creates a new instance of SVGDOMEnhancer

Method Detail

paint

public void paint(Graphics2D gfx,
                  Graph2D graph)
Renders the graph on the given graphics context.

Before the rendering process starts, method onPaint(Graphics2D, Graph2D, boolean) is invoked. After the rendering process has finished, onPainted(Graphics2D, Graph2D, boolean) is invoked.

Specified by:
paint in interface Graph2DRenderer
Overrides:
paint in class DefaultGraph2DRenderer

paintSloppy

public void paintSloppy(Graphics2D gfx,
                        Graph2D graph)
Renders the graph sloppily on the given graphics context.

Before the rendering process starts, method onPaint(Graphics2D, Graph2D, boolean) is invoked. After the rendering process has finished, onPainted(Graphics2D, Graph2D, boolean) is invoked.

Specified by:
paintSloppy in interface Graph2DRenderer
Overrides:
paintSloppy in class DefaultGraph2DRenderer

onPaint

protected void onPaint(Graphics2D gfx,
                       Graph2D graph,
                       boolean sloppy)
Notifies interested parties that the given graph is about to be painted.

The default implementation calls initializeDOM().

Called from paint(Graphics2D, Graph2D) and paintSloppy(Graphics2D, Graph2D).

Parameters:
gfx - the graphics context to paint on.
graph - the graph structure that will be painted.
sloppy - if true low-detail rendering was requested, otherwise high-detail rendering was requested.

onPainted

protected void onPainted(Graphics2D gfx,
                         Graph2D graph,
                         boolean sloppy)
Notifies interested parties that the given graph has been painted.

The default implementation does nothing.

Called from paint(Graphics2D, Graph2D) and paintSloppy(Graphics2D, Graph2D).

Parameters:
gfx - the graphics context on which the graph was painted.
graph - the graph structure that was painted.
sloppy - if true low-detail rendering was requested, otherwise high-detail rendering was requested.

paint

public void paint(Graphics2D gfx,
                  NodeRealizer r)
Overrides:
paint in class SVGGraph2DRenderer

paintSloppy

public void paintSloppy(Graphics2D gfx,
                        NodeRealizer r)
Overrides:
paintSloppy in class SVGGraph2DRenderer

paint

public void paint(Graphics2D gfx,
                  EdgeRealizer r)
Overrides:
paint in class SVGGraph2DRenderer

paintSloppy

public void paintSloppy(Graphics2D gfx,
                        EdgeRealizer r)
Overrides:
paintSloppy in class SVGGraph2DRenderer

paint

protected void paint(Graphics2D gfx,
                     NodeRealizer r,
                     boolean sloppyMode)
Renders the given node realizer on the given graphics context. After the rendering process is completed the callback method nodeAddedToDOM(y.base.Node, org.w3c.dom.Element) will be invoked. Also, the method nodeLabelAddedToDOM(NodeLabel, org.w3c.dom.Element) will be invoked for each node label that has been added to the SVG document.


paint

protected void paint(Graphics2D gfx,
                     EdgeRealizer r,
                     boolean sloppyMode)
Renders the given edge realizer on the given graphics context. After the rendering process is completed the callback method edgeAddedToDOM(Edge, org.w3c.dom.Element) will be invoked. Also, the method edgeLabelAddedToDOM(EdgeLabel, org.w3c.dom.Element) will be invoked for each edge label that has been added to the SVG document.


nodeAddedToDOM

protected void nodeAddedToDOM(Node yNode,
                              Element element)
Callback method that will be invoked whenever the given node has been added to the SVG document. The given DOM element is a named group element that encapsulates the SVG definition of the graph node.


nodeLabelAddedToDOM

protected void nodeLabelAddedToDOM(NodeLabel yNodeLabel,
                                   Element element)
Callback method that will be invoked whenever the given node label has been added to the SVG document. The given DOM element is a text element that represents the label in the SVG definition.


edgeAddedToDOM

protected void edgeAddedToDOM(Edge yEdge,
                              Element element)
Callback method that will be invoked whenever the given edge has been added to the SVG document. The given DOM element is a named group element that encapsulates the SVG definition of the graph edge.


edgeLabelAddedToDOM

protected void edgeLabelAddedToDOM(EdgeLabel yEdgeLabel,
                                   Element element)
Callback method that will be invoked whenever the given edge label has been added to the SVG document. The given DOM element is a text element that represents the label in the SVG definition.


initializeDOM

protected void initializeDOM()
Callback method that will be invoked just before the graph will be added to the SVG document. Overriding method gives implementors the chance to add global definitions to the SVG document.


createGroupID

protected String createGroupID(Node node)
Returns the group identifier assigned to the group element encapsulating the given node in the SVG document.

By default the identifier "y.node." + node.index() will be returned.


createGroupID

protected String createGroupID(Edge edge)
Returns the group identifier assigned to the group element encapsulating the given edge in the SVG document.

By default the identifier "y.edge." + edge.index() will be returned.


getLabelDetectionStrategy

public byte getLabelDetectionStrategy()
Returns the detection strategy used for DOM elements that enclose node and edge label graphics.

By default, strategy LABEL_DETECTION_BY_RECONFIGURING is set.

Returns:
the symbolic specifier representing the current label detection strategy.
See Also:
setLabelDetectionStrategy(byte)

setLabelDetectionStrategy

public void setLabelDetectionStrategy(byte labelDetectionStrategy)
Sets the detection strategy used for DOM elements that enclose node label and edge label graphics.

By default, strategy LABEL_DETECTION_BY_RECONFIGURING is set.

Parameters:
labelDetectionStrategy - one of
See Also:
getLabelDetectionStrategy()


© Copyright 2002-2015,
yWorks GmbH.
All rights reserved.