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

The following examples show how to use javafx.scene.shape.Path#setFill() . 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: 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 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: 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 4
Source File: Text3DHelper.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
private Path generatePath(){
    Path path = new Path(new MoveTo(list.get(0).x,list.get(0).y));
    list.stream().skip(1).forEach(p->path.getElements().add(new LineTo(p.x,p.y)));
    path.getElements().add(new ClosePath());
    path.setStroke(Color.GREEN);
    // Path must be filled to allow Shape.intersect
    path.setFill(Color.RED);
    return path;
}
 
Example 5
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 6
Source File: SunburstChart.java    From OEE-Designer with MIT License 5 votes vote down vote up
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Color FILL, final Color STROKE, final TreeNode NODE) {
    double  startAngleRad = Math.toRadians(START_ANGLE + 90);
    double  endAngleRad   = Math.toRadians(END_ANGLE + 90);
    boolean largeAngle    = Math.abs(END_ANGLE - START_ANGLE) > 180.0;

    double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad);
    double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad);

    double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad);
    double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad);

    double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad);
    double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad);

    double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad);
    double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad);

    MoveTo moveTo1 = new MoveTo(x1, y1);
    LineTo lineTo2 = new LineTo(x2, y2);
    ArcTo  arcTo3  = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true);
    LineTo lineTo4 = new LineTo(x4, y4);
    ArcTo  arcTo1  = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false);

    Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1);

    path.setFill(FILL);
    path.setStroke(STROKE);

    String tooltipText = new StringBuilder(NODE.getData().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getData().getValue())).toString();
    Tooltip.install(path, new Tooltip(tooltipText));

    path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED))));

    return path;
}
 
