Java Code Examples for javafx.scene.shape.Path#setStrokeWidth()

The following examples show how to use javafx.scene.shape.Path#setStrokeWidth() . 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: PathSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Path path = new Path();
           path.getElements().addAll(
            new MoveTo(25, 25),
            new HLineTo(45),
            new ArcTo(20, 20, 0, 80, 25, true, true)
            );
    path.setStroke(Color.web("#b9c0c5"));
    path.setStrokeWidth(5);
    path.getStrokeDashArray().addAll(15d,15d);
    path.setFill(null);
    javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
    effect.setOffsetX(1);
    effect.setOffsetY(1);
    effect.setRadius(3);
    effect.setColor(Color.rgb(0,0,0,0.6));
    path.setEffect(effect);
    return path;
}
 
Example 2
Source File: PathSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Path path = new Path();
           path.getElements().addAll(
            new MoveTo(25, 25),
            new HLineTo(45),
            new ArcTo(20, 20, 0, 80, 25, true, true)
            );
    path.setStroke(Color.web("#b9c0c5"));
    path.setStrokeWidth(5);
    path.getStrokeDashArray().addAll(15d,15d);
    path.setFill(null);
    javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
    effect.setOffsetX(1);
    effect.setOffsetY(1);
    effect.setRadius(3);
    effect.setColor(Color.rgb(0,0,0,0.6));
    path.setEffect(effect);
    return path;
}
 
Example 3
Source File: Paragraph.java    From Open-Lowcode with Eclipse Public License 2.0 6 votes vote down vote up
protected void displaySelection() {
	logger.finest(" - DisplaySelection - Try to print " + dragstartindex + " - " + dragendindex);
	if (this.dragstartindex >= 0)
		if (this.dragendindex >= 0)
			if (this.dragendindex > this.dragstartindex) {
				hideSelection();
				TextLayout textlayout = (TextLayout) invoke(getTextLayout, textflow);
				PathElement[] highlight = textlayout.getRange(this.dragstartindex, this.dragendindex,
						TextLayout.TYPE_TEXT, 0, 0);
				hightlightpath = new Path(highlight);
				hightlightpath.setManaged(false);
				hightlightpath.setFill(Color.web("#222235", 0.2));
				hightlightpath.setStrokeWidth(0);
				if (title)
					hightlightpath.setTranslateY(6);
				if (bulletpoint) {
					hightlightpath.setTranslateY(2);
					hightlightpath.setTranslateX(5);

				}
				textflow.getChildren().add(hightlightpath);
				textflow.requestLayout();
				textflow.requestFocus();
			}
}
 
