Search this API

y.view
Class DefaultGraph2DRenderer

java.lang.Object
  extended by y.view.DefaultGraph2DRenderer
All Implemented Interfaces:
Graph2DRenderer, OrderRenderer

public class DefaultGraph2DRenderer
extends java.lang.Object
implements OrderRenderer

Default Graph2DRenderer implementation. This class renders a Graph2D by invoking the paint method for the associated NodeRealizer and EdgeRealizer objects. This renderer is aware of nested graph hierarchies. It will first render a group node, then all of its children. To be more specific, the rendering order of nodes is determined by the HierarchyManager.preTraverse(y.view.hierarchy.HierarchyManager.NodeVisitor) method. Optionally the rendering order can be controlled via the setDrawEdgesFirst(boolean), the setLayeredPainting(boolean), and setNestedEdgeDrawingOrderEnabled(boolean) properties.

 

Constructor Summary
DefaultGraph2DRenderer()
           
 
Method Summary
protected  void beginLayerPainting(java.awt.Graphics2D gfx, int layer, boolean sloppy)
          Callback that is called before the given layer is painted.
protected  void endLayerPainting(java.awt.Graphics2D gfx, int layer, boolean sloppy)
          Callback that is called after the given layer has been painted.
 BridgeCalculator getBridgeCalculator()
          Returns the currently installed BridgeCalculator instance or null if no such instance is installed.
static BridgeCalculator getBridgeCalculator(EdgeRealizer er, java.awt.Graphics2D gfx)
          Determines and returns the currently used BridgeCalculator instance for the given EdgeRealizer and Graphics context.
 int getClipEnlargementValue()
          Returns the clip enlargement value.
 boolean getDrawEdgesFirst()
          Returns the drawing order of edges and nodes.
protected  java.lang.Object getEdgeLock(Edge edge)
          Returns the lock to synchronize intersects and paint calls on for the given edge.
 java.lang.Object getGlobalLock()
          Returns the global synchronization lock that should be used to synchronize all intersects and paint calls on.
protected  int getLayer(Graph2D graph, Edge edge)
          Callback method that determines the layer index for a given edge.
protected  int getLayer(Graph2D graph, Node n)
          Callback method that determines the layer index for a given node.
protected  java.lang.Object getNodeLock(Node node)
          Returns the lock to synchronize intersects and paint calls on for the given node.
 Graph2DTraversal getPaintOrder()
          Returns a Graph2DTraversal that implies the rendering order used by this DefaultGraph2DRenderer.
 Graph2DTraversal getSloppyPaintOrder()
          Returns a Graph2DTraversal that implies the sloppy rendering order used by this DefaultGraph2DRenderer.
protected  boolean intersects(EdgeRealizer er, java.awt.geom.Rectangle2D region)
          Checks if the given region overlaps with the edge.
protected  boolean intersects(NodeRealizer nr, java.awt.geom.Rectangle2D region)
          Checks if the given region overlaps with the node.
 boolean isDrawSelectionOnTop()
           
 boolean isHierarchicSloppyPaintOrderEnabled()
          Returns whether or not to paint nodes in the correct hierarchic order when in sloppy mode.
 boolean isLayeredPainting()
          Determines whether layers should be used to influence the painting order.
 boolean isNestedEdgeDrawingOrderEnabled()
          Returns whether or not edges and nodes are so that edges nested in other group nodes will be drawn in such an order that overlapping group nodes will not produce "unconnected edge" artifacts and edges will not be hidden by their encompassing group nodes.
 boolean isSloppyNestedEdgeDrawingOrderEnabled()
          Determines the mode for the sloppy drawing order of edges and nodes.
protected  boolean isSynchronizationEnabled()
          Determines whether or not intersects and paint calls should be synchronized.
protected  void paint(java.awt.Graphics2D gfx, EdgeRealizer er)
          Paints the given edge realizer on the graphics context.
 void paint(java.awt.Graphics2D gfx, Graph2D graph)
          Renders the given graph2D on the given Graphics2D context.
