package org.simantics.district.network.visualisations.model; import java.awt.Color; import java.util.Arrays; import java.util.List; public class DynamicColorMap { static List blues = Arrays.asList(new RGBIntensity(0, 0, 0.1), new RGBIntensity(0, 0, 0.5), new RGBIntensity(0, 0, 0.9)); public static final DynamicColorMap DEFAULT = new DynamicColorMap("default", blues); private String label; private List intensities; public DynamicColorMap(String label, List intensities) { this.label = label; this.intensities = intensities; } public String getLabel() { return label; } public List getIntensities() { return intensities; } public static class RGBIntensity { private double red; private double green; private double blue; public RGBIntensity(double red, double green, double blue) { this.red = red; this.green = green; this.blue = blue; } public double getRed() { return red; } public double getGreen() { return green; } public double getBlue() { return blue; } } public Color getColor(double value, double defaultMin, double defaultMax) { double gap = defaultMax - defaultMin; double singleGap = gap / getIntensities().size(); int i = 0; while (i < getIntensities().size() - 1) { if (value <= defaultMin + (i * singleGap)) { break; } i++; } RGBIntensity intensity = getIntensities().get(i); return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue()); } }