Example 4
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 5
Source File: PathSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PathSample() {
    super(180,90);
    // Create path shape - square
    Path path1 = new Path();
    path1.getElements().addAll(
            new MoveTo(25, 25),
            new HLineTo(65),
            new VLineTo(65),
            new LineTo(25, 65),
            new ClosePath()         
            );
    path1.setFill(null);
    path1.setStroke(Color.RED);
    path1.setStrokeWidth(2);

    // Create path shape - curves
    Path path2 = new Path();
    path2.getElements().addAll(
            new MoveTo(100, 45),
            new CubicCurveTo(120, 20, 130, 80, 140, 45),
            new QuadCurveTo(150, 0, 160, 45),
            new ArcTo(20, 40, 0, 180, 45, true, true)
            );
    path2.setFill(null);
    path2.setStroke(Color.DODGERBLUE);
    path2.setStrokeWidth(2);

    // show the path shapes;
    getChildren().add(new Group(path1, path2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()),
            new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example 6
Source File: PathSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PathSample() {
    super(180,90);
    // Create path shape - square
    Path path1 = new Path();
    path1.getElements().addAll(
            new MoveTo(25, 25),
            new HLineTo(65),
            new VLineTo(65),
            new LineTo(25, 65),
            new ClosePath()         
            );
    path1.setFill(null);
    path1.setStroke(Color.RED);
    path1.setStrokeWidth(2);

    // Create path shape - curves
    Path path2 = new Path();
    path2.getElements().addAll(
            new MoveTo(100, 45),
            new CubicCurveTo(120, 20, 130, 80, 140, 45),
            new QuadCurveTo(150, 0, 160, 45),
            new ArcTo(20, 40, 0, 180, 45, true, true)
            );
    path2.setFill(null);
    path2.setStroke(Color.DODGERBLUE);
    path2.setStrokeWidth(2);

    // show the path shapes;
    getChildren().add(new Group(path1, path2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()),
            new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example 7
Source File: ShapeChartArea.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
public ShapeChartArea(ChartSerie serie) {
    
    pFill = new Path();
    pFill.getStyleClass().add(serie.getStyleClass() + "-fill");
    pFill.setStrokeWidth(0.0);        
    
    pLine = new Path();
    pLine.getStyleClass().add(serie.getStyleClass() + "-line");        
    
    this.serie = serie;
    serie.setListener(this);
}
 
Example 8
Source File: StockTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    averagingListener = o -> handleEvents("AVERAGING_PERIOD");

    timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());

    state = State.CONSTANT;

    if (tile.isAutoScale()) tile.calcAutoScale();

    low            = tile.getMaxValue();
    high           = tile.getMinValue();
    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.setBoundsType(TextBoundsType.VISUAL);
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());

    valueUnitFlow = new TextFlow(valueText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);

    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());

    referenceLine = new Line();
    referenceLine.getStrokeDashArray().addAll(3d, 3d);
    referenceLine.setVisible(false);

    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());
    dot.setVisible(false);

    triangle = new Path();
    triangle.setStroke(null);
    triangle.setFill(state.color);
    indicatorPane = new StackPane(triangle);

    changeText = new Label(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() - tile.getReferenceValue())));
    changeText.setTextFill(state.color);
    changeText.setAlignment(Pos.CENTER_RIGHT);

    changePercentageText = new Text(new StringBuilder().append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() / tile.getReferenceValue() * 100.0) - 100.0)).append(Helper.PERCENTAGE).toString());
    changePercentageText.setFill(state.color);

    changePercentageFlow = new TextFlow(indicatorPane, changePercentageText);
    changePercentageFlow.setTextAlignment(TextAlignment.RIGHT);

    getPane().getChildren().addAll(titleText, valueUnitFlow, sparkLine, dot, referenceLine, highText, lowText, timeSpanText, text, changeText, changePercentageFlow);
}
 
Example 9
Source File: ViewGrid.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the view.
 * @param sh The model.
 */
ViewGrid(final Grid sh, final PathElementProducer pathProducer) {
	super(sh, pathProducer);
	maingrid = new Path();
	subgrid = new Path();
	mainGridLineCapUpdate = (o, formerv, newv) -> {
		maingrid.setStrokeLineCap(newv.doubleValue() > 0d ? StrokeLineCap.ROUND : StrokeLineCap.SQUARE);
		updatePath(true, false, false);
	};
	subGridLineCapUpdate = (o, formerv, newv) -> {
		subgrid.setStrokeLineCap(newv.doubleValue() > 0d ? StrokeLineCap.ROUND : StrokeLineCap.SQUARE);
		updatePath(false, true, false);
	};
	gridUpdate = (o, formerv, newv) -> updatePath(true, true, true);
	labelUpdate = (o, formerv, newv) -> updatePath(false, false, true);
	gridWidthUpdate = (o, formerv, newv) -> {
		maingrid.setStrokeWidth(model.getGridWidth());
		updatePath(false, false, true);
	};
	subGridUpdate = (o, formerv, newv) -> updatePath(false, true, false);

	getChildren().add(subgrid);
	getChildren().add(maingrid);

	maingrid.strokeProperty().bind(Bindings.createObjectBinding(() -> model.getLineColour().toJFX(), model.lineColourProperty()));
	model.gridDotsProperty().addListener(mainGridLineCapUpdate);
	subgrid.strokeProperty().bind(Bindings.createObjectBinding(() -> model.getSubGridColour().toJFX(), model.subGridColourProperty()));
	model.subGridDotsProperty().addListener(subGridLineCapUpdate);
	model.gridEndXProperty().addListener(gridUpdate);
	model.gridEndYProperty().addListener(gridUpdate);
	model.gridStartXProperty().addListener(gridUpdate);
	model.gridStartYProperty().addListener(gridUpdate);
	model.originXProperty().addListener(labelUpdate);
	model.originYProperty().addListener(labelUpdate);
	model.labelsSizeProperty().addListener(labelUpdate);
	model.yLabelWestProperty().addListener(labelUpdate);
	model.xLabelSouthProperty().addListener(labelUpdate);
	model.subGridDivProperty().addListener(subGridUpdate);
	model.gridWidthProperty().addListener(gridWidthUpdate);
	model.subGridWidthProperty().addListener(subGridUpdate);
	subgrid.strokeWidthProperty().bind(model.subGridWidthProperty());
	model.unitProperty().addListener(gridUpdate);

	updatePath(true, true, true);
}
 
