X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=era.mi%2Fsrc%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FColorDefinition.java;fp=era.mi%2Fsrc%2Fmograsim%2Flogic%2Fcore%2Ftypes%2FColorDefinition.java;h=7d69837a0cdc6a5e65347408977f740765564adc;hb=a28f7aa0dab4248e99159c5a647676170cb17a4e;hp=0000000000000000000000000000000000000000;hpb=80bfbd8ebf0ad8a7ad98584544a0c73f43e6f3b6;p=Mograsim.git diff --git a/era.mi/src/mograsim/logic/core/types/ColorDefinition.java b/era.mi/src/mograsim/logic/core/types/ColorDefinition.java new file mode 100644 index 00000000..7d69837a --- /dev/null +++ b/era.mi/src/mograsim/logic/core/types/ColorDefinition.java @@ -0,0 +1,54 @@ +package 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