Package uk.ac.starlink.ttools.plot2
Class LabelledLine
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.LabelledLine
-
public class LabelledLine extends java.lang.Object
Aggregates a line in graphics coordinates and its annotation. The annotation is intended for human consumption.- Since:
- 23 Jan 2019
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description LabelledLine(java.awt.geom.Point2D[] gps, java.lang.String label)
Constructs a labelled line with an arbitrary number of points.LabelledLine(java.awt.geom.Point2D gp0, java.awt.geom.Point2D gp1, java.lang.String label)
Constructs a straight labelled line between two points.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
drawLabel(java.awt.Graphics2D g2, java.awt.Color bg)
Draws the label in the middle of the line to a given graphics context.void
drawLine(java.awt.Graphics2D g2)
Draws the line to a given graphics context.java.lang.String
getLabel()
Returns the annotation.java.awt.geom.Path2D
getPath()
Returns a path object corresponding to this line.java.awt.geom.Point2D[]
getPoints()
Returns the array of points defining this line.java.lang.String
toString()
-
-
-
Constructor Detail
-
LabelledLine
public LabelledLine(java.awt.geom.Point2D gp0, java.awt.geom.Point2D gp1, java.lang.String label)
Constructs a straight labelled line between two points.- Parameters:
gp0
- start point in graphics spacegp1
- end point in graphics spacelabel
- human-readable annotation for line (may be null)
-
LabelledLine
public LabelledLine(java.awt.geom.Point2D[] gps, java.lang.String label)
Constructs a labelled line with an arbitrary number of points. Null elements may appear in the points array indicating a break in the line. There must be at least two array elements, and the first and last elements must both be non-null.- Parameters:
gps
- array of points in graphics space defining the linelabel
- human-readable annotation for line (may be null)
-
-
Method Detail
-
getPoints
public java.awt.geom.Point2D[] getPoints()
Returns the array of points defining this line.- Returns:
- array of (at least 2) points
-
getLabel
public java.lang.String getLabel()
Returns the annotation.- Returns:
- human-readable label for line
-
drawLine
public void drawLine(java.awt.Graphics2D g2)
Draws the line to a given graphics context. The current settings of the graphics context are used.- Parameters:
g2
- graphics context
-
getPath
public java.awt.geom.Path2D getPath()
Returns a path object corresponding to this line.- Returns:
- path
-
drawLabel
public void drawLabel(java.awt.Graphics2D g2, java.awt.Color bg)
Draws the label in the middle of the line to a given graphics context. The current settings of the graphics context are used. If a non-null background colour is supplied, a rectangle corresponding to the label bounds is plotted underneath the label itself.- Parameters:
g2
- graphics contextbg
- background colour, or null
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-