org.jgraph.graph

Class EdgeRenderer

public class EdgeRenderer extends JComponent implements CellViewRenderer, Serializable

This renderer displays entries that implement the CellView interface.
Field Summary
protected intbeginDeco
Painting attributes of the current edgeview
protected booleanbeginFill
Boolean attributes of the current edgeview.
protected intbeginSize
Painting attributes of the current edgeview
protected Bezierbezier
Cached bezier curve
protected ColorborderColor
Color attributes of the current edgeview.
protected booleanchildrenSelected
Boolean attributes of the current edgeview.
protected floatdashOffset
Contains the current dash offset.
protected ColordefaultBackground
Color attributes of the current edgeview.
protected ColordefaultForeground
Color attributes of the current edgeview.
protected intendDeco
Painting attributes of the current edgeview
protected booleanendFill
Boolean attributes of the current edgeview.
protected intendSize
Painting attributes of the current edgeview
FontextraLabelFont
Override this if you want the extra labels to appear in a special fontJ
protected booleanfocus
Boolean attributes of the current edgeview.
protected ColorfontColor
Color attributes of the current edgeview.
protected static GraphicsfontGraphics
Static Graphics used for Font Metrics
protected ColorgradientColor
The gradient color of the edge
protected WeakReferencegraph
Cache the current graph for drawing
protected ColorgridColor
The color of the graph grid
protected ColorhighlightColor
The color of highlighted cells
static booleanHIT_LABEL_EXACT
Switch for exact label hit detection on rotated labels.
protected booleanisMoveBelowZero
Boolean attributes of the current edgeview.
protected booleanlabelBorder
Boolean attributes of the current edgeview.
protected booleanlabelsEnabled
Cached value of whether the label is to be displayed
protected booleanlabelTransformEnabled
Boolean attributes of the current edgeview.
protected float[]lineDash
Contains the current dash pattern.
protected intlineStyle
Painting attributes of the current edgeview
protected floatlineWidth
Width of the current edge view
protected ColorlockedHandleColor
The color of the second available handle
static doubleLABELWIDTHBUFFER
When zooming a graph the font size jumps at certain zoom levels rather than scaling smoothly.
protected FontMetricsmetrics
Reference to the font metrics of the above
protected booleanopaque
Boolean attributes of the current edgeview.
protected booleanpreview
Boolean attributes of the current edgeview.
protected booleanselected
Boolean attributes of the current edgeview.
booleansimpleExtraLabels
A switch for painting the extra labels
protected Spline2Dspline
Cached spline curve
protected EdgeViewview
Cache the current edgeview for drawing
Constructor Summary
EdgeRenderer()
Constructs a renderer that may be used to render edges.
Method Summary
protected voidafterEdgePaint(Graphics g)
Hook method for painting after the default painting
protected voidbeforeEdgePaint(Graphics g)
Hook method for painting prior to default painting
protected ShapecreateLineEnd(int size, int style, Point2D src, Point2D dst)
Paint the current view's direction.
protected ShapecreateShape()
Returns the shape that represents the current edge in the context of the current graph.
protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, byte oldValue, byte newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, char oldValue, char newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, short oldValue, short newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, int oldValue, int newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, long oldValue, long newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, float oldValue, float newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, double oldValue, double newValue)
Overridden for performance reasons.
voidfirePropertyChange(String propertyName, boolean oldValue, boolean newValue)
Overridden for performance reasons.
Rectangle2DgetBounds(CellView value)
Returns the bounds of the edge shape.
Rectangle2DgetExtraLabelBounds(JGraph paintingContext, EdgeView view, int index)
Returns the label bounds of the specified view in the given graph.
Point2DgetExtraLabelPosition(EdgeView view, int index)
Returns the label position of the specified view in the given graph.
DimensiongetExtraLabelSize(JGraph paintingContext, EdgeView view, int index)
Returns the label size of the specified view in the given graph.
ColorgetGradientColor()
Rectangle2DgetLabelBounds(JGraph paintingContext, EdgeView view)
Returns the label bounds of the specified view in the given graph.
Rectangle2DgetLabelBounds(Point2D p, Dimension d, String label)
Returns the label bounds of the specified view in the given graph.
Point2DgetLabelPosition(EdgeView view)
Returns the label position of the specified view in the given graph.
protected Point2DgetLabelPosition(Point2D pos)
Returns the label position of the specified view in the given graph.
DimensiongetLabelSize(EdgeView view, String label)
Returns the label size of the specified view in the given graph.
Rectangle2DgetPaintBounds(EdgeView view)
Returns the bounds of the edge shape without label
ComponentgetRendererComponent(JGraph graph, CellView view, boolean sel, boolean focus, boolean preview)
Configure and return the renderer based on the passed in components.
protected voidinstallAttributes(CellView view)
Installs the attributes of specified cell in this renderer instance.
booleanintersects(JGraph graph, CellView value, Rectangle rect)
Returns true if the edge shape intersects the given rectangle.
protected booleanisFillable(int decoration)
voidpaint(Graphics g)
Paint the renderer.
protected voidpaintEdge(Graphics g)
Paints the edge itself
protected voidpaintLabel(Graphics g, String label, Point2D p, boolean mainLabel)
Paint the specified label for the current edgeview.
protected voidpaintLabels(Graphics g)
Draws the edge labels
protected voidpaintSelection(Graphics g)
Paints any selection effect applied to the edge
protected voidpaintSelectionBorder(Graphics g)
Provided for subclassers to paint a selection border.
voidrepaint(long tm, int x, int y, int width, int height)
Overridden for performance reasons.
voidrepaint(Rectangle r)
Overridden for performance reasons.
voidrevalidate()
Overridden for performance reasons.
voidsetGradientColor(Color gradientColor)
protected voidtranslateGraphics(Graphics g)
voidvalidate()
Overridden for performance reasons.

