# Class LabelledLine

java.lang.Object
uk.ac.starlink.ttools.plot2.LabelledLine

public class LabelledLine extends 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(Point2D[] gps, String label)`
Constructs a labelled line with an arbitrary number of points.
`LabelledLine(Point2D gp0, Point2D gp1, String label)`
Constructs a straight labelled line between two points.

## Method Summary

Modifier and Type
Method
Description
`void`
`drawLabel(Graphics2D g2, Color bg)`
Draws the label in the middle of the line to a given graphics context.
`void`
`drawLine(Graphics2D g2)`
Draws the line to a given graphics context.
`String`
`getLabel()`
Returns the annotation.
`Path2D`
`getPath()`
Returns a path object corresponding to this line.
`Point2D[]`
`getPoints()`
Returns the array of points defining this line.
`String`
`toString()`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### LabelledLine

public LabelledLine(Point2D gp0, Point2D gp1, String label)
Constructs a straight labelled line between two points.

Parameters:
  `gp0` - start point in graphics space
  `gp1` - end point in graphics space
  `label` - human-readable annotation for line (may be null)

### LabelledLine

public LabelledLine(Point2D[] gps, 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 line
  `label` - human-readable annotation for line (may be null)

## Method Details

### getPoints

public Point2D[] getPoints()
Returns the array of points defining this line.

Returns:
  array of (at least 2) points

### getLabel

public String getLabel()
Returns the annotation.

Returns:
  human-readable label for line

### drawLine

public void drawLine(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 Path2D getPath()
Returns a path object corresponding to this line.

Returns:
  path

### drawLabel

public void drawLabel(Graphics2D g2, 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 context
  `bg` - background colour, or null

### toString

public String toString()

Overrides:
  `toString` in class `Object`