Example 7
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 8
Source File: RadarNodeChart.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    stops = new ArrayList<>(16);
    for (Stop stop : getGradientStops()) {
        if (Double.compare(stop.getOffset(), 0.0) == 0) stops.add(new Stop(0, stop.getColor()));
        stops.add(new Stop(stop.getOffset() * 0.69924 + 0.285, stop.getColor()));
    }

    chartPath   = new Path();

    overlayPath = new Path();
    overlayPath.setFill(Color.TRANSPARENT);

    centerCircle = new Circle();

    thresholdCircle = new Circle();
    thresholdCircle.setFill(Color.TRANSPARENT);

    unitText = new Text(getUnit());
    unitText.setTextAlignment(TextAlignment.CENTER);
    unitText.setTextOrigin(VPos.CENTER);
    unitText.setFont(Fonts.latoLight(0.045 * PREFERRED_WIDTH));

    legendStep = (getMaxValue() - getMinValue()) / 5d;
    dropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.BLACK, 5, 0, 0, 0);

    minValueText = new Text(String.format(Locale.US, formatString, getMinValue()));
    minValueText.setTextAlignment(TextAlignment.CENTER);
    minValueText.setTextOrigin(VPos.CENTER);
    minValueText.setVisible(isLegendVisible());
    minValueText.setEffect(dropShadow);

    legend1Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep));
    legend1Text.setTextAlignment(TextAlignment.CENTER);
    legend1Text.setTextOrigin(VPos.CENTER);
    legend1Text.setVisible(isLegendVisible());
    legend1Text.setEffect(dropShadow);

    legend2Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 2));
    legend2Text.setTextAlignment(TextAlignment.CENTER);
    legend2Text.setTextOrigin(VPos.CENTER);
    legend2Text.setVisible(isLegendVisible());
    legend2Text.setEffect(dropShadow);

    legend3Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 3));
    legend3Text.setTextAlignment(TextAlignment.CENTER);
    legend3Text.setTextOrigin(VPos.CENTER);
    legend3Text.setVisible(isLegendVisible());
    legend3Text.setEffect(dropShadow);

    legend4Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 3));
    legend4Text.setTextAlignment(TextAlignment.CENTER);
    legend4Text.setTextOrigin(VPos.CENTER);
    legend4Text.setVisible(isLegendVisible());
    legend4Text.setEffect(dropShadow);

    maxValueText = new Text(String.format(Locale.US, formatString, getMaxValue()));
    maxValueText.setTextAlignment(TextAlignment.CENTER);
    maxValueText.setTextOrigin(VPos.CENTER);
    maxValueText.setVisible(isLegendVisible());
    maxValueText.setEffect(dropShadow);

    textGroup = new Group();

    // Add all nodes
    pane = new Pane(chartPath, overlayPath, centerCircle, thresholdCircle, textGroup, unitText, minValueText, legend1Text, legend2Text, legend3Text, legend4Text, maxValueText);

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

    sectionsAndAreasCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionsAndAreasCtx    = sectionsAndAreasCanvas.getGraphicsContext2D();

    tickCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    tickCtx    = tickCanvas.getGraphicsContext2D();

    alarmPane = new Pane();

    hour  = new Rectangle(3, 60);
    hour.setArcHeight(3);
    hour.setArcWidth(3);
    hour.setStroke(null);
    hour.setFill(clock.getHourColor());
    hour.getTransforms().setAll(hourRotate);

    minute = new Rectangle(3, 96);
    minute.setArcHeight(3);
    minute.setArcWidth(3);
    minute.setStroke(null);
    minute.setFill(clock.getMinuteColor());
    minute.getTransforms().setAll(minuteRotate);

    second = new Path();
    second.setFillRule(FillRule.EVEN_ODD);
    second.setStroke(null);
    second.setFill(clock.getSecondColor());
    second.getTransforms().setAll(secondRotate);
    enableNode(second, clock.isSecondsVisible());

    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);

    knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, 4.5);
    knob.setStroke(null);
    knob.setFill(clock.getKnobColor());
    knob.setEffect(dropShadow);

    shadowGroupHour   = new Group(hour);
    shadowGroupMinute = new Group(minute);
    shadowGroupSecond = new Group(second);

    shadowGroupHour.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
    shadowGroupMinute.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
    shadowGroupSecond.setEffect(clock.getShadowsEnabled() ? dropShadow : null);

    title = new Text("");
    title.setVisible(clock.isTitleVisible());
    title.setManaged(clock.isTitleVisible());

    text = new Text("");
    text.setVisible(clock.isTextVisible());
    text.setManaged(clock.isTextVisible());

    pane = new Pane(sectionsAndAreasCanvas, tickCanvas, alarmPane, title, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond, knob);
    pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(clock.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 10
Source File: SectionSkin.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);
        }
    }

    ring = new Path();
    ring.setFillRule(FillRule.EVEN_ODD);
    ring.setStroke(null);
    ring.setFill(Gauge.DARK_COLOR);
    ring.setEffect(new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.35), 1, 0, 0, 1));

    sectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionsCtx    = sectionsCanvas.getGraphicsContext2D();

    mask = new Circle();
    mask.setStroke(null);
    mask.setFill(gauge.getBackgroundPaint());

    knob = new Circle();
    knob.setStroke(null);
    knob.setFill(gauge.getKnobColor());

    angleStep = ANGLE_RANGE / (gauge.getRange());
    double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;

    needleRotate = new Rotate(180 - START_ANGLE);
    needleRotate.setAngle(Helper.clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle));

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.setStroke(null);
    needle.getTransforms().setAll(needleRotate);

    valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getMinValue()) + gauge.getUnit());
    valueText.setMouseTransparent(true);
    valueText.setTextOrigin(VPos.CENTER);
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

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

    // Add all nodes
    pane = new Pane(ring, sectionsCanvas, mask, knob, needle, valueText, titleText);

    getChildren().setAll(pane);
}
 
Example 11
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 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: 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 14
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 15
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 16
Source File: HighLowTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    oldValue = tile.getValue();
    double deviation = calculateDeviation();
    updateState(deviation);

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

    text = new Text(tile.getUnit());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());

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

    description = new Label(tile.getDescription());
    description.setAlignment(tile.getDescriptionAlignment());
    description.setWrapText(true);
    description.setTextFill(tile.getTextColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());
    
    triangle = new Path();
    triangle.setStroke(null);
    triangle.setFill(state.color);
    indicatorPane = new StackPane(triangle);

    deviationText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", deviation));
    deviationText.setFill(state.color);

    deviationUnitText = new Text("%");
    deviationUnitText.setFill(Tile.FOREGROUND);

    referenceUnitFlow = new TextFlow(indicatorPane, deviationText, deviationUnitText);
    referenceUnitFlow.setTextAlignment(TextAlignment.LEFT);

    getPane().getChildren().addAll(titleText, text, valueUnitFlow, description, referenceUnitFlow);

    //handleCurrentValue(tile.getValue());
}
 