Field Detail

beginDeco

protected transient int beginDeco
Painting attributes of the current edgeview

beginFill

protected transient boolean beginFill
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

beginSize

protected transient int beginSize
Painting attributes of the current edgeview

bezier

protected transient Bezier bezier
Cached bezier curve

borderColor

protected transient Color borderColor
Color attributes of the current edgeview. This components foreground is set to the edgecolor, the fontColor is in an extra variable. If the fontColor is null, the current foreground is used. The default background instead is used for text and is not visible if the label is not visible or if opaque is true.

childrenSelected

protected transient boolean childrenSelected
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

dashOffset

protected transient float dashOffset
Contains the current dash offset. Null means no offset.

defaultBackground

protected transient Color defaultBackground
Color attributes of the current edgeview. This components foreground is set to the edgecolor, the fontColor is in an extra variable. If the fontColor is null, the current foreground is used. The default background instead is used for text and is not visible if the label is not visible or if opaque is true.

defaultForeground

protected transient Color defaultForeground
Color attributes of the current edgeview. This components foreground is set to the edgecolor, the fontColor is in an extra variable. If the fontColor is null, the current foreground is used. The default background instead is used for text and is not visible if the label is not visible or if opaque is true.

endDeco

protected transient int endDeco
Painting attributes of the current edgeview

endFill

protected transient boolean endFill
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

endSize

protected transient int endSize
Painting attributes of the current edgeview

extraLabelFont

public Font extraLabelFont
Override this if you want the extra labels to appear in a special fontJ

focus

protected transient boolean focus
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

fontColor

protected transient Color fontColor
Color attributes of the current edgeview. This components foreground is set to the edgecolor, the fontColor is in an extra variable. If the fontColor is null, the current foreground is used. The default background instead is used for text and is not visible if the label is not visible or if opaque is true.

fontGraphics

protected static transient Graphics fontGraphics
Static Graphics used for Font Metrics

gradientColor

protected transient Color gradientColor
The gradient color of the edge

graph

protected transient WeakReference graph
Cache the current graph for drawing

gridColor

protected transient Color gridColor
The color of the graph grid

highlightColor

protected transient Color highlightColor
The color of highlighted cells

HIT_LABEL_EXACT

public static boolean HIT_LABEL_EXACT
Switch for exact label hit detection on rotated labels. Default is false.

isMoveBelowZero

protected transient boolean isMoveBelowZero
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

labelBorder

protected transient boolean labelBorder
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

labelsEnabled

protected transient boolean labelsEnabled
Cached value of whether the label is to be displayed

labelTransformEnabled

protected transient boolean labelTransformEnabled
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

lineDash

protected transient float[] lineDash
Contains the current dash pattern. Null means no pattern.

lineStyle

protected transient int lineStyle
Painting attributes of the current edgeview

lineWidth

protected transient float lineWidth
Width of the current edge view

lockedHandleColor

protected transient Color lockedHandleColor
The color of the second available handle

LABELWIDTHBUFFER

public static double LABELWIDTHBUFFER
When zooming a graph the font size jumps at certain zoom levels rather than scaling smoothly. Sometimes the zoom on the font is more than the component zoom and cropping occurs. This buffer allows for the maximum occurance of this

metrics

protected transient FontMetrics metrics
Reference to the font metrics of the above

opaque

protected transient boolean opaque
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

preview

protected transient boolean preview
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

selected

protected transient boolean selected
Boolean attributes of the current edgeview. Fill flags are checked for valid decorations.

simpleExtraLabels

public boolean simpleExtraLabels
A switch for painting the extra labels

spline

protected transient Spline2D spline
Cached spline curve

view

protected transient EdgeView view
Cache the current edgeview for drawing

Constructor Detail

