jwo.landserf.structure
Class ColourTable

java.lang.Object
  extended by jwo.landserf.structure.ColourTable
All Implemented Interfaces:
Serializable

public class ColourTable
extends Object
implements Serializable

Colour table class for storing colour rules associated with a spatial object. A colour table can be a set of rules, a 'raw' colour table where each attribute value is a 32 bit colour code (mostly used used for image files), or an 'attribute' table where each attribute is stored in the form of a colour. Most common are colour rules where each rule consists of two indices and associated RGBA colour values. Colours are interpolated for any values that fall between the lower and upper indices.

Version:
2.3, 11th February, 2009.
Author:
Jo Wood
See Also:
Serialized Form

Field Summary
static int ASPECT
          Indicates a (red-blue) aspect colour table.
static int BLACK
          Single black colour
static int COLOUR_ATTRIB
          Uses integer coding of the object's (floating point) attribute.
static int COLOUR_RAW
          Colour table uses raster values.
static int COLOUR_RULES
          Colour table uses colour rules.
static int DEFAULT
          Indicates a default (green-purple-white) colour table.
static int DIVERGING_BLURED
          Diverging blue to red colour table.
static int DIVERGING_BLUYELRED
          Diverging blue through yellow to to red table.
static int DIVERGING_GRNYEL
          Diverging blue to red colour table.
static int EXP_ORRED
          Exponential orange to red colour table.
static int FEATURES
          Indicates a feature class (black, blue, green, yellow, red ) colour table.
static int GREYSCALE
          Greyscale (black to white) colour table.
static int IMHOF_L1
          Imhof land surface colour scheme (green to beige).
static int IMHOF_L2
          Imhof land surface colour scheme (green to brown).
static int IMHOF_L3
          Imhof land surface colour scheme (green to orange).
static int IMHOF_L4
          Imhof land surface colour scheme (green to white).
static int IMHOF_S1
          Imhof sea colour scheme (blue to white).
static int IMHOF_S2
          Imhof sea colour scheme (dark blue to white).
static int IMHOF_SL
          Imhof sea and land colour scheme (dark blue to brown).
static int INV_GREYSCALE
          Inverted greyscale (white to black) colour table.
static int MSN_FEATURES
          Indicates a feature class (black, blue, green, yellow, red ) colour table.
static int RANDOM
          Random colour scheme for nominal data.
static int SLOPE
          Indicates a slope (white - yellow - black) colour table.
 
Constructor Summary
ColourTable()
          Creates an initial (black) colour table.
ColourTable(ColourTable oldColourTable)
          Creates a colour table based on a copy of a colour table.
 
Method Summary
 void addContinuousColourRule(float index, int colour)
          Adds a continuous colour rule to the colour table.
 void addContinuousColourRule(float index, int r, int g, int b)
          Adds a continuous colour rule to the colour table.
 void addContinuousColourRule(float index, int r, int g, int b, int a)
          Adds a continuous colour rule to the colour table.
 void addDiscreteColourRule(float index, int colour)
          Adds a discrete colour rule to the colour table.
 void addDiscreteColourRule(float index, int r, int g, int b)
          Adds a discrete colour rule to the colour table.
 void addDiscreteColourRule(float index, int r, int g, int b, int a)
          Adds a discrete colour rule to the colour table.
static int argbToRgba(int argb)
          Converts an ARGB into an RGBA colour.
 int findColour(float index)
          Interpolates a given index colour from colour rules.
static int getAlpha(int colour)
          Reports the alpha value of the given colour.
 Vector getColourRules()
          Returns the rules associated with the colour table
 int getColourTableType()
          Reports type of colour table (COLOUR_RULES, COLOUR_ATTRIB or COLOUR_RAW).
static String getHexString(int colour)
          Converts a given colour into its HTML-like hex string in the form #rrggbb.
static String getHexStringABGR(int colour)
          Converts a given colour into its hex string in the form aabbggrr.
 float getMaxIndex()
          Finds the highest index value in a set of colour rules.
 float getMinIndex()
          Finds the lowest index value in a set of colour rules.