Example 10
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();
    }
}
 
Example 11
Source File: IndicatorSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(gauge.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    sectionLayer = new Pane();
    sectionLayer.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));

    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, 0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(gauge.getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);
    //bar.setMouseTransparent(sectionsAlwaysVisible ? true : false);
    bar.setVisible(!sectionsAlwaysVisible);

    needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);

    needleMoveTo1       = new MoveTo();
    needleCubicCurveTo2 = new CubicCurveTo();
    needleCubicCurveTo3 = new CubicCurveTo();
    needleCubicCurveTo4 = new CubicCurveTo();
    needleCubicCurveTo5 = new CubicCurveTo();
    needleCubicCurveTo6 = new CubicCurveTo();
    needleCubicCurveTo7 = new CubicCurveTo();
    needleClosePath8    = new ClosePath();
    needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleCubicCurveTo5, needleCubicCurveTo6, needleCubicCurveTo7, needleClosePath8);
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(gauge.getNeedleColor());
    needle.setPickOnBounds(false);
    needle.setStrokeType(StrokeType.INSIDE);
    needle.setStrokeWidth(1);
    needle.setStroke(gauge.getBackgroundPaint());

    needleTooltip = new Tooltip(String.format(locale, formatString, gauge.getValue()));
    needleTooltip.setTextAlignment(TextAlignment.CENTER);
    Tooltip.install(needle, needleTooltip);

    minValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMinValue()));
    minValueText.setFill(gauge.getTitleColor());
    Helper.enableNode(minValueText, gauge.getTickLabelsVisible());

    maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
    maxValueText.setFill(gauge.getTitleColor());
    Helper.enableNode(maxValueText, gauge.getTickLabelsVisible());

    titleText = new Text(gauge.getTitle());
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    if (!sections.isEmpty() && sectionsVisible && !sectionsAlwaysVisible) {
        barTooltip = new Tooltip();
        barTooltip.setTextAlignment(TextAlignment.CENTER);
        Tooltip.install(bar, barTooltip);
    }

    pane = new Pane(barBackground, sectionLayer, bar, needle, minValueText, maxValueText, titleText);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 12
Source File: TinySkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, ANGLE_RANGE * 0.5 + 90, -ANGLE_RANGE);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(gauge.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionCtx    = sectionCanvas.getGraphicsContext2D();

    needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);

    needleMoveTo1        = new MoveTo();
    needleCubicCurveTo2  = new CubicCurveTo();
    needleCubicCurveTo3  = new CubicCurveTo();
    needleCubicCurveTo4  = new CubicCurveTo();
    needleCubicCurveTo5  = new CubicCurveTo();
    needleClosePath6     = new ClosePath();
    needleMoveTo7        = new MoveTo();
    needleCubicCurveTo8  = new CubicCurveTo();
    needleCubicCurveTo9  = new CubicCurveTo();
    needleCubicCurveTo10 = new CubicCurveTo();
    needleCubicCurveTo11 = new CubicCurveTo();
    needleClosePath12    = new ClosePath();
    needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleCubicCurveTo5, needleClosePath6,
                      needleMoveTo7, needleCubicCurveTo8, needleCubicCurveTo9, needleCubicCurveTo10, needleCubicCurveTo11, needleClosePath12);
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(gauge.getNeedleColor());
    needle.setStrokeType(StrokeType.INSIDE);
    needle.setStrokeWidth(1);
    needle.setStroke(gauge.getBackgroundPaint());

    needleTooltip = new Tooltip(String.format(locale, formatString, gauge.getValue()));
    needleTooltip.setTextAlignment(TextAlignment.CENTER);
    Tooltip.install(needle, needleTooltip);

    pane = new Pane(barBackground, sectionCanvas, needle);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 13