protected  void paint(java.awt.Graphics2D gfx, NodeRealizer nr)
          Paints the given node realizer on the graphics context.
protected  void paintLayered(java.awt.Graphics2D gfx, int layer, EdgeRealizer edgeRealizer)
          Callback that is called during a layered painting of an EdgeRealizer.
protected  void paintLayered(java.awt.Graphics2D gfx, int layer, NodeRealizer nodeRealizer)
          Callback that is called during a layered painting of a NodeRealizer.
protected  void paintSloppy(java.awt.Graphics2D gfx, EdgeRealizer er)
          Paints the given edge realizer sloppily on the graphics context.
 void paintSloppy(java.awt.Graphics2D gfx, Graph2D graph)
          Renders the given Graph2D on the given Graphics2D context.
protected  void paintSloppy(java.awt.Graphics2D gfx, NodeRealizer nr)
          Paints the given node realizer sloppily on the graphics context.
protected  void paintSloppyLayered(java.awt.Graphics2D gfx, int layer, EdgeRealizer edgeRealizer)
          Callback that is called during a sloppy layered painting of an EdgeRealizer.
protected  void paintSloppyLayered(java.awt.Graphics2D gfx, int layer, NodeRealizer nodeRealizer)
          Callback that is called during a sloppy layered painting of a NodeRealizer.
protected  void prepareBridgeCalculator(BridgeCalculator bridgeCalculator, Graph2D graph, java.awt.geom.Rectangle2D clip)
          Configures the BridgeCalculator instance appropriately by setting the right scope and resetting the instance on startup.
 void setBridgeCalculator(BridgeCalculator bridgeCalculator)
          Sets a BridgeCalculator instance or null if no such instance is installed.
 void setClipEnlargementValue(int enlargement)
          Sets the clip enlargement value.
 void setDrawEdgesFirst(boolean edgesFirst)
          Sets the drawing order of edges and nodes.
 void setDrawSelectionOnTop(boolean drawSelectionOnTop)
          Sets whether the selection and elements depending on the selection are drawn on top.
 void setGlobalLock(java.lang.Object lock)
          Specifies the global synchronization lock that should be used to synchronize all intersects and paint calls on.
 void setHierarchicSloppyPaintOrderEnabled(boolean enabled)
          Whether or not to paint nodes in the correct hierarchic order when when in sloppy mode.
 void setLayeredPainting(boolean layeredPainting)
          Determines whether layers should be used to influence the painting order.
 void setNestedEdgeDrawingOrderEnabled(boolean nestedEdgeDrawing)
          Influences the drawing order of edges and nodes.
 void setSloppyNestedEdgeDrawingOrderEnabled(boolean enabled)
          Influences the sloppy drawing order of edges and nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultGraph2DRenderer

public DefaultGraph2DRenderer()
Method Detail

getPaintOrder

public Graph2DTraversal getPaintOrder()
Returns a Graph2DTraversal that implies the rendering order used by this DefaultGraph2DRenderer.

Note that the values of this DefaultGraph2DRenderer's layeredPainting, nestedEdgeDrawingOrderEnabled, and drawEdgesFirst properties determine the order of elements in the returned traversal's iterators.

Specified by:
getPaintOrder in interface OrderRenderer
Returns:
a Graph2DTraversal that implies the rendering order used by this DefaultGraph2DRenderer.

getSloppyPaintOrder

public Graph2DTraversal getSloppyPaintOrder()
Returns a Graph2DTraversal that implies the sloppy rendering order used by this DefaultGraph2DRenderer.

Note that the values of this DefaultGraph2DRenderer's layeredPainting, nestedEdgeDrawingOrderEnabled, drawEdgesFirst, and hierarchicSloppyPaintOrderEnabled properties determine the order of elements in the returned traversal's iterators.

Specified by:
getSloppyPaintOrder in interface OrderRenderer
Returns:
a Graph2DTraversal that implies the sloppy rendering order used by this DefaultGraph2DRenderer.

