com.jgraph.components.labels

Class MultiLineVertexRenderer

public class MultiLineVertexRenderer extends VertexRenderer

Universal renderer for vertices and groups. This implementation supports drawing rectangles, circles, diamonds and rounded rectangles and optionally paints a gradient background, stretched background image and folding icon.
Field Summary
protected AreacylinderArea
Holds the area to be painted for the cylinder shape.
static StringCLIENTPROPERTY_SHOWFOLDINGICONS
Client property for JGraph to control the display of the folding icons.
protected Polygondiamond
Holds the shape to be painted for diamond cells.
protected JGraphgraph
Holds a reference to fetch the correct cell value from the model in paint.
protected ColorgraphBackground
Holds the background and foreground of the graph.
protected ColorgraphForeground
Holds the background and foreground of the graph.
static Rectanglehandle
Defines the root handle size and location.
protected booleanisEditing
Specifies whether the current view is a rich text value, and if the image should be stretched.
protected booleanisGroup
Specifies whether the current view is a rich text value, and if the image should be stretched.
protected booleanisRichText
Specifies whether the current view is a rich text value, and if the image should be stretched.
static intINSET
Defines the default inset to render rich text.
protected introundRectArc
Holds the round rect arc size for rounded rectangles.
protected intshape
Holds the shape of the current view.
protected booleanshowFoldingIcons
Specifies whether the current view is a rich text value, and if the image should be stretched.
protected booleanshowHeavyweight
Specified if a heavyweight should be painted.
protected booleanstretchImage
Specifies whether the current view is a rich text value, and if the image should be stretched.
static intSHAPE_CIRCLE
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.
static intSHAPE_CYLINDER
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.
static intSHAPE_DIAMOND
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.
static intSHAPE_RECTANGLE
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.
static intSHAPE_ROUNDED
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.
static intSHAPE_TRIANGLE
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.
static JTextPanetextPane
Holds the text pane to be used for rich text rendering.
protected ObjectuserObject
Holds the user object of the current cell.
protected ComponentvalueComponent
References the value component of the user object if one exists.
protected static JComponentwrapperRenderer
Holds the wrapper renderer used for heavyweights.
static DimensionZERO_DIMENSION
Defines a dimension of width and height 0.
Constructor Summary
MultiLineVertexRenderer()
Constructs a new vertex renderer.
Method Summary
static intgetArcSize(int width, int height)
Returns an appropriate arc for the corners of the rectangle for boundary size cases of width and height.
Point2DgetCirclePerimeterPoint(VertexView view, Point2D source, Point2D p)
Utility method to return the perimeter point for a circle.
Point2DgetDiamondPerimeterPoint(VertexView view, Point2D source, Point2D p)
Utility method to return the perimeter point for a diamond.
Point2DgetPerimeterPoint(VertexView view, Point2D source, Point2D p)
Overrides the parent's implementation to return the perimeter points for non-rectangular shapes, namely diamonds and circles.
DimensiongetPreferredSize()
Overrides the parent's implementation to return a slightly larger preferred size for circles and rounded rectangles.
ComponentgetRendererComponent(JGraph graph, CellView view, boolean sel, boolean focus, boolean preview)
Overrides the parent implementation to return the value component stored in the user object instead of this renderer if a value component exists.
Point2DgetTrianglePerimeterPoint(VertexView view, Point2D source, Point2D p)
Utility method to return the perimeter point for a triangle.
booleaninHitRegion(Point2D pt)
Detects whether or not a point has hit the folding icon.
voidinstallAttributes(CellView view)
Extends the parent's method to configure the renderer for displaying the specified view.
protected Point2Dintersection(Point2D lineOneStart, Point2D lineOneEnd, Point2D lineTwoStart, Point2D lineTwoEnd)
Find the point of intersection of two straight lines (which follow the equation y=mx+b) one line is an incoming edge and the other is one side of the diamond.
voidpaint(Graphics g)
Paints the renderer component for the configured view.
protected voidpaintBackground(Graphics g)
Utility method to paint the background for all non-rectangular shapes.
protected voidpaintFoldingIcon(Graphics g)
Utility method to paint the folding icon for groups.
protected voidpaintRichText(Graphics g)
Utility method to paint the rich text content for rich text values.
protected voidpaintShapeBorder(Graphics g)
Utility method to paint the border for all non-rectangular shapes.
protected voidresetAttributes()
Resets attributes that would affect rendering if the installAttributes is not being called, which is the case if the view is a group and it's groupOpaque attribute is set to false.