static ColourTable getPresetColourTable(int type)
          Creates a preset colour table scaled between default minimum and maximum values.
static ColourTable getPresetColourTable(int type, float min, float max)
          Creates a preset colour table between the given values.
 boolean modifyColourRule(float existingIndex, float newIndex, int newColour, int newType)
          Modifies the rule with the existing index to use the given index and colour.
static ColourTable readFile(InputStream inStream)
          Creates a colour table from the rules defined in the given input stream.
static ColourTable readFile(String fileName)
          Creates a colour table from the rules defined in the file with the given name.
 boolean removeColourRule(float index)
          Removes the rule with the given lower index.
static int rgbaToArgb(int rgba)
          Converts an RGBA into an ARGB colour.
 void setColourTableType(int cTableType)
          Sets the type of colour table (COLOUR_RULES, COLOUR_ATTRIB or COLOUR_RAW).
 ListModel toListModel()
          Converts the colour rules into a ListModel suitable for display by GUI JLists or JTables.
 String toString()
          Reports the current colour table rules.
 String[] toStringArray()
          Reports the current colour table rules.
static boolean writeFile(ColourTable colourTable, OutputStream outStream)
          Writes the given colour table out as a file using the given output stream.
static boolean writeFile(ColourTable colourTable, String fileName)
          Writes the given colour table out as a file using the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COLOUR_RULES

public static final int COLOUR_RULES
Colour table uses colour rules.

See Also:
Constant Field Values

COLOUR_RAW

public static final int COLOUR_RAW
Colour table uses raster values.

See Also:
Constant Field Values

COLOUR_ATTRIB

public static final int COLOUR_ATTRIB
Uses integer coding of the object's (floating point) attribute. Not for display, this table allows graphical buffers to preserve attributes of any object displayed using this colour scheme.

See Also:
Constant Field Values

DEFAULT

public static final int DEFAULT
Indicates a default (green-purple-white) colour table.

See Also:
Constant Field Values

FEATURES

public static final int FEATURES
Indicates a feature class (black, blue, green, yellow, red ) colour table.

See Also:
Constant Field Values

MSN_FEATURES

public static final int MSN_FEATURES
Indicates a feature class (black, blue, green, yellow, red ) colour table.

See Also:
Constant Field Values

SLOPE

public static final int SLOPE
Indicates a slope (white - yellow - black) colour table.

See Also:
Constant Field Values

ASPECT

public static final int ASPECT
Indicates a (red-blue) aspect colour table.

See Also:
Constant Field Values

DIVERGING_BLURED

public static final int DIVERGING_BLURED
Diverging blue to red colour table. Used for ProfC surfaces.

See Also:
Constant Field Values

DIVERGING_GRNYEL

public static final int DIVERGING_GRNYEL
Diverging blue to red colour table. Used for ProfC surfaces.

See Also:
Constant Field Values

DIVERGING_BLUYELRED

public static final int DIVERGING_BLUYELRED
Diverging blue through yellow to to red table. Based on Color Brewer's 'RdYlBu' diverging colour scheme.

See Also:
Constant Field Values

GREYSCALE

public static final int GREYSCALE
Greyscale (black to white) colour table.

See Also:
Constant Field Values

INV_GREYSCALE

public static final int INV_GREYSCALE
Inverted greyscale (white to black) colour table.

See Also:
Constant Field Values

IMHOF_L1

public static final int IMHOF_L1
Imhof land surface colour scheme (green to beige).

See Also:
Constant Field Values

IMHOF_L2

public static final int IMHOF_L2
Imhof land surface colour scheme (green to brown).

See Also:
Constant Field Values

IMHOF_L3

public static final int IMHOF_L3
Imhof land surface colour scheme (green to orange).

See Also:
Constant Field Values

IMHOF_L4

public static final int IMHOF_L4
Imhof land surface colour scheme (green to white).

See Also:
Constant Field Values

IMHOF_S1

public static final int IMHOF_S1
Imhof sea colour scheme (blue to white).

See Also:
Constant Field Values

IMHOF_S2