isLayeredPainting

public boolean isLayeredPainting()
Determines whether layers should be used to influence the painting order. The default is false.

Returns:
whether to use layers for painting.

setLayeredPainting

public void setLayeredPainting(boolean layeredPainting)
Determines whether layers should be used to influence the painting order. The default is false. If set to true for each rendered element the getLayer(y.view.Graph2D, y.base.Edge) and getLayer(y.view.Graph2D, y.base.Node) methods respectively will be queried to determine the layer and then they will be rendered layer by layer so that the elements with the lowest layer index will be rendered first. Eventually this will result in calls to paintLayered(java.awt.Graphics2D, int, y.view.NodeRealizer), paintLayered(java.awt.Graphics2D, int, y.view.EdgeRealizer) and their sloppy variants.

Parameters:
layeredPainting - whether to use layer information for the rendering order.

setNestedEdgeDrawingOrderEnabled

public void setNestedEdgeDrawingOrderEnabled(boolean nestedEdgeDrawing)
Influences the drawing order of edges and nodes. This setting only affects the drawing of hierarchically nested graphs. If the given argument is true then Group nodes will always be drawn in the correct hierarchical order but the drawing of edges and nodes is interleaved. This means that depending on the drawEdgesFirst property edges will always be drawn in front of group nodes if their end points belong to the respective group node. However one can still decide whether nodes from the same nesting level should be painted over or under those edges. If the given argument is false then the other settings take effect.

By default this is set to false, i.e. the other settings determine the behavior.

See Also:
setDrawEdgesFirst(boolean), setHierarchicSloppyPaintOrderEnabled(boolean)

isNestedEdgeDrawingOrderEnabled

public boolean isNestedEdgeDrawingOrderEnabled()
Returns whether or not edges and nodes are so that edges nested in other group nodes will be drawn in such an order that overlapping group nodes will not produce "unconnected edge" artifacts and edges will not be hidden by their encompassing group nodes. This setting can only be used for hierarchically nested graphs.

See Also:
setNestedEdgeDrawingOrderEnabled(boolean)

getBridgeCalculator

public BridgeCalculator getBridgeCalculator()
Returns the currently installed BridgeCalculator instance or null if no such instance is installed. By default no instance is configured for a DefaultGraph2DRenderer instance.

Returns:
the current BridgeCalculator instance
See Also:
prepareBridgeCalculator(y.view.BridgeCalculator, y.view.Graph2D, java.awt.geom.Rectangle2D)

setBridgeCalculator

public void setBridgeCalculator(BridgeCalculator bridgeCalculator)
Sets a BridgeCalculator instance or null if no such instance is installed. By default no instance is configured for a DefaultGraph2DRenderer instance. EdgeRealizer implementations interested in this instance can use the getBridgeCalculator(y.view.EdgeRealizer, java.awt.Graphics2D) instance to query the current instance.

Parameters:
bridgeCalculator - the new BridgeCalculator instance to use.
See Also:
prepareBridgeCalculator(y.view.BridgeCalculator, y.view.Graph2D, java.awt.geom.Rectangle2D)

setDrawEdgesFirst

public void setDrawEdgesFirst(boolean edgesFirst)
Sets the drawing order of edges and nodes. If the given argument is true then edges will be drawn prior to nodes. The effect of this setting is that nodes will be drawn atop of all drawn edges. If the given argument is false then nodes will drawn be prior to edges. The effect of that setting is that nodes will be drawn beneath all drawn edges.

By default nodes will be drawn first, then edges.


getDrawEdgesFirst

public boolean getDrawEdgesFirst()
Returns the drawing order of edges and nodes.

See Also:
setDrawEdgesFirst(boolean)

setDrawSelectionOnTop

public void setDrawSelectionOnTop(boolean drawSelectionOnTop)
Sets whether the selection and elements depending on the selection are drawn on top.

