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

The following examples show how to use javafx.scene.Node#prefWidth() . 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: ToolBarFlowPane.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
private void adjustToolBarWidth() {
    final double maxLength = 0.60 * chart.getWidth();
    double length = 0.0;
    for (Node node : this.getChildren()) {
        length += node.prefWidth(DEFAULT_TOOLBAR_HEIGHT);
    }
    length += 4 * cornerRadius.get();
    final double wrapLength = Math.min(maxLength, Math.max(length, 50));
    this.setPrefWrapLength(wrapLength);
    this.setMaxWidth(wrapLength);
    this.setWidth(maxLength);
    final int height = (int) Math.max(getHeight(), Math.max(getBoundsInParent().getHeight(), getBoundsInLocal().getHeight()));
    this.setMinHeight(height);

    this.setShape(ToolBarShapeHelper.getToolBarShape(wrapLength, height, cornerRadius.get()));
}
 
Example 3
Source File: MultiSelectSkin.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
	MultiSelect<E> control = getSkinnable();

	double usedLineWidth = 0;
	double hgap = control.getHgap().doubleValue();
	double vgap = control.getVgap().doubleValue();
	double prefHeight = getPrefRowHeight();

	double y = prefHeight;
	if (width == -1 && control.getWidth() > 0)
		width = control.getWidth();

	for (Node node : getChildren()) {
		double prefWidth = node.prefWidth(prefHeight);
		if (width > 0 && usedLineWidth + prefWidth > width && usedLineWidth > 0) {
			usedLineWidth = 0;
			y += prefHeight + vgap;
		}
		usedLineWidth += prefWidth + hgap;
	}

	return y;
}
 
Example 4
Source File: MultiSelectSkin.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) {
	double usedLineWidth = 0;
	double hgap = getSkinnable().getHgap().doubleValue();
	double vgap = getSkinnable().getVgap().doubleValue();
	double prefHeight = getPrefRowHeight();

	for (Node node : getChildren()) {
		double prefWidth = node.prefWidth(prefHeight);
		if (usedLineWidth + prefWidth > contentWidth && usedLineWidth > 0) {
			usedLineWidth = 0;
			contentY += prefHeight + vgap;
		}
		double x = usedLineWidth + contentX;
		node.resizeRelocate(x, contentY, prefWidth, prefHeight);
		usedLineWidth += prefWidth + hgap;
	}
}
 
Example 5
Source File: ListMenuSkin.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
protected void layoutChildren(double x, double y, double w, double h) {
	for (Node node : getChildren()) {
		if (getSkinnable().getOrientation() == Orientation.VERTICAL) {
			double prefHeight = node.prefHeight(-1);
			node.resizeRelocate(x, y, w, prefHeight);
			y += prefHeight;
		} else {
			double prefWidth = node.prefWidth(-1);
			node.resizeRelocate(x, y, prefWidth, h);
			x += prefWidth;
		}
	}
}
 
Example 6
Source File: MultiSelectSkin.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
/**
 * Compute pref width by placing equal amount of childen on each line, with a line height equal to the editors preferred
 * height plus the vgap. This will not be correct in every case, depending on the difference in the other childrens
 * preferred width, but it seems to be adequate.
 */
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
	MultiSelect<E> control = getSkinnable();

	double hgap = control.getHgap().doubleValue();
	double vgap = control.getVgap().doubleValue();
	double prefRowHeight = getPrefRowHeight();

	int childCount = getChildren().size();
	int rows = height <= 0 ? 1 : (int) Math.max(1, Math.floor((prefRowHeight + vgap) / height));
	int perRow = (int) Math.ceil(childCount / rows);

	double widestRow = 0;
	int childPos = 0;
	for (int rowCount = 0; rowCount < rows; rowCount++) {
		double rowWidth = 0;
		double childPosInRow = 0;

		while (childPosInRow < perRow && childPos < childCount) {
			Node child = getChildren().get(childPos);
			rowWidth += child.prefWidth(prefRowHeight) + hgap;
			childPos++;
			childPosInRow++;
		}

		if (rowWidth > widestRow)
			widestRow = rowWidth;
	}

	return widestRow + leftInset + rightInset - hgap;
}
 
