-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
AbstractHSLFunction.java
97 lines (85 loc) · 3.14 KB
/
AbstractHSLFunction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2017, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.filter.function.color;
import static org.geotools.filter.capability.FunctionNameImpl.parameter;
import java.awt.Color;
import java.util.Iterator;
import java.util.List;
import org.geotools.api.filter.capability.FunctionName;
import org.geotools.filter.FunctionImpl;
import org.geotools.filter.capability.FunctionNameImpl;
/**
* Base for lesscss.org HSL color manipulation functions
*
* @author Andrea Aime - GeoSolutions
*/
public abstract class AbstractHSLFunction extends FunctionImpl {
enum Method {
absolute,
relative
};
public static FunctionName NAME =
new FunctionNameImpl(
"abstractHSL",
parameter("result", Color.class),
parameter("color", Color.class),
parameter("amount", Float.class),
parameter("method", Method.class, 0, 1));
public AbstractHSLFunction(String name) {
this.functionName = new FunctionNameImpl(name, NAME.getReturn(), NAME.getArguments());
}
@Override
public Object evaluate(Object object) {
Color source = (Color) getParameterValue(object, 0);
float amount = (Float) getParameterValue(object, 1);
Method method = (Method) getParameterValue(object, 2, Method.absolute);
HSLColor hsl = new HSLColor(source);
if (method == Method.absolute) {
adjustAbsolute(amount, hsl);
} else {
adjustRelative(amount, hsl);
}
return hsl.toRGB();
}
protected abstract void adjustRelative(float amount, HSLColor hsl);
protected abstract void adjustAbsolute(float amount, HSLColor hsl);
/**
* Creates a String representation of this Function with the function name and the arguments.
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getName());
sb.append("(");
List<org.geotools.api.filter.expression.Expression> params = getParameters();
if (params != null) {
org.geotools.api.filter.expression.Expression exp;
for (Iterator<org.geotools.api.filter.expression.Expression> it = params.iterator();
it.hasNext(); ) {
exp = it.next();
sb.append("[");
sb.append(exp);
sb.append("]");
if (it.hasNext()) {
sb.append(", ");
}
}
}
sb.append(")");
return sb.toString();
}
}