Java Code Examples for javafx.scene.layout.Region#getPrefHeight()

The following examples show how to use javafx.scene.layout.Region#getPrefHeight() . 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: JFXMasonryPane.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
protected boolean validHeight(BoundingBox box, Region region, double cellH, double gutterX, double gutterY) {
    boolean valid = false;
    if (region.getMinHeight() != -1 && box.getHeight() * cellH + (box.getHeight() - 1) * 2 * gutterY < region.getMinHeight()) {
        return false;
    }

    if (region.getPrefHeight() == USE_COMPUTED_SIZE && box.getHeight() * cellH + (box.getHeight() - 1) * 2 * gutterY >= region
        .prefHeight(region.prefWidth(-1))) {
        valid = true;
    }
    if (region.getPrefHeight() != USE_COMPUTED_SIZE && box.getHeight() * cellH + (box.getHeight() - 1) * 2 * gutterY >= region
        .getPrefHeight()) {
        valid = true;
    }
    return valid;
}
 
Example 2
Source File: JFXMasonryPane.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
protected double getBLockHeight(Region region) {
    if (region.getMinHeight() != -1) {
        return region.getMinHeight();
    }
    if (region.getPrefHeight() != USE_COMPUTED_SIZE) {
        return region.getPrefHeight();
    } else {
        return region.prefHeight(getBLockWidth(region));
    }
}
 
Example 3
Source File: JFXUtil.java    From jfxutils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a "Scale Pane", which is a pane that scales as it resizes, instead of reflowing layout
 * like a normal pane. It can be used to create an effect like a presentation slide. There is no
 * attempt to preserve the aspect ratio.
 * <p>
 * If the region has an explicitly set preferred width and height, those are used unless
 * override is set true.
 * <p>
 * If the region already has a parent, the returned pane will replace it via the
 * {@link #replaceComponent(Node, Node)} method. The Region's parent must be a Pane in this case.
 *
 * @param region   non-null Region
 * @param w        default width, used if the region's width is calculated
 * @param h        default height, used if the region's height is calculated
 * @param override if true, w,h is the region's "100%" size even if the region has an explicit
 *                 preferred width and height set.
 *
 * @return the created StackPane, with preferred width and height set based on size determined by
 *         w, h, and override parameters.
 */
public static StackPane createScalePane( Region region, double w, double h, boolean override ) {
	//If the Region containing the GUI does not already have a preferred width and height, set it.
	//But, if it does, we can use that setting as the "standard" resolution.
	if ( override || region.getPrefWidth() == Region.USE_COMPUTED_SIZE )
		region.setPrefWidth( w );
	else
		w = region.getPrefWidth();

	if ( override || region.getPrefHeight() == Region.USE_COMPUTED_SIZE )
		region.setPrefHeight( h );
	else
		h = region.getPrefHeight();

	StackPane ret = new StackPane();
	ret.setPrefWidth( w );
	ret.setPrefHeight( h );
	if ( region.getParent() != null )
		replaceComponent( region, ret );

	//Wrap the resizable content in a non-resizable container (Group)
	Group group = new Group( region );
	//Place the Group in a StackPane, which will keep it centered
	ret.getChildren().add( group );

	//Bind the scene's width and height to the scaling parameters on the group
	group.scaleXProperty().bind( ret.widthProperty().divide( w ) );
	group.scaleYProperty().bind( ret.heightProperty().divide( h ) );

	return ret;
}
 
Example 4
Source File: RegionDetailPaneInfo.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void updateDetail(final String propertyName) {
    final boolean all = propertyName.equals("*") ? true : false;

    final Region region = (Region) getTarget();
    if (all || propertyName.equals("snapToPixel")) {
        snapToPixelDetail.setValue(region != null ? Boolean.toString(region.isSnapToPixel()) : "-");
        snapToPixelDetail.setIsDefault(region == null || region.isSnapToPixel());
        snapToPixelDetail.setSimpleProperty(region != null ? region.snapToPixelProperty() : null);
        if (!all)
            snapToPixelDetail.updated();
        if (!all)
            return;
    }
    if (all || propertyName.equals("insets")) {
        insetsDetail.setValue(region != null ? ConnectorUtils.serializeInsets(region.getInsets()) : null);
        insetsDetail.setIsDefault(region == null);
        if (!all)
            insetsDetail.updated();
        if (!all)
            return;
    }
    if (all || propertyName.equals("padding")) {
        paddingDetail.setValue(region != null ? ConnectorUtils.serializeInsets(region.getPadding()) : null);
        paddingDetail.setIsDefault(region == null);
        if (!all)
            paddingDetail.updated();
        if (!all)
            return;
    }
    if (all || propertyName.equals("minWidth") || propertyName.equals("minHeight")) {
        if (region != null) {
            final double minw = region.getMinWidth();
            final double minh = region.getMinHeight();
            minSizeOverrideDetail.setValue(ConnectorUtils.formatSize(minw) + " x " + ConnectorUtils.formatSize(minh));
            minSizeOverrideDetail.setIsDefault(minw == Region.USE_COMPUTED_SIZE && minh == Region.USE_COMPUTED_SIZE);
            minSizeOverrideDetail.setSimpleSizeProperty(region.minWidthProperty(), region.minHeightProperty());
        } else {
            minSizeOverrideDetail.setValue("-");
            minSizeOverrideDetail.setIsDefault(true);
            minSizeOverrideDetail.setSimpleSizeProperty(null, null);
        }
        if (!all)
            minSizeOverrideDetail.updated();
        if (!all)
            return;
    }
    if (all || propertyName.equals("prefWidth") || propertyName.equals("prefHeight")) {
        if (region != null) {
            final double prefw = region.getPrefWidth();
            final double prefh = region.getPrefHeight();
            prefSizeOverrideDetail.setValue(ConnectorUtils.formatSize(prefw) + " x " + ConnectorUtils.formatSize(prefh));
            prefSizeOverrideDetail.setIsDefault(prefw == Region.USE_COMPUTED_SIZE && prefh == Region.USE_COMPUTED_SIZE);
            prefSizeOverrideDetail.setSimpleSizeProperty(region.prefWidthProperty(), region.prefHeightProperty());
        } else {
            prefSizeOverrideDetail.setValue("-");
            prefSizeOverrideDetail.setIsDefault(true);
            prefSizeOverrideDetail.setSimpleSizeProperty(null, null);
        }
        if (!all)
            prefSizeOverrideDetail.updated();
        if (!all)
            return;
    }
    if (all || propertyName.equals("maxWidth") || propertyName.equals("maxHeight")) {
        if (region != null) {
            final double maxw = region.getMaxWidth();
            final double maxh = region.getMaxHeight();
            maxSizeOverrideDetail.setValue(ConnectorUtils.formatSize(maxw) + " x " + ConnectorUtils.formatSize(maxh));
            maxSizeOverrideDetail.setIsDefault(maxw == Region.USE_COMPUTED_SIZE && maxh == Region.USE_COMPUTED_SIZE);
            maxSizeOverrideDetail.setSimpleSizeProperty(region.maxWidthProperty(), region.maxHeightProperty());
        } else {
            maxSizeOverrideDetail.setValue("-");
            maxSizeOverrideDetail.setIsDefault(true);
            maxSizeOverrideDetail.setSimpleSizeProperty(null, null);
        }
        if (!all)
            maxSizeOverrideDetail.updated();
    }
    if (all)
        sendAllDetails();
}