Search this API

y.view
Class FramedEdgePainter

java.lang.Object
  extended by y.view.GenericEdgePainter
      extended by y.view.FramedEdgePainter
All Implemented Interfaces:
GenericEdgeRealizer.Painter

public class FramedEdgePainter
extends GenericEdgePainter

A GenericEdgeRealizer.Painter implementation that draws (and optionally fills) the outline of an edge.

This painter tries to calculate the combined outline of the edge path, the edge's source arrow, and the edge's target arrow. However, taking the outlines of arrows into account is supported only for shaped arrows (i.e. Arrow.getShape() not null). Moreover, even though that is the case for arrows PLAIN, DASH, SKEWED_DASH, and T_SHAPE, these arrows are rendered "as usual" without being outlined.

Sample visualization for line color BLACK, line type LINE_4, source arrow NONE, and target arrow STANDARD:

 

Field Summary
static java.lang.String PROPERTY_FILL_COLOR
          Style property key to specify a fill color for framed edges.
 
Constructor Summary
FramedEdgePainter()
          Initializes a new FramedEdgePainter instance.
 
Method Summary
protected  java.awt.Paint getFillPaint(EdgeRealizer context, boolean selected)
          Determines the background paint to fill the outline of the edge.
protected  java.awt.Stroke getLineStroke(EdgeRealizer context, boolean selected)
          Determines the stroke used to calculate the outline of the edge.
protected  java.awt.Stroke getOutlineStroke(EdgeRealizer context, boolean selected)
          Determines the stroke to draw the outline of the edge.
protected  double getSourceArrowScaleFactor(EdgeRealizer context, Arrow arrow, boolean selected)
          Calculates the scaling factor for the source arrow.
protected  java.awt.geom.AffineTransform getSourceArrowTransform(EdgeRealizer context, java.awt.geom.GeneralPath path, Arrow arrow, boolean selected)
          Calculates the transform that places the specified arrow at the source intersection of the given edge realizer.
protected  double getTargetArrowScaleFactor(EdgeRealizer context, Arrow arrow, boolean selected)
          Calculates the scaling factor for the target arrow.
protected  java.awt.geom.AffineTransform getTargetArrowTransform(EdgeRealizer context, java.awt.geom.GeneralPath path, Arrow arrow, boolean selected)
          Calculates the transform that places the specified arrow at the target intersection of the given edge realizer.
protected  void paintBackground(EdgeRealizer context, java.awt.Graphics2D gfx, java.awt.geom.GeneralPath path, java.awt.geom.GeneralPath outline, boolean selected)
          Fills the outline of the edge path (including arrow outlines).
protected  void paintForeground(EdgeRealizer context, java.awt.Graphics2D gfx, java.awt.geom.GeneralPath path, java.awt.geom.GeneralPath outline, boolean selected)
          Draws the outline of the edge path (including arrow outlines).
protected  void paintPath(EdgeRealizer context, BendList bends, java.awt.geom.GeneralPath path, java.awt.Graphics2D gfx, boolean selected)
          Paints the actual path and decorations of the edge.
protected  void paintSourceArrow(EdgeRealizer context, java.awt.Graphics2D gfx, java.awt.geom.GeneralPath path, Arrow arrow, java.awt.geom.AffineTransform t)
          Paints the source arrow if its outline could not be incorporated in the outline of the edge path.
protected  void paintTargetArrow(EdgeRealizer context, java.awt.Graphics2D gfx, java.awt.geom.GeneralPath path, Arrow arrow, java.awt.geom.AffineTransform t)
          Paints the target arrow if its outline could not be incorporated in the outline of the edge path.
protected  void renderPath(EdgeRealizer context, java.awt.Graphics2D gfx, java.awt.geom.GeneralPath path, boolean selected)
          Renders the edge represented by the given realizer by painting the outline of the edge.
 
Methods inherited from class y.view.GenericEdgePainter
adjustPath, getLinePaint, getSelectionLinePaint, getSelectionLineStroke, getSloppyLineStroke, initializeControlPolygonLine, initializeLine, initializeSelectionLine, paint, paintArrows, paintBends, paintControlPolygon, paintHighlightedBends, paintLabels, paintPorts, paintSloppy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_FILL_COLOR

