Search in sources :

Example 6 with SequentialTransition

use of javafx.animation.SequentialTransition in project tilesfx by HanSolo.

the class SmoothAreaChartTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    chartEventListener = e -> handleData();
    chartDataListener = c -> {
        while (c.next()) {
            if (c.wasAdded()) {
                c.getAddedSubList().forEach(addedItem -> addedItem.addChartDataEventListener(chartEventListener));
            } else if (c.wasRemoved()) {
                c.getRemoved().forEach(removedItem -> removedItem.removeChartDataEventListener(chartEventListener));
            }
        }
        handleData();
    };
    clickHandler = e -> select(e);
    endOfTransformationHandler = e -> selectorTooltip.hide();
    smoothing = tile.isSmoothing();
    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    fillClip = new Rectangle(0, 0, PREFERRED_WIDTH, PREFERRED_HEIGHT);
    strokeClip = new Rectangle(0, 0, PREFERRED_WIDTH, PREFERRED_HEIGHT);
    points = new ArrayList<>();
    fillPath = new Path();
    fillPath.setStroke(null);
    fillPath.setClip(fillClip);
    strokePath = new Path();
    strokePath.setFill(null);
    strokePath.setStroke(tile.getBarColor());
    strokePath.setClip(strokeClip);
    strokePath.setMouseTransparent(true);
    Helper.enableNode(fillPath, ChartType.AREA == tile.getChartType());
    canvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    canvas.setMouseTransparent(true);
    ctx = canvas.getGraphicsContext2D();
    dataPointsVisible = tile.getDataPointsVisible();
    valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(valueText, tile.isValueVisible());
    unitText = new Text(" " + tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    unitText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
    selector = new Circle();
    selectorTooltip = new Tooltip("");
    selectorTooltip.setWidth(60);
    selectorTooltip.setHeight(48);
    Tooltip.install(selector, selectorTooltip);
    FadeTransition fadeIn = new FadeTransition(Duration.millis(100), selector);
    fadeIn.setFromValue(0);
    fadeIn.setToValue(1);
    FadeTransition fadeOut = new FadeTransition(Duration.millis(100), selector);
    fadeOut.setFromValue(1);
    fadeOut.setToValue(0);
    fadeInFadeOut = new SequentialTransition(fadeIn, new PauseTransition(Duration.millis(3000)), fadeOut);
    handleData();
    getPane().getChildren().addAll(titleText, fillPath, strokePath, canvas, valueUnitFlow, selector);
}
Also used : EventHandler(javafx.event.EventHandler) Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) Fonts(eu.hansolo.tilesfx.fonts.Fonts) MouseEvent(javafx.scene.input.MouseEvent) CycleMethod(javafx.scene.paint.CycleMethod) LineTo(javafx.scene.shape.LineTo) ChartDataEventListener(eu.hansolo.tilesfx.events.ChartDataEventListener) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) LinearGradient(javafx.scene.paint.LinearGradient) TextFlow(javafx.scene.text.TextFlow) ArrayList(java.util.ArrayList) ChartData(eu.hansolo.tilesfx.chart.ChartData) FadeTransition(javafx.animation.FadeTransition) Helper(eu.hansolo.tilesfx.tools.Helper) ListChangeListener(javafx.collections.ListChangeListener) VPos(javafx.geometry.VPos) MoveTo(javafx.scene.shape.MoveTo) Point2D(javafx.geometry.Point2D) TextAlignment(javafx.scene.text.TextAlignment) Circle(javafx.scene.shape.Circle) Tooltip(javafx.scene.control.Tooltip) Tile(eu.hansolo.tilesfx.Tile) Color(javafx.scene.paint.Color) ChartType(eu.hansolo.tilesfx.Tile.ChartType) Stop(javafx.scene.paint.Stop) GraphicsContext(javafx.scene.canvas.GraphicsContext) Font(javafx.scene.text.Font) Canvas(javafx.scene.canvas.Canvas) PathElement(javafx.scene.shape.PathElement) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) ActionEvent(javafx.event.ActionEvent) Duration(javafx.util.Duration) List(java.util.List) PauseTransition(javafx.animation.PauseTransition) TileEvent(eu.hansolo.tilesfx.events.TileEvent) SequentialTransition(javafx.animation.SequentialTransition) Optional(java.util.Optional) Point(eu.hansolo.tilesfx.tools.Point) Comparator(java.util.Comparator) Path(javafx.scene.shape.Path) ClosePath(javafx.scene.shape.ClosePath) Circle(javafx.scene.shape.Circle) SequentialTransition(javafx.animation.SequentialTransition) FadeTransition(javafx.animation.FadeTransition) Canvas(javafx.scene.canvas.Canvas) Tooltip(javafx.scene.control.Tooltip) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) TextFlow(javafx.scene.text.TextFlow) PauseTransition(javafx.animation.PauseTransition)

