2801736200e01c9a7f0decc843213205cf099ee1
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / types / ColorDefinition.java
1 package net.mograsim.logic.core.types;
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 public class ColorDefinition
10 {
11         /**
12          * The built-in color constant defining this color.
13          */
14         public final ColorDefinition.BuiltInColor builtInColor;
15         /**
16          * The red color component defining this color.
17          */
18         public final int r;
19         /**
20          * The green color component defining this color.
21          */
22         public final int g;
23         /**
24          * The blue color component defining this color.
25          */
26         public final int b;
27
28         public ColorDefinition(ColorDefinition.BuiltInColor col)
29         {
30                 if (col == null)
31                         throw new IllegalArgumentException("Illegal built-in color: " + col);
32                 this.builtInColor = col;
33                 this.r = -1;
34                 this.g = -1;
35                 this.b = -1;
36         }
37
38         public ColorDefinition(int r, int g, int b)
39         {
40                 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
41                         throw new IllegalArgumentException("Illegal color components: r=" + r + "; g=" + g + "; b=" + b);
42                 this.builtInColor = null;
43                 this.r = r;
44                 this.g = g;
45                 this.b = b;
46         }
47
48         public static enum BuiltInColor
49         {
50                 COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_DARK_RED, COLOR_GREEN, COLOR_DARK_GREEN, COLOR_YELLOW, COLOR_DARK_YELLOW, COLOR_BLUE,
51                 COLOR_DARK_BLUE, COLOR_MAGENTA, COLOR_DARK_MAGENTA, COLOR_CYAN, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY;
52         }
53
54 }