toxi.color
Class ColorList

java.lang.Object
  extended by toxi.color.ColorList
All Implemented Interfaces:
java.lang.Iterable<Color>

public class ColorList
extends java.lang.Object
implements java.lang.Iterable<Color>


Field Summary
protected  java.util.ArrayList<Color> colors
           
 
Constructor Summary
ColorList()
          Creates an empty list.
ColorList(java.util.ArrayList<Color> colours)
          Creates a ColorList by wrapping the given ArrayList of colours.
ColorList(Color c)
          Creates a color list with the supplied color as first entry.
ColorList(Color[] colourArray)
          Creates new ColorList from the given array of colors.
ColorList(ColorList list)
          Creates a deep copy of the given ColorList.
ColorList(int[] argbArray)
          Creates a new colour list from the array of ARGB values.
 
Method Summary
 ColorList add(Color c)
          Adds the given color to the list
 ColorList addAll(java.util.Collection<Color> collection)
          Add the all entries of the Color collection to the list.
 ColorList clusterSort(ColorAccessCriteria clusterCriteria, ColorAccessCriteria subClusterCriteria, int numClusters, boolean isReversed)
          Sorts the list based on two criteria to create clusters/segments within the list.
 boolean contains(Color col)
          Checks if the given color is part of the list.
static ColorList createFromARGBArray(int[] pixels, int num, boolean uniqueOnly)
          Creates a new ColorList of colors sampled from the given ARGB image array.
static ColorList createUsingStrategy(ColorTheoryStrategy strategy, Color c)
          Creates a ColorList based on the ColorTheoryStrategy instance and the given source color.
static ColorList createUsingStrategy(java.lang.String name, Color c)
          Creates a ColorList based on the ColorTheoryStrategy name and the given source color.
 Color get(int i)
          Returns the color at the given index.
 Color getAverage()
          Calculates and returns the average color of the list.
 ColorList getBlended(float amount)
          Creates a new ColorList by blending all colors in the list with each other (successive indices only)
 Color getDarkest()
          Finds and returns the darkest color of the list.
 Color getLightest()
          Finds and returns the lightest color of the list.
 ColorList getReverse()
          Returns a reversed copy of the current list.
 java.util.Iterator<Color> iterator()
          Returns an iterator over the internal list.
 ColorList reverse()
          Reverses the current order of the list.
 ColorList sort()
          Convenience method.
protected  ColorList sortByComparator(java.util.Comparator<Color> comp, boolean isReversed)
          Sorts the list using the given comparator.
 ColorList sortByCriteria(ColorAccessCriteria criteria, boolean isReversed)
          Sorts the list using the given ColorAccessCriteria.
 ColorList sortByDistance(boolean isReversed)
          Sorts the list by relative distance to each predecessor, starting with the darkest colour in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colors

protected java.util.ArrayList<Color> colors
Constructor Detail

ColorList

public ColorList()
Creates an empty list.


ColorList

public ColorList(Color c)
Creates a color list with the supplied color as first entry.

Parameters:
c - color

ColorList

public ColorList(ColorList list)
Creates a deep copy of the given ColorList.

Parameters:
list - source list

ColorList

public ColorList(java.util.ArrayList<Color> colours)
Creates a ColorList by wrapping the given ArrayList of colours.

Parameters:
colours -

ColorList

public ColorList(Color[] colourArray)
Creates new ColorList from the given array of colors.

Parameters:
colourArray -

ColorList

public ColorList(int[] argbArray)
Creates a new colour list from the array of ARGB values.

Parameters:
argbArray -
Method Detail

iterator

public java.util.Iterator<Color> iterator()
Returns an iterator over the internal list.

Specified by:
iterator in interface java.lang.Iterable<Color>
Returns:

createUsingStrategy

public static final ColorList createUsingStrategy(ColorTheoryStrategy strategy,
                                                  Color c)
Creates a ColorList based on the ColorTheoryStrategy instance and the given source color.

Parameters:
strategy -
c -
Returns:

createUsingStrategy

public static final ColorList createUsingStrategy(java.lang.String name,
                                                  Color c)
Creates a ColorList based on the ColorTheoryStrategy name and the given source color.

Parameters:
name -
c -
Returns:
new color list of null, if the supplied strategy name is not mapped to a registered implementation.

createFromARGBArray

public static final ColorList createFromARGBArray(int[] pixels,
                                                  int num,
                                                  boolean uniqueOnly)
Creates a new ColorList of colors sampled from the given ARGB image array.

Parameters:
pixels -
num - number of colors samples (clipped automatically to number of pixels in the image)
uniqueOnly - flag if only unique samples are to be taken (doesn't guarantee unique colors though)
Returns:
new color list

add

public ColorList add(Color c)
Adds the given color to the list

Parameters:
c -
Returns:
itself

addAll

public ColorList addAll(java.util.Collection<Color> collection)
Add the all entries of the Color collection to the list.

Parameters:
collection -
Returns:
itself

getDarkest

public Color getDarkest()
Finds and returns the darkest color of the list.

Returns:
darkest color or null if there're no entries yet.

getLightest

public Color getLightest()
Finds and returns the lightest color of the list.

Returns:
lightest color or null, if there're no entries yet.

getAverage

public Color getAverage()
Calculates and returns the average color of the list.

Returns:
average color or null, if there're no entries yet.

getBlended

public ColorList getBlended(float amount)
Creates a new ColorList by blending all colors in the list with each other (successive indices only)

Parameters:
amount - blend amount
Returns:
new color list

sortByDistance

public ColorList sortByDistance(boolean isReversed)
Sorts the list by relative distance to each predecessor, starting with the darkest colour in the list.

Parameters:
isReversed - true, if list is to be sorted in reverse.
Returns:
itself

sortByComparator

protected ColorList sortByComparator(java.util.Comparator<Color> comp,
                                     boolean isReversed)
Sorts the list using the given comparator.

Parameters:
comp -
isReversed -
Returns:
itself

sortByCriteria

public ColorList sortByCriteria(ColorAccessCriteria criteria,
                                boolean isReversed)
Sorts the list using the given ColorAccessCriteria.

Parameters:
criteria -
isReversed -
Returns:
itself

sort

public ColorList sort()
Convenience method. Sorts the list by hue.

Returns:
itself

clusterSort

public ColorList clusterSort(ColorAccessCriteria clusterCriteria,
                             ColorAccessCriteria subClusterCriteria,
                             int numClusters,
                             boolean isReversed)
Sorts the list based on two criteria to create clusters/segments within the list.

Parameters:
clusterCriteria -
subClusterCriteria -
numClusters -
isReversed -
Returns:

reverse

public ColorList reverse()
Reverses the current order of the list.

Returns:
itself

getReverse

public ColorList getReverse()
Returns a reversed copy of the current list.

Returns:

get

public Color get(int i)
Returns the color at the given index.

Parameters:
i -
Returns:

contains

public boolean contains(Color col)
Checks if the given color is part of the list. Check is done by value, not instance.

Parameters:
col -
Returns:
true, if the color is present.