package eu.hansolo.enzo.vumeter; import eu.hansolo.enzo.common.Section; import javafx.beans.property.BooleanProperty; import javafx.beans.property.DoubleProperty; import javafx.beans.property.IntegerProperty; import javafx.beans.property.ListProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.Property; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleListProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Dimension2D; import javafx.geometry.Orientation; import java.util.HashMap; import java.util.List; /** * User: hansolo * Date: 04.11.13 * Time: 13:25 */ public class VuMeterBuilder <B extends VuMeterBuilder<B>> { private HashMap<String, Property> properties = new HashMap<>(); // ******************** Constructors ************************************** protected VuMeterBuilder() { } // ******************** Methods ******************************************* public final static VuMeterBuilder create() { return new VuMeterBuilder(); } public final VuMeterBuilder value(final double VALUE) { properties.put("value", new SimpleDoubleProperty(VALUE)); return this; } public final VuMeterBuilder noOfLeds(final int NO_OF_LEDS) { properties.put("noOfLeds", new SimpleIntegerProperty(NO_OF_LEDS)); return this; } public final VuMeterBuilder orientation(final Orientation ORIENTATION) { properties.put("orientation", new SimpleObjectProperty<Orientation>(ORIENTATION)); return this; } public final VuMeterBuilder peakValueVisible(final boolean PEAK_VALUE_VISIBLE) { properties.put("peakValueVisible", new SimpleBooleanProperty(PEAK_VALUE_VISIBLE)); return this; } public final VuMeterBuilder sections(final Section... SECTIONS) { return sections(FXCollections.observableArrayList(SECTIONS)); } public final VuMeterBuilder sections(final List<Section> SECTIONS) { return sections(FXCollections.observableArrayList(SECTIONS)); } public final VuMeterBuilder sections(final ObservableList<Section> SECTIONS) { properties.put("sections", new SimpleListProperty<>(SECTIONS)); return this; } public final VuMeterBuilder styleClass(final String STYLE_CLASS) { properties.put("styleClass", new SimpleStringProperty(STYLE_CLASS)); return this; } public final VuMeterBuilder interactive(final boolean INTERACTIVE) { properties.put("interactive", new SimpleBooleanProperty(INTERACTIVE)); return this; } public final B prefSize(final double WIDTH, final double HEIGHT) { properties.put("prefSize", new SimpleObjectProperty<>(new Dimension2D(WIDTH, HEIGHT))); return (B)this; } public final B minSize(final double WIDTH, final double HEIGHT) { properties.put("minSize", new SimpleObjectProperty<>(new Dimension2D(WIDTH, HEIGHT))); return (B)this; } public final B maxSize(final double WIDTH, final double HEIGHT) { properties.put("maxSize", new SimpleObjectProperty<>(new Dimension2D(WIDTH, HEIGHT))); return (B)this; } public final B prefWidth(final double PREF_WIDTH) { properties.put("prefWidth", new SimpleDoubleProperty(PREF_WIDTH)); return (B)this; } public final B prefHeight(final double PREF_HEIGHT) { properties.put("prefHeight", new SimpleDoubleProperty(PREF_HEIGHT)); return (B)this; } public final B minWidth(final double MIN_WIDTH) { properties.put("minWidth", new SimpleDoubleProperty(MIN_WIDTH)); return (B)this; } public final B minHeight(final double MIN_HEIGHT) { properties.put("minHeight", new SimpleDoubleProperty(MIN_HEIGHT)); return (B)this; } public final B maxWidth(final double MAX_WIDTH) { properties.put("maxWidth", new SimpleDoubleProperty(MAX_WIDTH)); return (B)this; } public final B maxHeight(final double MAX_HEIGHT) { properties.put("maxHeight", new SimpleDoubleProperty(MAX_HEIGHT)); return (B)this; } public final B scaleX(final double SCALE_X) { properties.put("scaleX", new SimpleDoubleProperty(SCALE_X)); return (B)this; } public final B scaleY(final double SCALE_Y) { properties.put("scaleY", new SimpleDoubleProperty(SCALE_Y)); return (B)this; } public final B layoutX(final double LAYOUT_X) { properties.put("layoutX", new SimpleDoubleProperty(LAYOUT_X)); return (B)this; } public final B layoutY(final double LAYOUT_Y) { properties.put("layoutY", new SimpleDoubleProperty(LAYOUT_Y)); return (B)this; } public final B translateX(final double TRANSLATE_X) { properties.put("translateX", new SimpleDoubleProperty(TRANSLATE_X)); return (B)this; } public final B translateY(final double TRANSLATE_Y) { properties.put("translateY", new SimpleDoubleProperty(TRANSLATE_Y)); return (B)this; } public final VuMeter build() { final VuMeter CONTROL = new VuMeter(); for (String key : properties.keySet()) { if ("prefSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); CONTROL.setPrefSize(dim.getWidth(), dim.getHeight()); } else if("minSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); CONTROL.setPrefSize(dim.getWidth(), dim.getHeight()); } else if("maxSize".equals(key)) { Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get(); CONTROL.setPrefSize(dim.getWidth(), dim.getHeight()); } else if("prefWidth".equals(key)) { CONTROL.setPrefWidth(((DoubleProperty) properties.get(key)).get()); } else if("prefHeight".equals(key)) { CONTROL.setPrefHeight(((DoubleProperty) properties.get(key)).get()); } else if("minWidth".equals(key)) { CONTROL.setMinWidth(((DoubleProperty) properties.get(key)).get()); } else if("minHeight".equals(key)) { CONTROL.setMinHeight(((DoubleProperty) properties.get(key)).get()); } else if("maxWidth".equals(key)) { CONTROL.setMaxWidth(((DoubleProperty) properties.get(key)).get()); } else if("maxHeight".equals(key)) { CONTROL.setMaxHeight(((DoubleProperty) properties.get(key)).get()); } else if("scaleX".equals(key)) { CONTROL.setScaleX(((DoubleProperty) properties.get(key)).get()); } else if("scaleY".equals(key)) { CONTROL.setScaleY(((DoubleProperty) properties.get(key)).get()); } else if ("layoutX".equals(key)) { CONTROL.setLayoutX(((DoubleProperty) properties.get(key)).get()); } else if ("layoutY".equals(key)) { CONTROL.setLayoutY(((DoubleProperty) properties.get(key)).get()); } else if ("translateX".equals(key)) { CONTROL.setTranslateX(((DoubleProperty) properties.get(key)).get()); } else if ("translateY".equals(key)) { CONTROL.setTranslateY(((DoubleProperty) properties.get(key)).get()); } else if("styleClass".equals(key)) { CONTROL.getStyleClass().setAll("led", ((StringProperty) properties.get(key)).get()); } else if ("noOfLeds".equals(key)) { CONTROL.setNoOfLeds(((IntegerProperty) properties.get(key)).get()); } else if ("orientation".equals(key)) { CONTROL.setOrientation(((ObjectProperty<Orientation>) properties.get(key)).get()); } else if ("peakValueVisible".equals(key)) { CONTROL.setPeakValueVisible(((BooleanProperty) properties.get(key)).get()); } else if ("value".equals(key)) { CONTROL.setValue(((DoubleProperty) properties.get(key)).get()); } else if ("sections".equals(key)) { CONTROL.setSections(((ListProperty<Section>) properties.get(key)).get()); } else if ("interactive".equals(key)) { CONTROL.setInteractive(((BooleanProperty) properties.get(key)).get()); } } return CONTROL; } }