Search in sources :

Example 11 with Section

use of eu.hansolo.enzo.common.Section in project Board-Instrumentation-Framework by intel.

the class DemoSimpleGauge method init.

@Override
public void init() {
    thermoMeter = SimpleGaugeBuilder.create().prefSize(400, 400).sections(new Section(0, 16.66666, "0"), new Section(16.66666, 33.33333, "1"), new Section(33.33333, 50.0, "2"), new Section(50.0, 66.66666, "3"), new Section(66.66666, 83.33333, "4"), new Section(83.33333, 100.0, "5")).title("Temperature").unit("C").value(20).styleClass(SimpleGauge.STYLE_CLASS_GREEN_TO_RED_6).build();
    wattMeter = SimpleGaugeBuilder.create().prefSize(400, 400).sections(new Section(0, 16.66666, "0"), new Section(16.66666, 33.33333, "1"), new Section(33.33333, 50.0, "2"), new Section(50.0, 66.66666, "3"), new Section(66.66666, 83.33333, "4"), new Section(83.33333, 100.0, "5")).unit("W").measuredRangeVisible(true).rangeFill(Color.rgb(0, 0, 200, 0.5)).styleClass(SimpleGauge.STYLE_CLASS_GREEN_TO_DARKGREEN_6).build();
    energyMeter = SimpleGaugeBuilder.create().prefSize(400, 400).sections(new Section(0, 10, "A++"), new Section(10, 20, "A+"), new Section(20, 30, "A"), new Section(30, 40, "B"), new Section(40, 50, "C"), new Section(50, 60, "D"), new Section(60, 70, "E"), new Section(70, 80, "F"), new Section(80, 90, "G"), new Section(90, 100, "H")).sectionTextVisible(true).unit("W").styleClass(SimpleGauge.STYLE_CLASS_GREEN_TO_RED_10).build();
    lastTimerCall = System.nanoTime() + 2_000_000_000l;
    timer = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastTimerCall + 5_000_000_000l) {
                thermoMeter.setValue(RND.nextDouble() * 100);
                wattMeter.setValue(RND.nextDouble() * 100);
                energyMeter.setValue(RND.nextDouble() * 100);
                lastTimerCall = now;
            }
        }
    };
}
Also used : AnimationTimer(javafx.animation.AnimationTimer) Section(eu.hansolo.enzo.common.Section)

Example 12 with Section

use of eu.hansolo.enzo.common.Section in project Board-Instrumentation-Framework by intel.

the class DoubleRadialGauge method registerListeners.

private void registerListeners() {
    sectionsOne.addListener((ListChangeListener<Section>) c -> IntStream.range(0, sectionsOne.size()).parallel().forEachOrdered(i -> {
        Section section = sectionsOne.get(i);
        switch(i) {
            case 0:
                setSectionFill0One(section.getColor());
                break;
            case 1:
                setSectionFill1One(section.getColor());
                break;
            case 2:
                setSectionFill2One(section.getColor());
                break;
            case 3:
                setSectionFill3One(section.getColor());
                break;
            case 4:
                setSectionFill4One(section.getColor());
                break;
        }
    }));
    areasOne.addListener((ListChangeListener<Section>) c -> IntStream.range(0, areasOne.size()).parallel().forEachOrdered(i -> {
        Section area = areasOne.get(i);
        switch(i) {
            case 0:
                setAreaFill0One(area.getColor());
                break;
            case 1:
                setAreaFill1One(area.getColor());
                break;
            case 2:
                setAreaFill2One(area.getColor());
                break;
            case 3:
                setAreaFill3One(area.getColor());
                break;
            case 4:
                setAreaFill4One(area.getColor());
                break;
        }
    }));
    sectionsTwo.addListener((ListChangeListener<Section>) c -> IntStream.range(0, sectionsTwo.size()).parallel().forEachOrdered(i -> {
        Section section = sectionsTwo.get(i);
        switch(i) {
            case 0:
                setSectionFill0Two(section.getColor());
                break;
            case 1:
                setSectionFill1Two(section.getColor());
                break;
            case 2:
                setSectionFill2Two(section.getColor());
                break;
            case 3:
                setSectionFill3Two(section.getColor());
                break;
            case 4:
                setSectionFill4Two(section.getColor());
                break;
        }
    }));
    areasTwo.addListener((ListChangeListener<Section>) c -> IntStream.range(0, areasTwo.size()).parallel().forEachOrdered(i -> {
        Section area = areasTwo.get(i);
        switch(i) {
            case 0:
                setAreaFill0Two(area.getColor());
                break;
            case 1:
                setAreaFill1Two(area.getColor());
                break;
            case 2:
                setAreaFill2Two(area.getColor());
                break;
            case 3:
                setAreaFill3Two(area.getColor());
                break;
            case 4:
                setAreaFill4Two(area.getColor());
                break;
        }
    }));
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) DoubleRadialGaugeSkin(eu.hansolo.enzo.gauge.skin.DoubleRadialGaugeSkin) PseudoClass(javafx.css.PseudoClass) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Control(javafx.scene.control.Control) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) Skin(javafx.scene.control.Skin) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) StyleConverter(javafx.css.StyleConverter) ListChangeListener(javafx.collections.ListChangeListener) Locale(java.util.Locale) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) StyleableProperty(javafx.css.StyleableProperty) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Section(eu.hansolo.enzo.common.Section) CssMetaData(javafx.css.CssMetaData) DecimalFormat(java.text.DecimalFormat) BooleanPropertyBase(javafx.beans.property.BooleanPropertyBase) AnimationTimer(javafx.animation.AnimationTimer) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) List(java.util.List) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) StyleableObjectProperty(javafx.css.StyleableObjectProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Paint(javafx.scene.paint.Paint) DoublePropertyBase(javafx.beans.property.DoublePropertyBase) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) Collections(java.util.Collections) Styleable(javafx.css.Styleable) Section(eu.hansolo.enzo.common.Section)