public static final int IMHOF_S2
Imhof sea colour scheme (dark blue to white).

See Also:
Constant Field Values

IMHOF_SL

public static final int IMHOF_SL
Imhof sea and land colour scheme (dark blue to brown).

See Also:
Constant Field Values

EXP_ORRED

public static final int EXP_ORRED
Exponential orange to red colour table. Based in Color Brewer's 'OrRd' nine-sequence colour scheme.

See Also:
Constant Field Values

RANDOM

public static final int RANDOM
Random colour scheme for nominal data.

See Also:
Constant Field Values

BLACK

public static final int BLACK
Single black colour

See Also:
Constant Field Values
Constructor Detail

ColourTable

public ColourTable()
Creates an initial (black) colour table.


ColourTable

public ColourTable(ColourTable oldColourTable)
Creates a colour table based on a copy of a colour table.

Parameters:
oldColourTable - Old colour table to copy.
Method Detail

addDiscreteColourRule

public void addDiscreteColourRule(float index,
                                  int r,
                                  int g,
                                  int b)
Adds a discrete colour rule to the colour table.

Parameters:
index - Index value associated with rule.
r - Red colour component (scaled between 0-255) associated with index.
g - Green colour component (scaled between 0-255) associated with index.
b - Blue colour component (scaled between 0-255) associated with index.

addDiscreteColourRule

public void addDiscreteColourRule(float index,
                                  int r,
                                  int g,
                                  int b,
                                  int a)
Adds a discrete colour rule to the colour table.

Parameters:
index - Index value associated with rule.
r - Red colour component (scaled between 0-255) associated with index.
g - Green colour component (scaled between 0-255) associated with index.
b - Blue colour component (scaled between 0-255) associated with index.
a - Alpha (opacity) component (scaled between 0-255) associated with index.

addDiscreteColourRule

public void addDiscreteColourRule(float index,
                                  int colour)
Adds a discrete colour rule to the colour table. Combined RGBA version.

Parameters:
index - Index value associated with rule.
colour - Colour value associated with index.

addContinuousColourRule

public void addContinuousColourRule(float index,
                                    int r,
                                    int g,
                                    int b)
Adds a continuous colour rule to the colour table.

Parameters:
index - Index value associated with rule.
r - Red colour component (scaled between 0-255) associated with index.
g - Green colour component (scaled between 0-255) associated with index.
b - Blue colour component (scaled between 0-255) associated with index.

addContinuousColourRule

public void addContinuousColourRule(float index,
                                    int r,
                                    int g,
                                    int b,
                                    int a)
Adds a continuous colour rule to the colour table.

Parameters:
index - Index value associated with rule.
r - Red colour component (scaled between 0-255) associated with index.
g - Green colour component (scaled between 0-255) associated with index.
b - Blue colour component (scaled between 0-255) associated with index.
a - Alpha (opacity) component (scaled between 0-255) associated with index.

addContinuousColourRule

public void addContinuousColourRule(float index,
                                    int colour)
Adds a continuous colour rule to the colour table. Combined RGBA version.

Parameters:
index - Index value associated with rule.
colour - Colour value associated with index.

removeColourRule

public boolean removeColourRule(float index)
Removes the rule with the given lower index.

Parameters:
index - Lower index identifying rule to remove.
Returns:
True if rule with given lower index found and removed.

modifyColourRule

public boolean modifyColourRule(float existingIndex,
                                float newIndex,
                                int newColour,
                                int newType)
Modifies the rule with the existing index to use the given index and colour.

Parameters:
existingIndex - Index value associated with rule.
newIndex - New index value associated with rule.
newColour - Colour value associated with index.
newType - New type of rule (either DISCRETE or CONTINUOUS).
Returns:
True if rule with given index found.

findColour

public int findColour(float index)
Interpolates a given index colour from colour rules.

Parameters:
index - Index to associated interpolated colour with.
Returns:
Interpolated colour.

getMinIndex

public float getMinIndex()
Finds the lowest index value in a set of colour rules.

Returns:
Minimum index value.

getMaxIndex

