Class MultiLineVertexRenderer
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
org.jgraph.graph.VertexRenderer
com.jgraph.components.labels.MultiLineVertexRenderer
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, CellViewRenderer
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class JLabel
JLabel.AccessibleJLabelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringClient property for JGraph to control the display of the folding icons.protected AreaHolds the area to be painted for the cylinder shape.protected PolygonHolds the shape to be painted for diamond cells.protected JGraphHolds a reference to fetch the correct cell value from the model in paint.protected ColorHolds the background and foreground of the graph.protected ColorHolds the background and foreground of the graph.static RectangleDefines the root handle size and location.static intDefines the default inset to render rich text.protected booleanSpecifies whether the current view is a rich text value, and if the image should be stretched.protected booleanSpecifies whether the current view is a rich text value, and if the image should be stretched.protected booleanSpecifies whether the current view is a rich text value, and if the image should be stretched.protected intHolds the round rect arc size for rounded rectangles.protected intHolds the shape of the current view.static final intDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.static final intDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.static final intDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.static final intDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.static final intDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.static final intDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.protected booleanSpecifies whether the current view is a rich text value, and if the image should be stretched.protected booleanSpecified if a heavyweight should be painted.protected booleanSpecifies whether the current view is a rich text value, and if the image should be stretched.static JTextPaneHolds the text pane to be used for rich text rendering.protected ObjectHolds the user object of the current cell.protected ComponentReferences the value component of the user object if one exists.protected static JComponentHolds the wrapper renderer used for heavyweights.static DimensionDefines a dimension of width and height 0.Fields inherited from class VertexRenderer
bordercolor, borderWidth, childrenSelected, defaultBackground, defaultForeground, gradientColor, gridColor, hasFocus, highlightColor, isDoubleBuffered, labelEnabled, lockedHandleColor, preview, selected, viewFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetArcSize(int width, int height) Returns an appropriate arc for the corners of the rectangle for boundary size cases of width and height.getCirclePerimeterPoint(VertexView view, Point2D source, Point2D p) Utility method to return the perimeter point for a circle.getDiamondPerimeterPoint(VertexView view, Point2D source, Point2D p) Utility method to return the perimeter point for a diamond.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.Overrides the parent's implementation to return a slightly larger preferred size for circles and rounded rectangles.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.getTrianglePerimeterPoint(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.voidPaints the renderer component for the configured view.protected voidUtility method to paint the background for all non-rectangular shapes.protected voidUtility method to paint the folding icon for groups.protected voidUtility method to paint the rich text content for rich text values.protected voidUtility method to paint the border for all non-rectangular shapes.protected voidResets attributes that would affect rendering if theinstallAttributes(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 VertexRenderer
firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getGradientColor, paintSelectionBorder, repaint, repaint, revalidate, setGradientColor, validateMethods inherited from class 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, updateUIMethods inherited from class 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateMethods inherited from class 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, transferFocusDownCycle, validateTreeMethods inherited from class 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
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
Defines a dimension of width and height 0. -
INSET
public static int INSETDefines the default inset to render rich text. -
handle
Defines the root handle size and location. -
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_RECTANGLEDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.- See Also:
-
SHAPE_CIRCLE
public static final int SHAPE_CIRCLEDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.- See Also:
-
SHAPE_DIAMOND
public static final int SHAPE_DIAMONDDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.- See Also:
-
SHAPE_ROUNDED
public static final int SHAPE_ROUNDEDDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.- See Also:
-
SHAPE_CYLINDER
public static final int SHAPE_CYLINDERDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.- See Also:
-
SHAPE_TRIANGLE
public static final int SHAPE_TRIANGLEDefines the shape constants to be used as values for theCellConstants.VERTEXSHAPEattributes.- See Also:
-
textPane
Holds the text pane to be used for rich text rendering. -
wrapperRenderer
Holds the wrapper renderer used for heavyweights. -
userObject
Holds the user object of the current cell. -
shape
protected int shapeHolds the shape of the current view. -
isRichText
protected boolean isRichTextSpecifies whether the current view is a rich text value, and if the image should be stretched. -
stretchImage
protected boolean stretchImageSpecifies whether the current view is a rich text value, and if the image should be stretched. -
isEditing
protected boolean isEditingSpecifies whether the current view is a rich text value, and if the image should be stretched. -
showFoldingIcons
protected boolean showFoldingIconsSpecifies whether the current view is a rich text value, and if the image should be stretched. -
isGroup
protected boolean isGroupSpecifies whether the current view is a rich text value, and if the image should be stretched. -
graphBackground
Holds the background and foreground of the graph. -
graphForeground
Holds the background and foreground of the graph. -
valueComponent
References the value component of the user object if one exists. -
cylinderArea
Holds the area to be painted for the cylinder shape. -
diamond
Holds the shape to be painted for diamond cells. -
roundRectArc
protected int roundRectArcHolds the round rect arc size for rounded rectangles. -
showHeavyweight
protected transient boolean showHeavyweightSpecified if a heavyweight should be painted. Default is true.
-
-
Constructor Details
-
MultiLineVertexRenderer
public MultiLineVertexRenderer()Constructs a new vertex renderer.
-
-
Method Details
-
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.- Specified by:
getRendererComponentin interfaceCellViewRenderer- Overrides:
getRendererComponentin classVertexRenderer- 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
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:
paintin classVertexRenderer- Parameters:
g- The graphics to paint the cell to.
-
paintBackground
Utility method to paint the background for all non-rectangular shapes.- Parameters:
g- The graphics to paint the background to.
-
paintRichText
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
Utility method to paint the border for all non-rectangular shapes.- Parameters:
g- The graphics to paint the border to.
-
paintFoldingIcon
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
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:
getPerimeterPointin classVertexRenderer- 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
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
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
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 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.
-
getPreferredSize
Overrides the parent's implementation to return a slightly larger preferred size for circles and rounded rectangles.- Overrides:
getPreferredSizein classJComponent- Returns:
- Returns the preferreds size for the current view.
-
resetAttributes
protected void resetAttributes()Resets attributes that would affect rendering if theinstallAttributes(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:
resetAttributesin classVertexRenderer
-
installAttributes
Extends the parent's method to configure the renderer for displaying the specified view.- Overrides:
installAttributesin classVertexRenderer- Parameters:
view- The view to configure the renderer for.
-
inHitRegion
Detects whether or not a point has hit the folding icon. This implementation never returns true if theCLIENTPROPERTY_SHOWFOLDINGICONSis not set on the enclosing graph.- Parameters:
pt- The point to check- Returns:
- Returns true if
ptintersects with the folding icon.
-