EdgeRenderer

public EdgeRenderer()
Constructs a renderer that may be used to render edges.

Method Detail

afterEdgePaint

protected void afterEdgePaint(Graphics g)
Hook method for painting after the default painting

Parameters: g the graphics object being painted to

beforeEdgePaint

protected void beforeEdgePaint(Graphics g)
Hook method for painting prior to default painting

Parameters: g the graphics object being painted to

createLineEnd

protected Shape createLineEnd(int size, int style, Point2D src, Point2D dst)
Paint the current view's direction. Sets tmpPoint as a side-effect such that the invoking method can use it to determine the connection point to this decoration.

createShape

protected Shape createShape()
Returns the shape that represents the current edge in the context of the current graph. This method sets the global beginShape, lineShape and endShape variables as a side-effect.

firePropertyChange

protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, byte oldValue, byte newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, char oldValue, char newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, short oldValue, short newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, int oldValue, int newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, long oldValue, long newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, float oldValue, float newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, double oldValue, double newValue)
Overridden for performance reasons. See the Implementation Note for more information.

firePropertyChange

public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
Overridden for performance reasons. See the Implementation Note for more information.

getBounds

public Rectangle2D getBounds(CellView value)
Returns the bounds of the edge shape.

getExtraLabelBounds

public Rectangle2D getExtraLabelBounds(JGraph paintingContext, EdgeView view, int index)
Returns the label bounds of the specified view in the given graph. Note: The index is the position of the String object for the label in the extra labels array of the view.

getExtraLabelPosition

public Point2D getExtraLabelPosition(EdgeView view, int index)
Returns the label position of the specified view in the given graph.

getExtraLabelSize

public Dimension getExtraLabelSize(JGraph paintingContext, EdgeView view, int index)
Returns the label size of the specified view in the given graph.

getGradientColor

public Color getGradientColor()

Returns: Returns the gradientColor.

getLabelBounds

public Rectangle2D getLabelBounds(JGraph paintingContext, EdgeView view)
Returns the label bounds of the specified view in the given graph.

getLabelBounds

public Rectangle2D getLabelBounds(Point2D p, Dimension d, String label)
Returns the label bounds of the specified view in the given graph.

getLabelPosition

public Point2D getLabelPosition(EdgeView view)
Returns the label position of the specified view in the given graph.

getLabelPosition

protected Point2D getLabelPosition(Point2D pos)
Returns the label position of the specified view in the given graph.

getLabelSize

public Dimension getLabelSize(EdgeView view, String label)
Returns the label size of the specified view in the given graph.

getPaintBounds

public Rectangle2D getPaintBounds(EdgeView view)
Returns the bounds of the edge shape without label

getRendererComponent

public Component getRendererComponent(JGraph graph, CellView view, boolean sel, boolean focus, boolean preview)
Configure and return the renderer based on the passed in components. The value is typically set from messaging the graph with convertValueToString.

Parameters: graph the graph that that defines the rendering context. view the cell view that should be rendered. sel whether the object is selected. focus whether the object has the focus. preview whether we are drawing a preview.

Returns: the component used to render the value.

installAttributes

protected void installAttributes(CellView view)
Installs the attributes of specified cell in this renderer instance. This means, retrieve every published key from the cells hashtable and set global variables or superclass properties accordingly.

Parameters: view the cell view to retrieve the attribute values from.

intersects

public boolean intersects(JGraph graph, CellView value, Rectangle rect)
Returns true if the edge shape intersects the given rectangle.

isFillable

protected boolean isFillable(int decoration)

paint

public void paint(Graphics g)
Paint the renderer.

paintEdge

protected void paintEdge(Graphics g)
Paints the edge itself

Parameters: g the graphics object being painted to

paintLabel

protected void paintLabel(Graphics g, String label, Point2D p, boolean mainLabel)
Paint the specified label for the current edgeview.

paintLabels

protected void paintLabels(Graphics g)
Draws the edge labels

Parameters: g the graphics object being painted to

paintSelection

protected void paintSelection(Graphics g)
Paints any selection effect applied to the edge

Parameters: g the graphics object being painted to

paintSelectionBorder

protected void paintSelectionBorder(Graphics g)
Provided for subclassers to paint a selection border.

repaint

public void repaint(long tm, int x, int y, int width, int height)
Overridden for performance reasons. See the Implementation Note for more information.

repaint

public void repaint(Rectangle r)
Overridden for performance reasons. See the Implementation Note for more information.

revalidate

public void revalidate()
Overridden for performance reasons. See the Implementation Note for more information.

setGradientColor

public void setGradientColor(Color gradientColor)

Parameters: gradientColor The gradientColor to set.

translateGraphics

protected void translateGraphics(Graphics g)

validate

public void validate()
Overridden for performance reasons. See the Implementation Note for more information.
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.