Class EdgeView

  • All Implemented Interfaces:
    java.io.Serializable, CellView

    public class EdgeView
    extends AbstractCellView
    The default implementation of an edge view. The getEdgeRenderer method assumes a renderer of type EdgeRenderer. If you provide a custom renderer to a subclass, you must also override the methods that call this method, namely: getShape, getLabelBounds, getExtraLabelBounds, intersects and getBounds.
    See Also:
    Serialized Form
    • Field Detail

      • renderer

        public static transient EdgeRenderer renderer
        Renderer for the class.
      • points

        protected java.util.List points
        List of points of the edge. May contain ports.
      • source

        protected CellView source
        Cached source and target portview of the edge.
      • target

        protected CellView target
        Cached source and target portview of the edge.
      • sourceParentView

        protected CellView sourceParentView
      • targetParentView

        protected CellView targetParentView
      • labelPosition

        protected java.awt.geom.Point2D labelPosition
        Cached label position of the edge.
      • extraLabelPositions

        protected java.awt.geom.Point2D[] extraLabelPositions
      • labelVector

        protected transient java.awt.geom.Point2D labelVector
      • beginShape

        public transient java.awt.Shape beginShape
        Drawing attributes that are created on the fly
      • endShape

        public transient java.awt.Shape endShape
        Drawing attributes that are created on the fly
      • lineShape

        public transient java.awt.Shape lineShape
        Drawing attributes that are created on the fly
      • sharedPath

        public transient java.awt.geom.GeneralPath sharedPath
        Shared-path tune-up.
      • cachedBounds

        protected transient java.awt.geom.Rectangle2D cachedBounds
    • Constructor Detail

      • EdgeView

        public EdgeView()
        Constructs an empty edge view.
      • EdgeView

        public EdgeView​(java.lang.Object cell)
        Constructs an edge view for the specified model object.
        Parameters:
        cell - reference to the model object
    • Method Detail

      • refresh

        public void refresh​(GraphLayoutCache cache,
                            CellMapper mapper,
                            boolean createDependentViews)
        Overrides the parent method to udpate the cached points, source and target port. If the source or target is removed, a point is inserted into the array of points.
        Specified by:
        refresh in interface CellView
        Overrides:
        refresh in class AbstractCellView
        Parameters:
        cache - the graph model to be used
        mapper - the cell mapper to be used
        createDependentViews - whether or not to create a view if one does not already exist
      • checkDefaultLabelPosition

        protected void checkDefaultLabelPosition()
        Hook for subclassers to avoid default label positions.
      • invalidate

        protected void invalidate()
        Resets the cached values of the edge view
      • getShape

        public java.awt.Shape getShape()
        Returns the shape of the view according to the last rendering state
      • intersects

        public boolean intersects​(JGraph graph,
                                  java.awt.geom.Rectangle2D rect)
        Returns true if this view intersects the given rectangle.
        Specified by:
        intersects in interface CellView
        Overrides:
        intersects in class AbstractCellView
        Parameters:
        graph - the JGraph instance of the view
        rect - the rectangle within which intersection is being checked for
        Returns:
        whether or not the rectangle specified intersects the view
      • getHandle

        public CellHandle getHandle​(GraphContext context)
        Returns a cell handle for the view.
        Specified by:
        getHandle in interface CellView
        Specified by:
        getHandle in class AbstractCellView
        Parameters:
        context - the context of this cell view (cells indirectly affected by it)
        Returns:
        the cell handle for this view
      • getSource

        public CellView getSource()
        Returns the CellView that represents the source of the edge.
      • getSourceParentView

        public CellView getSourceParentView()
      • setSource

        public void setSource​(CellView sourceView)
        Sets the sourceView of the edge.
      • getTarget

        public CellView getTarget()
        Returns the CellView that represents the target of the edge.
      • getTargetParentView

        public CellView getTargetParentView()
      • setTarget

        public void setTarget​(CellView targetView)
        Sets the targetView of the edge.
      • getExtraLabelPosition

        public java.awt.geom.Point2D getExtraLabelPosition​(int index)
        Returns a point that describes the position of the label.
      • getLabelPosition

        public java.awt.geom.Point2D getLabelPosition()
        Returns a point that describes the position of the label.
      • setLabelPosition

        public void setLabelPosition​(java.awt.geom.Point2D pos)
        Sets the description of the label position.
      • setExtraLabelPosition

        public void setExtraLabelPosition​(int index,
                                          java.awt.geom.Point2D pos)
        Sets the description of the label position.
      • isLoop

        public boolean isLoop()
        Returns true if the edge is a loop.
      • getPoints

        public java.util.List getPoints()
        Returns the points.
        Returns:
        List
      • getPointCount

        public int getPointCount()
        Returns the number of point for this edge.
      • getPoint

        public java.awt.geom.Point2D getPoint​(int index)
        Returns the cached points for this edge.
      • getNearestPoint

        protected java.awt.geom.Point2D getNearestPoint​(boolean source)
        Returns the nearest point wrt to the source or target. This method returns the next or previous point or port in the points list, eg. if source is true it returns the location of the point or port at index 1 without calling the getLocation method on any ports.
        Likewise, the method returns the location at index getPointCount()-2 if source is false.
      • getPointLocation

        protected java.awt.geom.Point2D getPointLocation​(int index)
        Returns the point of edge at index. Avoids calling getLocation on any ports of edge.
        This is used from within getPoint to pass the nearest point to the portview to find it's location. This uses the center point of the parent view to determine the port view's location to avoid infinite recursion.
      • setPoint

        public void setPoint​(int index,
                             java.awt.geom.Point2D p)
        Sets the point at index to p.
      • addPoint

        public void addPoint​(int index,
                             java.awt.geom.Point2D p)
        Adds p at position index.
      • removePoint

        public void removePoint​(int index)
        Removes the point at position index.
      • addExtraLabel

        public void addExtraLabel​(java.awt.geom.Point2D location,
                                  java.lang.Object label)
        Adds an extra label.
      • removeExtraLabel

        public void removeExtraLabel​(int index)
        Removes the point at position index.
      • getFirstPointOfSegment

        public int getFirstPointOfSegment()
        Utility method that returns the first point of the pair that forms the segment that is relativeX along the edge as a proportion
        Returns:
        the index of the first point. A value of -1 indicate to use the first and last points
      • getLabelVector

        public java.awt.geom.Point2D getLabelVector()
        Hook to return the vector that is taken as the base vector to compute relative label positions. Normally, the vector goes from the first to the last point on the edge, unless these points are equal, in which case the average distance of all points to the source point is used.
      • getAbsoluteLabelPosition

        protected java.awt.geom.Point2D getAbsoluteLabelPosition()
        Returns the absolute position of the main label
        Returns:
        the absolute position of the main label
      • getAbsoluteExtraLabelPosition

        protected java.awt.geom.Point2D getAbsoluteExtraLabelPosition​(int index)
        Returns the absolute position of the specified extra label
        Parameters:
        index - the index of the extra label
        Returns:
        the absolute position of the specified extra label
      • getAbsoluteLabelPositionFromRelative

        protected java.awt.geom.Point2D getAbsoluteLabelPositionFromRelative​(java.awt.geom.Point2D geometry)
        Converts relative label position to absolute and allows for any label offset.
        Parameters:
        geometry - the relative label position
        Returns:
        the absolute label position including any offset
      • convertRelativeLabelPositionToAbsolute

        protected java.awt.geom.Point2D convertRelativeLabelPositionToAbsolute​(java.awt.geom.Point2D geometry)
        Converts an relative label position (x is distance along edge and y is distance above/below edge vector) into an absolute co-ordination point
        Parameters:
        geometry - the relative label position
        Returns:
        the absolute label position
      • getLength

        public static double getLength​(CellView view)
      • getPerimeterPoint

        public java.awt.geom.Point2D getPerimeterPoint​(EdgeView edge,
                                                       java.awt.geom.Point2D source,
                                                       java.awt.geom.Point2D p)
        Description copied from class: AbstractCellView
        Returns the intersection of the bounding rectangle and the straight line between the source and the specified point p. The specified point is expected not to intersect the bounds. Note: You must override this method if you use a different renderer. This is because this method relies on the VertexRenderer interface, which can not be safely assumed for subclassers.
        Specified by:
        getPerimeterPoint in interface CellView
        Overrides:
        getPerimeterPoint in class AbstractCellView