Example 7 with SequentialTransition

use of javafx.animation.SequentialTransition in project tilesfx by HanSolo.

the class SmoothedChart method init.

// ******************** Initialization ************************************
private void init() {
    _smoothed = true;
    _chartType = ChartType.LINE;
    _subDivisions = 16;
    _snapToTicks = false;
    _selectorFillColor = Color.WHITE;
    _selectorStrokeColor = Color.RED;
    _selectorSize = 10;
    _decimals = 2;
    _interactive = true;
    _tooltipTimeout = 2000;
    formatString = "%.2f";
    strokePaths = new ArrayList<>();
    clickHandler = e -> select(e);
    endOfTransformationHandler = e -> selectorTooltip.hide();
    seriesListener = change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedItem -> {
                    final Series<X, Y> series = addedItem;
                    final Path strokePath = (Path) ((Group) series.getNode()).getChildren().get(1);
                    final Path fillPath = (Path) ((Group) series.getNode()).getChildren().get(0);
                    fillPath.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePath.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePaths.add(strokePath);
                    series.getData().forEach(data -> data.YValueProperty().addListener(o -> layoutPlotChildren()));
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedItem -> {
                    final Series<X, Y> series = removedItem;
                    final Path strokePath = (Path) ((Group) series.getNode()).getChildren().get(1);
                    final Path fillPath = (Path) ((Group) series.getNode()).getChildren().get(0);
                    fillPath.removeEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePath.removeEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
                    strokePaths.remove(strokePath);
                });
            }
        }
    };
    // Add selector to chart
    selector = new Circle();
    selector.setFill(_selectorFillColor);
    selector.setStroke(_selectorStrokeColor);
    selector.setOpacity(0);
    selectorTooltip = new Tooltip("");
    Tooltip.install(selector, selectorTooltip);
    FadeTransition fadeIn = new FadeTransition(Duration.millis(100), selector);
    fadeIn.setFromValue(0);
    fadeIn.setToValue(1);
    timeBeforeFadeOut = new PauseTransition(Duration.millis(_tooltipTimeout));
    FadeTransition fadeOut = new FadeTransition(Duration.millis(100), selector);
    fadeOut.setFromValue(1);
    fadeOut.setToValue(0);
    fadeInFadeOut = new SequentialTransition(fadeIn, timeBeforeFadeOut, fadeOut);
    fadeInFadeOut.setOnFinished(endOfTransformationHandler);
    chartPlotBackground = getChartPlotBackground();
    chartPlotBackground.widthProperty().addListener(o -> resizeSelector());
    chartPlotBackground.heightProperty().addListener(o -> resizeSelector());
    chartPlotBackground.layoutYProperty().addListener(o -> resizeSelector());
    Path horizontalGridLines = getHorizontalGridLines();
    if (null != horizontalGridLines) {
        horizontalGridLines.setMouseTransparent(true);
    }
    Path verticalGridLines = getVerticalGridLines();
    if (null != verticalGridLines) {
        verticalGridLines.setMouseTransparent(true);
    }
    getChartChildren().addAll(selector);
}
Also used : ClosePath(javafx.scene.shape.ClosePath) Path(javafx.scene.shape.Path) EventHandler(javafx.event.EventHandler) ClosePath(javafx.scene.shape.ClosePath) LineTo(javafx.scene.shape.LineTo) StackPane(javafx.scene.layout.StackPane) XYChart(javafx.scene.chart.XYChart) Side(javafx.geometry.Side) Line(javafx.scene.shape.Line) ListChangeListener(javafx.collections.ListChangeListener) Locale(java.util.Locale) MoveTo(javafx.scene.shape.MoveTo) Point2D(javafx.geometry.Point2D) Circle(javafx.scene.shape.Circle) Border(javafx.scene.layout.Border) PathElement(javafx.scene.shape.PathElement) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) BooleanPropertyBase(javafx.beans.property.BooleanPropertyBase) BorderStroke(javafx.scene.layout.BorderStroke) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) PauseTransition(javafx.animation.PauseTransition) Paint(javafx.scene.paint.Paint) DoublePropertyBase(javafx.beans.property.DoublePropertyBase) AreaChart(javafx.scene.chart.AreaChart) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) SmoothedChartEvent(eu.hansolo.tilesfx.events.SmoothedChartEvent) Bounds(javafx.geometry.Bounds) CornerRadii(javafx.scene.layout.CornerRadii) Path(javafx.scene.shape.Path) MouseEvent(javafx.scene.input.MouseEvent) DoubleProperty(javafx.beans.property.DoubleProperty) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) FadeTransition(javafx.animation.FadeTransition) Insets(javafx.geometry.Insets) Helper(eu.hansolo.tilesfx.tools.Helper) BackgroundFill(javafx.scene.layout.BackgroundFill) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Dimension2D(javafx.geometry.Dimension2D) Node(javafx.scene.Node) ObjectPropertyBase(javafx.beans.property.ObjectPropertyBase) IntegerPropertyBase(javafx.beans.property.IntegerPropertyBase) Background(javafx.scene.layout.Background) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) ActionEvent(javafx.event.ActionEvent) SequentialTransition(javafx.animation.SequentialTransition) Axis(javafx.scene.chart.Axis) Point(eu.hansolo.tilesfx.tools.Point) Group(javafx.scene.Group) Circle(javafx.scene.shape.Circle) FadeTransition(javafx.animation.FadeTransition) Tooltip(javafx.scene.control.Tooltip) SequentialTransition(javafx.animation.SequentialTransition) PauseTransition(javafx.animation.PauseTransition)