public static final java.lang.String PROPERTY_FILL_COLOR
Style property key to specify a fill color for framed edges.

See Also:
Constant Field Values
Constructor Detail

FramedEdgePainter

public FramedEdgePainter()
Initializes a new FramedEdgePainter instance.

Method Detail

paintPath

protected void paintPath(EdgeRealizer context,
                         BendList bends,
                         java.awt.geom.GeneralPath path,
                         java.awt.Graphics2D gfx,
                         boolean selected)
Paints the actual path and decorations of the edge.

Calls renderPath(EdgeRealizer, java.awt.Graphics2D, java.awt.geom.GeneralPath, boolean).

Note: This implementation does not call GenericEdgePainter.paintArrows(EdgeRealizer, BendList, java.awt.geom.GeneralPath, java.awt.Graphics2D), because the outlines of arrows are incorporated into the outline of the edge path in renderPath(EdgeRealizer, java.awt.Graphics2D, java.awt.geom.GeneralPath, boolean) (if possible).

Overrides:
paintPath in class GenericEdgePainter
Parameters:
context - the visual representation of the edge to paint.
bends - the list of bends that the current context holds
path - the GeneralPath instance that can be used to calculate a new result.
gfx - the graphics context to paint upon.
selected - whether or not the edge should be painted as selected.

renderPath

protected void renderPath(EdgeRealizer context,
                          java.awt.Graphics2D gfx,
                          java.awt.geom.GeneralPath path,
                          boolean selected)
Renders the edge represented by the given realizer by painting the outline of the edge. If possible, the outlines of the realizer's source arrow and target arrow are incorporated into the outline of the edge. Outlines of arrows are incorporated, if the arrows' shape property is not null. Notable exceptions to this rule are Arrow.PLAIN, Arrow.DASH, Arrow.SKEWED_DASH, and Arrow.T_SHAPE. If an arrow's outline is not incorporated into the outline, the arrow is painted as usual (see paintSourceArrow and paintTargetArrow respectively).

Calls getSourceArrowTransform, getTargetArrowTransform, paintBackground, paintForeground and if necessary paintSourceArrow and paintTargetArrow.

Overrides:
renderPath in class GenericEdgePainter
Parameters:
context - the visual representation of the edge to paint.
gfx - the graphics context to paint upon.
path - the GeneralPath instance that can be used to calculate a new result.
selected - whether or not the edge should be painted as selected.

paintForeground

protected void paintForeground(EdgeRealizer context,
                               java.awt.Graphics2D gfx,
                               java.awt.geom.GeneralPath path,
                               java.awt.geom.GeneralPath outline,
                               boolean selected)
Draws the outline of the edge path (including arrow outlines).

Calls getOutlineStroke(EdgeRealizer, boolean).

Parameters:
context - the visual representation of the edge to paint.
gfx - the graphics context to paint upon.
path - the edge path that is outlined.
outline - the outline to draw.
selected - whether or not the edge should be painted as selected.

paintBackground

protected void paintBackground(EdgeRealizer context,
                               java.awt.Graphics2D gfx,
                               java.awt.geom.GeneralPath path,
                               java.awt.geom.GeneralPath outline,
                               boolean selected)
Fills the outline of the edge path (including arrow outlines).

Calls getFillPaint(EdgeRealizer, boolean).

Parameters:
context - the visual representation of the edge to paint.
gfx - the graphics context to paint upon.
path - the edge path that is outlined.
outline - the outline to fill.
selected - whether or not the edge should be painted as selected.

getSourceArrowTransform

protected java.awt.geom.AffineTransform getSourceArrowTransform(EdgeRealizer context,
                                                                java.awt.geom.GeneralPath path,
                                                                Arrow arrow,
                                                                boolean selected)
Calculates the transform that places the specified arrow at the source intersection of the given edge realizer.

Note: For performance reason this method may returned a thread-local, shared instance of AffineTransform.

Calls getSourceArrowScaleFactor(EdgeRealizer, Arrow, boolean).

Parameters:
context - the visual representation of the edge to paint.
path - the edge path that is outlined.
arrow - the source arrow to be positioned.
selected - whether or not the edge should be painted as selected.
Returns:
the transform that places the specified arrow at the source intersection of the given edge realizer.

