Java Code Examples for javafx.scene.shape.MoveTo#setX()

The following examples show how to use javafx.scene.shape.MoveTo#setX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewArrowableTraitPath.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void clipPath(final Path path) {
	final Path clip = pathProducer.clonePath(path);
	clip.setFill(path.getFill());
	clip.setStrokeWidth(path.getStrokeWidth());

	if(!clip.getElements().isEmpty()) { // Defensive programming
		final Optional<Point> pt1 = getArrowReducedPoint(arrows.get(0).arrow);
		final Optional<Point> pt2 = getArrowReducedPoint(arrows.get(arrows.size() - 1).arrow);

		if(pt1.isPresent() && clip.getElements().get(0) instanceof MoveTo) { // Defensive programming
			// Changing the first point to the one at the beginning of the arrow.
			final MoveTo moveTo = (MoveTo) clip.getElements().get(0);
			moveTo.setX(pt1.get().getX());
			moveTo.setY(pt1.get().getY());
		}

		pt2.ifPresent(pt -> {
			if(clip.getElements().get(clip.getElements().size() - 1) instanceof LineTo) {
				final LineTo lineTo = (LineTo) clip.getElements().get(clip.getElements().size() - 1);
				lineTo.setX(pt.getX());
				lineTo.setY(pt.getY());
			}else if(clip.getElements().get(clip.getElements().size() - 1) instanceof CubicCurveTo) {
				final CubicCurveTo ccTo = (CubicCurveTo) clip.getElements().get(clip.getElements().size() - 1);
				ccTo.setX(pt.getX());
				ccTo.setY(pt.getY());
			}
		});
	}

	clip.setStrokeWidth(path.getStrokeWidth());
	clip.setStrokeLineCap(path.getStrokeLineCap());
	path.setClip(clip);
}
 
Example 2
Source File: StockTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void handleCurrentValue(final double VALUE) {
    low  = Statistics.getMin(dataList);
    high = Statistics.getMax(dataList);
    if (Helper.equals(low, high)) {
        low  = minValue;
        high = maxValue;
    }
    range = high - low;

    double minX           = graphBounds.getX();
    double maxX           = minX + graphBounds.getWidth();
    double minY           = graphBounds.getY();
    double maxY           = minY + graphBounds.getHeight();
    double stepX          = graphBounds.getWidth() / (noOfDatapoints - 1);
    double stepY          = graphBounds.getHeight() / range;
    double referenceValue = tile.getReferenceValue();

    if(!dataList.isEmpty()) {
        MoveTo begin = (MoveTo) pathElements.get(0);
        begin.setX(minX);
        begin.setY(maxY - Math.abs(low - dataList.get(0)) * stepY);
        for (int i = 1; i < (noOfDatapoints - 1); i++) {
            LineTo lineTo = (LineTo) pathElements.get(i);
            lineTo.setX(minX + i * stepX);
            lineTo.setY(maxY - Math.abs(low - dataList.get(i)) * stepY);
        }
        LineTo end = (LineTo) pathElements.get(noOfDatapoints - 1);
        end.setX(maxX);
        end.setY(maxY - Math.abs(low - dataList.get(noOfDatapoints - 1)) * stepY);

        dot.setCenterX(maxX);
        dot.setCenterY(end.getY());

        updateState(VALUE, referenceValue);

        referenceLine.setStartY(maxY - Math.abs(low - referenceValue) * stepY);
        referenceLine.setEndY(maxY - Math.abs(low - referenceValue) * stepY);

        changeText.setText(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (VALUE - referenceValue)));
        changePercentageText.setText(new StringBuilder().append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (VALUE / referenceValue * 100.0) - 100.0)).append("\u0025").toString());

        RotateTransition rotateTransition = new RotateTransition(Duration.millis(200), triangle);
        rotateTransition.setFromAngle(triangle.getRotate());
        rotateTransition.setToAngle(state.angle);

        FillTransition fillIndicatorTransition = new FillTransition(Duration.millis(200), triangle);
        fillIndicatorTransition.setFromValue((Color) triangle.getFill());
        fillIndicatorTransition.setToValue(state.color);

        FillTransition fillReferenceTransition = new FillTransition(Duration.millis(200), changePercentageText);
        fillReferenceTransition.setFromValue((Color) triangle.getFill());
        fillReferenceTransition.setToValue(state.color);

        ParallelTransition parallelTransition = new ParallelTransition(rotateTransition, fillIndicatorTransition, fillReferenceTransition);
        parallelTransition.play();
    }
    valueText.setText(String.format(locale, formatString, VALUE));

    highText.setText(String.format(locale, formatString, high));
    lowText.setText(String.format(locale, formatString, low));

    if (!tile.isTextVisible() && null != movingAverage.getTimeSpan()) {
        timeSpanText.setText(createTimeSpanText());
        text.setText(timeFormatter.format(movingAverage.getLastEntry().getTimestampAsDateTime(tile.getZoneId())));

    }
    resizeDynamicText();
}
 
