Java Code Examples for javafx.scene.Node#setScaleX()

The following examples show how to use javafx.scene.Node#setScaleX() . 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: FxIconBuilder.java    From FxDock with Apache License 2.0 8 votes vote down vote up
/** auto fit last node, useful for svg paths */
public void autoFitLastElement()
{
	Node n = last();
	double w = n.prefHeight(width);
	double h = n.prefWidth(height);
	double sx = width / w;
	double sy = height / h;
	
	double sc = Math.min(sx, sy);
	n.setScaleX(sc);
	n.setScaleY(sc);
	
	Bounds b = n.getBoundsInLocal();
	double dx = (width / 2.0) - b.getMinX() - (b.getWidth() / 2.0);
	double dy = (height / 2.0) - b.getMinY() - (b.getHeight() / 2.0);
	n.setTranslateX(dx);
	n.setTranslateY(dy);
}
 
Example 2
Source File: FxIconBuilder.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected void applyNodeProperties(Node n)
{
	n.setOpacity(opacity);
	n.setScaleX(scale);
	n.setScaleY(scale);
	n.setTranslateX(xtranslate);
	n.setTranslateY(ytranslate);
	n.setEffect(effect);
	n.setRotate(rotate);
}
 
Example 3
Source File: CircularProgressTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void resize() {
    super.resize();
    width  = tile.getWidth() - tile.getInsets().getLeft() - tile.getInsets().getRight();
    height = tile.getHeight() - tile.getInsets().getTop() - tile.getInsets().getBottom();
    size   = width < height ? width : height;

    if (width > 0 && height > 0) {
        pane.setMaxSize(width, height);
        pane.setPrefSize(width, height);

        double chartWidth  = contentBounds.getWidth();
        double chartHeight = contentBounds.getHeight();
        chartSize          = chartWidth < chartHeight ? chartWidth : chartHeight;

        double maxContainerSize = chartSize * 0.5;
        double containerWidth   = maxContainerSize - size * 0.1;
        double containerHeight  = tile.isTextVisible() ? height - maxContainerSize * 0.28 : height - maxContainerSize * 0.205;

        double radius = chartSize * 0.495 - contentBounds.getX();

        barBackground.setCenterX(contentCenterX);
        barBackground.setCenterY(contentCenterY);
        barBackground.setRadiusX(radius);
        barBackground.setRadiusY(radius);
        barBackground.setStrokeWidth(chartSize * 0.1);

        bar.setCenterX(contentCenterX);
        bar.setCenterY(contentCenterY);
        bar.setRadiusX(radius);
        bar.setRadiusY(radius);
        bar.setStrokeWidth(chartSize * 0.1);

        separator.setStartX(contentCenterX);
        separator.setStartY(contentCenterX - radius - chartSize * 0.05);
        separator.setEndX(contentCenterX);
        separator.setEndY(contentCenterX - radius + chartSize * 0.05);

        if (graphicContainer.isVisible() && containerWidth > 0 && containerHeight > 0) {
            graphicContainer.setMinSize(containerWidth, containerHeight);
            graphicContainer.setMaxSize(containerWidth, containerHeight);
            graphicContainer.setPrefSize(containerWidth, containerHeight);
            graphicContainer.relocate((width - containerWidth) * 0.5, (height - containerHeight) * 0.35);

            //if (null != tile) {
                Node graphic = tile.getGraphic();
                if (tile.getGraphic() instanceof Shape) {
                    double graphicWidth  = graphic.getBoundsInLocal().getWidth();
                    double graphicHeight = graphic.getBoundsInLocal().getHeight();

                    if (graphicWidth > containerWidth || graphicHeight > containerHeight) {
                        double scale;
                        if (graphicWidth - containerWidth > graphicHeight - containerHeight) {
                            scale = containerWidth / graphicWidth;
                        } else {
                            scale = containerHeight / graphicHeight;
                        }

                        graphic.setScaleX(scale);
                        graphic.setScaleY(scale);
                    }
                } else if (tile.getGraphic() instanceof ImageView) {
                    ((ImageView) graphic).setFitWidth(containerWidth);
                    ((ImageView) graphic).setFitHeight(containerHeight);
                }
            //}
        }
        resizeStaticText();
        percentageFlow.setPrefWidth(width * 0.9);
        percentageFlow.relocate(width * 0.05, graphicContainer.isVisible() ? bar.getCenterY() + chartSize * 0.12 : bar.getCenterY() - chartSize * 0.12);

        valueUnitFlow.setPrefWidth(width * 0.9);
        valueUnitFlow.relocate(width * 0.05, graphicContainer.isVisible() ? bar.getCenterY() - chartSize * 0.32 : bar.getCenterY() + chartSize * 0.15);
    }
}
 
