# Class XYShape

java.lang.Object
uk.ac.starlink.ttools.plot2.layer.XYShape

Direct Known Subclasses:
  `BasicXYShape, FatLineXYShape, LineXYShape, StrokeXYShape`

public abstract class XYShape extends Object
Abstract superclass for shapes characterised by a pair of short integer values. These values typically represent the horizontal and vertical extent of a shape, but they don't have to.

This object acts as a factory for Glyphs. These glyphs are lazily cached per instance of this class for small values of the X and Y coordinates (since there aren't very many of them, and they are probably used frequently); for larger values, the glyphs are created on demand.

Since:
  16 Jan 2015
Author:
  Mark Taylor

## Field Summary

Fields
Modifier and Type
Field
Description
`static Glyph`
`POINT`
Glyph that paints a single pixel at the origin.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`XYShape(String name)`
Constructs a shape with a default cache limit and single-pixel point glyph.
`protected`
`XYShape(String name, int maxCacheRadius, Glyph pointGlyph)`
Constructs a shape with a specified cache limit and point glyph.

## Method Summary

Modifier and Type
Method
Description
`protected abstract Glyph`
`createGlyph(short sx, short sy)`
Constructs a new glyph with given coordinates.
`static Icon`
`createIcon(XYShape shape, int width, int height, boolean useComponentColor)`
Returns an icon displaying a given shape.
`Glyph`
`getGlyph(short sx, short sy)`
Obtains a glyph characterised by a given pair of values.
`String`
`getName()`
Returns the name of this shape.
`boolean`
`isCached(short sx, short sy)`
Indicates whether a glyph of a given size will be cached.
`String`
`toString()`

### Methods inherited from class Object

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

## Field Details

### POINT

public static Glyph POINT
Glyph that paints a single pixel at the origin.

## Constructor Details

### XYShape

protected XYShape(String name, int maxCacheRadius, Glyph pointGlyph)
Constructs a shape with a specified cache limit and point glyph.

Parameters:
  `name` - shape name
  `maxCacheRadius` - glyphs are cached if both input values have an absolute value lower than or equal to this limit
  `pointGlyph` - glyph to dispense for zero-length lines; may be null for no special-case behaviour

### XYShape

protected XYShape(String name)
Constructs a shape with a default cache limit and single-pixel point glyph.

Parameters:
  `name` - shape name

## Method Details

### getName

public String getName()
Returns the name of this shape.

Returns:
  name

### isCached

public boolean isCached(short sx, short sy)
Indicates whether a glyph of a given size will be cached.

Parameters:
  `sx` - X radius
  `sy` - Y radius
Returns:
  true iff glyph will be cached, false if it will be created on demand

### getGlyph

public Glyph getGlyph(short sx, short sy)
Obtains a glyph characterised by a given pair of values. The glyph may be newly created or obtained from a cache.

Parameters:
  `sx` - X value
  `sy` - Y value
Returns:
  glyph

### createGlyph

protected abstract Glyph createGlyph(short sx, short sy)
Constructs a new glyph with given coordinates.

Parameters:
  `sx` - X value
  `sy` - Y value
Returns:
  new glyph

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### createIcon

public static Icon createIcon(XYShape shape, int width, int height, boolean useComponentColor)
Returns an icon displaying a given shape. The assumption is that the X and Y values are half width and half height of the shape.

Parameters:
  `shape` - shape
  `width` - icon width
  `height` - icon height
  `useComponentColor` - if true, the glyph will be painted in the component's foreground colour
Returns:
  icon