Example 3
Source File: StockTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void handleCurrentValue(final double VALUE) {
    low  = Statistics.getMin(dataList);
    high = Statistics.getMax(dataList);
    if (Helper.equals(low, high)) {
        low  = minValue;
        high = maxValue;
    }
    range = high - low;

    double minX           = graphBounds.getX();
    double maxX           = minX + graphBounds.getWidth();
    double minY           = graphBounds.getY();
    double maxY           = minY + graphBounds.getHeight();
    double stepX          = graphBounds.getWidth() / (noOfDatapoints - 1);
    double stepY          = graphBounds.getHeight() / range;
    double referenceValue = tile.getReferenceValue();

    if(!dataList.isEmpty()) {
        MoveTo begin = (MoveTo) pathElements.get(0);
        begin.setX(minX);
        begin.setY(maxY - Math.abs(low - dataList.get(0)) * stepY);
        for (int i = 1; i < (noOfDatapoints - 1); i++) {
            LineTo lineTo = (LineTo) pathElements.get(i);
            lineTo.setX(minX + i * stepX);
            lineTo.setY(maxY - Math.abs(low - dataList.get(i)) * stepY);
        }
        LineTo end = (LineTo) pathElements.get(noOfDatapoints - 1);
        end.setX(maxX);
        end.setY(maxY - Math.abs(low - dataList.get(noOfDatapoints - 1)) * stepY);

        dot.setCenterX(maxX);
        dot.setCenterY(end.getY());

        updateState(VALUE, referenceValue);

        referenceLine.setStartY(maxY - Math.abs(low - referenceValue) * stepY);
        referenceLine.setEndY(maxY - Math.abs(low - referenceValue) * stepY);

        changeText.setText(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (VALUE - referenceValue)));

        StringBuilder changePercentageTextBuilder = new StringBuilder();
        if (Double.compare(tile.getReferenceValue(), 0.0) == 0) {
            changePercentageTextBuilder.append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", 0.0));
        } else {
            changePercentageTextBuilder.append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (VALUE / tile.getReferenceValue() * 100.0) - 100.0));
        }
        changePercentageTextBuilder.append(Helper.PERCENTAGE);
        changePercentageText.setText(changePercentageTextBuilder.toString());

        RotateTransition rotateTransition = new RotateTransition(Duration.millis(200), triangle);
        rotateTransition.setFromAngle(triangle.getRotate());
        rotateTransition.setToAngle(state.angle);

        FillTransition fillIndicatorTransition = new FillTransition(Duration.millis(200), triangle);
        fillIndicatorTransition.setFromValue((Color) triangle.getFill());
        fillIndicatorTransition.setToValue(state.color);

        FillTransition fillReferenceTransition = new FillTransition(Duration.millis(200), changePercentageText);
        fillReferenceTransition.setFromValue((Color) triangle.getFill());
        fillReferenceTransition.setToValue(state.color);

        ParallelTransition parallelTransition = new ParallelTransition(rotateTransition, fillIndicatorTransition, fillReferenceTransition);
        parallelTransition.play();
    }
    if (tile.getCustomDecimalFormatEnabled()) {
        valueText.setText(decimalFormat.format(VALUE));
    } else {
        valueText.setText(String.format(locale, formatString, VALUE));
    }

    highText.setText(String.format(locale, formatString, high));
    lowText.setText(String.format(locale, formatString, low));

    if (!tile.isTextVisible() && null != movingAverage.getTimeSpan()) {
        timeSpanText.setText(createTimeSpanText());
        text.setText(timeFormatter.format(movingAverage.getLastEntry().getTimestampAsDateTime(tile.getZoneId())));

    }
    resizeDynamicText();
}
 
