1 package org.simantics.district.network.profile;
3 import java.util.Optional;
5 import org.simantics.db.Resource;
6 import org.simantics.scl.runtime.function.Function1;
9 * @author Tuukka Lehtonen
11 public class DiagramSettings {
13 public final Optional<Function1<Resource, Double>> vertexScaleProperty;
14 public final double vertexScaleGain;
15 public final double vertexScaleBias;
16 public final Optional<Function1<Resource, Double>> edgeThicknessProperty;
17 public final double edgeThicknessGain;
18 public final double edgeThicknessBias;
19 public final Optional<Function1<Resource, Double>> arrowLengthProperty;
20 public final double arrowLengthGain;
21 public final double arrowLengthBias;
22 public final Optional<Function1<Resource, Double>> elementColoringFunction;
23 public final float elementColoringGradientHue;
24 public final float elementColoringGradientSaturation;
25 public final transient ColorGradient coloringGradient;
27 public DiagramSettings(
28 Function1<Resource, Double> vertexScaleProperty, double vertexScaleGain, double vertexScaleBias,
29 Function1<Resource, Double> edgeThicknessProperty, double edgeThicknessGain, double edgeThicknessBias,
30 Function1<Resource, Double> arrowLengthProperty, double arrowLengthGain, double arrowLengthBias,
31 Function1<Resource, Double> elementColoringFunction,
32 float elementColoringGradientHue,
33 float elementColoringGradientSaturation
35 this.vertexScaleProperty = Optional.ofNullable(vertexScaleProperty);
36 this.vertexScaleGain = vertexScaleGain;
37 this.vertexScaleBias = vertexScaleBias;
38 this.edgeThicknessProperty = Optional.ofNullable(edgeThicknessProperty);
39 this.edgeThicknessGain = edgeThicknessGain;
40 this.edgeThicknessBias = edgeThicknessBias;
41 this.arrowLengthProperty = Optional.ofNullable(arrowLengthProperty);
42 this.arrowLengthGain = arrowLengthGain;
43 this.arrowLengthBias = arrowLengthBias;
44 this.elementColoringFunction = Optional.ofNullable(elementColoringFunction);
45 this.elementColoringGradientHue = elementColoringGradientHue;
46 this.elementColoringGradientSaturation = elementColoringGradientSaturation;
47 this.coloringGradient = Colors.cached(
49 elementColoringGradientHue,
50 elementColoringGradientSaturation)
55 public int hashCode() {
58 result = prime * result + edgeThicknessProperty.hashCode();
59 result = prime * result + arrowLengthProperty.hashCode();
61 temp = Double.doubleToLongBits(edgeThicknessGain);
62 result = prime * result + (int) (temp ^ (temp >>> 32));
63 temp = Double.doubleToLongBits(edgeThicknessBias);
64 result = prime * result + (int) (temp ^ (temp >>> 32));
65 temp = Double.doubleToLongBits(arrowLengthGain);
66 result = prime * result + (int) (temp ^ (temp >>> 32));
67 temp = Double.doubleToLongBits(arrowLengthBias);
68 result = prime * result + (int) (temp ^ (temp >>> 32));
69 result = prime * result + vertexScaleProperty.hashCode();
70 temp = Double.doubleToLongBits(vertexScaleGain);
71 result = prime * result + (int) (temp ^ (temp >>> 32));
72 temp = Double.doubleToLongBits(vertexScaleBias);
73 result = prime * result + (int) (temp ^ (temp >>> 32));
74 result = prime * result + elementColoringFunction.hashCode();
75 result = prime * result + Float.floatToIntBits(elementColoringGradientHue);
76 result = prime * result + Float.floatToIntBits(elementColoringGradientSaturation);
81 public boolean equals(Object obj) {
86 if (getClass() != obj.getClass())
88 DiagramSettings other = (DiagramSettings) obj;
89 if (!edgeThicknessProperty.equals(other.edgeThicknessProperty))
91 if (Double.doubleToLongBits(edgeThicknessGain) != Double.doubleToLongBits(other.edgeThicknessGain))
93 if (Double.doubleToLongBits(edgeThicknessBias) != Double.doubleToLongBits(other.edgeThicknessBias))
95 if (!arrowLengthProperty.equals(other.arrowLengthProperty))
97 if (Double.doubleToLongBits(arrowLengthGain) != Double.doubleToLongBits(other.arrowLengthGain))
99 if (Double.doubleToLongBits(arrowLengthBias) != Double.doubleToLongBits(other.arrowLengthBias))
101 if (!vertexScaleProperty.equals(other.vertexScaleProperty))
103 if (Double.doubleToLongBits(vertexScaleGain) != Double.doubleToLongBits(other.vertexScaleGain))
105 if (Double.doubleToLongBits(vertexScaleBias) != Double.doubleToLongBits(other.vertexScaleBias))
107 if (!elementColoringFunction.equals(other.elementColoringFunction))
109 if (Float.floatToIntBits(elementColoringGradientHue) != Float.floatToIntBits(other.elementColoringGradientHue))
111 if (Float.floatToIntBits(elementColoringGradientSaturation) != Float.floatToIntBits(other.elementColoringGradientSaturation))
117 public String toString() {
118 return String.format("DiagramSettings[%s * %f + %f - %s * %f + %f - %s * %f + %f - coloringFunction: %s, hue: %f, saturation: %f]",
119 vertexScaleProperty.toString(), vertexScaleGain, vertexScaleBias,
120 edgeThicknessProperty, edgeThicknessGain, edgeThicknessBias,
121 arrowLengthProperty, arrowLengthGain, arrowLengthBias,
122 elementColoringFunction.toString(),
123 elementColoringGradientHue, elementColoringGradientSaturation