Search in sources :

Example 31 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class BarChartItem method initGraphics.

// ******************** Initialization ************************************
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }
    nameText = new Text(getName());
    nameText.setTextOrigin(VPos.TOP);
    valueText = new Text(String.format(locale, formatString, getValue()));
    valueText.setTextOrigin(VPos.TOP);
    barBackground = new Rectangle();
    bar = new Rectangle();
    pane = new Pane(nameText, valueText, barBackground, bar);
    pane.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
    getChildren().setAll(pane);
}
Also used : Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) Pane(javafx.scene.layout.Pane)

Example 32 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class GaugeSparkLineTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    averagingListener = o -> handleEvents("AVERAGING_PERIOD");
    highlightSectionListener = o -> handleEvents("HIGHLIGHT_SECTIONS");
    timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());
    if (tile.isAutoScale())
        tile.calcAutoScale();
    niceScaleY = new NiceScale(tile.getMinValue(), tile.getMaxValue());
    niceScaleY.setMaxTicks(5);
    tickLineColor = Color.color(Tile.FOREGROUND.getRed(), Tile.FOREGROUND.getGreen(), Tile.FOREGROUND.getBlue(), 0.50);
    horizontalTickLines = new ArrayList<>(5);
    tickLabelsY = new ArrayList<>(5);
    for (int i = 0; i < 5; i++) {
        Line hLine = new Line(0, 0, 0, 0);
        hLine.getStrokeDashArray().addAll(1.0, 2.0);
        hLine.setStroke(Color.TRANSPARENT);
        horizontalTickLines.add(hLine);
        Text tickLabelY = new Text("");
        tickLabelY.setFill(Color.TRANSPARENT);
        tickLabelsY.add(tickLabelY);
    }
    gradientLookup = new GradientLookup(tile.getGradientStops());
    low = tile.getMaxValue();
    high = tile.getMinValue();
    stdDeviation = 0;
    movingAverage = tile.getMovingAverage();
    noOfDatapoints = tile.getAveragingPeriod();
    dataList = new LinkedList<>();
    // To get smooth lines in the chart we need at least 4 values
    if (noOfDatapoints < 4)
        throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");
    graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);
    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    valueText = new Text(String.format(locale, formatString, tile.getValue()));
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());
    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
    averageText = new Text(String.format(locale, formatString, tile.getAverage()));
    averageText.setFill(Tile.FOREGROUND);
    Helper.enableNode(averageText, tile.isAverageVisible());
    text = new Text(tile.getText());
    text.setTextOrigin(VPos.TOP);
    text.setFill(tile.getTextColor());
    timeSpanText = new Text("");
    timeSpanText.setTextOrigin(VPos.TOP);
    timeSpanText.setFill(tile.getTextColor());
    Helper.enableNode(timeSpanText, !tile.isTextVisible());
    stdDeviationArea = new Rectangle();
    Helper.enableNode(stdDeviationArea, tile.isAverageVisible());
    averageLine = new Line();
    averageLine.setStroke(Tile.FOREGROUND);
    averageLine.getStrokeDashArray().addAll(PREFERRED_WIDTH * 0.005, PREFERRED_WIDTH * 0.005);
    Helper.enableNode(averageLine, tile.isAverageVisible());
    pathElements = new ArrayList<>(noOfDatapoints);
    pathElements.add(0, new MoveTo());
    for (int i = 1; i < noOfDatapoints; i++) {
        pathElements.add(i, new LineTo());
    }
    sparkLine = new Path();
    sparkLine.getElements().addAll(pathElements);
    sparkLine.setFill(null);
    sparkLine.setStroke(tile.getBarColor());
    sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
    sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
    sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);
    dot = new Circle();
    dot.setFill(tile.getBarColor());
    sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionCtx = sectionCanvas.getGraphicsContext2D();
    highlightSectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    highlightSectionCtx = sectionCanvas.getGraphicsContext2D();
    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, tile.getStartAngle() - 45, tile.getAngleRange());
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(tile.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.125);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);
    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, tile.getStartAngle() - 135, 0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(tile.getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.125);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);
    minValueText = new Text();
    maxValueText = new Text();
    getPane().getChildren().addAll(sectionCanvas, highlightSectionCanvas, barBackground, bar, minValueText, maxValueText, titleText, valueUnitFlow, stdDeviationArea, averageLine, sparkLine, dot, averageText, timeSpanText, text);
    getPane().getChildren().addAll(horizontalTickLines);
    getPane().getChildren().addAll(tickLabelsY);
}
Also used : Path(javafx.scene.shape.Path) Circle(javafx.scene.shape.Circle) LineTo(javafx.scene.shape.LineTo) Canvas(javafx.scene.canvas.Canvas) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) CacheHint(javafx.scene.CacheHint) Point(eu.hansolo.tilesfx.tools.Point) Line(javafx.scene.shape.Line) Arc(javafx.scene.shape.Arc) MoveTo(javafx.scene.shape.MoveTo) NiceScale(eu.hansolo.tilesfx.tools.NiceScale) TextFlow(javafx.scene.text.TextFlow) GradientLookup(eu.hansolo.tilesfx.tools.GradientLookup)