Example 8 with SequentialTransition

use of javafx.animation.SequentialTransition in project Board-Instrumentation-Framework by intel.

the class GaugeSkin method fadeBackToInteractive.

private void fadeBackToInteractive() {
    FadeTransition fadeUnitOut = new FadeTransition(Duration.millis(425), unitText);
    fadeUnitOut.setFromValue(1.0);
    fadeUnitOut.setToValue(0.0);
    FadeTransition fadeValueOut = new FadeTransition(Duration.millis(425), valueText);
    fadeValueOut.setFromValue(1.0);
    fadeValueOut.setToValue(0.0);
    PauseTransition pause = new PauseTransition(Duration.millis(50));
    FadeTransition fadeUnitIn = new FadeTransition(Duration.millis(425), unitText);
    fadeUnitIn.setFromValue(0.0);
    fadeUnitIn.setToValue(1.0);
    FadeTransition fadeValueIn = new FadeTransition(Duration.millis(425), valueText);
    fadeValueIn.setFromValue(0.0);
    fadeValueIn.setToValue(1.0);
    ParallelTransition parallelIn = new ParallelTransition(fadeUnitIn, fadeValueIn);
    ParallelTransition parallelOut = new ParallelTransition(fadeUnitOut, fadeValueOut);
    parallelOut.setOnFinished(event -> {
        unitText.setText("Interactive");
        valueText.setText("");
        resizeText();
    });
    SequentialTransition sequence = new SequentialTransition(parallelOut, pause, parallelIn);
    sequence.play();
}
Also used : SequentialTransition(javafx.animation.SequentialTransition) FadeTransition(javafx.animation.FadeTransition) PauseTransition(javafx.animation.PauseTransition) ParallelTransition(javafx.animation.ParallelTransition)

Aggregations

SequentialTransition (javafx.animation.SequentialTransition)8 PauseTransition (javafx.animation.PauseTransition)6 FadeTransition (javafx.animation.FadeTransition)5 ParallelTransition (javafx.animation.ParallelTransition)4 Helper (eu.hansolo.tilesfx.tools.Helper)2 Point (eu.hansolo.tilesfx.tools.Point)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ListChangeListener (javafx.collections.ListChangeListener)2 ActionEvent (javafx.event.ActionEvent)2 EventHandler (javafx.event.EventHandler)2 Point2D (javafx.geometry.Point2D)2 Tooltip (javafx.scene.control.Tooltip)2 MouseEvent (javafx.scene.input.MouseEvent)2 Color (javafx.scene.paint.Color)2 Circle (javafx.scene.shape.Circle)2 ClosePath (javafx.scene.shape.ClosePath)2 LineTo (javafx.scene.shape.LineTo)2 MoveTo (javafx.scene.shape.MoveTo)2 Path (javafx.scene.shape.Path)2