Example 4
Source File: Helper.java    From OEE-Designer with MIT License 4 votes vote down vote up
public static final void scaleNodeTo(final Node NODE, final double TARGET_WIDTH, final double TARGET_HEIGHT) {
	NODE.setScaleX(TARGET_WIDTH / NODE.getLayoutBounds().getWidth());
	NODE.setScaleY(TARGET_HEIGHT / NODE.getLayoutBounds().getHeight());
}
 
Example 5
Source File: CircularProgressTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void resize() {
    super.resize();
    width  = tile.getWidth() - tile.getInsets().getLeft() - tile.getInsets().getRight();
    height = tile.getHeight() - tile.getInsets().getTop() - tile.getInsets().getBottom();
    size   = width < height ? width : height;

    if (tile.isShowing() && width > 0 && height > 0) {
        pane.setMaxSize(width, height);
        pane.setPrefSize(width, height);

        double chartWidth  = contentBounds.getWidth();
        double chartHeight = contentBounds.getHeight();
        chartSize          = chartWidth < chartHeight ? chartWidth : chartHeight;

        double maxContainerSize = chartSize * 0.5;
        double containerWidth   = maxContainerSize - size * 0.1;
        double containerHeight  = tile.isTextVisible() ? height - maxContainerSize * 0.28 : height - maxContainerSize * 0.205;

        double radius = chartSize * 0.495 - contentBounds.getX();

        barBackground.setCenterX(contentCenterX);
        barBackground.setCenterY(contentCenterY);
        barBackground.setRadiusX(radius);
        barBackground.setRadiusY(radius);
        barBackground.setStrokeWidth(chartSize * 0.1);

        bar.setCenterX(contentCenterX);
        bar.setCenterY(contentCenterY);
        bar.setRadiusX(radius);
        bar.setRadiusY(radius);
        bar.setStrokeWidth(chartSize * 0.1);

        separator.setStartX(contentCenterX);
        separator.setStartY(contentCenterX - radius - chartSize * 0.05);
        separator.setEndX(contentCenterX);
        separator.setEndY(contentCenterX - radius + chartSize * 0.05);

        if (graphicContainer.isVisible() && containerWidth > 0 && containerHeight > 0) {
            graphicContainer.setMinSize(containerWidth, containerHeight);
            graphicContainer.setMaxSize(containerWidth, containerHeight);
            graphicContainer.setPrefSize(containerWidth, containerHeight);
            graphicContainer.relocate((width - containerWidth) * 0.5, (height - containerHeight) * 0.35);

            if (null != tile) {
                Node graphic = tile.getGraphic();
                if (tile.getGraphic() instanceof Shape) {
                    double graphicWidth  = graphic.getBoundsInLocal().getWidth();
                    double graphicHeight = graphic.getBoundsInLocal().getHeight();

                    if (graphicWidth > containerWidth || graphicHeight > containerHeight) {
                        double scale;
                        if (graphicWidth - containerWidth > graphicHeight - containerHeight) {
                            scale = containerWidth / graphicWidth;
                        } else {
                            scale = containerHeight / graphicHeight;
                        }

                        graphic.setScaleX(scale);
                        graphic.setScaleY(scale);
                    }
                } else if (tile.getGraphic() instanceof ImageView) {
                    ((ImageView) graphic).setFitWidth(containerWidth);
                    ((ImageView) graphic).setFitHeight(containerHeight);
                }
            }
        }
        resizeStaticText();
        percentageFlow.setPrefWidth(width * 0.9);
        percentageFlow.relocate(width * 0.05, graphicContainer.isVisible() ? bar.getCenterY() + chartSize * 0.12 : bar.getCenterY() - chartSize * 0.12);

        valueUnitFlow.setPrefWidth(width * 0.9);
        valueUnitFlow.relocate(width * 0.05, graphicContainer.isVisible() ? bar.getCenterY() - chartSize * 0.32 : bar.getCenterY() + chartSize * 0.15);
    }
}
 
Example 6
Source File: CustomTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void resize() {
    super.resize();
    width  = tile.getWidth() - tile.getInsets().getLeft() - tile.getInsets().getRight();
    height = tile.getHeight() - tile.getInsets().getTop() - tile.getInsets().getBottom();
    size   = width < height ? width : height;

    double containerWidth  = contentBounds.getWidth();
    double containerHeight = contentBounds.getHeight();

    if (tile.isShowing() && width > 0 && height > 0) {
        pane.setMaxSize(width, height);
        pane.setPrefSize(width, height);

        if (containerWidth > 0 && containerHeight > 0) {
            graphicContainer.setMinSize(containerWidth, containerHeight);
            graphicContainer.setMaxSize(containerWidth, containerHeight);
            graphicContainer.setPrefSize(containerWidth, containerHeight);
            graphicContainer.relocate(contentBounds.getX(), contentBounds.getY());

            if (null != tile) {
                Node graphic = tile.getGraphic();
                if (tile.getGraphic() instanceof Shape) {
                    double graphicWidth  = graphic.getBoundsInLocal().getWidth();
                    double graphicHeight = graphic.getBoundsInLocal().getHeight();

                 if (graphicWidth > containerWidth || graphicHeight > containerHeight) {
                  double scale = 1;

                  if (graphicWidth - containerWidth > graphicHeight - containerHeight) {
                   scale = containerWidth / graphicWidth;
                  } else {
                      scale = containerHeight / graphicHeight;
                        }

                  graphic.setScaleX(scale);
                  graphic.setScaleY(scale);
                 }
                } else if (tile.getGraphic() instanceof ImageView) {
                    ImageView imgView = (ImageView) graphic;
                    imgView.setPreserveRatio(true);
                    imgView.setFitWidth(containerWidth);
                    imgView.setFitHeight(containerHeight);
                    //((ImageView) graphic).setFitWidth(containerWidth);
                    //((ImageView) graphic).setFitHeight(containerHeight);
                }
            }
        }
        resizeStaticText();
    }
}
 