Example 4
Source File: TileSparklineSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawChart(final double VALUE) {
    low  = Statistics.getMin(dataList);
    high = Statistics.getMax(dataList);
    if (Double.compare(low, high) == 0) {
        low  = minValue;
        high = maxValue;
    }
    range = high - low;

    double minX  = graphBounds.getX();
    double maxX  = minX + graphBounds.getWidth();
    double minY  = graphBounds.getY();
    double maxY  = minY + graphBounds.getHeight();
    double stepX = graphBounds.getWidth() / (noOfDatapoints - 1);
    double stepY = graphBounds.getHeight() / range;

    if (gauge.isSmoothing()) {
        smooth(dataList);
    } else {
        MoveTo begin = (MoveTo) pathElements.get(0);
        begin.setX(minX);
        begin.setY(maxY - Math.abs(low - dataList.get(0)) * stepY);
        for (int i = 1; i < (noOfDatapoints - 1); i++) {
            LineTo lineTo = (LineTo) pathElements.get(i);
            lineTo.setX(minX + i * stepX);
            lineTo.setY(maxY - Math.abs(low - dataList.get(i)) * stepY);
        }
        LineTo end = (LineTo) pathElements.get(noOfDatapoints - 1);
        end.setX(maxX);
        end.setY(maxY - Math.abs(low - dataList.get(noOfDatapoints - 1)) * stepY);

        dot.setCenterX(maxX);
        dot.setCenterY(end.getY());
    }

    double average = gauge.getAverage();
    double averageY = clamp(minY, maxY, maxY - Math.abs(low - average) * stepY);

    averageLine.setStartX(minX);
    averageLine.setEndX(maxX);
    averageLine.setStartY(averageY);
    averageLine.setEndY(averageY);

    stdDeviationArea.setY(averageLine.getStartY() - (stdDeviation * 0.5 * stepY));
    stdDeviationArea.setHeight(stdDeviation * stepY);

    valueText.setText(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), VALUE));
    averageText.setText(String.format(locale, formatString, average));

    highText.setText(String.format(locale, formatString, high));
    lowText.setText(String.format(locale, formatString, low));
    resizeDynamicText();
}
 