getSourceArrowScaleFactor

protected double getSourceArrowScaleFactor(EdgeRealizer context,
                                           Arrow arrow,
                                           boolean selected)
Calculates the scaling factor for the source arrow. The scaling factor is factored into the source arrow transform to accommodate for the width of the realizer's line stroke.

Parameters:
context - the visual representation of the edge to paint.
arrow - the source arrow to be scaled up.
selected - whether or not the edge should be painted as selected.
Returns:
the scaling factor for the source arrow.

getTargetArrowTransform

protected java.awt.geom.AffineTransform getTargetArrowTransform(EdgeRealizer context,
                                                                java.awt.geom.GeneralPath path,
                                                                Arrow arrow,
                                                                boolean selected)
Calculates the transform that places the specified arrow at the target intersection of the given edge realizer.

Note: For performance reason this method may returned a thread-local, shared instance of AffineTransform.

Calls getTargetArrowScaleFactor(EdgeRealizer, Arrow, boolean).

Parameters:
context - the visual representation of the edge to paint.
path - the edge path that is outlined.
arrow - the target arrow to be positioned.
selected - whether or not the edge should be painted as selected.
Returns:
the transform that places the specified arrow at the target intersection of the given edge realizer.

getTargetArrowScaleFactor

protected double getTargetArrowScaleFactor(EdgeRealizer context,
                                           Arrow arrow,
                                           boolean selected)
Calculates the scaling factor for the target arrow. The scaling factor is factored into the target arrow transform to accommodate for the width of the realizer's line stroke.

Parameters:
context - the visual representation of the edge to paint.
arrow - the target arrow to be scaled up.
selected - whether or not the edge should be painted as selected.
Returns:
the scaling factor for the target arrow.

paintSourceArrow

protected void paintSourceArrow(EdgeRealizer context,
                                java.awt.Graphics2D gfx,
                                java.awt.geom.GeneralPath path,
                                Arrow arrow,
                                java.awt.geom.AffineTransform t)
Paints the source arrow if its outline could not be incorporated in the outline of the edge path.

The default implementation calls arrow.paint(gfx, t).

Called from renderPath.

Parameters:
context - the visual representation of the edge to paint.
gfx - the graphics context to paint upon.
path - the edge path that is outlined.
arrow - the source arrow that is rendered.
t - the transformation used for positioning the source arrow.

paintTargetArrow

protected void paintTargetArrow(EdgeRealizer context,
                                java.awt.Graphics2D gfx,
                                java.awt.geom.GeneralPath path,
                                Arrow arrow,
                                java.awt.geom.AffineTransform t)
Paints the target arrow if its outline could not be incorporated in the outline of the edge path.

The default implementation calls arrow.paint(gfx, t).

Called from renderPath.

Parameters:
context - the visual representation of the edge to paint.
gfx - the graphics context to paint upon.
path - the edge path that is outlined.
arrow - the target arrow that is rendered.
t - the transformation used for positioning the target arrow.

getFillPaint

protected java.awt.Paint getFillPaint(EdgeRealizer context,
                                      boolean selected)
Determines the background paint to fill the outline of the edge.

Called from paintBackground.

Parameters:
context - the visual representation of the edge to paint.
selected - whether or not the edge should be painted as selected.
Returns:
the background paint or null if no background should be painted.

getOutlineStroke

protected java.awt.Stroke getOutlineStroke(EdgeRealizer context,
                                           boolean selected)
Determines the stroke to draw the outline of the edge.

The default implementation uses the dash pattern of the specified edge realizer's line type and a line width of 1.

Called from paintForeground.

Parameters:
context - the visual representation of the edge to paint.
selected - whether or not the edge should be painted as selected.
Returns:
the stroke to draw the outline of the edge.

getLineStroke

protected java.awt.Stroke getLineStroke(EdgeRealizer context,
                                        boolean selected)
Determines the stroke used to calculate the outline of the edge.

The default implementation uses a solid line the width of the specified edge realizer's line type.

Called from initializeLine and initializeSelectionLine.

Overrides:
getLineStroke in class GenericEdgePainter
Parameters:
context - the EdgeRealizer context that is used for the current painting
selected - whether or not the edge is selected
Returns:
the stroke used to calculate the outline of the edge.

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