Field Detail

cylinderArea

protected Area cylinderArea
Holds the area to be painted for the cylinder shape.

CLIENTPROPERTY_SHOWFOLDINGICONS

public static String CLIENTPROPERTY_SHOWFOLDINGICONS
Client property for JGraph to control the display of the folding icons. Default is true, eg if the property is missing the icons are painted. To switch this feature off, use the following code:
 
 graph.putClientProperty(
 JGraphpadVertexRenderer.CLIENTPROPERTY_SHOWFOLDINGICONS, new
 Boolean(false));
 
 

diamond

protected Polygon diamond
Holds the shape to be painted for diamond cells.

graph

protected JGraph graph
Holds a reference to fetch the correct cell value from the model in paint. This should go into getComponentRenderer.

graphBackground

protected Color graphBackground
Holds the background and foreground of the graph.

graphForeground

protected Color graphForeground
Holds the background and foreground of the graph.

handle

public static Rectangle handle
Defines the root handle size and location.

isEditing

protected boolean isEditing
Specifies whether the current view is a rich text value, and if the image should be stretched.

isGroup

protected boolean isGroup
Specifies whether the current view is a rich text value, and if the image should be stretched.

isRichText

protected boolean isRichText
Specifies whether the current view is a rich text value, and if the image should be stretched.

INSET

public static int INSET
Defines the default inset to render rich text.

roundRectArc

protected int roundRectArc
Holds the round rect arc size for rounded rectangles.

shape

protected int shape
Holds the shape of the current view.

showFoldingIcons

protected boolean showFoldingIcons
Specifies whether the current view is a rich text value, and if the image should be stretched.

showHeavyweight

protected transient boolean showHeavyweight
Specified if a heavyweight should be painted. Default is true.

stretchImage

protected boolean stretchImage
Specifies whether the current view is a rich text value, and if the image should be stretched.

SHAPE_CIRCLE

public static final int SHAPE_CIRCLE
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.

SHAPE_CYLINDER

public static final int SHAPE_CYLINDER
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.

SHAPE_DIAMOND

public static final int SHAPE_DIAMOND
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.

SHAPE_RECTANGLE

public static final int SHAPE_RECTANGLE
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.

SHAPE_ROUNDED

public static final int SHAPE_ROUNDED
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.

SHAPE_TRIANGLE

public static final int SHAPE_TRIANGLE
Defines the shape constants to be used as values for the VERTEXSHAPE attributes.

textPane

public static JTextPane textPane
Holds the text pane to be used for rich text rendering.

userObject

protected Object userObject
Holds the user object of the current cell.

valueComponent

protected Component valueComponent
References the value component of the user object if one exists.

wrapperRenderer

protected static JComponent wrapperRenderer
Holds the wrapper renderer used for heavyweights.

ZERO_DIMENSION

public static Dimension ZERO_DIMENSION
Defines a dimension of width and height 0.

Constructor Detail

MultiLineVertexRenderer

public MultiLineVertexRenderer()
Constructs a new vertex renderer.

Method Detail

getArcSize

public static int getArcSize(int width, int height)
Returns an appropriate arc for the corners of the rectangle for boundary size cases of width and height. The arc width of a rectangle is 1/5th of the larger of the two of the dimensions passed in, but at most 1/2 of the smaller of the two. 1/5 because it looks nice and 1/2 so the arc can complete in the given dimension

Parameters: width The width to compute the arc size for. height The height to compute the arc size for.

Returns: Returns the arc size.

getCirclePerimeterPoint

public Point2D getCirclePerimeterPoint(VertexView view, Point2D source, Point2D p)
Utility method to return the perimeter point for a circle.

