summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-26 15:51:31 +0200
committerSimon Rettberg2015-08-26 15:51:31 +0200
commit025699e6fe0abf7266704696231d2e841694d60b (patch)
treef6e183a1af4b7f54f6233be957b4c5ee90a6061b /dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper
parent[client] LectureImageList Page for Wizard (diff)
downloadtutor-module-025699e6fe0abf7266704696231d2e841694d60b.tar.gz
tutor-module-025699e6fe0abf7266704696231d2e841694d60b.tar.xz
tutor-module-025699e6fe0abf7266704696231d2e841694d60b.zip
[client] Simplify ListTable interfaces, add util class for color handling
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ColorUtil.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ColorUtil.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ColorUtil.java
new file mode 100644
index 00000000..6b30a8cd
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ColorUtil.java
@@ -0,0 +1,59 @@
+package org.openslx.dozmod.gui.helper;
+
+import java.awt.Color;
+
+public class ColorUtil {
+
+ private static float[] squared(Color color) {
+ float[] vals = color.getRGBComponents(null);
+ vals[0] *= vals[0];
+ vals[1] *= vals[1];
+ vals[2] *= vals[2];
+ return vals;
+ }
+
+ private static Color sqrt(float... floatVals) {
+ floatVals[0] = (float) Math.sqrt(floatVals[0]);
+ floatVals[1] = (float) Math.sqrt(floatVals[1]);
+ floatVals[2] = (float) Math.sqrt(floatVals[2]);
+ return new Color(floatVals[0], floatVals[1], floatVals[2]);
+ }
+
+ public static Color blendFast(Color color1, Color color2, float wc1) {
+ float[] c1 = color1.getColorComponents(null);
+ float[] c2 = color2.getColorComponents(null);
+ float wc2 = 1f - wc1;
+ return new Color(c1[0] * wc1 + c2[0] * wc2, c1[1] * wc1 + c2[1] * wc2, c1[2] * wc1 + c2[2] * wc2);
+ }
+
+ public static Color blend(Color color1, Color color2, float wc1) {
+ float[] c1 = squared(color1);
+ float[] c2 = squared(color2);
+ float wc2 = 1f - wc1;
+ return sqrt(c1[0] * wc1 + c2[0] * wc2, c1[1] * wc1 + c2[1] * wc2, c1[2] * wc1 + c2[2] * wc2);
+ }
+
+ public static Color add(Color color1, Color color2, float wc1) {
+ float[] c1 = squared(color1);
+ float[] c2 = squared(color2);
+ c1[0] += c2[0];
+ c1[1] += c2[1];
+ c1[2] += c2[2];
+ float max = Math.max(Math.max(c1[0], c1[1]), c1[2]);
+ if (max > 1f) {
+ c1[0] /= max;
+ c1[1] /= max;
+ c1[2] /= max;
+ }
+ return sqrt(c1[0], c1[1], c1[2]);
+ }
+
+ public static float getBrightness(Color color) {
+ return Color.RGBtoHSB(color.getRed(), color.getBlue(), color.getGreen(), null)[2];
+ }
+
+ public static Color contrastColor(Color color) {
+ return new Color(color.getRed() ^ 0x80, color.getGreen() ^ 0x80, color.getBlue() ^ 0x80);
+ }
+
+}