Java Code Examples for eu.hansolo.tilesfx.tools.Helper#clamp()

The following examples show how to use eu.hansolo.tilesfx.tools.Helper#clamp() . 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: Gauge2TileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void handleCurrentValue(final double VALUE) {
    double needleStartAngle = angleRange * 0.5;
    double targetAngle = (VALUE - minValue) * angleStep - needleStartAngle;
    targetAngle = Helper.clamp(-needleStartAngle, -needleStartAngle + angleRange, targetAngle);
    needleRotate.setAngle(targetAngle);
    needleRectRotate.setAngle(targetAngle);
    bar.setLength(-angleStep * VALUE);
    if (tile.isStrokeWithGradient()) {
        needle.setFill(gradientLookup.getColorAt(VALUE / tile.getRange()));
        bar.setStroke(conicalGradient.getImagePattern(barBounds));
    } else {
        needle.setFill(tile.getNeedleColor());
        bar.setStroke(tile.getBarColor());
    }

    if (tile.getCustomDecimalFormatEnabled()) {
        valueText.setText(decimalFormat.format(VALUE));
    } else {
        valueText.setText(String.format(locale, formatString, VALUE));
    }
    resizeDynamicText();
}
 
Example 2
Source File: BarChartTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void resizeItems() {
    double itemHeight = Helper.clamp(30, 72, height * 0.14);
    barChartPane.getChildren().forEach(node -> {
        BarChartItem item = (BarChartItem) node;
        item.setParentSize(width, height);
        item.setPrefSize(width, itemHeight);
        item.setMaxSize(width, itemHeight);
    });
}
 
Example 3
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setSymbolSize(final Series<X, Y> SERIES, final double SIZE) {
    if (!getData().contains(SERIES)) { return; }
    if (SERIES.getData().isEmpty()) { return; }
    double symbolSize = Helper.clamp(0, 30, SIZE);
    for (XYChart.Data<X, Y> data : SERIES.getData()) {
        StackPane stackPane = (StackPane) data.getNode();
        if (null == stackPane) { continue; }
        stackPane.setPrefSize(symbolSize, symbolSize);
    }
}
 
Example 4
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setTooltipTimeout(final double TIMEOUT) {
    if (null == tooltipTimeout) {
        _tooltipTimeout = Helper.clamp(0, 10000, TIMEOUT);
        timeBeforeFadeOut.setDuration(Duration.millis(_tooltipTimeout));
    } else {
        tooltipTimeout.set(TIMEOUT);
    }
}
 
Example 5
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setDecimals(final int DECIMALS) {
    if (null == decimals) {
        _decimals    = Helper.clamp(0, MAX_DECIMALS, DECIMALS);
        formatString = new StringBuilder("%.").append(_decimals).append("f").toString();
    } else {
        decimals.set(DECIMALS);
    }
}
 
Example 6
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setSelectorSize(final double SIZE) {
    if (null == selectorSize) {
        _selectorSize = Helper.clamp(1, 20, SIZE);
    } else {
        selectorSize.set(SIZE);
    }
}
 
Example 7
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setSubDivisions(final int SUB_DIVISIONS) {
    if (null == subDivisions) {
        _subDivisions = Helper.clamp(1, MAX_SUBDIVISIONS, SUB_DIVISIONS);
        layoutPlotChildren();
    } else {
        subDivisions.set(SUB_DIVISIONS);
    }
}
 
Example 8
Source File: GaugeTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void handleCurrentValue(final double VALUE) {
    double needleStartAngle = angleRange * 0.5;
    double targetAngle = (VALUE - minValue) * angleStep - needleStartAngle;
    targetAngle = Helper.clamp(-needleStartAngle, -needleStartAngle + angleRange, targetAngle);
    needleRotate.setAngle(targetAngle);
    needleRectRotate.setAngle(targetAngle);
    if (tile.getCustomDecimalFormatEnabled()) {
        valueText.setText(decimalFormat.format(VALUE));
    } else {
        valueText.setText(String.format(locale, formatString, VALUE));
    }
    thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
    resizeDynamicText();
    highlightSections(VALUE);
}
 
Example 9
Source File: BarGaugeTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void setBar( final double VALUE ) {
    double barLength    = 0;
    double barStart     = 0;
    double step         = tile.getAngleStep();
    double clampedValue = Helper.clamp(minValue, maxValue, VALUE);

    if ( tile.isStartFromZero() ) {
        if ( ( VALUE > minValue || minValue < 0 ) && ( VALUE < maxValue || maxValue > 0 ) ) {
            if ( maxValue < 0 ) {
                barStart = START_ANGLE - 270 - ANGLE_RANGE;
                barLength = ( maxValue - clampedValue ) * step;
            } else if ( minValue > 0 ) {
                barStart = START_ANGLE - 270;
                barLength = ( minValue - clampedValue ) * step;
            } else {
                barStart = START_ANGLE - 270 + minValue * step;
                barLength = -clampedValue * step;
            }
        }
    } else {
        barStart = START_ANGLE - 270;
        barLength = ( minValue - clampedValue ) * step;
    }

    bar.setStartAngle(barStart);
    bar.setLength(barLength);

    setBarColor(VALUE);
}
 