Parameters: view The view that defines the bounds of the circle. source The start point of theline to intersect with the circle. p The end point of the line to intersect with the circle.

Returns: The interaction of the circle and the line between source and p.

getDiamondPerimeterPoint

public Point2D getDiamondPerimeterPoint(VertexView view, Point2D source, Point2D p)
Utility method to return the perimeter point for a diamond.

Parameters: view The view that defines the bounds of the diamond. source The start point of theline to intersect with the diamond. p The end point of the line to intersect with the diamond.

Returns: The interaction of the diamond and the line between source and p.

getPerimeterPoint

public Point2D getPerimeterPoint(VertexView view, Point2D source, Point2D p)
Overrides the parent's implementation to return the perimeter points for non-rectangular shapes, namely diamonds and circles. The source point is typically ignored and the center point is used instead.

Parameters: view The view to return the perimeter point for. source The location of the start point of the line to be intersected with the boundaries. p The location of the end point of the line to be intersected with the boundaries.

getPreferredSize

public Dimension getPreferredSize()
Overrides the parent's implementation to return a slightly larger preferred size for circles and rounded rectangles.

Returns: Returns the preferreds size for the current view.

getRendererComponent

public Component getRendererComponent(JGraph graph, CellView view, boolean sel, boolean focus, boolean preview)
Overrides the parent implementation to return the value component stored in the user object instead of this renderer if a value component exists. This applies some of the values installed to this renderer to the value component (border, opaque) if the latter is a JComponent.

Returns: Returns a configured renderer for the specified view.

getTrianglePerimeterPoint

public Point2D getTrianglePerimeterPoint(VertexView view, Point2D source, Point2D p)
Utility method to return the perimeter point for a triangle.

Parameters: view The view that defines the bounds of the diamond. source The start point of theline to intersect with the diamond. p The end point of the line to intersect with the diamond.

Returns: The interaction of the diamond and the line between source and p.

inHitRegion

public boolean inHitRegion(Point2D pt)
Detects whether or not a point has hit the folding icon. This implementation never returns true if the CLIENTPROPERTY_SHOWFOLDINGICONS is not set on the enclosing graph.

Parameters: pt The point to check

Returns: Returns true if pt intersects with the folding icon.

installAttributes

public void installAttributes(CellView view)
Extends the parent's method to configure the renderer for displaying the specified view.

Parameters: view The view to configure the renderer for.

intersection

protected Point2D intersection(Point2D lineOneStart, Point2D lineOneEnd, Point2D lineTwoStart, Point2D lineTwoEnd)
Find the point of intersection of two straight lines (which follow the equation y=mx+b) one line is an incoming edge and the other is one side of the diamond.

Parameters: lineOneStart The start point of the first line. lineOneEnd The end point of the first line. lineTwoStart The start point of the second line. lineTwoEnd The end point of the second line.

Returns: Returns the intersection point between the first and the second line.

paint

public void paint(Graphics g)
Paints the renderer component for the configured view. This implementation consists of three parts: painting the background, gradient and stretched image, painting the content by doing a supercall and calling the rich text renderer if required, and finally paint the border, selection border and the folding handle.

Parameters: g The graphics to paint the cell to.

paintBackground

protected void paintBackground(Graphics g)
Utility method to paint the background for all non-rectangular shapes.

Parameters: g The graphics to paint the background to.

paintFoldingIcon

protected void paintFoldingIcon(Graphics g)
Utility method to paint the folding icon for groups.

Parameters: g The graphics to paint the border to.

paintRichText

protected void paintRichText(Graphics g)
Utility method to paint the rich text content for rich text values. This implementation simulates rich text vertical alignment by translating the graphics before painting the textPane.

Parameters: g The graphics to paint the rich text content to.

paintShapeBorder

protected void paintShapeBorder(Graphics g)
Utility method to paint the border for all non-rectangular shapes.

Parameters: g The graphics to paint the border to.

resetAttributes

protected void resetAttributes()
Resets attributes that would affect rendering if the installAttributes is not being called, which is the case if the view is a group and it's groupOpaque attribute is set to false.
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.