Example 17
Source File: SimpleSkin.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);
        }
    }

    sectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionsCtx    = sectionsCanvas.getGraphicsContext2D();

    needleRotate   = new Rotate(180 - START_ANGLE);

    angleStep          = ANGLE_RANGE / (gauge.getRange());
    double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
    needleRotate.setAngle(Helper.clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle));

    needleMoveTo1       = new MoveTo();
    needleCubicCurveTo2 = new CubicCurveTo();
    needleCubicCurveTo3 = new CubicCurveTo();
    needleCubicCurveTo4 = new CubicCurveTo();
    needleLineTo5       = new LineTo();
    needleLineTo6       = new LineTo();
    needleCubicCurveTo7 = new CubicCurveTo();
    needleClosePath8    = new ClosePath();
    needle              = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleLineTo6, needleCubicCurveTo7, needleClosePath8);
    needle.setFillRule(FillRule.EVEN_ODD);

    needle.getTransforms().setAll(needleRotate);
    needle.setFill(gauge.getNeedleColor());
    needle.setStroke(gauge.getBorderPaint());
    needle.setStrokeLineCap(StrokeLineCap.ROUND);
    needle.setStrokeLineJoin(StrokeLineJoin.BEVEL);

    valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getMinValue()) + gauge.getUnit());
    valueText.setMouseTransparent(true);
    valueText.setTextOrigin(VPos.CENTER);
    valueText.setFill(gauge.getValueColor());
    enableNode(valueText, gauge.isValueVisible());

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

    subTitleText = new Text(gauge.getSubTitle());
    subTitleText.setTextOrigin(VPos.CENTER);
    subTitleText.setFill(gauge.getSubTitleColor());
    enableNode(subTitleText, !gauge.getSubTitle().isEmpty());

    // Add all nodes
    pane = new Pane(sectionsCanvas, needle, valueText, titleText, subTitleText);

    getChildren().setAll(pane);
}
 
