All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.hansolo.fx.countries.tools.HeatMapBuilder Maven / Gradle / Ivy

package eu.hansolo.fx.countries.tools;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.geometry.Dimension2D;

import java.util.HashMap;


public class HeatMapBuilder> {
    private HashMap properties = new HashMap<>();


    // ******************** Constructors **************************************
    protected HeatMapBuilder() {
    }


    // ******************** Methods *******************************************
    public final static HeatMapBuilder create() {
        return new HeatMapBuilder();
    }

    public final B prefSize(final double WIDTH, final double HEIGHT) {
        return prefSize(new Dimension2D(WIDTH, HEIGHT));
    }

    public final B prefSize(final Dimension2D PREF_SIZE) {
        properties.put("prefSize", new SimpleObjectProperty<>(PREF_SIZE));
        return (B)this;
    }

    public final B width(final double WIDTH) {
        properties.put("width", new SimpleDoubleProperty(WIDTH));
        return (B)this;
    }

    public final B height(final double HEIGHT) {
        properties.put("height", new SimpleDoubleProperty(HEIGHT));
        return (B)this;
    }

    public final B colorMapping(final Mapping COLOR_MAPPING) {
        properties.put("colorMapping", new SimpleObjectProperty<>(COLOR_MAPPING));
        return (B)this;
    }

    public final B spotRadius(final double SPOT_RADIUS) {
        properties.put("spotRadius", new SimpleDoubleProperty(SPOT_RADIUS));
        return (B)this;
    }

    public final B fadeColors(final boolean FADE_COLORS) {
        properties.put("fadeColors", new SimpleBooleanProperty(FADE_COLORS));
        return (B)this;
    }

    public final B heatMapOpacity(final double HEAT_MAP_OPACITY) {
        properties.put("heatMapOpacity", new SimpleDoubleProperty(HEAT_MAP_OPACITY));
        return (B)this;
    }

    public final B opacityDistribution(final OpacityDistribution OPACITY_DISTRIBUTION) {
        properties.put("opacityDistribution", new SimpleObjectProperty<>(OPACITY_DISTRIBUTION));
        return (B)this;
    }

    public final HeatMap build() {
        double              width               = 400;
        double              height              = 400;
        Mapping             colorMapping        = ColorMapping.LIME_YELLOW_RED;
        double              spotRadius          = 15.5;
        boolean             fadeColors          = false;
        double              heatMapOpacity      = 0.5;
        OpacityDistribution opacityDistribution = OpacityDistribution.CUSTOM;

        for (String key : properties.keySet()) {
            if ("prefSize".equals(key)) {
                Dimension2D dim = ((ObjectProperty) properties.get(key)).get();
                width  = dim.getWidth();
                height = dim.getHeight();
            } else if ("width".equals(key)) {
                width = ((DoubleProperty) properties.get(key)).get();
            } else if ("height".equals(key)) {
                height = ((DoubleProperty) properties.get(key)).get();
            } else if ("colorMapping".equals(key)) {
                colorMapping = ((ObjectProperty) properties.get(key)).get();
            } else if ("spotRadius".equals(key)) {
                spotRadius = ((DoubleProperty) properties.get(key)).get();
            } else if ("fadeColors".equals(key)) {
                fadeColors = ((BooleanProperty) properties.get(key)).get();
            } else if ("heatMapOpacity".equals(key)) {
                heatMapOpacity = ((DoubleProperty) properties.get(key)).get();
            } else if ("opacityDistribution".equals(key)) {
                opacityDistribution = ((ObjectProperty) properties.get(key)).get();
            }
        }
        return new HeatMap(width,  height, colorMapping, spotRadius, fadeColors, heatMapOpacity, opacityDistribution);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy