uk.ac.starlink.ttools.plot2.layer
Class XYShape

java.lang.Object
  extended by uk.ac.starlink.ttools.plot2.layer.XYShape
Direct Known Subclasses:
LineXYShape

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
static Glyph POINT
          Glyph that paints a single pixel at the origin.
 
Constructor Summary
protected XYShape(String name)
          Constructs a shape with a default cache limit.
protected XYShape(String name, int maxCacheRadius)
          Constructs a shape with a specified cache limit.
 
Method Summary
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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

POINT

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

Constructor Detail

XYShape

protected XYShape(String name,
                  int maxCacheRadius)
Constructs a shape with a specified cache limit.

Parameters:
name - shape name
maxCacheRadius - glyphs are cached if both input values have an absolute value lower than or equal to this limit

XYShape

protected XYShape(String name)
Constructs a shape with a default cache limit.

Parameters:
name - shape name
Method Detail

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


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.