Example 7
Source File: FlowBox.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public Helper()
{
	Insets m = getInsets();
	top = m.getTop();
	bottom = m.getBottom();
	left = m.getLeft();
	right = m.getRight();
	double lh = 0.0;
	
	children = getChildren();
	sz = children.size();
	widths = new double[sz];
	
	for(int i=0; i<sz; i++)
	{
		Node ch = children.get(i);
		if(ch.isManaged())
		{
			double w = ch.prefWidth(-1);
			widths[i] = w;
			
			double h = ch.prefHeight(-1);
			if(h > lh)
			{
				lh = h;
			}
		}
	}
	
	lineHeight = lh;
}
 
Example 8
Source File: NodeDetailPaneInfo.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void updateAllDetails() {
    final Node node = (Node) getTarget();

    // No property change events on these
    resizableDetail.setValue(node != null ? Boolean.toString(node.isResizable()) : "-");
    // boolean showResizable = node != null && node.isResizable();
    resizableDetail.setIsDefault(node == null);

    Orientation bias = null;
    if (node != null) {
        bias = node.getContentBias();
        contentBiasDetail.setValue(bias != null ? bias.toString() : "none");
    } else {
        contentBiasDetail.setValue("-");
    }
    contentBiasDetail.setIsDefault(node == null || node.getContentBias() == null);

    baselineDetail.setValue(node != null ? f.format(node.getBaselineOffset()) : "-");
    baselineDetail.setIsDefault(node == null);

    if (node != null) {
        double minw = 0;
        double minh = 0;
        double prefw = 0;
        double prefh = 0;
        double maxw = 0;
        double maxh = 0;

        if (bias == null) {
            minSizeDetail.setLabel("minWidth(-1)/minHeight(-1):");
            prefSizeDetail.setLabel("prefWidth(-1)/prefHeight(-1):");
            maxSizeDetail.setLabel("maxWidth(-1)/maxHeight(-1):");
            minw = node.minWidth(-1);
            minh = node.minHeight(-1);
            prefw = node.prefWidth(-1);
            prefh = node.prefHeight(-1);
            maxw = node.maxWidth(-1);
            maxh = node.maxHeight(-1);
        } else if (bias == Orientation.HORIZONTAL) {
            minSizeDetail.setLabel("minWidth(-1)/minHeight(w):");
            prefSizeDetail.setLabel("prefWidth(-1)/prefHeight(w):");
            maxSizeDetail.setLabel("maxWidth(-1)/maxHeight(w):");
            minw = node.minWidth(-1);
            minh = node.minHeight(minw);
            prefw = node.prefWidth(-1);
            prefh = node.prefHeight(prefw);
            maxw = node.maxWidth(-1);
            maxh = node.maxHeight(maxw);
        } else { // VERTICAL
            minSizeDetail.setLabel("minWidth(h)/minHeight(-1):");
            prefSizeDetail.setLabel("prefWidth(h)/prefHeight(-1):");
            maxSizeDetail.setLabel("maxWidth(h)/maxHeight(-1):");
            minh = node.minHeight(-1);
            minw = node.minWidth(minh);
            prefh = node.prefHeight(-1);
            prefw = node.prefWidth(prefh);
            maxh = node.maxHeight(-1);
            maxw = node.maxWidth(maxh);
        }

        minSizeDetail.setValue(f.format(minw) + " x " + f.format(minh));
        prefSizeDetail.setValue(f.format(prefw) + " x " + f.format(prefh));
        maxSizeDetail.setValue((maxw >= Double.MAX_VALUE ? "MAXVALUE" : f.format(maxw)) + " x " + (maxh >= Double.MAX_VALUE ? "MAXVALUE" : f.format(maxh)));
    } else {
        minSizeDetail.setValue("-");
        prefSizeDetail.setValue("-");
        maxSizeDetail.setValue("-");
    }
    final boolean fade = node == null || !node.isResizable();
    minSizeDetail.setIsDefault(fade);
    prefSizeDetail.setIsDefault(fade);
    maxSizeDetail.setIsDefault(fade);
    @SuppressWarnings("rawtypes") final ObservableMap map = node != null && node.hasProperties() ? node.getProperties() : null;
    constraintsDetail.setValue(ConnectorUtils.serializePropertyMap(map));
    constraintsDetail.setIsDefault(map == null || map.size() == 0);

    updateDetail("*");
}
 