Example 13 with Section

use of eu.hansolo.enzo.common.Section in project Board-Instrumentation-Framework by intel.

the class SimpleGaugeSkin method drawSections.

private final void drawSections() {
    sectionsCtx.clearRect(0, 0, size, size);
    final double MIN_VALUE = getSkinnable().getMinValue();
    final double MAX_VALUE = getSkinnable().getMaxValue();
    final double OFFSET = getSkinnable().getStartAngle() - 90;
    final int NO_OF_SECTIONS = getSkinnable().getSections().size();
    final double SECTIONS_OFFSET = size * 0.015;
    final double SECTIONS_SIZE = size - (size * 0.03);
    angleStep = getSkinnable().getAngleRange() / (getSkinnable().getMaxValue() - getSkinnable().getMinValue());
    double sinValue;
    double cosValue;
    for (int i = 0; i < NO_OF_SECTIONS; i++) {
        final Section SECTION = getSkinnable().getSections().get(i);
        final double SECTION_START_ANGLE;
        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE)
            continue;
        if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
            SECTION_START_ANGLE = MIN_VALUE * angleStep;
        } else {
            SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
        }
        final double SECTION_ANGLE_EXTEND;
        if (SECTION.getStop() > MAX_VALUE) {
            SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
        } else {
            SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
        }
        sectionsCtx.save();
        switch(i) {
            case 0:
                sectionsCtx.setFill(getSkinnable().getSectionFill0());
                break;
            case 1:
                sectionsCtx.setFill(getSkinnable().getSectionFill1());
                break;
            case 2:
                sectionsCtx.setFill(getSkinnable().getSectionFill2());
                break;
            case 3:
                sectionsCtx.setFill(getSkinnable().getSectionFill3());
                break;
            case 4:
                sectionsCtx.setFill(getSkinnable().getSectionFill4());
                break;
            case 5:
                sectionsCtx.setFill(getSkinnable().getSectionFill5());
                break;
            case 6:
                sectionsCtx.setFill(getSkinnable().getSectionFill6());
                break;
            case 7:
                sectionsCtx.setFill(getSkinnable().getSectionFill7());
                break;
            case 8:
                sectionsCtx.setFill(getSkinnable().getSectionFill8());
                break;
            case 9:
                sectionsCtx.setFill(getSkinnable().getSectionFill9());
                break;
        }
        sectionsCtx.fillArc(SECTIONS_OFFSET, SECTIONS_OFFSET, SECTIONS_SIZE, SECTIONS_SIZE, (OFFSET - SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.ROUND);
        // Draw Section Text
        if (getSkinnable().isSectionTextVisible()) {
            sinValue = -Math.sin(Math.toRadians(OFFSET - 90 - SECTION_START_ANGLE - SECTION_ANGLE_EXTEND * 0.5));
            cosValue = -Math.cos(Math.toRadians(OFFSET - 90 - SECTION_START_ANGLE - SECTION_ANGLE_EXTEND * 0.5));
            Point2D textPoint = new Point2D(size * 0.5 + size * 0.365 * sinValue, size * 0.5 + size * 0.365 * cosValue);
            if (getSkinnable().isCustomFontEnabled()) {
                sectionsCtx.setFont(Font.font(getSkinnable().getCustomFont().getFamily(), FontWeight.NORMAL, 0.08 * size));
            } else {
                sectionsCtx.setFont(Fonts.robotoMedium(0.08 * size));
            }
            sectionsCtx.setTextAlign(TextAlignment.CENTER);
            sectionsCtx.setTextBaseline(VPos.CENTER);
            sectionsCtx.setFill(getSkinnable().getSectionTextColor());
            sectionsCtx.fillText(SECTION.getText(), textPoint.getX(), textPoint.getY());
        }
        // Draw Section Icon
        if (size > 0) {
            if (getSkinnable().isSectionIconVisible() && !getSkinnable().isSectionTextVisible()) {
                if (null != SECTION.getImage()) {
                    Image icon = SECTION.getImage();
                    sinValue = -Math.sin(Math.toRadians(OFFSET - 90 - SECTION_START_ANGLE - SECTION_ANGLE_EXTEND * 0.5));
                    cosValue = -Math.cos(Math.toRadians(OFFSET - 90 - SECTION_START_ANGLE - SECTION_ANGLE_EXTEND * 0.5));
                    Point2D iconPoint = new Point2D(size * 0.5 + size * 0.365 * sinValue, size * 0.5 + size * 0.365 * cosValue);
                    sectionsCtx.drawImage(icon, iconPoint.getX() - size * 0.06, iconPoint.getY() - size * 0.06, size * 0.12, size * 0.12);
                }
            }
        }
        sectionsCtx.restore();
    }
    // Draw white border around area
    sectionsCtx.setStroke(getSkinnable().getBorderColor());
    sectionsCtx.setLineWidth(size * 0.025);
    sectionsCtx.strokeArc(SECTIONS_OFFSET, SECTIONS_OFFSET, SECTIONS_SIZE, SECTIONS_SIZE, OFFSET + 90, getSkinnable().getAngleRange(), ArcType.ROUND);
}
Also used : Point2D(javafx.geometry.Point2D) Image(javafx.scene.image.Image) Section(eu.hansolo.enzo.common.Section) CacheHint(javafx.scene.CacheHint)