Example 7
Source File: CustomScrollableTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void resize() {
    super.resize();
    width  = tile.getWidth() - tile.getInsets().getLeft() - tile.getInsets().getRight();
    height = tile.getHeight() - tile.getInsets().getTop() - tile.getInsets().getBottom();
    size   = width < height ? width : height;

    double containerWidth  = contentBounds.getWidth();
    double containerHeight = contentBounds.getHeight();
    if (null == verticalScrollBar) {
        for (Node n : graphicContainer.lookupAll(".scroll-bar")) {
            if (n instanceof ScrollBar) {
                ScrollBar bar = (ScrollBar) n;
                if (bar.getOrientation().equals(Orientation.VERTICAL)) {
                    verticalScrollBar = bar;
                    verticalScrollBar.visibleProperty().addListener((o, ov, nv) -> {
                        if (nv) {
                            scrollBarWidth = verticalScrollBar.getLayoutBounds().getWidth();
                        }
                    });
                    break;
                }
            }
        }
    } else {
        if (verticalScrollBar.isVisible()) {
            contentBounds.setWidth(contentBounds.getWidth() - scrollBarWidth);
        } else {
            contentBounds.setWidth(contentBounds.getWidth() + scrollBarWidth);
        }
    }

    if (tile.isShowing() && width > 0 && height > 0) {
        pane.setMaxSize(width, height);
        pane.setPrefSize(width, height);

        if (containerWidth > 0 && containerHeight > 0) {
            graphicContainer.setMinSize(containerWidth, containerHeight);
            graphicContainer.setMaxSize(containerWidth, containerHeight);
            graphicContainer.setPrefSize(containerWidth, containerHeight);
            graphicContainer.relocate(contentBounds.getX(), contentBounds.getY());

            if (null != tile) {
                Node graphic = tile.getGraphic();
                if (tile.getGraphic() instanceof Shape) {
                    double graphicWidth  = graphic.getBoundsInLocal().getWidth();
                    double graphicHeight = graphic.getBoundsInLocal().getHeight();

                    if (graphicWidth > containerWidth || graphicHeight > containerHeight) {
                        double scale = 1;

                        if (graphicWidth - containerWidth > graphicHeight - containerHeight) {
                            scale = containerWidth / graphicWidth;
                        } else {
                            scale = containerHeight / graphicHeight;
                        }

                        graphic.setScaleX(scale);
                        graphic.setScaleY(scale);
                    }
                } else if (tile.getGraphic() instanceof ImageView) {
                    ImageView imgView = (ImageView) graphic;
                    imgView.setPreserveRatio(true);
                    imgView.setFitWidth(containerWidth);
                    imgView.setFitHeight(containerHeight);
                    //((ImageView) graphic).setFitWidth(containerWidth);
                    //((ImageView) graphic).setFitHeight(containerHeight);
                }
            }
        }
        resizeStaticText();
    }
}
 
Example 8
Source File: Helper.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final void scaleNodeTo(final Node NODE, final double TARGET_WIDTH, final double TARGET_HEIGHT) {
    NODE.setScaleX(TARGET_WIDTH / NODE.getLayoutBounds().getWidth());
    NODE.setScaleY(TARGET_HEIGHT / NODE.getLayoutBounds().getHeight());
}
 
Example 9
Source File: JFXAlertAnimation.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void initAnimation(Node contentContainer, Node overlay) {
    overlay.setOpacity(0);
    contentContainer.setScaleX(0);
    contentContainer.setScaleY(0);
}
 
Example 10
Source File: JFXAlertAnimation.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void initAnimation(Node contentContainer, Node overlay) {
    overlay.setOpacity(0);
    contentContainer.setScaleX(.80);
    contentContainer.setScaleY(.80);
}
 
Example 11
Source File: JFXNodesList.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
protected void initNode(Node node) {
    node.setScaleX(0);
    node.setScaleY(0);
    node.getStyleClass().add("sub-node");
}