Example 33 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class GaugeSparkLineTileSkin method resize.

@Override
protected void resize() {
    super.resize();
    graphBounds = new Rectangle((width - (size * 0.35)) * 0.5, (height - (size * 0.35)) * 0.5, size * 0.35, size * 0.35);
    tickLabelFontSize = graphBounds.getHeight() * 0.1;
    Font tickLabelFont = Fonts.latoRegular(tickLabelFontSize);
    tickLabelsY.forEach(label -> {
        enableNode(label, tickLabelFontSize >= 6);
        label.setFont(tickLabelFont);
    });
    horizontalTickLines.forEach(line -> line.setStrokeWidth(0.5));
    stdDeviationArea.setX(graphBounds.getX());
    stdDeviationArea.setWidth(graphBounds.getWidth());
    averageLine.getStrokeDashArray().setAll(graphBounds.getWidth() * 0.01, graphBounds.getWidth() * 0.01);
    handleCurrentValue(tile.getValue());
    if (tile.getAveragingPeriod() < 250) {
        sparkLine.setStrokeWidth(size * 0.005);
        dot.setRadius(size * 0.01);
    } else if (tile.getAveragingPeriod() < 500) {
        sparkLine.setStrokeWidth(size * 0.003);
        dot.setRadius(size * 0.0105);
    } else {
        sparkLine.setStrokeWidth(size * 0.002);
        dot.setRadius(size * 0.007);
    }
    if (tile.isStrokeWithGradient()) {
        setupGradient();
    }
    resizeStaticText();
    resizeDynamicText();
    valueUnitFlow.setPrefWidth(width - doubleInset);
    valueUnitFlow.relocate(inset, height * 0.5 + size * 0.25);
    sectionCanvas.setWidth(width);
    sectionCanvas.setHeight(height);
    highlightSectionCanvas.setWidth(width);
    highlightSectionCanvas.setHeight(height);
    barBackground.setCenterX(width * 0.5);
    barBackground.setCenterY(height * 0.5);
    barBackground.setRadiusX(size * 0.3);
    barBackground.setRadiusY(size * 0.3);
    barBackground.setStrokeWidth(size * 0.07);
    bar.setCenterX(width * 0.5);
    bar.setCenterY(height * 0.5);
    bar.setRadiusX(size * 0.3);
    bar.setRadiusY(size * 0.3);
    bar.setStrokeWidth(size * 0.07);
}
Also used : Rectangle(javafx.scene.shape.Rectangle) Font(javafx.scene.text.Font)