Example 14 with Section

use of eu.hansolo.enzo.common.Section in project Board-Instrumentation-Framework by intel.

the class VuMeterBuilder method build.

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;
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Dimension2D(javafx.geometry.Dimension2D) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) DoubleProperty(javafx.beans.property.DoubleProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Section(eu.hansolo.enzo.common.Section)

Example 15 with Section

use of eu.hansolo.enzo.common.Section in project Board-Instrumentation-Framework by intel.

the class VuMeterSkin method initGraphics.

private void initGraphics() {
    hBox = new HBox();
    hBox.getStyleClass().setAll("vu-meter");
    hBox.setSpacing(getSkinnable().getLedSpacing());
    vBox = new VBox();
    vBox.getStyleClass().setAll("vu-meter");
    vBox.setSpacing(getSkinnable().getLedSpacing());
    leds = FXCollections.observableArrayList();
    for (int i = 0; i < getSkinnable().getNoOfLeds(); i++) {
        Region led = new Region();
        led.setOnMouseClicked(new WeakEventHandler<>(event -> active = !active));
        led.setOnMouseEntered(new WeakEventHandler<>(event -> handleMouseEvent(event)));
        if (getSkinnable().getSections().isEmpty()) {
            led.getStyleClass().setAll("led");
        } else {
            for (Section section : getSkinnable().getSections()) {
                if (section.contains(i * stepSize.doubleValue())) {
                    led.getStyleClass().setAll("led", section.getStyleClass());
                }
            }
        }
        leds.add(led);
    }
    if (Orientation.HORIZONTAL == getSkinnable().getOrientation()) {
        vBox.setManaged(false);
        vBox.setVisible(false);
        hBox.getChildren().setAll(leds);
        peakLedIndex = 0;
    } else {
        hBox.setManaged(false);
        hBox.setVisible(false);
        FXCollections.reverse(leds);
        vBox.getChildren().setAll(leds);
        peakLedIndex = leds.size() - 1;
    }
    // Add all nodes
    getChildren().setAll(hBox, vBox);
}
Also used : IntStream(java.util.stream.IntStream) Orientation(javafx.geometry.Orientation) SkinBase(javafx.scene.control.SkinBase) HBox(javafx.scene.layout.HBox) VuMeter(eu.hansolo.enzo.vumeter.VuMeter) Section(eu.hansolo.enzo.common.Section) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) WeakEventHandler(javafx.event.WeakEventHandler) DoubleProperty(javafx.beans.property.DoubleProperty) Skin(javafx.scene.control.Skin) VBox(javafx.scene.layout.VBox) AnimationTimer(javafx.animation.AnimationTimer) Region(javafx.scene.layout.Region) ListChangeListener(javafx.collections.ListChangeListener) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) HBox(javafx.scene.layout.HBox) Region(javafx.scene.layout.Region) VBox(javafx.scene.layout.VBox) Section(eu.hansolo.enzo.common.Section)

Aggregations

Section (eu.hansolo.enzo.common.Section)31 AnimationTimer (javafx.animation.AnimationTimer)10 DoubleProperty (javafx.beans.property.DoubleProperty)8 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)8 Marker (eu.hansolo.enzo.common.Marker)6 IntStream (java.util.stream.IntStream)6 BooleanProperty (javafx.beans.property.BooleanProperty)6 ObjectProperty (javafx.beans.property.ObjectProperty)6 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)6 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)6 StringProperty (javafx.beans.property.StringProperty)6 ListChangeListener (javafx.collections.ListChangeListener)6 Skin (javafx.scene.control.Skin)6 Color (javafx.scene.paint.Color)6 ArrayList (java.util.ArrayList)5 FXCollections (javafx.collections.FXCollections)5 ObservableList (javafx.collections.ObservableList)5 List (java.util.List)4 Locale (java.util.Locale)4