Parameters:
drawSelectionOnTop - whether the selection is drawn on top

isDrawSelectionOnTop

public boolean isDrawSelectionOnTop()
Returns:
whether the selection and elements depending on the selection are drawn on top.

setClipEnlargementValue

public void setClipEnlargementValue(int enlargement)
Sets the clip enlargement value. Before a graph object gets rendered by this class, it will be tested if it intersects the clip bounds. This test relies upon the results of the node and edge realizer intersection methods. If these intersection methods are not accurate enough, repaint errors can be the result. Increasing the clip enlargement value for this class can prevent such errors, by clipping objects more defensively.

By default this value is set to 10.


getClipEnlargementValue

public int getClipEnlargementValue()
Returns the clip enlargement value.

See Also:
setClipEnlargementValue(int)

setHierarchicSloppyPaintOrderEnabled

public void setHierarchicSloppyPaintOrderEnabled(boolean enabled)
Whether or not to paint nodes in the correct hierarchic order when when in sloppy mode. By default this feature is enabled.


isHierarchicSloppyPaintOrderEnabled

public boolean isHierarchicSloppyPaintOrderEnabled()
Returns whether or not to paint nodes in the correct hierarchic order when in sloppy mode.

See Also:
setHierarchicSloppyPaintOrderEnabled(boolean)

paint

public void paint(java.awt.Graphics2D gfx,
                  Graph2D graph)
Renders the given graph2D on the given Graphics2D context. Rendering is performed by calling the paint() method of each Node- and EdgeRealizer associated with the nodes and edges of the graph.

Specified by:
paint in interface Graph2DRenderer

beginLayerPainting

protected void beginLayerPainting(java.awt.Graphics2D gfx,
                                  int layer,
                                  boolean sloppy)
Callback that is called before the given layer is painted. This implementation does nothing.

Parameters:
gfx - the graphics to paint on
layer - the layer that will be painted.
sloppy - whether to do sloppy painting
See Also:
setLayeredPainting(boolean)

endLayerPainting

protected void endLayerPainting(java.awt.Graphics2D gfx,
                                int layer,
                                boolean sloppy)
Callback that is called after the given layer has been painted. This implementation does nothing.

Parameters:
gfx - the graphics to paint on
layer - the layer that has been painted.
sloppy - whether to do sloppy painting
See Also:
setLayeredPainting(boolean)

paintLayered

protected void paintLayered(java.awt.Graphics2D gfx,
                            int layer,
                            NodeRealizer nodeRealizer)
Callback that is called during a layered painting of a NodeRealizer. This implementation simply delegates to paint(java.awt.Graphics2D, y.view.NodeRealizer)

Parameters:
gfx - the graphics to use
layer - the layer index to paint on
nodeRealizer - the node realizer to paint

paintLayered

protected void paintLayered(java.awt.Graphics2D gfx,
                            int layer,
                            EdgeRealizer edgeRealizer)
Callback that is called during a layered painting of an EdgeRealizer. This implementation simply delegates to paint(java.awt.Graphics2D, y.view.EdgeRealizer)

Parameters:
gfx - the graphics to use
layer - the layer index to paint on
edgeRealizer - the edge realizer to paint

paintSloppyLayered

protected void paintSloppyLayered(java.awt.Graphics2D gfx,
                                  int layer,
                                  NodeRealizer nodeRealizer)
Callback that is called during a sloppy layered painting of a NodeRealizer. This implementation simply delegates to paintSloppy(java.awt.Graphics2D, y.view.NodeRealizer)

Parameters:
gfx - the graphics to use
layer - the layer index to paint on
nodeRealizer - the node realizer to paint

paintSloppyLayered

protected void paintSloppyLayered(java.awt.Graphics2D gfx,
                                  int layer,
                                  EdgeRealizer edgeRealizer)
Callback that is called during a sloppy layered painting of an EdgeRealizer. This implementation simply delegates to paintSloppy(java.awt.Graphics2D, y.view.EdgeRealizer)

