JGraph
v5.13.0.4


com.jgraph.components.labels
Class MultiLineVertexRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by org.jgraph.graph.VertexRenderer
                      extended by com.jgraph.components.labels.MultiLineVertexRenderer
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants, CellViewRenderer

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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String CLIENTPROPERTY_SHOWFOLDINGICONS
          Client property for JGraph to control the display of the folding icons.
protected  java.awt.geom.Area cylinderArea
          Holds the area to be painted for the cylinder shape.
protected  java.awt.Polygon diamond
          Holds the shape to be painted for diamond cells.
protected  JGraph graph
          Holds a reference to fetch the correct cell value from the model in paint.
protected  java.awt.Color graphBackground
          Holds the background and foreground of the graph.
protected  java.awt.Color graphForeground
          Holds the background and foreground of the graph.
static java.awt.Rectangle handle
          Defines the root handle size and location.
static int INSET
          Defines the default inset to render rich text.
protected  boolean isEditing
          Specifies whether the current view is a rich text value, and if the image should be stretched.
protected  boolean isGroup
          Specifies whether the current view is a rich text value, and if the image should be stretched.
protected  boolean isRichText
          Specifies whether the current view is a rich text value, and if the image should be stretched.
protected  int roundRectArc
          Holds the round rect arc size for rounded rectangles.
protected  int shape
          Holds the shape of the current view.
static int SHAPE_CIRCLE
          Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
static int SHAPE_CYLINDER
          Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
static int SHAPE_DIAMOND
          Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
static int SHAPE_RECTANGLE
          Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
static int SHAPE_ROUNDED
          Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
static int SHAPE_TRIANGLE
          Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
protected  boolean showFoldingIcons
          Specifies whether the current view is a rich text value, and if the image should be stretched.
protected  boolean showHeavyweight
          Specified if a heavyweight should be painted.
protected  boolean stretchImage
          Specifies whether the current view is a rich text value, and if the image should be stretched.
static javax.swing.JTextPane textPane
          Holds the text pane to be used for rich text rendering.
protected  java.lang.Object userObject
          Holds the user object of the current cell.
protected  java.awt.Component valueComponent
          References the value component of the user object if one exists.
protected static javax.swing.JComponent wrapperRenderer
          Holds the wrapper renderer used for heavyweights.
static java.awt.Dimension ZERO_DIMENSION
          Defines a dimension of width and height 0.
 
Fields inherited from class org.jgraph.graph.VertexRenderer
bordercolor, borderWidth, childrenSelected, defaultBackground, defaultForeground, gradientColor, gridColor, hasFocus, highlightColor, isDoubleBuffered, labelEnabled, lockedHandleColor, preview, selected, view
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MultiLineVertexRenderer()
          Constructs a new vertex renderer.
 
Method Summary
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.
 java.awt.geom.Point2D getCirclePerimeterPoint(VertexView view, java.awt.geom.Point2D source, java.awt.geom.Point2D p)
          Utility method to return the perimeter point for a circle.
 java.awt.geom.Point2D getDiamondPerimeterPoint(VertexView view, java.awt.geom.Point2D source, java.awt.geom.Point2D p)
          Utility method to return the perimeter point for a diamond.
 java.awt.geom.Point2D getPerimeterPoint(VertexView view, java.awt.geom.Point2D source, java.awt.geom.Point2D p)
          Overrides the parent's implementation to return the perimeter points for non-rectangular shapes, namely diamonds and circles.
 java.awt.Dimension getPreferredSize()
          Overrides the parent's implementation to return a slightly larger preferred size for circles and rounded rectangles.
 java.awt.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.
 java.awt.geom.Point2D getTrianglePerimeterPoint(VertexView view, java.awt.geom.Point2D source, java.awt.geom.Point2D p)
          Utility method to return the perimeter point for a triangle.
 boolean inHitRegion(java.awt.geom.Point2D pt)
          Detects whether or not a point has hit the folding icon.
 void installAttributes(CellView view)
          Extends the parent's method to configure the renderer for displaying the specified view.
