Created net.mograsim.preferences
[Mograsim.git] / net.mograsim.preferences / src / net / mograsim / preferences / ColorDefinition.java
1 package net.mograsim.preferences;
2
3 /**
4  * A way to define a color with the possibility to use colors built into the system (called "system colors" in SWT).
5  * <p>
6  * A {@link ColorDefinition} is defined either by a {@link BuiltInColor} constant, in which case <code>r==g==b==-1</code>, or by red / green
7  * / blue components, in which case <code>builtInColor==null</code>
8  * 
9  * @author Daniel Kirschten
10  */
11 public class ColorDefinition
12 {
13         /**
14          * The built-in color constant defining this color.
15          */
16         public final ColorDefinition.BuiltInColor builtInColor;
17         /**
18          * The red color component defining this color.
19          */
20         public final int r;
21         /**
22          * The green color component defining this color.
23          */
24         public final int g;
25         /**
26          * The blue color component defining this color.
27          */
28         public final int b;
29
30         public ColorDefinition(ColorDefinition.BuiltInColor col)
31         {
32                 if (col == null)
33                         throw new IllegalArgumentException("Illegal built-in color: " + col);
34                 this.builtInColor = col;
35                 this.r = -1;
36                 this.g = -1;
37                 this.b = -1;
38         }
39
40         public ColorDefinition(int r, int g, int b)
41         {
42                 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
43                         throw new IllegalArgumentException("Illegal color components: r=" + r + "; g=" + g + "; b=" + b);
44                 this.builtInColor = null;
45                 this.r = r;
46                 this.g = g;
47                 this.b = b;
48         }
49
50         public static enum BuiltInColor
51         {
52                 COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_DARK_RED, COLOR_GREEN, COLOR_DARK_GREEN, COLOR_YELLOW, COLOR_DARK_YELLOW, COLOR_BLUE,
53                 COLOR_DARK_BLUE, COLOR_MAGENTA, COLOR_DARK_MAGENTA, COLOR_CYAN, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY;
54         }
55
56 }