Class XYShape
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.layer.XYShape
-
- Direct Known Subclasses:
LineXYShape
,StrokeXYShape
public abstract class XYShape extends java.lang.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
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Glyph
createGlyph(short sx, short sy)
Constructs a new glyph with given coordinates.static javax.swing.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.java.lang.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.java.lang.String
toString()
-
-
-
Field Detail
-
POINT
public static Glyph POINT
Glyph that paints a single pixel at the origin.
-
-
Constructor Detail
-
XYShape
protected XYShape(java.lang.String name, int maxCacheRadius)
Constructs a shape with a specified cache limit.- Parameters:
name
- shape namemaxCacheRadius
- glyphs are cached if both input values have an absolute value lower than or equal to this limit
-
XYShape
protected XYShape(java.lang.String name)
Constructs a shape with a default cache limit.- Parameters:
name
- shape name
-
-
Method Detail
-
getName
public java.lang.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 radiussy
- 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 valuesy
- Y value- Returns:
- glyph
-
createGlyph
protected abstract Glyph createGlyph(short sx, short sy)
Constructs a new glyph with given coordinates.- Parameters:
sx
- X valuesy
- Y value- Returns:
- new glyph
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
createIcon
public static javax.swing.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
- shapewidth
- icon widthheight
- icon heightuseComponentColor
- if true, the glyph will be painted in the component's foreground colour- Returns:
- icon
-
-