Example 5
Source File: QualityGauge.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private void resize() {
    width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
    height = getHeight() - getInsets().getTop() - getInsets().getBottom();

    if (aspectRatio * width > height) {
        width = 1 / (aspectRatio / height);
    } else if (1 / (aspectRatio / height) > width) {
        height = aspectRatio * width;
    }

    if (width > 0 && height > 0) {
        pane.setMaxSize(width, height);
        pane.setPrefSize(width, height);
        pane.relocate((getWidth() - width) * 0.5, (getHeight() - height) * 0.5);

        centerX = width * 0.5;
        centerY = height * 0.94736842;

        int    noOfSections = sections.size();
        double radius       = width * 0.43831169;
        double sinValue;
        double cosValue;
        Color  sectionColor;
        for (int i = 0 ; i < noOfSections ; i++) {
            sinValue     = Math.sin(Math.toRadians(-sectionAngle * (i + 0.5) + model.getStartAngle() + 270));
            cosValue     = Math.cos(Math.toRadians(-sectionAngle * (i + 0.5) + model.getStartAngle() + 270));
            sectionColor = model.getSections().get(i).getColor();
            LinearGradient secFill = new LinearGradient(centerX + radius * sinValue, centerY + radius * cosValue,
                                                        centerX, centerY,
                                                        false, CycleMethod.NO_CYCLE,
                                                        new Stop(0.0, sectionColor),
                                                        new Stop(0.2, sectionColor),
                                                        new Stop(0.2, sectionColor.deriveColor(0, 0.8, 1.1, 1)),
                                                        new Stop(1.0, sectionColor.deriveColor(0, 0.8, 1.1, 1)));

            Path sec = sections.get(i);
            sec.setFill(secFill);
            sec.setStrokeWidth(height * 0.01);

            MoveTo moveTo = (MoveTo) sec.getElements().get(0);
            moveTo.setX(centerX); moveTo.setY(centerY);

            sinValue = Math.sin(Math.toRadians(-sectionAngle * i + model.getStartAngle() + 270));
            cosValue = Math.cos(Math.toRadians(-sectionAngle * i + model.getStartAngle() + 270));
            LineTo lineTo1 = (LineTo) sec.getElements().get(1);
            lineTo1.setX(centerX + radius * sinValue); lineTo1.setY(centerY + radius * cosValue);

            sinValue = Math.sin(Math.toRadians(-sectionAngle * (i + 1) + model.getStartAngle() + 270));
            cosValue = Math.cos(Math.toRadians(-sectionAngle * (i + 1) + model.getStartAngle() + 270));
            LineTo lineTo2 = (LineTo) sec.getElements().get(2);
            lineTo2.setX(centerX + radius * sinValue); lineTo2.setY(centerY + radius * cosValue);
        }

        currentQualityRotate.setPivotX(centerX);
        currentQualityRotate.setPivotY(centerY);

        moveTo.setX(centerX); moveTo.setY(centerY);
        lineTo1.setX(centerX + width * 0.06856705); lineTo1.setY(height * 0.12174644);
        cubicCurveTo1.setControlX1(centerX + width * 0.06856705); cubicCurveTo1.setControlY1(height * 0.12174644); cubicCurveTo1.setControlX2(centerX + width * 0.06899351); cubicCurveTo1.setControlY2(height * 0.11400031); cubicCurveTo1.setX(centerX + width * 0.06899351); cubicCurveTo1.setY(height * 0.10990712);
        cubicCurveTo2.setControlX1(centerX + width * 0.06899351); cubicCurveTo2.setControlY1(height * 0.03723715);  cubicCurveTo2.setControlX2(centerX + width * 0.03810455); cubicCurveTo2.setControlY2(-height * 0.02167183); cubicCurveTo2.setX(centerX); cubicCurveTo2.setY(-height * 0.02167183);
        cubicCurveTo3.setControlX1(centerX + -width * 0.03810455); cubicCurveTo3.setControlY1(-height * 0.02167183); cubicCurveTo3.setControlX2(centerX - width * 0.06899351); cubicCurveTo3.setControlY2(height * 0.03723715); cubicCurveTo3.setX(centerX - width * 0.06899351); cubicCurveTo3.setY(height * 0.10990712);
        cubicCurveTo4.setControlX1(centerX - width * 0.06899351); cubicCurveTo4.setControlY1(height * 0.11400031); cubicCurveTo4.setControlX2(centerX - width * 0.06856705); cubicCurveTo4.setControlY2(height * 0.12174644); cubicCurveTo4.setX(centerX - width * 0.06856705); cubicCurveTo4.setY(height * 0.12174644);
        lineTo2.setX(centerX); lineTo2.setY(centerY);
        currentQuality.setStrokeWidth(height * 0.01);

        updateValue();

        knob.setCenterX(width * 0.5); knob.setCenterY(height * 0.94736842); knob.setRadius(height * 0.05572755);
        knob.setStrokeWidth(height * 0.01);

        redraw();
    }
}