|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.nite.gui.util.ValueColourMap
public class ValueColourMap
A trick: If you have a number of values in a certain dimension, and you want to keep them apart by colouring them differently, you can use a map that gives a distinguishable colour for each known value. If you don't know the values beforehand, it would be nicer and more efficient if the mapping starts out empty, and assigns colours to certain values only when you actually request the colour.
A value colour map maps objects to colours. For each colour there is a
darker foreground variant and a lighter background variant. When you call
getValueColour()
,
getValueTextColour()
, or
getValueBackColour
), the colour
map will check whether it already contains an entry for the specified object.
If so, the object's colour is returned. Otherwise a new colour is created and
the object-colour pair is put in the map.
You can choose to use a global colour map for the entire application
(see getGlobalColourMap()
) or a local colour
map (see getLocalColourMap()
).
When you create a local colour map, you can specify whether the colour map should cycle through a finite set of colours or it should create a new colour for every new object.
If you restart your application and you want to have the same colours for the same objects, make sure that you request the colours in the same order every time and let the map cycle through colours.
Method Summary | |
---|---|
void |
dumpKeys()
For debug purposes only. |
static java.awt.Color |
getColour(java.lang.Object value)
Retrieves the foreground colour for the specified object from the global colour map. |
static ValueColourMap |
getGlobalColourMap()
Returns the global colour map. |
java.util.Set |
getKeys()
|
static ValueColourMap |
getLocalColourMap(boolean cycle)
Creates a new local colour map and returns it. |
java.awt.Color |
getValueBackColour(java.lang.Object value)
Retrieves the background colour for the specified object from this colour map. |
java.awt.Color |
getValueColour(java.lang.Object value)
Returns the foreground colour of the specified object. |
java.awt.Color |
getValueTextColour(java.lang.Object value)
Retrieves the foreground colour for the specified object from this colour map. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static ValueColourMap getGlobalColourMap()
Returns the global colour map. If the global colour map has not been created yet, this method will create it. The global colour map will NOT cycle through colours, but create a new colour for every new object.
public static ValueColourMap getLocalColourMap(boolean cycle)
Creates a new local colour map and returns it. If cycle
is true, the colour map will cycle through a finite set of colours.
Otherwise it will create a new colour for every new object.
cycle
- true if the colour map should cycle through colours, false
otherwise
public static java.awt.Color getColour(java.lang.Object value)
Retrieves the foreground colour for the specified object from the global colour map. If the global colour map has not been created yet, this method will create it. If the map does not contain an entry for the specified object, the object will be mapped to a colour and the object-colour pair is put in the global colour map.
value
- an object
public java.awt.Color getValueColour(java.lang.Object value)
Returns the foreground colour of the specified object. Same as
getValueTextColour()
.
public java.awt.Color getValueTextColour(java.lang.Object value)
Retrieves the foreground colour for the specified object from this colour map. If the map does not contain an entry for the specified object, the object will be mapped to a colour and the object-colour pair is put in the colour map.
value
- an object
public java.awt.Color getValueBackColour(java.lang.Object value)
Retrieves the background colour for the specified object from this colour map. If the map does not contain an entry for the specified object, the object will be mapped to a colour and the object-colour pair is put in the colour map.
value
- an object
public void dumpKeys()
Shows all keys in the global map
public java.util.Set getKeys()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |