Class GraphicEdge

All Implemented Interfaces:
Edge, Element

public class GraphicEdge
extends GraphicElement
implements Edge
Graphical edge.

The graphic edge defines its source and target node as well as a direction, a string label and a style from the style sheet.

See Also:
GraphicGraph
  • Field Details

    • from

      public GraphicNode from
      The first node.
    • to

      public GraphicNode to
      The second node.
    • directed

      public boolean directed
      Is the edge directed ?.
    • multi

      public int multi
      In case of a multi-graph this is the index of the edge between to and from.
    • group

      public GraphicEdge.EdgeGroup group
      If non null, this gives the number of edges between the two same nodes.
    • ctrl

      public double[] ctrl
      Control points for curved edges or polylines. This contains the control points of an edge. If the edge is in 2D each sequence of two cells gives the x and y coordinates of a control point. Else each sequence of three cells gives the x, y and z coordinates. Therefore the number of control points can be obtained by dividing by 2 or 3 the length of this array. For example for cubic Bezier curves in 2D this array contains four cells. The control points are ordered from node0 to node1.
  • Constructor Details

    • GraphicEdge

      public GraphicEdge​(String id, GraphicNode from, GraphicNode to, boolean dir, HashMap<String,​Object> attributes)
      New graphic edge.
      Parameters:
      id - The edge unique identifier.
      from - The source node.
      to - The target node.
      dir - True if the edge is directed in the direction from-to.
      attributes - A set of initial attributes.
  • Method Details

    • getSelectorType

      public Selector.Type getSelectorType()
      Description copied from class: GraphicElement
      Type of selector for the graphic element (Node, Edge, Sprite ?).
      Specified by:
      getSelectorType in class GraphicElement
    • otherNode

      public GraphicNode otherNode​(GraphicNode n)
      Obtain the node that is not "n" attached to this edge.
      Parameters:
      n - One of the node of this edge.
      Returns:
      The other node of this edge.
    • getX

      public double getX()
      Description copied from class: GraphicElement
      Abscissa of the element, always in GU (graph units). For edges this is the X of the "from" node.
      Specified by:
      getX in class GraphicElement
    • getY

      public double getY()
      Description copied from class: GraphicElement
      Ordinate of the element, always in GU (graph units). For edges this is the Y of the "from" node.
      Specified by:
      getY in class GraphicElement
    • getZ

      public double getZ()
      Description copied from class: GraphicElement
      Depth of the element, always in GU (graph units). For edges this is the Z of the "from" node.
      Specified by:
      getZ in class GraphicElement
    • getControlPoints

      public double[] getControlPoints()
      Control points for curved edges or polylines. This contains the control points of an edge. If the edge is in 2D each sequence of two cells gives the x and y coordinates of a control point. Else each sequence of three cells gives the x, y and z coordinates. Therefore the number of control points can be obtained by dividing by 2 or 3 the length of this array. For example for cubic Bezier curves in 2D this array contains four cells. The control points are ordered from node0 to node1. The units are "graph units".
      Returns:
      The control points coordinates or null if this edge is a straight line.
    • isCurve

      public boolean isCurve()
      True if the the edge defines control points to draw a curve or polyline. This does not mean the edge style asks to paint the edge as a curve, only that control points are defined.
      Returns:
      True if control points are available.
    • setControlPoints

      public void setControlPoints​(double[] points)
      Change the control points array for this edge.
      Parameters:
      points - The new set of points. See the getControlPoints() method for an explanation on the organisation of this array.
      See Also:
      getControlPoints()
    • getMultiIndex

      public int getMultiIndex()
      This edge is the i-th between the two same nodes.
      Returns:
      The edge index between the two nodes if there are several such edges.
    • move

      public void move​(double x, double y, double z)
      Description copied from class: GraphicElement
      Try to force the element to move at the give location in graph units (GU). For edges, this may move the two attached nodes.
      Specified by:
      move in class GraphicElement
      Parameters:
      x - The new X.
      y - The new Y.
      z - the new Z.
    • removed

      public void removed()
    • getNode0

      public Node getNode0()
      Description copied from interface: Edge
      First node of the edge.

      This is equivalent to the Edge.getSourceNode() method, but may be clearer in the source code if the graph you are using is not directed.

      Specified by:
      getNode0 in interface Edge
      Returns:
      The first node of the edge.
      See Also:
      Edge.getNode1(), Edge.getSourceNode()
    • getNode1

      public Node getNode1()
      Description copied from interface: Edge
      Second node of the edge.

      This is equivalent to the Edge.getTargetNode() method, but may be clearer in the source code if the graph you are using is not directed.

      Specified by:
      getNode1 in interface Edge
      Returns:
      The second node of the edge.
      See Also:
      Edge.getNode0(), Edge.getTargetNode()
    • getGroup

      public GraphicEdge.EdgeGroup getGroup()
      If there are several edges between two nodes, this edge pertains to a group. Else this method returns null.
      Returns:
      The group of edges between two same nodes, null if the edge is alone between the two nodes.
    • getOpposite

      public Node getOpposite​(Node node)
      Description copied from interface: Edge
      When knowing one node and one edge of this node, this method return the node at the other end of the edge.

      Return null if the given node is not at any end of the edge.

      Specified by:
      getOpposite in interface Edge
      Parameters:
      node - The node we search the opposite of.
      Returns:
      the opposite node of the given node.
    • getSourceNode

      public Node getSourceNode()
      Description copied from interface: Edge
      Start node.

      When the edge is directed this is the source node, in this case you can get the opposite node using Edge.getTargetNode(). This is equivalent to the Edge.getNode0() method but may be clearer in the source code if the graph you are using is directed.

      Specified by:
      getSourceNode in interface Edge
      Returns:
      The origin node of the edge.
      See Also:
      Edge.getNode0(), Edge.getTargetNode()
    • getTargetNode

      public Node getTargetNode()
      Description copied from interface: Edge
      End node.

      When the edge is directed this is the target node, in this case you can get the opposite node using Edge.getSourceNode(). This is equivalent to the Edge.getNode1() method but may be clearer in the source code if the graph you are using is directed.

      Specified by:
      getTargetNode in interface Edge
      Returns:
      The destination node of the edge.
      See Also:
      Edge.getNode1(), Edge.getSourceNode()
    • isDirected

      public boolean isDirected()
      Description copied from interface: Edge
      Is the edge directed ?.
      Specified by:
      isDirected in interface Edge
      Returns:
      True if the edge is directed.
    • isLoop

      public boolean isLoop()
      Description copied from interface: Edge
      Does the source and target of this edge identify the same node ?.
      Specified by:
      isLoop in interface Edge
      Returns:
      True if this edge is a loop.
    • setDirected

      public void setDirected​(boolean on)
    • switchDirection

      public void switchDirection()