Source File: KpiSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(gauge.getBarColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
    thresholdBar.setType(ArcType.OPEN);
    thresholdBar.setStroke(gauge.getThresholdColor());
    thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
    thresholdBar.setFill(null);

    needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(gauge.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);

    titleText = new Text(gauge.getTitle());
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

    minValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMinValue()));
    minValueText.setFill(gauge.getTitleColor());

    maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
    maxValueText.setFill(gauge.getTitleColor());

    thresholdText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getThreshold()));
    thresholdText.setFill(gauge.getTitleColor());
    Helper.enableNode(thresholdText, Double.compare(gauge.getThreshold(), gauge.getMinValue()) != 0 && Double.compare(gauge.getThreshold(), gauge.getMaxValue()) != 0);

    pane = new Pane(barBackground, thresholdBar, needle, titleText, valueText, minValueText, maxValueText, thresholdText);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 14
Source File: TileKpiSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(gauge.getBarColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
    thresholdBar.setType(ArcType.OPEN);
    thresholdBar.setStroke(gauge.getThresholdColor());
    thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
    thresholdBar.setFill(null);
    enableNode(thresholdBar, !gauge.getSectionsVisible());

    sectionPane = new Pane();
    enableNode(sectionPane, gauge.getSectionsVisible());

    if (sectionsVisible) { drawSections(); }

    alertIcon = new Path();
    alertIcon.setFillRule(FillRule.EVEN_ODD);
    alertIcon.setFill(Color.YELLOW);
    alertIcon.setStroke(null);
    enableNode(alertIcon, gauge.isAlert());
    alertTooltip = new Tooltip(gauge.getAlertMessage());
    Tooltip.install(alertIcon, alertTooltip);

    needleRotate     = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
    needleRectRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);

    needleRect = new Rectangle();
    needleRect.setFill(gauge.getBackgroundPaint());
    needleRect.getTransforms().setAll(needleRectRotate);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(gauge.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);

    titleText = new Text(gauge.getTitle());
    titleText.setFill(gauge.getTitleColor());
    enableNode(titleText, !gauge.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, gauge.getCurrentValue()));
    valueText.setFill(gauge.getValueColor());
    enableNode(valueText, gauge.isValueVisible() && !gauge.isAlert());

    unitText = new Text(gauge.getUnit());
    unitText.setFill(gauge.getUnitColor());
    enableNode(unitText, gauge.isValueVisible() && !gauge.isAlert());

    minValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMinValue()));
    minValueText.setFill(gauge.getTitleColor());

    maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
    maxValueText.setFill(gauge.getTitleColor());

    thresholdRect = new Rectangle();
    thresholdRect.setFill(sectionsVisible ? GRAY : gauge.getThresholdColor());
    enableNode(thresholdRect, gauge.isThresholdVisible());

    thresholdText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getThreshold()));
    thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : gauge.getBackgroundPaint());
    enableNode(thresholdText, gauge.isThresholdVisible());

    pane = new Pane(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueText, unitText, minValueText, maxValueText, thresholdRect, thresholdText);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 15