Example 18
Source File: TimerControlTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    currentValueListener = o -> {
        if (tile.isRunning()) { return; } // Update time only if clock is not already running
        updateTime(ZonedDateTime.ofInstant(Instant.ofEpochSecond(tile.getCurrentTime()), ZoneId.of(ZoneId.systemDefault().getId())));
    };
    timeListener         = o -> updateTime(tile.getTime());

    dateFormatter = DateTimeFormatter.ofPattern("EE d", tile.getLocale());

    sectionMap   = new HashMap<>(tile.getTimeSections().size());
    for (TimeSection section : tile.getTimeSections()) { sectionMap.put(section, new Arc()); }

    minuteRotate = new Rotate();
    hourRotate   = new Rotate();
    secondRotate = new Rotate();

    sectionsPane = new Pane();
    sectionsPane.getChildren().addAll(sectionMap.values());
    Helper.enableNode(sectionsPane, tile.getSectionsVisible());

    minuteTickMarks = new Path();
    minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
    minuteTickMarks.setFill(null);
    minuteTickMarks.setStroke(tile.getMinuteColor());
    minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

    hourTickMarks = new Path();
    hourTickMarks.setFillRule(FillRule.EVEN_ODD);
    hourTickMarks.setFill(null);
    hourTickMarks.setStroke(tile.getHourColor());
    hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);

    hour = new Rectangle(3, 60);
    hour.setArcHeight(3);
    hour.setArcWidth(3);
    hour.setStroke(tile.getHourColor());
    hour.getTransforms().setAll(hourRotate);

    minute = new Rectangle(3, 96);
    minute.setArcHeight(3);
    minute.setArcWidth(3);
    minute.setStroke(tile.getMinuteColor());
    minute.getTransforms().setAll(minuteRotate);

    second = new Rectangle(1, 96);
    second.setArcHeight(1);
    second.setArcWidth(1);
    second.setStroke(tile.getSecondColor());
    second.getTransforms().setAll(secondRotate);
    second.setVisible(tile.isSecondsVisible());
    second.setManaged(tile.isSecondsVisible());

    knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, 4.5);
    knob.setStroke(Color.web("#282a3280"));

    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);

    shadowGroupHour   = new Group(hour);
    shadowGroupMinute = new Group(minute);
    shadowGroupSecond = new Group(second, knob);

    shadowGroupHour.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
    shadowGroupMinute.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
    shadowGroupSecond.setEffect(tile.isShadowsEnabled() ? dropShadow : null);

    titleText = new Text("");
    titleText.setTextOrigin(VPos.TOP);
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    amPmText = new Text(tile.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");

    dateText = new Text("");
    Helper.enableNode(dateText, tile.isDateVisible());

    text = new Text("");
    Helper.enableNode(text, tile.isTextVisible());

    getPane().getChildren().addAll(sectionsPane, hourTickMarks, minuteTickMarks, titleText, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
}
 
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: DashboardSkin.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);
        }
    }

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

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

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

    minValue = gauge.getMinValue();
    minText  = new Text(String.format(locale, otherFormatString, minValue));
    minText.setTextOrigin(VPos.CENTER);
    minText.setFill(gauge.getValueColor());

    maxText = new Text(String.format(locale, otherFormatString, gauge.getMaxValue()));
    maxText.setTextOrigin(VPos.CENTER);
    maxText.setFill(gauge.getValueColor());

    boolean tickLabelsVisible = gauge.getTickLabelsVisible();
    Helper.enableNode(minText, tickLabelsVisible);
    Helper.enableNode(maxText, tickLabelsVisible);

    innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.3), 30.0, 0.0, 0.0, 10.0);

    barBackgroundStart          = new MoveTo(0, 0.675 * PREFERRED_HEIGHT);
    barBackgroundOuterArc       = new ArcTo(0.675 * PREFERRED_HEIGHT, 0.675 * PREFERRED_HEIGHT, 0, PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT, true, true);
    barBackgroundLineToInnerArc = new LineTo(0.72222 * PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT);
    barBackgroundInnerArc       = new ArcTo(0.3 * PREFERRED_HEIGHT, 0.3 * PREFERRED_HEIGHT, 0, 0.27778 * PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT, false, false);

    barBackground = new Path();
    barBackground.setFillRule(FillRule.EVEN_ODD);
    barBackground.getElements().add(barBackgroundStart);
    barBackground.getElements().add(barBackgroundOuterArc);
    barBackground.getElements().add(barBackgroundLineToInnerArc);
    barBackground.getElements().add(barBackgroundInnerArc);
    barBackground.getElements().add(new ClosePath());
    barBackground.setFill(gauge.getBarBackgroundColor());
    barBackground.setStroke(gauge.getBorderPaint());
    barBackground.setEffect(gauge.isShadowsEnabled() ? innerShadow : null);

    dataBarStart          = new MoveTo(0, 0.675 * PREFERRED_HEIGHT);
    dataBarOuterArc       = new ArcTo(0.675 * PREFERRED_HEIGHT, 0.675 * PREFERRED_HEIGHT, 0, 0, 0, false, true);
    dataBarLineToInnerArc = new LineTo(0.27778 * PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT);
    dataBarInnerArc       = new ArcTo(0.3 * PREFERRED_HEIGHT, 0.3 * PREFERRED_HEIGHT, 0, 0, 0, false, false);

    dataBar = new Path();
    dataBar.setFillRule(FillRule.EVEN_ODD);
    dataBar.getElements().add(dataBarStart);
    dataBar.getElements().add(dataBarOuterArc);
    dataBar.getElements().add(dataBarLineToInnerArc);
    dataBar.getElements().add(dataBarInnerArc);
    dataBar.getElements().add(new ClosePath());
    dataBar.setFill(gauge.getBarColor());
    dataBar.setStroke(gauge.getBorderPaint());
    dataBar.setEffect(gauge.isShadowsEnabled() ? innerShadow : null);

    threshold = new Line();
    threshold.setStrokeLineCap(StrokeLineCap.BUTT);
    Helper.enableNode(threshold, gauge.isThresholdVisible());

    thresholdText = new Text(String.format(locale, formatString, gauge.getThreshold()));
    Helper.enableNode(thresholdText, gauge.isThresholdVisible());

    pane = new Pane(unitText, titleText, valueText, minText, maxText, barBackground, dataBar, threshold, 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);
}