X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FColorDefinition.java;fp=era.mi%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FColorDefinition.java;h=2801736200e01c9a7f0decc843213205cf099ee1;hb=0009789a8df6b8d4562b6e1cbfa75102a7516ea8;hp=0000000000000000000000000000000000000000;hpb=a28f7aa0dab4248e99159c5a647676170cb17a4e;p=Mograsim.git diff --git a/era.mi/src/net/mograsim/logic/core/types/ColorDefinition.java b/era.mi/src/net/mograsim/logic/core/types/ColorDefinition.java new file mode 100644 index 00000000..28017362 --- /dev/null +++ b/era.mi/src/net/mograsim/logic/core/types/ColorDefinition.java @@ -0,0 +1,54 @@ +package net.mograsim.logic.core.types; + +/** + * A way to define a color with the possibility to use colors built into the system (called "system colors" in SWT). + *

+ * A {@link ColorDefinition} is defined either by a {@link BuiltInColor} constant, in which case r==g==b==-1, or by red / green + * / blue components, in which case builtInColor==null + */ +public class ColorDefinition +{ + /** + * The built-in color constant defining this color. + */ + public final ColorDefinition.BuiltInColor builtInColor; + /** + * The red color component defining this color. + */ + public final int r; + /** + * The green color component defining this color. + */ + public final int g; + /** + * The blue color component defining this color. + */ + public final int b; + + public ColorDefinition(ColorDefinition.BuiltInColor col) + { + if (col == null) + throw new IllegalArgumentException("Illegal built-in color: " + col); + this.builtInColor = col; + this.r = -1; + this.g = -1; + this.b = -1; + } + + public ColorDefinition(int r, int g, int b) + { + if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) + throw new IllegalArgumentException("Illegal color components: r=" + r + "; g=" + g + "; b=" + b); + this.builtInColor = null; + this.r = r; + this.g = g; + this.b = b; + } + + public static enum BuiltInColor + { + COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_DARK_RED, COLOR_GREEN, COLOR_DARK_GREEN, COLOR_YELLOW, COLOR_DARK_YELLOW, COLOR_BLUE, + COLOR_DARK_BLUE, COLOR_MAGENTA, COLOR_DARK_MAGENTA, COLOR_CYAN, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY; + } + +} \ No newline at end of file