Java Code Examples for javafx.geometry.Pos#getVpos()

The following examples show how to use javafx.geometry.Pos#getVpos() . 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: HiddenSidesPaneSkin.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private double getPrefAlignmentV(final Node node, final double contentHeight) {
    final Pos alignment = StackPane.getAlignment(node);
    if (alignment == null) {
        return 0.0;
    }
    switch (alignment.getVpos()) {
    case BOTTOM:
        return contentHeight - node.getLayoutBounds().getHeight();
    case CENTER:
        return 0.5 * (contentHeight - node.getLayoutBounds().getHeight());
    case TOP:
    default:
        return 0.0;
    }
}
 
Example 2
Source File: PanningSupport.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Removes free space between the contents and the viewport for the sides
 * specified by the given {@link Pos}.
 *
 * @param viewportPolicy
 *            The {@link ViewportPolicy} that is used to remove free space.
 * @param orientation
 *            The orientation {@link Pos} that specifies the sides where
 *            free space is reduced, or the contents is aligned,
 *            respectively.
 * @param alignIfContentsFit
 *            <code>true</code> to indicate that contents are aligned with
 *            the given {@link Pos} if they completely fit into the
 *            viewport, <code>false</code> to indicate that contents are not
 *            aligned, but only free space is reduced if the contents do not
 *            fit into the viewport.
 */
public void removeFreeSpace(ViewportPolicy viewportPolicy, Pos orientation,
		boolean alignIfContentsFit) {
	InfiniteCanvas canvas = (InfiniteCanvas) viewportPolicy.getAdaptable()
			.getRoot().getViewer().getCanvas();
	// determine contents and viewport bounds
	Rectangle viewportBoundsInCanvasLocal = new Rectangle(0, 0,
			canvas.getWidth(), canvas.getHeight());
	Rectangle contentBoundsInCanvasLocal = FX2Geometry
			.toRectangle(canvas.getContentBounds());

	// compute translation based on given alignment position, free space,
	// and contents-may-fit flag
	HPos hpos = orientation.getHpos();
	double deltaTx = 0;
	if (hpos != null) {
		if (HPos.RIGHT.equals(hpos)) {
			double freeSpaceRight = viewportBoundsInCanvasLocal.getRight().x
					- contentBoundsInCanvasLocal.getRight().x;
			deltaTx = alignIfContentsFit && contentBoundsInCanvasLocal
					.getWidth() <= viewportBoundsInCanvasLocal.getWidth()
					|| contentBoundsInCanvasLocal
							.getWidth() > viewportBoundsInCanvasLocal
									.getWidth()
							&& freeSpaceRight > 0 ? freeSpaceRight : 0;
		} else if (HPos.LEFT.equals(hpos)) {
			double freeSpaceLeft = contentBoundsInCanvasLocal.getLeft().x
					- viewportBoundsInCanvasLocal.getLeft().x;
			deltaTx = alignIfContentsFit && contentBoundsInCanvasLocal
					.getWidth() <= viewportBoundsInCanvasLocal.getWidth()
					|| contentBoundsInCanvasLocal
							.getWidth() > viewportBoundsInCanvasLocal
									.getWidth()
							&& freeSpaceLeft > 0 ? -freeSpaceLeft : 0;
		}
		// TODO: HPos.CENTER
	}

	VPos vpos = orientation.getVpos();
	double deltaTy = 0;
	if (vpos != null) {
		if (VPos.BOTTOM.equals(vpos)) {
			double freeSpaceBottom = viewportBoundsInCanvasLocal
					.getBottom().y
					- contentBoundsInCanvasLocal.getBottom().y;
			deltaTy = alignIfContentsFit && contentBoundsInCanvasLocal
					.getHeight() <= viewportBoundsInCanvasLocal.getHeight()
					|| contentBoundsInCanvasLocal
							.getHeight() > viewportBoundsInCanvasLocal
									.getHeight()
							&& freeSpaceBottom > 0 ? freeSpaceBottom : 0;
		} else if (VPos.TOP.equals(vpos)) {
			double freeSpaceTop = contentBoundsInCanvasLocal.getTop().y
					- viewportBoundsInCanvasLocal.getTop().y;
			deltaTy = alignIfContentsFit && contentBoundsInCanvasLocal
					.getHeight() <= viewportBoundsInCanvasLocal.getHeight()
					|| contentBoundsInCanvasLocal
							.getHeight() > viewportBoundsInCanvasLocal
									.getHeight()
							&& freeSpaceTop > 0 ? -freeSpaceTop : 0;
		}
		// TODO: VPos.CENTER
	}
	if (deltaTx != 0 || deltaTy != 0) {
		viewportPolicy.scroll(true, deltaTx, deltaTy);
	}
}
 
Example 3
Source File: JFXNodesList.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
protected void layoutChildren() {
    performingLayout = true;

    List<Node> children = getChildren();

    Insets insets = getInsets();
    double width = getWidth();
    double rotate = getRotate();
    double height = getHeight();
    double left = snapSpace(insets.getLeft());
    double right = snapSpace(insets.getRight());
    double space = snapSpace(getSpacing());
    boolean isFillWidth = isFillWidth();
    double contentWidth = width - left - right;


    Pos alignment = getAlignment();
    alignment = alignment == null ? Pos.TOP_CENTER : alignment;
    final HPos hpos = alignment.getHpos();
    final VPos vpos = alignment.getVpos();

    double y = 0;

    for (int i = 0, size = children.size(); i < size; i++) {
        Node child = children.get(i);
        child.autosize();
        child.setRotate(rotate % 180 == 0 ? rotate : -rotate);

        // init child node if not added using addAnimatedChild method
        if (!animationsMap.containsKey(child)) {
            if (child instanceof JFXNodesList) {
                StackPane container = new StackPane(child);
                container.setPickOnBounds(false);
                getChildren().set(i, container);
            }
            initChild(child, i, null, true);
        }

        double x = 0;
        double childWidth = child.getLayoutBounds().getWidth();
        double childHeight = child.getLayoutBounds().getHeight();


        if(childWidth > width){
            switch (hpos) {
                case CENTER:
                    x = snapPosition(contentWidth - childWidth) / 2;
                    break;
            }
            Node alignToChild = getAlignNodeToChild(child);
            if (alignToChild != null && child instanceof Parent) {
                ((Parent) child).layout();
                double alignedWidth = alignToChild.getLayoutBounds().getWidth();
                double alignedX = alignToChild.getLayoutX();
                if(childWidth / 2 > alignedX + alignedWidth){
                    alignedWidth = -(childWidth / 2 - (alignedWidth/2 + alignedX));
                }else{
                    alignedWidth = alignedWidth/2 + alignedX - childWidth / 2;
                }
                child.setTranslateX(-alignedWidth * Math.cos(Math.toRadians(rotate)));
                child.setTranslateY(alignedWidth * Math.cos(Math.toRadians(90 - rotate)));
            }
        }else{
            childWidth = contentWidth;
        }

        final Insets margin = getMargin(child);
        if (margin != null) {
            childWidth += margin.getLeft() + margin.getRight();
            childHeight += margin.getTop() + margin.getRight();
        }

        layoutInArea(child, x, y, childWidth, childHeight,
            /* baseline shouldn't matter */0,
            margin, isFillWidth, true, hpos, vpos);

        y += child.getLayoutBounds().getHeight() + space;
        if (margin != null) {
            y += margin.getTop() + margin.getBottom();
        }
        y = snapPosition(y);
    }

    performingLayout = false;
}