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);
    }
private void initGraphics ( ) { 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 ( ) ) ; pane = new Pane ( sectionsCanvas , needle , valueText , titleText , subTitleText ) ; getChildren ( ) . setAll ( pane ) ; }
******************** Initialization ************************************