jfig.gui
Class ColorCache

java.lang.Object
  extended byjfig.gui.ColorCache

public class ColorCache
extends java.lang.Object

singleton to manage colors and FIG color-indices.

This class tries to achieve a more or less transparent mapping between color names (Strings), rgb-values, and the curios color numbers used in the XFIG3.1 file format.

Typically, this class is used only by the attribute editor to set new line and fill colors, and during import of xfig-files into jfig. This is a singleton class. Use getColorCache() to retrieve the one and only ColorCache.

Once the mapping from names or rgb-values to a Java java.awt.Color object has been done, all other editor functions and classes should use these Color objects only.

Note: user colors, once allocated, are preserved when loading a new FIG file. Naturally, all user colors specified in that file override the current settings. This algorithm can lead to an 'inflation' of (unused) user colors. Also note that requesting the same color with different user color indices will result in multiple assignments of the same color. Beware!


Field Summary
static int BLACK
           
static int BLUE
           
static int BLUE2
           
static int BLUE3
           
static int BLUE4
           
static int BROWN2
           
static int BROWN3
           
static int BROWN4
           
static int CYAN
           
static int CYAN2
           
static int CYAN3
           
static int CYAN4
           
static int GOLD
           
static int GREEN
           
static int GREEN2
           
static int GREEN3
           
static int GREEN4
           
static int LTBLUE
           
static int MAGENTA
           
static int MAGENTA2
           
static int MAGENTA3
           
static int MAGENTA4
           
static int PINK
           
static int PINK2
           
static int PINK3
           
static int PINK4
           
static int RED
           
static int RED2
           
static int RED3
           
static int RED4
           
static int WHITE
           
static int YELLOW
           
 
Method Summary
 void clearUserColors()
           
 java.awt.Color get(int i)
           
 java.awt.Color get(int index, int area_fill)
          get(): get a Color for given index and xfig 'area_fill' attribute
 java.awt.Color get(java.lang.String s)
          Return the Color corresponding to String s.
 java.awt.Color get(java.lang.String s, int area_fill)
          get(): get a Color for given name and xfig 'area_fill' attribute
 java.awt.Color getColorAt(int index)
           
static ColorCache getColorCache()
          getColorCache(): retrieve a reference to our global color cache
 java.util.Vector getColorIndices()
          getColorIndices(): Construct and return a Vector with the indices of all currently defined colors.
 java.util.Vector getColorNames()
          getColorNames(): Construct and return a Vector with the names of all currently defined colors.
 int getColorNumber(java.awt.Color c)
           
 java.awt.Color getFIG21Gray(int area_fill)
          get the FIG 2.1 gray value corresponding to the 'area_fill' attribute
 int getFigColorIndex(int index)
           
 int getIndex(java.awt.Color c)
           
 long getTimestamp()
           
 boolean hasUserColors()
           
 int numberOfColors()
           
 void put(java.lang.String s, int i, java.awt.Color c)
          Add a new Color c with Index i and Name s into our Hashtables.
 void putUserColor(int index, int rgb)
           
 int registerUserColor(java.awt.Color c)
          register Color c with this cache: return the Color index, if already in the cache, else add the Color to the cache and return the new index.
 void removeUserColor(int i)
           
 void setDebug(boolean b)
           
 java.awt.Color xfig_area_fill(java.awt.Color c, int area_fill)
          xfig_area_fill(): calculate the new Color corresponding to a given xfig 'area_fill' attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLACK

public static int BLACK

BLUE

public static int BLUE

GREEN

public static int GREEN

CYAN

public static int CYAN

RED

public static int RED

MAGENTA

public static int MAGENTA

YELLOW

public static int YELLOW

WHITE

public static int WHITE

BLUE4

public static int BLUE4

BLUE3

public static int BLUE3

BLUE2

public static int BLUE2

LTBLUE

public static int LTBLUE

GREEN4

public static int GREEN4

GREEN3

public static int GREEN3

GREEN2

public static int GREEN2

CYAN4

public static int CYAN4

CYAN3

public static int CYAN3

CYAN2

public static int CYAN2

RED4

public static int RED4

RED3

public static int RED3

RED2

public static int RED2

MAGENTA4

public static int MAGENTA4

MAGENTA3

public static int MAGENTA3

MAGENTA2

public static int MAGENTA2

BROWN4

public static int BROWN4

BROWN3

public static int BROWN3

BROWN2

public static int BROWN2

PINK4

public static int PINK4

PINK3

public static int PINK3

PINK2

public static int PINK2

PINK

public static int PINK

GOLD

public static int GOLD
Method Detail

getColorCache

public static ColorCache getColorCache()
getColorCache(): retrieve a reference to our global color cache


getTimestamp

public long getTimestamp()

setDebug

public void setDebug(boolean b)

put

public void put(java.lang.String s,
                int i,
                java.awt.Color c)
Add a new Color c with Index i and Name s into our Hashtables. As each call to put changes the contents of this ColorCache, we update our timestamp.


get

public java.awt.Color get(java.lang.String s)
Return the Color corresponding to String s. The calling objects must be prepared to handle the null pointer that will be returned for unknown Colors.


get

public java.awt.Color get(int i)

getIndex

public int getIndex(java.awt.Color c)

getFigColorIndex

public int getFigColorIndex(int index)

getColorAt

public java.awt.Color getColorAt(int index)

numberOfColors

public int numberOfColors()

getColorNames

public java.util.Vector getColorNames()
getColorNames(): Construct and return a Vector with the names of all currently defined colors.


getColorIndices

public java.util.Vector getColorIndices()
getColorIndices(): Construct and return a Vector with the indices of all currently defined colors.


getColorNumber

public int getColorNumber(java.awt.Color c)

get

public java.awt.Color get(java.lang.String s,
                          int area_fill)
get(): get a Color for given name and xfig 'area_fill' attribute


get

public java.awt.Color get(int index,
                          int area_fill)
get(): get a Color for given index and xfig 'area_fill' attribute


xfig_area_fill

public java.awt.Color xfig_area_fill(java.awt.Color c,
                                     int area_fill)
xfig_area_fill(): calculate the new Color corresponding to a given xfig 'area_fill' attribute. This method contains all knowledge about the (ugly) XFIG conventions and codes for mixed colors and fill styles.

jfig does not support XFIG pattern fills (specified by area_fill values >= 20 / 40) and will use orange color as a warning.


getFIG21Gray

public java.awt.Color getFIG21Gray(int area_fill)
get the FIG 2.1 gray value corresponding to the 'area_fill' attribute


putUserColor

public void putUserColor(int index,
                         int rgb)

hasUserColors

public boolean hasUserColors()

registerUserColor

public int registerUserColor(java.awt.Color c)
register Color c with this cache: return the Color index, if already in the cache, else add the Color to the cache and return the new index.


clearUserColors

public void clearUserColors()

removeUserColor

public void removeUserColor(int i)