Example 34 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class SparkLineTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    averagingListener = o -> handleEvents("AVERAGING");
    timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());
    if (tile.isAutoScale())
        tile.calcAutoScale();
    niceScaleY = new NiceScale(tile.getMinValue(), tile.getMaxValue());
    niceScaleY.setMaxTicks(5);
    tickLineColor = Color.color(tile.getChartGridColor().getRed(), tile.getChartGridColor().getGreen(), tile.getChartGridColor().getBlue(), 0.5);
    horizontalTickLines = new ArrayList<>(5);
    tickLabelsY = new ArrayList<>(5);
    for (int i = 0; i < 5; i++) {
        Line hLine = new Line(0, 0, 0, 0);
        hLine.getStrokeDashArray().addAll(1.0, 2.0);
        hLine.setStroke(Color.TRANSPARENT);
        horizontalTickLines.add(hLine);
        Text tickLabelY = new Text("");
        tickLabelY.setFill(Color.TRANSPARENT);
        tickLabelsY.add(tickLabelY);
    }
    gradientLookup = new GradientLookup(tile.getGradientStops());
    low = tile.getMaxValue();
    high = tile.getMinValue();
    stdDeviation = 0;
    movingAverage = tile.getMovingAverage();
    noOfDatapoints = tile.getAveragingPeriod();
    dataList = new LinkedList<>();
    // To get smooth lines in the chart we need at least 4 values
    if (noOfDatapoints < 4)
        throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");
    graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);
    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    valueText = new Text(String.format(locale, formatString, tile.getValue()));
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());
    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());
    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
    averageText = new Text(String.format(locale, formatString, tile.getAverage()));
    averageText.setFill(Tile.FOREGROUND);
    Helper.enableNode(averageText, tile.isAverageVisible());
    highText = new Text();
    highText.setTextOrigin(VPos.BOTTOM);
    highText.setFill(tile.getValueColor());
    lowText = new Text();
    lowText.setTextOrigin(VPos.TOP);
    lowText.setFill(tile.getValueColor());
    text = new Text(tile.getText());
    text.setTextOrigin(VPos.TOP);
    text.setFill(tile.getTextColor());
    timeSpanText = new Text("");
    timeSpanText.setTextOrigin(VPos.TOP);
    timeSpanText.setFill(tile.getTextColor());
    Helper.enableNode(timeSpanText, !tile.isTextVisible());
    stdDeviationArea = new Rectangle();
    Helper.enableNode(stdDeviationArea, tile.isAverageVisible());
    averageLine = new Line();
    averageLine.setStroke(Tile.FOREGROUND);
    averageLine.getStrokeDashArray().addAll(PREFERRED_WIDTH * 0.005, PREFERRED_WIDTH * 0.005);
    Helper.enableNode(averageLine, tile.isAverageVisible());
    pathElements = new ArrayList<>(noOfDatapoints);
    pathElements.add(0, new MoveTo());
    for (int i = 1; i < noOfDatapoints; i++) {
        pathElements.add(i, new LineTo());
    }
    sparkLine = new Path();
    sparkLine.getElements().addAll(pathElements);
    sparkLine.setFill(null);
    sparkLine.setStroke(tile.getBarColor());
    sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
    sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
    sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);
    dot = new Circle();
    dot.setFill(tile.getBarColor());
    getPane().getChildren().addAll(titleText, valueUnitFlow, stdDeviationArea, averageLine, sparkLine, dot, averageText, highText, lowText, timeSpanText, text);
    getPane().getChildren().addAll(horizontalTickLines);
    getPane().getChildren().addAll(tickLabelsY);
}
Also used : Path(javafx.scene.shape.Path) Circle(javafx.scene.shape.Circle) LineTo(javafx.scene.shape.LineTo) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) Point(eu.hansolo.tilesfx.tools.Point) Line(javafx.scene.shape.Line) MoveTo(javafx.scene.shape.MoveTo) NiceScale(eu.hansolo.tilesfx.tools.NiceScale) TextFlow(javafx.scene.text.TextFlow) GradientLookup(eu.hansolo.tilesfx.tools.GradientLookup)

Example 35 with Rectangle

use of javafx.scene.shape.Rectangle in project tilesfx by HanSolo.

the class SparkLineTileSkin method resize.

@Override
protected void resize() {
    super.resize();
    graphBounds = new Rectangle(contentBounds.getX(), titleText.isVisible() ? size * 0.5 : size * 0.4, contentBounds.getWidth(), titleText.isVisible() ? height - size * 0.61 : height - size * 0.51);
    tickLabelFontSize = graphBounds.getHeight() * 0.1;
    Font tickLabelFont = Fonts.latoRegular(tickLabelFontSize);
    tickLabelsY.forEach(label -> {
        enableNode(label, tickLabelFontSize >= 6);
        label.setFont(tickLabelFont);
    });
    horizontalTickLines.forEach(line -> line.setStrokeWidth(0.5));
    stdDeviationArea.setX(graphBounds.getX());
    stdDeviationArea.setWidth(graphBounds.getWidth());
    averageLine.getStrokeDashArray().setAll(graphBounds.getWidth() * 0.01, graphBounds.getWidth() * 0.01);
    handleCurrentValue(tile.getValue());
    if (tile.getAveragingPeriod() < 250) {
        sparkLine.setStrokeWidth(size * 0.01);
        dot.setRadius(size * 0.014);
    } else if (tile.getAveragingPeriod() < 500) {
        sparkLine.setStrokeWidth(size * 0.0075);
        dot.setRadius(size * 0.0105);
    } else {
        sparkLine.setStrokeWidth(size * 0.005);
        dot.setRadius(size * 0.007);
    }
    if (tile.isStrokeWithGradient()) {
        setupGradient();
    }
    resizeStaticText();
    resizeDynamicText();
    valueUnitFlow.setPrefWidth(width - size * 0.1);
    valueUnitFlow.relocate(size * 0.05, contentBounds.getY());
}
Also used : Rectangle(javafx.scene.shape.Rectangle) Font(javafx.scene.text.Font)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)135 Text (javafx.scene.text.Text)23 Entity (com.almasb.fxgl.entity.Entity)21 Point2D (javafx.geometry.Point2D)17 Circle (javafx.scene.shape.Circle)16 Group (javafx.scene.Group)13 Pane (javafx.scene.layout.Pane)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 HitBox (com.almasb.fxgl.physics.HitBox)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Node (javafx.scene.Node)7 PlayerControl (common.PlayerControl)6 Timeline (javafx.animation.Timeline)6 StackPane (javafx.scene.layout.StackPane)6 Stage (javafx.stage.Stage)6 Region (javafx.scene.layout.Region)5