Example 9
Source File: StructuredListCellSkin.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) {
    double leftContentWidth = 0;
    if (getSkinnable().getLeftContent() != null) {
        Node leftContent = getSkinnable().getLeftContent();
        leftContentWidth = leftContent.prefWidth(contentHeight);
        double leftContentHeight = Math.min(leftContent.prefHeight(leftContentWidth), contentHeight);
        leftContent.resize(leftContentWidth, leftContentHeight);
        if (leftContentAlignment.get().equals(VPos.TOP)) {
            leftContent.relocate(contentX, contentY);
        } else if (leftContentAlignment.get().equals(VPos.CENTER)) {
            leftContent.relocate(contentX, contentY + (contentHeight - leftContentHeight) / 2);
        } else {
            leftContent.relocate(contentX, contentY + (contentHeight - leftContentHeight));
        }
    }

    double rightContentWidth = 0;
    if (getSkinnable().getRightContent() != null) {
        Node rightContent = getSkinnable().getRightContent();
        rightContentWidth = rightContent.prefWidth(contentHeight);
        double rightContentHeight = Math.min(rightContent.prefHeight(rightContentWidth), contentHeight);
        rightContent.resize(rightContentWidth, rightContentHeight);
        if (rightContentAlignment.get().equals(VPos.TOP)) {
            rightContent.relocate(contentX + contentWidth - rightContentWidth, contentY);
        } else if (rightContentAlignment.get().equals(VPos.CENTER)) {
            rightContent.relocate(contentX + contentWidth - rightContentWidth, contentY + (contentHeight - rightContentHeight) / 2);
        } else {
            rightContent.relocate(contentX + contentWidth - rightContentWidth, contentY + (contentHeight - rightContentHeight));
        }
    }

    if (getSkinnable().getCenterContent() != null) {
        Node centerContent = getSkinnable().getCenterContent();

        double maxWidthForCenterContent = contentWidth - leftContentWidth - rightContentWidth - spacing.get().doubleValue() * 2;
        double maxHeigthForCenterContent = contentHeight;

        double centerContentWidth = Math.min(centerContent.maxWidth(contentHeight), maxWidthForCenterContent);
        double centerContentHeight = Math.min(centerContent.maxHeight(centerContentWidth), maxHeigthForCenterContent);
        centerContent.resize(centerContentWidth, centerContentHeight);

        if (centerContentAlignment.get().equals(Pos.TOP_LEFT)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue(), contentY);
        } else if (centerContentAlignment.get().equals(Pos.TOP_CENTER)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue() + (maxWidthForCenterContent - centerContentWidth) / 2, contentY);
        } else if (centerContentAlignment.get().equals(Pos.TOP_RIGHT)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue() + (maxWidthForCenterContent - centerContentWidth), contentY);
        } else if (centerContentAlignment.get().equals(Pos.CENTER_LEFT)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue(), contentY + (maxHeigthForCenterContent - centerContentHeight) / 2);
        } else if (centerContentAlignment.get().equals(Pos.CENTER)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue() + (maxWidthForCenterContent - centerContentWidth) / 2, contentY + (maxHeigthForCenterContent - centerContentHeight) / 2);
        } else if (centerContentAlignment.get().equals(Pos.CENTER_RIGHT)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue() + (maxWidthForCenterContent - centerContentWidth), contentY + (maxHeigthForCenterContent - centerContentHeight) / 2);
        } else if (centerContentAlignment.get().equals(Pos.BOTTOM_LEFT)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue(), contentY + (maxHeigthForCenterContent - centerContentHeight));
        } else if (centerContentAlignment.get().equals(Pos.BOTTOM_CENTER)) {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue() + (maxWidthForCenterContent - centerContentWidth) / 2, contentY + (maxHeigthForCenterContent - centerContentHeight));
        } else {
            centerContent.relocate(contentX + leftContentWidth + spacing.get().doubleValue() + (maxWidthForCenterContent - centerContentWidth), contentY + (maxHeigthForCenterContent - centerContentHeight));
        }
    }
}
 
Example 10
Source File: OrientationHelper.java    From Flowless with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public double prefLength(Node node, double breadth) {
    return node.prefWidth(breadth);
}
 
Example 11
Source File: OrientationHelper.java    From Flowless with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public double prefBreadth(Node node) {
    return node.prefWidth(-1);
}