Class LineElement

java.lang.Object
All Implemented Interfaces:
java.lang.Cloneable, ConnectorRestrictions, Drawable, Groupable, Referenceable, Referenceable.Annotatable, Referenceable.Citable, Referenceable.Evidenceable
Direct Known Subclasses:
GraphicalLine, Interaction

public abstract class LineElement
extends PathwayElement
implements Groupable, ConnectorRestrictions
This abstract class stores information for a Line pathway element, e.g. GraphicalLine or Interaction.
Author:
finterly
  • Field Details

  • Constructor Details

    • LineElement

      public LineElement()
      Instantiates a line pathway element. NB: Property groupRef is to be set by setGroupRefTo(Group). In GPML, groupRef refers to the elementId (formerly groupId) of the parent gpml:Group. Note, a group can also belong in another group. Graphics properties have default values and can be set after a line pathway element is already instantiated.
  • Method Details

    • getStartArrowHeadType

      public ArrowHeadType getStartArrowHeadType()
      Returns the arrowHead property of the start point. Arrowhead specifies the glyph at the ends of graphical lines and interactions. Intermediate points have arrowhead type UNDIRECTED (the absence of an arrowhead).
      Returns:
      startArrowHeadType the arrow head type.
    • setStartArrowHeadType

      public void setStartArrowHeadType​(ArrowHeadType value)
      Sets the arrow head type of the start point.
      Parameters:
      value - the arrow head type to set.
    • getEndArrowHeadType

      public ArrowHeadType getEndArrowHeadType()
      Returns the arrowHead property of the end point. Arrowhead specifies the glyph at the ends of graphical lines and interactions. Intermediate points have arrowhead type UNDIRECTED (the absence of an arrowhead).
      Returns:
      endArrowHeadType the arrow head type.
    • setEndArrowHeadType

      public void setEndArrowHeadType​(ArrowHeadType value)
      Sets the arrow head type of the end point.
      Parameters:
      value - the arrow head type to set.
    • getGroupRef

      public Group getGroupRef()
      Returns the parent group of this pathway element. In GPML, groupRef refers to the elementId (formerly groupId) of the parent gpml:Group.
      Specified by:
      getGroupRef in interface Groupable
      Returns:
      groupRef the parent group of this pathway element.
    • hasGroupRef

      public boolean hasGroupRef()
      Checks whether this pathway element belongs to a group.
      Specified by:
      hasGroupRef in interface Groupable
      Returns:
      true if and only if the group of this pathway element is effective.
    • setGroupRefTo

      public void setGroupRefTo​(Group v)
      Verifies if given parent group is new and valid. Sets the parent group of this pathway element. Adds this pathway element to the the pathwayElements list of the new parent group. If there is an old parent group, this pathway element is removed from its pathwayElements list.
      Specified by:
      setGroupRefTo in interface Groupable
      Parameters:
      v - the new parent group to set.
    • setGroupRef

      private void setGroupRef​(Group v)
      Sets the parent group for this pathway element.
      Parameters:
      v - the given group to set.
    • unsetGroupRef

      public void unsetGroupRef()
      Unsets the parent group, if any, from this pathway element.
      Specified by:
      unsetGroupRef in interface Groupable
    • getLinePoints

      public java.util.List<LineElement.LinePoint> getLinePoints()
      Get the points for this line.
      Returns:
      points the list of points, an empty list if no anchors are defined.
    • setLinePoints

      public void setLinePoints​(java.util.List<LineElement.LinePoint> points)
      Sets linePoints to the given list of LinePoints. Removes old points removeLinePoints(java.util.List<org.pathvisio.libgpml.model.LineElement.LinePoint>), if any, then adds new points addLinePoints(java.util.List<org.pathvisio.libgpml.model.LineElement.LinePoint>). In the case of updating waypoints, start and end line points are preserved and should not be removed.
      Parameters:
      points - the list of points to set.
    • addLinePoints

      private void addLinePoints​(java.util.List<LineElement.LinePoint> points)
      Adds all given points to the linePoints list. Adds each point to the pathway model PathwayModel.addPathwayObject(org.pathvisio.libgpml.model.PathwayObject) if applicable. This method is called only by setLinePoints(java.util.List<org.pathvisio.libgpml.model.LineElement.LinePoint>).
      Parameters:
      points - the points to add to pathway model..
    • removeLinePoints

      private void removeLinePoints​(java.util.List<LineElement.LinePoint> toRemove)
      Removes all points from the given line points list.

      NB:

      1. Called from setLinePoints(java.util.List<org.pathvisio.libgpml.model.LineElement.LinePoint>). For which in some cases, start and end line points are preserved and should not be removed.
      2. When this line element is terminated terminate(), all points of linePoints list are removed.
      Parameters:
      toRemove - the list of points to remove.
    • getAnchors

      public java.util.List<LineElement.Anchor> getAnchors()
      Get the anchors for this line.
      Returns:
      anchors the list of anchors, an empty list if no anchors are defined.
    • hasAnchor

      public boolean hasAnchor​(LineElement.Anchor anchor)
      Checks whether anchors has the given anchor.
      Parameters:
      anchor - the anchor to look for.
      Returns:
      true if has anchor, false otherwise.
    • addAnchor

      public void addAnchor​(LineElement.Anchor anchor)
      Adds given anchor to anchors list. Sets lineElement for the given anchor.
      Parameters:
      anchor - the anchor to be added.
    • addAnchor

      public LineElement.Anchor addAnchor​(double position, AnchorShapeType anchorShapeType)
      Adds a new anchor to this line at the given position with anchorShapeType property. Calls addAnchor(Anchor anchor).
      Parameters:
      position - the relative position on the line, between 0 (start) to 1 (end).
      anchorShapeType - the shape type of the anchor.
    • addAnchor

      public LineElement.Anchor addAnchor​(java.lang.String elementId, double position, AnchorShapeType anchorShapeType)
      Creates and adds a new anchor to this line at the given position with anchorShapeType property. Anchor elementId is set immediately after creation. This method is used when reading gpml.Calls addAnchor(Anchor anchor).
      Parameters:
      elementId - the elementId to set for created anchor.
      position - the relative position on the line, between 0 (start) to 1 (end).
      anchorShapeType - the shape type of the anchor.
    • removeAnchor

      public void removeAnchor​(LineElement.Anchor anchor)
      Removes given anchor from the anchors list. Anchor ceases to exist and is terminated.
      Parameters:
      anchor - the anchor to be removed.
    • removeAnchors

      private void removeAnchors()
      Removes all anchors from the anchors list.
    • getLineColor

      public java.awt.Color getLineColor()
      Returns the color of a line.
      Returns:
      lineColor the color of a line.
    • setLineColor

      public void setLineColor​(java.awt.Color v)
      Sets the color of a line.
      Parameters:
      v - the color of a line.
      Throws:
      java.lang.IllegalArgumentException - if color null.
    • getLineStyle

      public LineStyleType getLineStyle()
      Returns the visual appearance of a line, e.g. Solid or Broken.
      Returns:
      lineStyle the style of a line.
    • setLineStyle

      public void setLineStyle​(LineStyleType v)
      Sets the visual appearance of a line, e.g. Solid or Broken.
      Parameters:
      v - the line style to set.
      Throws:
      java.lang.IllegalArgumentException - if lineStyle null.
    • getLineWidth

      public double getLineWidth()
      Returns the pixel value for the width of a line.
      Returns:
      lineWidth the width of a line.
    • setLineWidth

      public void setLineWidth​(double v)
      Sets the pixel value for the width of a line.
      Parameters:
      v - the width of a line.
      Throws:
      java.lang.IllegalArgumentException - if lineWidth is a negative value.
    • getConnectorType

      public ConnectorType getConnectorType()
      Returns the value of the connectorType property. Specifies a set of rules to govern layout of Graphical Lines and Interactions. PathVisio (Java): Line Type and GPML: ConnectorType e.g. Curved, Elbow, Straight
      Returns:
      connectorType the layout of a line.
    • setConnectorType

      public void setConnectorType​(ConnectorType v)
      Sets the value of the connectorType property. Specifies a set of rules to govern layout of Graphical Lines and Interactions. PathVisio (Java): Line Type and GPML: ConnectorType e.g. Curved, Elbow, Straight
      Parameters:
      v - the layout of a line.
      Throws:
      java.lang.IllegalArgumentException - if ConnectorType null.
    • getZOrder

      public int getZOrder()
      Returns the z-order of this pathway element.
      Specified by:
      getZOrder in interface Drawable
      Returns:
      zOrder the order of this pathway element.
    • setZOrder

      public void setZOrder​(int v)
      Sets the z-order of this pathway element.
      Specified by:
      setZOrder in interface Drawable
      Parameters:
      v - the order of this pathway element.
    • getStartLinePoint

      public LineElement.LinePoint getStartLinePoint()
      Returns the start (first) point of points list.
      Returns:
      the first point of points list.
    • setStartLinePoint

      public void setStartLinePoint​(LineElement.LinePoint linePoint)
      Sets start linePoint coordinates to the coordinates of the given linePoint.
      Parameters:
      linePoint - the given line point.
    • getEndLinePoint

      public LineElement.LinePoint getEndLinePoint()
      Returns the end (last) point of points list.
      Returns:
      the last point of points list.
    • setEndLinePoint

      public void setEndLinePoint​(LineElement.LinePoint linePoint)
      Sets end linePoint coordinates to the coordinates of the given linePoint.
      Parameters:
      linePoint - the given line point.
    • getStartLinePointX

      public double getStartLinePointX()
      Returns the x coordinate of the start point.
      Returns:
      the x coordinate of the start point.
    • setStartLinePointX

      public void setStartLinePointX​(double v)
      Sets the x coordinate of the start point.
      Parameters:
      v - the value to set.
    • getStartLinePointY

      public double getStartLinePointY()
      Returns the y coordinate of the start point.
      Returns:
      the y coordinate of the start point.
    • setStartLinePointY

      public void setStartLinePointY​(double v)
      Sets the y coordinate of the start point.
      Parameters:
      v - the value to set.
    • getEndLinePointX

      public double getEndLinePointX()
      Returns the x coordinate of the end point.
      Returns:
      the x coordinate of the end point.
    • setEndLinePointX

      public void setEndLinePointX​(double v)
      Sets the x coordinate of the end point.
      Parameters:
      v - the value to set.
    • getEndLinePointY

      public double getEndLinePointY()
      Returns the y coordinate of the end point.
      Returns:
      the y coordinate of the end point.
    • setEndLinePointY

      public void setEndLinePointY​(double v)
      Sets the y coordinate of the end point.
      Parameters:
      v - the value to set.
    • getStartElementRef

      public GraphLink.LinkableTo getStartElementRef()
      Returns the elementRef of the end point.
      Returns:
      the elementRef linkableTo pathway element.
    • setStartElementRef

      public void setStartElementRef​(GraphLink.LinkableTo elementRef)
      Sets the elementRef for the start point.
      Parameters:
      elementRef - to link to.
    • getEndElementRef

      public GraphLink.LinkableTo getEndElementRef()
      Returns the elementRef of the end point.
      Returns:
      the elementRef linkableTo pathway element.
    • setEndElementRef

      public void setEndElementRef​(GraphLink.LinkableTo elementRef)
      Sets the elementRef for the end point.
      Parameters:
      elementRef - to link to.
    • getStartPoint2D

      public java.awt.geom.Point2D getStartPoint2D()
      converts start point from MPoint to Point2D
      Specified by:
      getStartPoint2D in interface ConnectorRestrictions
      Returns:
      the start point.
    • getEndPoint2D

      public java.awt.geom.Point2D getEndPoint2D()
      converts end point from MPoint to Point2D
      Specified by:
      getEndPoint2D in interface ConnectorRestrictions
      Returns:
      the end point.
    • getPoints2D

      public java.util.List<java.awt.geom.Point2D> getPoints2D()
      converts all points from MPoint to Point2D
    • getRotatedBounds

      public java.awt.geom.Rectangle2D getRotatedBounds()
      Returns the rectangular bounds of this line pathway elements. This method simply calls getBounds() because lines do not have property rotation.
      Specified by:
      getRotatedBounds in interface Groupable
      Returns:
      the rectangular bounds for this line pathway element.
    • getBounds

      public java.awt.geom.Rectangle2D getBounds()
      Returns the rectangular bounds for this line pathway element. The bounds for a line is calculated from its ends points (first and last).
      Specified by:
      getBounds in interface Groupable
      Returns:
      the rectangular bounds for this line pathway element.
    • getCenterX

      public double getCenterX()
      Returns the center x coordinate of the bounding box around (start, end) this line pathway element.
      Specified by:
      getCenterX in interface Groupable
      Returns:
      the center x coordinate.
    • setCenterX

      public void setCenterX​(double v)
      Sets the x position of the center of the line. This makes the line move as a whole
      Specified by:
      setCenterX in interface Groupable
      Parameters:
      v - the center x coordinate to set.
    • getCenterY

      public double getCenterY()
      Returns the center y coordinate of the bounding box around (start, end) this line pathway element.
      Specified by:
      getCenterY in interface Groupable
      Returns:
      the center y coordinate
    • setCenterY

      public void setCenterY​(double v)
      Sets the y position of the center of the line. This makes the line move as a whole.
      Specified by:
      setCenterY in interface Groupable
      Parameters:
      v - the center y coordinate to set.
    • getWidth

      public double getWidth()
      Calculates and returns the width of the bounding box around (start, end) this line pathway element.
      Specified by:
      getWidth in interface Groupable
      Returns:
      width the width.
    • getHeight

      public double getHeight()
      Calculates and returns the height of the bounding box around (start, end) this line pathway element.
      Specified by:
      getHeight in interface Groupable
      Returns:
      height the height.
    • getLeft

      public double getLeft()
      Returns the left x coordinate of the bounding box around (start, end) this line pathway element.
      Specified by:
      getLeft in interface Groupable
      Returns:
      left the left x coordinate.
    • setLeft

      public void setLeft​(double v)
      Sets the position of the left side of the rectangular bounds of the line
      Specified by:
      setLeft in interface Groupable
      Parameters:
      v - the left x coordinate to set.
    • getTop

      public double getTop()
      Returns the top y coordinate of the bounding box around (start, end) this line pathway element.
      Specified by:
      getTop in interface Groupable
      Returns:
      the top y coordinate.
    • setTop

      public void setTop​(double v)
      Sets the position of the top side of the rectangular bounds of the line
      Specified by:
      setTop in interface Groupable
      Parameters:
      v - the top y coordinate to set.
    • getDirectionX

      private int getDirectionX()
      returns the sign of end.x - start.x
    • getDirectionY

      private int getDirectionY()
      returns the sign of end.y - start.y
    • toAbsoluteCoordinate

      public java.awt.geom.Point2D toAbsoluteCoordinate​(java.awt.geom.Point2D p)
      Description copied from interface: Groupable
      Converts a point to pathway coordinates (relative to the pathway).
      Specified by:
      toAbsoluteCoordinate in interface Drawable
      Specified by:
      toAbsoluteCoordinate in interface Groupable
      Parameters:
      p -
      Returns:
    • toRelativeCoordinate

      public java.awt.geom.Point2D toRelativeCoordinate​(java.awt.geom.Point2D mp)
      Description copied from interface: Groupable
      Converts a point to shape coordinates (relative to the bounds of the object)
      Specified by:
      toRelativeCoordinate in interface Drawable
      Specified by:
      toRelativeCoordinate in interface Groupable
      Parameters:
      mp - a point in absolute model coordinates
      Returns:
      the same point relative to the bounding box of this pathway element: -1,-1 meaning the top-left corner, 1,1 meaning the bottom right corner, and 0,0 meaning the center.
    • getConnectorShape

      public ConnectorShape getConnectorShape()
      The Connector Shape for this line - the connector shape can calculate a Shape based on the connector type (straight, elbow or curved) and possibly way points
    • getStartSide

      public int getStartSide()
      Calculate on which side of a PathwayElement (SIDE_NORTH, SIDE_EAST, SIDE_SOUTH or SIDE_WEST) the start of this line is connected to. If the start is not connected to anything, returns SIDE_WEST
      Specified by:
      getStartSide in interface ConnectorRestrictions
      Returns:
      The side, one of the SIDE_* constants
    • getEndSide

      public int getEndSide()
      Calculate on which side of a PathwayElement (SIDE_NORTH, SIDE_EAST, SIDE_SOUTH or SIDE_WEST) the end of this line is connected to. If the end is not connected to anything, returns SIDE_EAST
      Specified by:
      getEndSide in interface ConnectorRestrictions
      Returns:
      The side, one of the SIDE_* constants
    • getAttachedLineDirection

      private int getAttachedLineDirection​(LineElement.Anchor anchor)
    • findAnchorSegment

      private ConnectorShape.Segment findAnchorSegment​(LineElement attLine, double pos)
    • almostPerfectAlignment

      private boolean almostPerfectAlignment​(int side)
      Check if either the line segment has less than or equal to 10 degree alignment with the side passed
      Parameters:
      side -
      Returns:
      true if less or equal to 10 degree alignment else false
    • getClockwisePerpendicularSide

      private int getClockwisePerpendicularSide​(int side)
      Returns the Perpendicular for a SIDE_* constant (e.g. SIDE_EAST, SIDE_WEST)
    • adjustWayPointPreferences

      public void adjustWayPointPreferences​(ConnectorShape.WayPoint[] waypoints)
    • resetWayPointPreferences

      public void resetWayPointPreferences()
    • getWayPointPreferences

      public ConnectorShape.WayPoint[] getWayPointPreferences()
      Get the preferred waypoints, to which the connector must draw it's path. The waypoints returned by this method are preferences and the connector shape may decide not to use them if they are invalid.
      Specified by:
      getWayPointPreferences in interface ConnectorRestrictions
    • getSide

      private static int getSide​(double x, double y, double cx, double cy)
      Get the side of the given pathway element to which the x and y coordinates connect
      Parameters:
      x - the x coordinate
      y - the y coordinate
      cx -
      cy - // e The element to find the side of
      Returns:
      One of the SIDE_* constants
    • getSide

      private static int getSide​(double relX, double relY)
    • getOppositeSide

      private int getOppositeSide​(int side)
      Returns the opposite for a SIDE_* constant (e.g. SIDE_EAST, SIDE_WEST)
    • mayCross

      public java.awt.geom.Rectangle2D mayCross​(java.awt.geom.Point2D point)
      Check if the connector may cross this point Optionally, returns a shape that defines the boundaries of the area around this point that the connector may not cross. This method can be used for advanced connectors that route along other objects on the drawing
      Specified by:
      mayCross in interface ConnectorRestrictions
      Parameters:
      point - the point to check.
      Returns:
      A shape that defines the boundaries of the area around this point that the connector may not cross. Returning null is allowed for implementing classes.
    • setPathwayModelTo

      protected void setPathwayModelTo​(PathwayModel pathwayModel) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
      Sets the pathway model for this pathway element. NB: Only set when a pathway model adds this pathway element. NB: This method is not used directly. It is called by PathwayModel.addPathwayObject(org.pathvisio.libgpml.model.PathwayObject).
      Overrides:
      setPathwayModelTo in class PathwayObject
      Parameters:
      pathwayModel - the parent pathway model.
      Throws:
      java.lang.IllegalArgumentException
      java.lang.IllegalStateException
    • terminate

      protected void terminate()
      Terminates this LineElement. The pathway model, if any, is unset from this anchor.Links to all annotationRefs, citationRefs, and evidenceRefs are removed from this data node.
      Overrides:
      terminate in class PathwayElement
    • copyValuesFrom

      public void copyValuesFrom​(LineElement src)
      Copies values from the given source pathway element.

      NB:

      1. GroupRef is not copied, but can be set later if the parent group and all other pathway element members are copied.
      Parameters:
      src - the source pathway element.
    • getStaticPropertyKeys

      public java.util.Set<StaticProperty> getStaticPropertyKeys()
      Returns all static properties for this pathway object.
      Overrides:
      getStaticPropertyKeys in class PathwayElement
      Returns:
      result the set of static property for this pathway object.
    • getStaticProperty

      public java.lang.Object getStaticProperty​(StaticProperty key)
      Returns static property value for given key.
      Overrides:
      getStaticProperty in class PathwayElement
      Parameters:
      key - the key.
      Returns:
      the static property value.
    • setStaticProperty

      public void setStaticProperty​(StaticProperty key, java.lang.Object value)
      This works so that o.setNotes(x) is the equivalent of o.setProperty("Notes", x); Value may be null in some cases, e.g. graphRef
      Overrides:
      setStaticProperty in class PathwayElement
      Parameters:
      key - the key.
      value - the property value.