public float getMaxIndex()
Finds the highest index value in a set of colour rules.

Returns:
Maximum index value.

toString

public String toString()
Reports the current colour table rules.

Overrides:
toString in class Object
Returns:
String containing current colour table.

toStringArray

public String[] toStringArray()
Reports the current colour table rules.

Returns:
String containing current colour table.

toListModel

public ListModel toListModel()
Converts the colour rules into a ListModel suitable for display by GUI JLists or JTables. If colour table is not empty, each element is a ColourRule and so can perform detailed query of its colours and indices. If it is empty, the list model will contain a single string indicating table is empty.

Returns:
ListModel representation of the colour rules.

getColourTableType

public int getColourTableType()
Reports type of colour table (COLOUR_RULES, COLOUR_ATTRIB or COLOUR_RAW).

Returns:
Type of colour table.

setColourTableType

public void setColourTableType(int cTableType)
Sets the type of colour table (COLOUR_RULES, COLOUR_ATTRIB or COLOUR_RAW).

Parameters:
cTableType - Type of colour table.

getColourRules

public Vector getColourRules()
Returns the rules associated with the colour table

Returns:
Ordered list of colour table rules.

rgbaToArgb

public static int rgbaToArgb(int rgba)
Converts an RGBA into an ARGB colour.

Parameters:
rgba - RGBA format colour.
Returns:
ARGB format colour.

argbToRgba

public static int argbToRgba(int argb)
Converts an ARGB into an RGBA colour.

Parameters:
argb - ARGB format colour.
Returns:
RGBA format colour.

getHexString

public static String getHexString(int colour)
Converts a given colour into its HTML-like hex string in the form #rrggbb.

Parameters:
colour - Colour to convert.
Returns:
HTML hex string representing colour.

getHexStringABGR

public static String getHexStringABGR(int colour)
Converts a given colour into its hex string in the form aabbggrr.

Parameters:
colour - Colour to convert.
Returns:
Hex string representing colour.

getAlpha

public static int getAlpha(int colour)
Reports the alpha value of the given colour.

Parameters:
colour - Colour to query.
Returns:
Alpha value of the colour (scaled from 0 (transparent) to 255 (opaque).

getPresetColourTable

public static ColourTable getPresetColourTable(int type)
Creates a preset colour table scaled between default minimum and maximum values.

Parameters:
type - Type of colour table to create (DEFAULT, GREYSCALE, SLOPE etc.).
Returns:
New colour table.

getPresetColourTable

public static ColourTable getPresetColourTable(int type,
                                               float min,
                                               float max)
Creates a preset colour table between the given values.

Parameters:
type - Type of colour table to create (DEFAULT, GREYSCALE, SLOPE etc.).
min - Minimum value.
max - Maximum value.
Returns:
Colour table scaled between given min and max values.

readFile

public static ColourTable readFile(String fileName)
Creates a colour table from the rules defined in the file with the given name. The file should be a landSerf colour table file containing XML defining a set of colour rules. This can be created using the writeFile() method.

Parameters:
fileName - Name of file containing rules.
Returns:
Colour table created or null if problems creating table from file.

readFile

public static ColourTable readFile(InputStream inStream)
Creates a colour table from the rules defined in the given input stream. The file should be a landSerf colour table file containing XML defining a set of colour rules. This can be created using the writeFile() method.

Parameters:
inStream - Name of file containing rules.
Returns:
Colour table created or null if problems creating table from file.

writeFile

public static boolean writeFile(ColourTable colourTable,
                                String fileName)
Writes the given colour table out as a file using the given name. The file can be read back in using one of the readFile() methods.

Parameters:
colourTable - Colour table to be written.
fileName - Name of file to contain rules.
Returns:
True if file written successfully.

writeFile

public static boolean writeFile(ColourTable colourTable,
                                OutputStream outStream)
Writes the given colour table out as a file using the given output stream. The file can be read back in using one of the readFile() methods.

Parameters:
colourTable - Colour table to be written.
outStream - Output stream of the file to contain rules.
Returns:
True if file written successfully.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009