Example 10
Source File: LeaderBoardTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void resizeItems() {
    double itemHeight = Helper.clamp(30, 72, height * 0.14);
    leaderBoardPane.getChildren().forEach(node -> {
        LeaderBoardItem item = (LeaderBoardItem) node;
        item.setParentSize(width, height);
        item.setPrefSize(width, itemHeight);
        item.setMaxSize(width, itemHeight);
    });
}
 
Example 11
Source File: LeaderBoardItem.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void resize() {
    width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
    height = getHeight() - getInsets().getTop() - getInsets().getBottom();
    size   = parentWidth < parentHeight ? parentWidth : parentHeight;

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

    if (width > 0 && height > 0) {
        double itemHeight = Helper.clamp(MINIMUM_HEIGHT, MAXIMUM_HEIGHT, height * 0.14);
        pane.setMinSize(parentWidth, itemHeight);
        pane.setMaxSize(parentWidth, itemHeight);
        pane.setPrefSize(parentWidth, itemHeight);

        drawTriangle();
        
        triangle.setLayoutX(size * 0.05);
        triangle.setLayoutY((height - triangle.getBoundsInLocal().getHeight()) * 0.25);

        double fontSize = Helper.clamp(12, MAXIMUM_HEIGHT * 0.5, size * 0.06);

        nameText.setFont(Fonts.latoRegular(fontSize));
        nameText.setX(size * 0.12);
        nameText.setY(0);

        valueText.setFont(Fonts.latoRegular(fontSize));
        valueText.relocate((parentWidth - size * 0.05) - valueText.getLayoutBounds().getWidth(), 0);

        separator.setStartX(size * 0.05);
        separator.setStartY(fontSize * 1.5);
        separator.setEndX(parentWidth - size * 0.05);
        separator.setEndY(fontSize * 1.5);

        redraw();
    }
}
 
Example 12
Source File: GaugeSparkLineTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void setBar(final double VALUE) {
    double barLength    = 0;
    double barStart     = 0;
    double min          = tile.getMinValue();
    double max          = tile.getMaxValue();
    double step         = tile.getAngleStep();
    double clampedValue = Helper.clamp(min, max, VALUE);

    if ( tile.isStartFromZero() ) {
        if ( ( VALUE > min || min < 0 ) && ( VALUE < max || max > 0 ) ) {
            if ( max < 0 ) {
                barStart = tile.getStartAngle() - 135 - tile.getAngleRange();
                barLength = ( max - clampedValue ) * step;
            } else if ( min > 0 ) {
                barStart = tile.getStartAngle() -135;
                barLength = ( min - clampedValue ) * step;
            } else {
                barStart = tile.getStartAngle() - 135 + min * step;
                barLength = - clampedValue * step;
            }
        }
    } else {
        barStart = tile.getStartAngle() - 135;
        barLength = ( min - clampedValue ) * step;
    }

    bar.setStartAngle(barStart);
    bar.setLength(barLength);

    if ( tile.getSectionsVisible() && !sections.isEmpty() ) {
        bar.setStroke(tile.getBarColor());
        for ( Section section : sections ) {
            if ( section.contains(VALUE) ) {
                bar.setStroke(section.getColor());
                break;
            }
        }
    }
}
 
Example 13
Source File: BarChartItem.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
private void resize() {
    width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
    height = getHeight() - getInsets().getTop() - getInsets().getBottom();
    size   = parentWidth < parentHeight ? parentWidth : parentHeight;

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

    if (width > 0 && height > 0) {
        stepSize = (parentWidth - size * 0.15) / maxValue;
        double itemHeight = Helper.clamp(MINIMUM_HEIGHT, MAXIMUM_HEIGHT, height * 0.14);
        pane.setMinSize(parentWidth, itemHeight);
        pane.setMaxSize(parentWidth, itemHeight);
        pane.setPrefSize(parentWidth, itemHeight);

        double fontSize = Helper.clamp(12, MAXIMUM_HEIGHT * 0.5, size * 0.06);

        nameText.setFont(Fonts.latoRegular(fontSize));
        nameText.setX(size * 0.05);
        nameText.setY(0);

        valueText.setFont(Fonts.latoRegular(fontSize));
        valueText.relocate((parentWidth - size * 0.05) - valueText.getLayoutBounds().getWidth(), 0);

        barBackground.setX(size * 0.075);
        barBackground.setY(fontSize * 1.5);
        barBackground.setWidth(parentWidth - size * 0.15);
        barBackground.setHeight(size * 0.01);
        barBackground.setHeight(fontSize / 6);

        bar.setX(size * 0.075);
        bar.setY(fontSize * 1.35);
        bar.setWidth(clamp(0, (parentWidth - size * 0.15), getValue() * stepSize));
        bar.setHeight(fontSize / 2);

        redraw();
    }
}
 
