Class MultiLineVertexRenderer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, 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:
  • Field Details

    • 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));
      
      
    • ZERO_DIMENSION

      public static 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 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:
    • SHAPE_CIRCLE

      public static final int SHAPE_CIRCLE
      Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
      See Also:
    • SHAPE_DIAMOND

      public static final int SHAPE_DIAMOND
      Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
      See Also:
    • SHAPE_ROUNDED

      public static final int SHAPE_ROUNDED
      Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
      See Also:
    • SHAPE_CYLINDER

      public static final int SHAPE_CYLINDER
      Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
      See Also:
    • SHAPE_TRIANGLE

      public static final int SHAPE_TRIANGLE
      Defines the shape constants to be used as values for the CellConstants.VERTEXSHAPE attributes.
      See Also:
    • textPane

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

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

      protected 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 Color graphBackground
      Holds the background and foreground of the graph.
    • graphForeground

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

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

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

      protected 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 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:
      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(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(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(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.
    • paintFoldingIcon

      protected void paintFoldingIcon(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 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.
      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 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.
    • 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.
    • 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

      public Dimension getPreferredSize()
      Overrides the parent's implementation to return a slightly larger preferred size for circles and rounded rectangles.
      Overrides:
      getPreferredSize in class 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(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.