protected  java.awt.geom.Point2D intersection(java.awt.geom.Point2D lineOneStart, java.awt.geom.Point2D lineOneEnd, java.awt.geom.Point2D lineTwoStart, java.awt.geom.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.
 void paint(java.awt.Graphics g)
          Paints the renderer component for the configured view.
protected  void paintBackground(java.awt.Graphics g)
          Utility method to paint the background for all non-rectangular shapes.
protected  void paintFoldingIcon(java.awt.Graphics g)
          Utility method to paint the folding icon for groups.
protected  void paintRichText(java.awt.Graphics g)
          Utility method to paint the rich text content for rich text values.
protected  void paintShapeBorder(java.awt.Graphics g)
          Utility method to paint the border for all non-rectangular shapes.
protected  void resetAttributes()
          Resets attributes that would affect rendering if the installAttributes(CellView) is not being called, which is the case if the view is a group and it's groupOpaque attribute is set to false.
 
Methods inherited from class org.jgraph.graph.VertexRenderer
firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getGradientColor, paintSelectionBorder, repaint, repaint, revalidate, setGradientColor, validate
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLIENTPROPERTY_SHOWFOLDINGICONS

public static java.lang.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));
 
 


ZERO_DIMENSION

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


INSET

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


handle

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


graph

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


SHAPE_RECTANGLE

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

See Also:
Constant Field Values

SHAPE_CIRCLE

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

See Also:
Constant Field Values

SHAPE_DIAMOND

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

See Also:
Constant Field Values

SHAPE_ROUNDED

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

See Also:
Constant Field Values

SHAPE_CYLINDER

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

See Also:
Constant Field Values

SHAPE_TRIANGLE

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

See Also:
Constant Field Values

textPane

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


wrapperRenderer

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


userObject

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


shape

protected int shape
Holds the shape of the current view.


isRichText

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


stretchImage

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


isEditing

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


showFoldingIcons

protected boolean showFoldingIcons
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.


graphBackground

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


graphForeground

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


valueComponent

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


cylinderArea

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


diamond

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


roundRectArc

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


showHeavyweight

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

Constructor Detail

MultiLineVertexRenderer

public MultiLineVertexRenderer()
Constructs a new vertex renderer.

Method Detail

getRendererComponent

public java.awt.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.

Specified by:
getRendererComponent in interface CellViewRenderer
Overrides:
getRendererComponent in class VertexRenderer
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:
Returns a configured renderer for the specified view.

paint

public void paint(java.awt.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.

Overrides:
paint in class VertexRenderer
Parameters:
g - The graphics to paint the cell to.

paintBackground

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

Parameters:
g - The graphics to paint the background to.

paintRichText

protected void paintRichText(java.awt.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(java.awt.Graphics g)
Utility method to paint the border for all non-rectangular shapes.

Parameters:
g - The graphics to paint the border to.

paintFoldingIcon

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

Parameters:
g - The graphics to paint the border to.

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.

getPerimeterPoint

public java.awt.geom.Point2D getPerimeterPoint(VertexView view,
                                               java.awt.geom.Point2D source,
                                               java.awt.geom.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.

Overrides:
getPerimeterPoint in class VertexRenderer
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.

getCirclePerimeterPoint

public java.awt.geom.Point2D getCirclePerimeterPoint(VertexView view,
                                                     java.awt.geom.Point2D source,
                                                     java.awt.geom.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 java.awt.geom.Point2D getDiamondPerimeterPoint(VertexView view,
                                                      java.awt.geom.Point2D source,
                                                      java.awt.geom.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.

getTrianglePerimeterPoint

public java.awt.geom.Point2D getTrianglePerimeterPoint(VertexView view,
                                                       java.awt.geom.Point2D source,
                                                       java.awt.geom.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.

intersection

protected java.awt.geom.Point2D intersection(java.awt.geom.Point2D lineOneStart,
                                             java.awt.geom.Point2D lineOneEnd,
                                             java.awt.geom.Point2D lineTwoStart,
                                             java.awt.geom.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.

getPreferredSize

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

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
Returns the preferreds size for the current view.

resetAttributes

protected void resetAttributes()
Resets attributes that would affect rendering if the installAttributes(CellView) is not being called, which is the case if the view is a group and it's groupOpaque attribute is set to false.

Overrides:
resetAttributes in class VertexRenderer

installAttributes

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

Overrides:
installAttributes in class VertexRenderer
Parameters:
view - The view to configure the renderer for.

inHitRegion

public boolean inHitRegion(java.awt.geom.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.

JGraph
v5.13.0.4


Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.