Example 14
Source File: BarGaugeTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void resize() {
    super.resize();

    handleCurrentValue(tile.getValue());

    resizeStaticText();
    resizeDynamicText();

    double centerX = width * 0.5;
    double centerY = height * 0.85;

    valueUnitFlow.setPrefWidth(width - size * 0.1);
    valueUnitFlow.relocate(size * 0.05, contentBounds.getY());
    valueUnitFlow.setMaxHeight(valueText.getFont().getSize());

    fractionLine.setStartX(width - 0.17 * size);
    fractionLine.setStartY(tile.getTitle().isEmpty() ? size * 0.2 : size * 0.3);
    fractionLine.setEndX(width - 0.05 * size);
    fractionLine.setEndY(tile.getTitle().isEmpty() ? size * 0.2 : size * 0.3);
    fractionLine.setStroke(tile.getUnitColor());
    fractionLine.setStrokeWidth(size * 0.005);

    unitFlow.setTranslateY(-size * 0.005);

    barBackground.setCenterX(centerX);
    barBackground.setCenterY(centerY);
    barBackground.setRadiusX(size * 0.325);
    barBackground.setRadiusY(size * 0.325);
    barBackground.setStrokeWidth(size * 0.15);

    bar.setCenterX(centerX);
    bar.setCenterY(centerY);
    bar.setRadiusX(size * 0.325);
    bar.setRadiusY(size * 0.325);
    bar.setStrokeWidth(size * 0.15);

    lowerThreshold.setStrokeWidth(Helper.clamp(1.0, 2.0, 0.00675676 * size));
    double lowerThresholdInnerRadius = 0.25 * size;
    double lowerThresholdOuterRadius = 0.40 * size;
    double lowerThresholdAngle       = Helper.clamp(90.0, 270.0, (tile.getThreshold() - minValue) * angleStep + 90.0);
    lowerThreshold.setStartX(centerX + lowerThresholdInnerRadius * Math.sin(-Math.toRadians(lowerThresholdAngle)));
    lowerThreshold.setStartY(centerY + lowerThresholdInnerRadius * Math.cos(-Math.toRadians(lowerThresholdAngle)));
    lowerThreshold.setEndX(centerX + lowerThresholdOuterRadius * Math.sin(-Math.toRadians(lowerThresholdAngle)));
    lowerThreshold.setEndY(centerY + lowerThresholdOuterRadius * Math.cos(-Math.toRadians(lowerThresholdAngle)));

    double lowerThresholdTextRadius = 0.43 * size;
    lowerThresholdText.setText(String.format(locale, tickLabelFormatString, tile.getThreshold()));
    lowerThresholdText.setFont(Fonts.latoRegular(size * 0.047));
    lowerThresholdText.setRotate(lowerThresholdAngle + 180);
    lowerThresholdText.relocate(centerX - (lowerThresholdText.getLayoutBounds().getWidth() * 0.5) + lowerThresholdTextRadius * Math.sin(-Math.toRadians(lowerThresholdAngle)),
                           centerY - (lowerThresholdText.getLayoutBounds().getWidth() * 0.5) + lowerThresholdTextRadius * Math.cos(-Math.toRadians(lowerThresholdAngle)));
    
    threshold.setStrokeWidth(Helper.clamp(1.0, 2.0, 0.00675676 * size));
    double thresholdInnerRadius = 0.25 * size;
    double thresholdOuterRadius = 0.40 * size;
    double thresholdAngle       = Helper.clamp(90.0, 270.0, (tile.getThreshold() - minValue) * angleStep + 90.0);
    threshold.setStartX(centerX + thresholdInnerRadius * Math.sin(-Math.toRadians(thresholdAngle)));
    threshold.setStartY(centerY + thresholdInnerRadius * Math.cos(-Math.toRadians(thresholdAngle)));
    threshold.setEndX(centerX + thresholdOuterRadius * Math.sin(-Math.toRadians(thresholdAngle)));
    threshold.setEndY(centerY + thresholdOuterRadius * Math.cos(-Math.toRadians(thresholdAngle)));

    double thresholdTextRadius = 0.43 * size;
    thresholdText.setText(String.format(locale, tickLabelFormatString, tile.getThreshold()));
    thresholdText.setFont(Fonts.latoRegular(size * 0.047));
    thresholdText.setRotate(thresholdAngle + 180);
    thresholdText.relocate(centerX - (thresholdText.getLayoutBounds().getWidth() * 0.5) + thresholdTextRadius * Math.sin(-Math.toRadians(thresholdAngle)),
                           centerY - (thresholdText.getLayoutBounds().getWidth() * 0.5) + thresholdTextRadius * Math.cos(-Math.toRadians(thresholdAngle)));
}
 
