mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-11 06:40:53 +00:00
extracted HTML-mapping of colors into abstract color class
This commit is contained in:
1 parent
e952f42176
commit
2b472d1c02
3 files changed
+25
-32
No files matched your search
Executable
+23
@@ -0,0 +1,23 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import com.sap.sailing.domain.common.Color;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
|
||||
public abstract class AbstractColor implements Color {
|
||||
private static final long serialVersionUID = 7758884012281863458L;
|
||||
|
||||
@Override
|
||||
public String getAsHtml() {
|
||||
Triple<Integer, Integer, Integer> asRGB = getAsRGB();
|
||||
return "#" + toBrowserHexValue(asRGB.getA()) + toBrowserHexValue(asRGB.getB())
|
||||
+ toBrowserHexValue(asRGB.getC());
|
||||
}
|
||||
|
||||
private static String toBrowserHexValue(int number) {
|
||||
StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
|
||||
while (builder.length() < 2) {
|
||||
builder.append("0");
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
}
|
||||
}
|
||||
+1
-17
@@ -1,6 +1,5 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import com.sap.sailing.domain.common.Color;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
|
||||
/**
|
||||
@@ -9,7 +8,7 @@ import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
*
|
||||
* @author Frank
|
||||
*/
|
||||
public class HSVColor implements Color {
|
||||
public class HSVColor extends AbstractColor {
|
||||
private static final long serialVersionUID = 7602013229606352246L;
|
||||
|
||||
protected float hue;
|
||||
@@ -86,21 +85,6 @@ public class HSVColor implements Color {
|
||||
return RGBColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsHtml() {
|
||||
Triple<Integer, Integer, Integer> asRGB = getAsRGB();
|
||||
return "#" + toBrowserHexValue(asRGB.getA()) + toBrowserHexValue(asRGB.getB())
|
||||
+ toBrowserHexValue(asRGB.getC());
|
||||
}
|
||||
|
||||
private static String toBrowserHexValue(int number) {
|
||||
StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
|
||||
while (builder.length() < 2) {
|
||||
builder.append("0");
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Triple<Float, Float, Float> getAsHSV() {
|
||||
return new Triple<Float, Float, Float>(hue, saturation, brightness);
|
||||
|
||||
+1
-15
@@ -1,13 +1,12 @@
|
||||
package com.sap.sailing.domain.common.impl;
|
||||
|
||||
import com.sap.sailing.domain.common.Color;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
|
||||
/**
|
||||
* A color defined in the RGB color schema
|
||||
* @author Frank
|
||||
*/
|
||||
public class RGBColor implements Color {
|
||||
public class RGBColor extends AbstractColor {
|
||||
private static final long serialVersionUID = -4091876840771631308L;
|
||||
protected int red;
|
||||
protected int green;
|
||||
@@ -78,19 +77,6 @@ public class RGBColor implements Color {
|
||||
return HSVColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsHtml() {
|
||||
return "#" + toBrowserHexValue(red) + toBrowserHexValue(green) + toBrowserHexValue(blue);
|
||||
}
|
||||
|
||||
private static String toBrowserHexValue(int number) {
|
||||
StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
|
||||
while (builder.length() < 2) {
|
||||
builder.append("0");
|
||||
}
|
||||
return builder.toString().toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
Reference in new issue
Block a user