X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.preferences%2Fsrc%2Fnet%2Fmograsim%2Fpreferences%2FColorDefinition.java;fp=plugins%2Fnet.mograsim.preferences%2Fsrc%2Fnet%2Fmograsim%2Fpreferences%2FColorDefinition.java;h=621de5f6f9de140bfd8956c0c7d06779005b0894;hb=7d05144c25daa53e60fc9ed9fd503546a86567f8;hp=0000000000000000000000000000000000000000;hpb=8bed58cd47f4e53a0a83e066d38864aa6875502f;p=Mograsim.git diff --git a/plugins/net.mograsim.preferences/src/net/mograsim/preferences/ColorDefinition.java b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/ColorDefinition.java new file mode 100644 index 00000000..621de5f6 --- /dev/null +++ b/plugins/net.mograsim.preferences/src/net/mograsim/preferences/ColorDefinition.java @@ -0,0 +1,89 @@ +package net.mograsim.preferences; + +/** + * 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 + * + * @author Daniel Kirschten + */ +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; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + b; + result = prime * result + ((builtInColor == null) ? 0 : builtInColor.hashCode()); + result = prime * result + g; + result = prime * result + r; + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ColorDefinition other = (ColorDefinition) obj; + if (b != other.b) + return false; + if (builtInColor != other.builtInColor) + return false; + if (g != other.g) + return false; + if (r != other.r) + return false; + return true; + } + + 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