facets.util.shade
Class ShadeSet

java.lang.Object
  extended by facets.util.shade.ShadeSet

public class ShadeSet
extends java.lang.Object

Extensible, sortable set of Shades.


Field Summary
static int SORT_BLUE
          Sort index.
static int SORT_BRIGHTNESS
          Sort index.
static int SORT_GREEN
          Sort index.
static int SORT_HUE
          Sort index.
static int SORT_RED
          Sort index.
static int SORT_SATURATION
          Sort index.
static int SORT_SNAP
          Sort index.
static int SORT_TITLE
          Sort index.
static int SORTS
          Sort index.
 
Constructor Summary
protected ShadeSet(Shade[] shades, ShadeSet master)
          Core constructor, not public API.
  ShadeSet(ShadeSet master)
          Constructor for public API.
 
Method Summary
 Shade addShade(Shade shade)
          Adds shade to the working set, providing no equivalent shade is already stored.
 boolean isAddedShade(Shade shade)
          True if shade is not a member of the internal reference set.
 void setSort(int sort)
          Sets the sort used by shades.
 Shade[] shades()
          The sorted contents of the working set of Shades.
protected  int snapBits()
          The bit length to be used when 'snapping' new to existing shades.
 Shade snapShade(Shade shade)
          Checks whether shade can be 'snapped' to an existing shade.
 int sort()
          The sort used by shades.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SORT_TITLE

public static final int SORT_TITLE
Sort index.

See Also:
Constant Field Values

SORT_SNAP

public static final int SORT_SNAP
Sort index.

See Also:
Constant Field Values

SORT_HUE

public static final int SORT_HUE
Sort index.

See Also:
Constant Field Values

SORT_SATURATION

public static final int SORT_SATURATION
Sort index.

See Also:
Constant Field Values

SORT_BRIGHTNESS

public static final int SORT_BRIGHTNESS
Sort index.

See Also:
Constant Field Values

SORT_RED

public static final int SORT_RED
Sort index.

See Also:
Constant Field Values

SORT_GREEN

public static final int SORT_GREEN
Sort index.

See Also:
Constant Field Values

SORT_BLUE

public static final int SORT_BLUE
Sort index.

See Also:
Constant Field Values

SORTS

public static final int SORTS
Sort index.

See Also:
Constant Field Values
Constructor Detail

ShadeSet

public ShadeSet(ShadeSet master)
Constructor for public API.

Parameters:
master - has its reference set shared by the instance, which creates its own working set.

A suitable master is Shades.HTML_SET which can be shared between instances.


ShadeSet

protected ShadeSet(Shade[] shades,
                   ShadeSet master)
Core constructor, not public API.

One of shades or master may be null.

Parameters:
shades - if non-null and master is null are stored as an internal reference set, with duplicates (by either colour or title) removed
master - if non-null shares its reference set with the new instance; in which case shades are ignored.

In either case an extensible working set is initialised from the reference set; it is this working set that is accessible via shades.

This constructor is not public API and should be regarded as package-private except for documentation purposes.

Method Detail

addShade

public final Shade addShade(Shade shade)
Adds shade to the working set, providing no equivalent shade is already stored.

Any shade of the same title is replaced by shade.

Parameters:
shade - must be non-null.
Returns:
shade if successful, otherwise the existing equivalent shade.

isAddedShade

public final boolean isAddedShade(Shade shade)
True if shade is not a member of the internal reference set.

Parameters:
shade - must be non-null

setSort

public final void setSort(int sort)
Sets the sort used by shades.

Parameters:
sort - should be one of the SORT_XXX constants.

shades

public final Shade[] shades()
The sorted contents of the working set of Shades.


snapShade

public final Shade snapShade(Shade shade)
Checks whether shade can be 'snapped' to an existing shade.

Returns the existing shade if found, otherwise shade.

Parameters:
shade - must be non-null

sort

public final int sort()
The sort used by shades.

Sort will be one of the SORT_XXX constants.


snapBits

protected int snapBits()
The bit length to be used when 'snapping' new to existing shades.

Default is 9.

See Also:
Shade.snapRGB(int)