Example 15
Source File: StatusTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void resize() {
    super.resize();

    description.setPrefSize(contentBounds.getWidth(), contentBounds.getHeight());
    description.relocate(contentBounds.getX(), contentBounds.getY());

    double oneThirdWidth = width / 3;
    double iconSize      = Helper.clamp(1, height * 0.1, oneThirdWidth * 0.5);
    double offsetX       = (oneThirdWidth - iconSize) * 0.5;

    verticalDivider.setStartX(0);
    verticalDivider.setEndX(width);
    verticalDivider.setStartY(height * 0.35);
    verticalDivider.setEndY(height * 0.35);

    horizontal1Divider.setStartX(oneThirdWidth);
    horizontal1Divider.setStartY(height * 0.4);
    horizontal1Divider.setEndX(oneThirdWidth);
    horizontal1Divider.setEndY(height * 0.8);

    horizontal2Divider.setStartX(2 * oneThirdWidth);
    horizontal2Divider.setStartY(height * 0.4);
    horizontal2Divider.setEndX(2 * oneThirdWidth);
    horizontal2Divider.setEndY(height * 0.8);

    leftGraphicsPane.setMinSize(iconSize, iconSize);
    leftGraphicsPane.setPrefSize(iconSize, iconSize);
    leftGraphicsPane.setMaxSize(iconSize, iconSize);
    leftGraphicsPane.relocate(offsetX, height * 0.425);

    middleGraphicsPane.setMinSize(iconSize, iconSize);
    middleGraphicsPane.setPrefSize(iconSize, iconSize);
    middleGraphicsPane.setMaxSize(iconSize, iconSize);
    middleGraphicsPane.relocate(oneThirdWidth + offsetX, height * 0.425);

    rightGraphicsPane.setMinSize(iconSize, iconSize);
    rightGraphicsPane.setPrefSize(iconSize, iconSize);
    rightGraphicsPane.setMaxSize(iconSize, iconSize);
    rightGraphicsPane.relocate(2 * oneThirdWidth + offsetX, height * 0.425);

    leftValueLabel.setPrefWidth(oneThirdWidth);
    middleValueLabel.setPrefWidth(oneThirdWidth);
    rightValueLabel.setPrefWidth(oneThirdWidth);

    leftLabel.setPrefWidth(oneThirdWidth);
    middleLabel.setPrefWidth(oneThirdWidth);
    rightLabel.setPrefWidth(oneThirdWidth);

    leftLabel.setFont(Fonts.latoRegular(size * 0.035));
    middleLabel.setFont(Fonts.latoRegular(size * 0.035));
    rightLabel.setFont(Fonts.latoRegular(size * 0.035));

    leftLabel.relocate(0, height * 0.75);
    middleLabel.relocate(oneThirdWidth, height * 0.75);
    rightLabel.relocate(width - oneThirdWidth, height * 0.75);
}
 
Example 16
Source File: PixelMatrix.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public void setSpacerSizeFactor(final double FACTOR) {
    spacerSizeFactor         = Helper.clamp(0.0, 0.2, FACTOR);
    spacer                   = useSpacer ? pixelSize * spacerSizeFactor : 0;
    pixelSizeMinusDoubleSpacer = pixelSize - spacer * 2;
    drawMatrix();
}
 
Example 17
Source File: FlagIcon.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public FlagIcon(final Flag FLAG, final double FLAG_SIZE) {
    flag     = FLAG;
    flagSize = Helper.clamp(5, 1024, FLAG_SIZE);
    initGraphics();
    registerListeners();
}
 
Example 18
Source File: FlagIcon.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public void setFlag(final Flag FLAG, final double FLAG_SIZE) {
    if (null == FLAG) { throw new IllegalArgumentException("Flag cannot be null"); }
    flag     = FLAG;
    flagSize = Helper.clamp(5, 1024, FLAG_SIZE);
    redraw();
}
 
Example 19
Source File: FlagIcon.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public void setFlagSize(final double FLAG_SIZE) {
    flagSize = Helper.clamp(5, 1024, FLAG_SIZE);
    redraw();
}