Source File: TileSparklineSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);

    titleText = new Text(gauge.getTitle());
    titleText.setFill(gauge.getTitleColor());
    Helper.enableNode(titleText, !gauge.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, gauge.getValue()));
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

    unitText = new Text(gauge.getUnit());
    unitText.setFill(gauge.getUnitColor());
    Helper.enableNode(unitText, !gauge.getUnit().isEmpty());

    averageText = new Text(String.format(locale, formatString, gauge.getAverage()));
    averageText.setFill(gauge.getAverageColor());
    Helper.enableNode(averageText, gauge.isAverageVisible());

    highText = new Text();
    highText.setTextOrigin(VPos.BOTTOM);
    highText.setFill(gauge.getValueColor());

    lowText = new Text();
    lowText.setTextOrigin(VPos.TOP);
    lowText.setFill(gauge.getValueColor());

    subTitleText = new Text(gauge.getSubTitle());
    subTitleText.setTextOrigin(VPos.TOP);
    subTitleText.setFill(gauge.getSubTitleColor());

    stdDeviationArea = new Rectangle();
    Helper.enableNode(stdDeviationArea, gauge.isAverageVisible());

    averageLine = new Line();
    averageLine.setStroke(gauge.getAverageColor());
    averageLine.getStrokeDashArray().addAll(PREFERRED_WIDTH * 0.005, PREFERRED_WIDTH * 0.005);
    Helper.enableNode(averageLine, gauge.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(gauge.getBarColor());
    sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
    sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
    sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);

    dot = new Circle();
    dot.setFill(gauge.getBarColor());

    pane = new Pane(titleText, valueText, unitText, stdDeviationArea, averageLine, sparkLine, dot, averageText, highText, lowText, subTitleText);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 16
Source File: Gauge2TileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    angleRange = tile.getAngleRange();
    angleStep  = tile.getAngleStep();

    if (tile.isAutoScale()) tile.calcAutoScale();
    oldValue = tile.getValue();

    barBackgroundColor = tile.getBarBackgroundColor();
    gradientLookup     = new GradientLookup(tile.getGradientStops());

    knob = new Circle();

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(barBackgroundColor);
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.ROUND);
    barBackground.setFill(null);

    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, 0);
    bar.setType(ArcType.OPEN);
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    bar.setStrokeLineCap(StrokeLineCap.ROUND);
    bar.setFill(null);

    barBounds = new Rectangle();

    createConicalGradient();

    needleRotate     = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(tile.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);

    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());

    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());

    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.CENTER);

    minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
    minValueText.setFill(tile.getTitleColor());
    minValueText.setTextOrigin(VPos.CENTER);

    maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
    maxValueText.setFill(tile.getTitleColor());
    maxValueText.setTextOrigin(VPos.CENTER);

    text = new Text(tile.getText());
    text.setTextOrigin(VPos.TOP);
    text.setFill(tile.getTextColor());

    getPane().getChildren().addAll(knob, barBackground, bar, needle, titleText, valueUnitFlow, minValueText, maxValueText, text);
}
 
Example 17
Source File: GaugeTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    if (tile.isAutoScale()) tile.calcAutoScale();
    oldValue          = tile.getValue();
    sectionMap        = new HashMap<>(sections.size());
    for(Section section : sections) { sectionMap.put(section, new Arc()); }

    barColor       = tile.getBarColor();
    thresholdColor = tile.getThresholdColor();

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(barColor);
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
    thresholdBar.setType(ArcType.OPEN);
    thresholdBar.setStroke(tile.getThresholdColor());
    thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
    thresholdBar.setFill(null);
    Helper.enableNode(thresholdBar, !tile.getSectionsVisible());

    sectionPane = new Pane();
    Helper.enableNode(sectionPane, tile.getSectionsVisible());

    if (sectionsVisible) { drawSections(); }

    alertIcon = new Path();
    alertIcon.setFillRule(FillRule.EVEN_ODD);
    alertIcon.setFill(Color.YELLOW);
    alertIcon.setStroke(null);
    Helper.enableNode(alertIcon, tile.isAlert());
    alertTooltip = new Tooltip(tile.getAlertMessage());
    Tooltip.install(alertIcon, alertTooltip);

    needleRotate     = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);

    needleRect = new Rectangle();
    needleRect.setFill(tile.getBackgroundColor());
    needleRect.getTransforms().setAll(needleRectRotate);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(tile.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);

    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());

    upperUnitText = new Text("");
    upperUnitText.setFill(tile.getUnitColor());
    Helper.enableNode(upperUnitText, !tile.getUnit().isEmpty());

    fractionLine = new Line();

    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());

    unitFlow = new VBox(upperUnitText, unitText);
    unitFlow.setAlignment(Pos.CENTER_RIGHT);

    valueUnitFlow = new HBox(valueText, unitFlow);
    valueUnitFlow.setAlignment(Pos.CENTER);
    valueUnitFlow.setMouseTransparent(true);

    minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
    minValueText.setFill(tile.getTitleColor());

    maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
    maxValueText.setFill(tile.getTitleColor());

    thresholdRect = new Rectangle();
    thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
    Helper.enableNode(thresholdRect, tile.isThresholdVisible());

    thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
    thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
    Helper.enableNode(thresholdText, tile.isThresholdVisible());

    getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, fractionLine, minValueText, maxValueText, thresholdRect, thresholdText);
}
 