Parameters:
gfx - the graphics to use
layer - the layer index to paint on
edgeRealizer - the edge realizer to paint

getLayer

protected int getLayer(Graph2D graph,
                       Edge edge)
Callback method that determines the layer index for a given edge. This implementation returns the maximum of the result of a get layer call for both adjacent nodes.

Parameters:
graph - the graph that contains the edge
edge - the edge to determine the layer index for
Returns:
the zero-based layer index

getLayer

protected int getLayer(Graph2D graph,
                       Node n)
Callback method that determines the layer index for a given node. This implementation yields the hierarchical depth of the node in the hierarchy or 0.

Parameters:
graph - the graph that contains the edge
n - the node to determine the layer index for
Returns:
the zero-based layer index

prepareBridgeCalculator

protected void prepareBridgeCalculator(BridgeCalculator bridgeCalculator,
                                       Graph2D graph,
                                       java.awt.geom.Rectangle2D clip)
Configures the BridgeCalculator instance appropriately by setting the right scope and resetting the instance on startup. If the mode of the calculator is set to values other than BridgeCalculator.CROSSING_MODE_ORDER_INDUCED This method will invoke for each EdgeRealizer EdgeRealizer.registerObstacles(y.view.BridgeCalculator).

Parameters:
bridgeCalculator - the instance to prepare for the upcoming rendering to gfx
graph - the graph that will be rendered in the following pass
clip - the clip that will be used for the upcoming rendering

getBridgeCalculator

public static BridgeCalculator getBridgeCalculator(EdgeRealizer er,
                                                   java.awt.Graphics2D gfx)
Determines and returns the currently used BridgeCalculator instance for the given EdgeRealizer and Graphics context.

Parameters:
er - the EdgeRealizer which is interested in the BridgeCalculator
gfx - the gfx context that will be used to render the edge
Returns:
the appropriate BridgeCalculator or null
See Also:
setBridgeCalculator(y.view.BridgeCalculator), getBridgeCalculator()

setSloppyNestedEdgeDrawingOrderEnabled

public void setSloppyNestedEdgeDrawingOrderEnabled(boolean enabled)
Influences the sloppy drawing order of edges and nodes. This setting only affects the drawing of hierarchically nested graphs. If the given argument is true then Group nodes will always be drawn in the correct hierarchical order but the drawing of edges and nodes is interleaved. This means that depending on the drawEdgesFirst property edges will always be drawn in front of group nodes if their end points belong to the respective group node. However one can still decide whether nodes from the same nesting level should be painted over or under those edges. If the given argument is false then the other settings take effect.

By default this is set to false, i.e. the other settings determine the behavior.

See Also:
setDrawEdgesFirst(boolean), setHierarchicSloppyPaintOrderEnabled(boolean), isSloppyNestedEdgeDrawingOrderEnabled(), setNestedEdgeDrawingOrderEnabled(boolean)

isSloppyNestedEdgeDrawingOrderEnabled

public boolean isSloppyNestedEdgeDrawingOrderEnabled()
Determines the mode for the sloppy drawing order of edges and nodes. This setting only affects the drawing of hierarchically nested graphs. If this is set to true then Group nodes will always be drawn in the correct hierarchical order but the drawing of edges and nodes is interleaved. This means that depending on the drawEdgesFirst property edges will always be drawn in front of group nodes if their end points belong to the respective group node. However one can still decide whether nodes from the same nesting level should be painted over or under those edges. If the value is false then the other settings take effect.

By default this is set to false, i.e. the other settings determine the behavior.

See Also:
setDrawEdgesFirst(boolean), setHierarchicSloppyPaintOrderEnabled(boolean), setNestedEdgeDrawingOrderEnabled(boolean)

intersects

protected boolean intersects(NodeRealizer nr,
                             java.awt.geom.Rectangle2D region)
Checks if the given region overlaps with the node. This method may be overwritten to adjust the intersection detection.

By default it is tested if the node's bounding box including labels and node ports overlaps with the region.

Parameters:
nr - the realizer of the node
region - the rectangular region to be tested
Returns:
true if the node intersects with the region, false otherwise.

intersects

protected boolean intersects(EdgeRealizer er,
                             java.awt.geom.Rectangle2D region)
Checks if the given region overlaps with the edge. This method may be overwritten to adjust the intersection detection.

By default it is tested if some bends or end points of the edge lie within the region, labels are ignored.

Parameters:
er - the realizer of the edge
region - the rectangular region to be tested
Returns:
true if the edge crosses the region, false otherwise.

paintSloppy

public void paintSloppy(java.awt.Graphics2D gfx,
                        Graph2D graph)
Renders the given Graph2D on the given Graphics2D context. the rendering process should be quick and can be sloppy.

Rendering is performed by calling the paintSloppy() method of each Node- and EdgeRealizer associated with the nodes and edges of the graph.

Specified by:
paintSloppy in interface Graph2DRenderer

paint

protected void paint(java.awt.Graphics2D gfx,
                     NodeRealizer nr)
Paints the given node realizer on the graphics context.


paint

protected void paint(java.awt.Graphics2D gfx,
                     EdgeRealizer er)
Paints the given edge realizer on the graphics context.


paintSloppy

protected void paintSloppy(java.awt.Graphics2D gfx,
                           NodeRealizer nr)
Paints the given node realizer sloppily on the graphics context.


paintSloppy

protected void paintSloppy(java.awt.Graphics2D gfx,
                           EdgeRealizer er)
Paints the given edge realizer sloppily on the graphics context.


getGlobalLock

public java.lang.Object getGlobalLock()
Returns the global synchronization lock that should be used to synchronize all intersects and paint calls on.

By default, this lock will be null and intersection calculation and painting will not be synchronized.

See Also:
setGlobalLock(Object), isSynchronizationEnabled(), getNodeLock(y.base.Node), getEdgeLock(y.base.Edge)

setGlobalLock

public void setGlobalLock(java.lang.Object lock)
Specifies the global synchronization lock that should be used to synchronize all intersects and paint calls on.

By default, this lock will be null and intersection calculation and painting will not be synchronized.

Parameters:
lock - the object instance to synchronize all intersects and paint calls on.
See Also:
setGlobalLock(Object), isSynchronizationEnabled(), getNodeLock(y.base.Node), getEdgeLock(y.base.Edge)

isSynchronizationEnabled

protected boolean isSynchronizationEnabled()
Determines whether or not intersects and paint calls should be synchronized. Intersection calculation and painting should be synchronized if multiple threads paint one graph instance e.g. during printing.

By default, this method returns true if getGlobalLock() returns a non-null global lock and false otherwise.

Returns:
true if intersects and paint calls should be synchronized; false otherwise.
See Also:
getGlobalLock(), setGlobalLock(Object), getNodeLock(y.base.Node), getEdgeLock(y.base.Edge)

getEdgeLock

protected java.lang.Object getEdgeLock(Edge edge)
Returns the lock to synchronize intersects and paint calls on for the given edge.

By default, this method will return the given edge if this class' global lock is null; otherwise the global lock is returned.

Client code may overwrite this method for fine-grained control over synchronization locks.

This method may not return null.

Parameters:
edge - the edge that is about to be painted.
Returns:
the synchronization lock used for intersection calculation and painting of the given edge.
See Also:
getGlobalLock(), isSynchronizationEnabled()

getNodeLock

protected java.lang.Object getNodeLock(Node node)
Returns the lock to synchronize intersects and paint calls on for the given node.

By default, this method will return the given node if this class' global lock is null; otherwise the global lock is returned.

Client code may overwrite this method for fine-grained control over synchronization locks.

This method may not return null.

Parameters:
node - the node that is about to be painted.
Returns:
the synchronization lock used for intersection calculation and painting of the given node.
See Also:
getGlobalLock(), isSynchronizationEnabled()

© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.