Example 18
Source File: StockTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    averagingListener = o -> handleEvents("AVERAGING_PERIOD");

    timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());

    state = State.CONSTANT;

    if (tile.isAutoScale()) tile.calcAutoScale();

    low            = tile.getMaxValue();
    high           = tile.getMinValue();
    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.setBoundsType(TextBoundsType.VISUAL);
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());

    valueUnitFlow = new TextFlow(valueText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);

    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());

    referenceLine = new Line();
    referenceLine.getStrokeDashArray().addAll(3d, 3d);
    referenceLine.setVisible(false);

    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());
    dot.setVisible(false);

    triangle = new Path();
    triangle.setStroke(null);
    triangle.setFill(state.color);
    indicatorPane = new StackPane(triangle);

    changeText = new Label(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() - tile.getReferenceValue())));
    changeText.setTextFill(state.color);
    changeText.setAlignment(Pos.CENTER_RIGHT);

    changePercentageText = new Text(new StringBuilder().append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() / tile.getReferenceValue() * 100.0) - 100.0)).append("\u0025").toString());
    changePercentageText.setFill(state.color);

    changePercentageFlow = new TextFlow(indicatorPane, changePercentageText);
    changePercentageFlow.setTextAlignment(TextAlignment.RIGHT);

    getPane().getChildren().addAll(titleText, valueUnitFlow, sparkLine, dot, referenceLine, highText, lowText, timeSpanText, text, changeText, changePercentageFlow);
}
 
Example 19
Source File: SparkLineTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@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);
}
 
Example 20
Source File: GaugeTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    if (tile.isAutoScale()) tile.calcAutoScale();
    oldValue          = tile.getValue();
    sectionMap        = new HashMap<>(sections.size());
    for(Section section : sections) { sectionMap.put(section, new Arc()); }

    barColor       = tile.getBarColor();
    thresholdColor = tile.getThresholdColor();

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(barColor);
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
    thresholdBar.setType(ArcType.OPEN);
    thresholdBar.setStroke(tile.getThresholdColor());
    thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
    thresholdBar.setFill(null);
    Helper.enableNode(thresholdBar, !tile.getSectionsVisible());

    sectionPane = new Pane();
    Helper.enableNode(sectionPane, tile.getSectionsVisible());

    if (sectionsVisible) { drawSections(); }

    alertIcon = new Path();
    alertIcon.setFillRule(FillRule.EVEN_ODD);
    alertIcon.setFill(Color.YELLOW);
    alertIcon.setStroke(null);
    Helper.enableNode(alertIcon, tile.isAlert());
    alertTooltip = new Tooltip(tile.getAlertMessage());
    Tooltip.install(alertIcon, alertTooltip);

    needleRotate     = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
    needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);

    needleRect = new Rectangle();
    needleRect.setFill(tile.getBackgroundColor());
    needleRect.getTransforms().setAll(needleRectRotate);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(tile.getNeedleColor());
    needle.setStrokeWidth(0);
    needle.setStroke(Color.TRANSPARENT);

    titleText = new Text(tile.getTitle());
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());

    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    unitText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(unitText, tile.isValueVisible() && !tile.isAlert());

    valueUnitFlow = new TextFlow(valueText, unitText);
    valueUnitFlow.setTextAlignment(TextAlignment.CENTER);

    minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
    minValueText.setFill(tile.getTitleColor());

    maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
    maxValueText.setFill(tile.getTitleColor());

    thresholdRect = new Rectangle();
    thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
    Helper.enableNode(thresholdRect, tile.isThresholdVisible());

    thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
    thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
    Helper.enableNode(thresholdText, tile.isThresholdVisible());

    getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, minValueText, maxValueText, thresholdRect, thresholdText);
}