Java Code Examples for javafx.scene.control.ScrollPane#setHvalue()

The following examples show how to use javafx.scene.control.ScrollPane#setHvalue() . 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: ImagePanel.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private static void ensureVisible(ScrollPane pane, Node node) {
    Bounds viewport = pane.getViewportBounds();
    double contentHeight = pane.getContent().getBoundsInLocal().getHeight();
    double contentWidth = pane.getContent().getBoundsInLocal().getWidth();
    double nodeMinY = node.getBoundsInParent().getMinY();
    double nodeMaxY = node.getBoundsInParent().getMaxY();
    double nodeMinX = node.getBoundsInParent().getMinX();
    double nodeMaxX = node.getBoundsInParent().getMaxX();
    double viewportMinY = (contentHeight - viewport.getHeight()) * pane.getVvalue();
    double viewportMaxY = viewportMinY + viewport.getHeight();
    double viewportMinX = (contentWidth - viewport.getWidth()) * pane.getHvalue();
    double viewportMaxX = viewportMinX + viewport.getWidth();
    if (nodeMinY < viewportMinY) {
        pane.setVvalue(nodeMinY / (contentHeight - viewport.getHeight()));
    } else if (nodeMaxY > viewportMaxY) {
        pane.setVvalue((nodeMaxY - viewport.getHeight()) / (contentHeight - viewport.getHeight()));
    }
    if (nodeMinX < viewportMinX) {
        pane.setHvalue(nodeMinX / (contentWidth - viewport.getWidth()));
    } else if (nodeMaxX > viewportMaxX) {
        pane.setHvalue((nodeMaxX - viewport.getWidth()) / (contentWidth - viewport.getWidth()));
    }

}
 
Example 2
Source File: FXEventQueueDevice.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
protected void ensureVisible(Node target) {
    ScrollPane scrollPane = getParentScrollPane(target);
    if (scrollPane == null) {
        return;
    }
    Node content = scrollPane.getContent();
    Bounds contentBounds = content.localToScene(content.getBoundsInLocal());
    Bounds viewportBounds = scrollPane.getViewportBounds();
    Bounds nodeBounds = target.localToScene(target.getBoundsInLocal());
    if (scrollPane.contains(nodeBounds.getMinX() - contentBounds.getMinX(), nodeBounds.getMinY() - contentBounds.getMinY())) {
        return;
    }
    double toVScroll = (nodeBounds.getMinY() - contentBounds.getMinY())
            * ((scrollPane.getVmax() - scrollPane.getVmin()) / (contentBounds.getHeight() - viewportBounds.getHeight()));
    scrollPane.setVvalue(toVScroll);
    double toHScroll = (nodeBounds.getMinX() - contentBounds.getMinX())
            * ((scrollPane.getHmax() - scrollPane.getHmin()) / (contentBounds.getWidth() - viewportBounds.getWidth()));
    scrollPane.setHvalue(toHScroll);
}
 
Example 3
Source File: ScrollPaneSample2.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private void scrollTo(Node target) {
    ScrollPane scrollPane = getParentScrollPane(target);
    if (scrollPane == null)
        return;
    Node content = scrollPane.getContent();
    Bounds contentBounds = content.localToScene(content.getBoundsInLocal());
    Bounds viewportBounds = scrollPane.getViewportBounds();
    Bounds nodeBounds = target.localToScene(target.getBoundsInLocal());
    double toVScroll = (nodeBounds.getMinY() - contentBounds.getMinY())
            * ((scrollPane.getVmax() - scrollPane.getVmin()) / (contentBounds.getHeight() - viewportBounds.getHeight()));
    if (toVScroll >= scrollPane.getVmin() && toVScroll < scrollPane.getVmax())
        scrollPane.setVvalue(toVScroll);
    double toHScroll = (nodeBounds.getMinX() - contentBounds.getMinX())
            * ((scrollPane.getHmax() - scrollPane.getHmin()) / (contentBounds.getWidth() - viewportBounds.getWidth()));
    if (toHScroll >= scrollPane.getHmin() && toHScroll < scrollPane.getHmax())
        scrollPane.setHvalue(toHScroll);
}
 
Example 4
Source File: ZoomPane.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
private static void repositionScroller(Node scrollContent, ScrollPane scroller, double scaleFactor,
		Point2D scrollOffset) {
	double scrollXOffset = scrollOffset.getX();
	double scrollYOffset = scrollOffset.getY();
	double extraWidth = scrollContent.getLayoutBounds().getWidth() - scroller.getViewportBounds().getWidth();
	if (extraWidth > 0) {
		double halfWidth = scroller.getViewportBounds().getWidth() / 2;
		double newScrollXOffset = (scaleFactor - 1) * halfWidth + scaleFactor * scrollXOffset;
		scroller.setHvalue(
				scroller.getHmin() + newScrollXOffset * (scroller.getHmax() - scroller.getHmin()) / extraWidth);
	} else {
		scroller.setHvalue(scroller.getHmin());
	}
	double extraHeight = scrollContent.getLayoutBounds().getHeight() - scroller.getViewportBounds().getHeight();
	if (extraHeight > 0) {
		double halfHeight = scroller.getViewportBounds().getHeight() / 2;
		double newScrollYOffset = (scaleFactor - 1) * halfHeight + scaleFactor * scrollYOffset;
		scroller.setVvalue(
				scroller.getVmin() + newScrollYOffset * (scroller.getVmax() - scroller.getVmin()) / extraHeight);
	} else {
		scroller.setHvalue(scroller.getHmin());
	}
}
 
Example 5
Source File: JFXRepresentation.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Ctrl-Wheel zoom gesture help function
 *  Repositioning scrollbars in scroller so that the zoom centre stays at mouse cursor
 */
private void repositionScroller(final Node scrollContent, final ScrollPane scroller, final double scaleFactor, final Point2D scrollOffset, final Point2D mouse)
{
    double scrollXOffset = scrollOffset.getX();
    double scrollYOffset = scrollOffset.getY();
    double extraWidth = scrollContent.getLayoutBounds().getWidth() - scroller.getViewportBounds().getWidth();
    if (extraWidth > 0)
    {
        double newScrollXOffset = (scaleFactor - 1) *  mouse.getX() + scaleFactor * scrollXOffset;
        scroller.setHvalue(scroller.getHmin() + newScrollXOffset * (scroller.getHmax() - scroller.getHmin()) / extraWidth);
    }
    else
        scroller.setHvalue(scroller.getHmin());
    double extraHeight = scrollContent.getLayoutBounds().getHeight() - scroller.getViewportBounds().getHeight();
    if (extraHeight > 0)
    {
        double newScrollYOffset = (scaleFactor - 1) * mouse.getY() + scaleFactor * scrollYOffset;
        scroller.setVvalue(scroller.getVmin() + newScrollYOffset * (scroller.getVmax() - scroller.getVmin()) / extraHeight);
    }
    else
        scroller.setHvalue(scroller.getHmin());
}
 
Example 6
Source File: Canvas.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setZoom(final double x, final double y, final double z) {
	if(z <= getMaxZoom() && z >= getMinZoom() && !MathUtils.INST.equalsDouble(z, zoom.getValue())) {
		final double oldZoom = zoom.get();
		final ScrollPane sp = getScrollPane();
		zoom.setValue(z);
		setScaleX(z);
		setScaleY(z);

		if(MathUtils.INST.isValidPt(x, y) && sp != null) {
			sp.layout();

			final double newX = x / oldZoom * z;
			final double newY = y / oldZoom * z;
			final double gapX = newX - x;
			final double gapY = newY - y;
			final double gapInH = gapX / (getWidth() - sp.getViewportBounds().getWidth());
			final double gapInV = gapY / (getHeight() - sp.getViewportBounds().getHeight());

			sp.setHvalue(sp.getHvalue() + gapInH);
			sp.setVvalue(sp.getVvalue() + gapInV);
		}
		setModified(true);
	}
}
 
Example 7
Source File: OnlyScrollPaneSkin.java    From oim-fx with MIT License 5 votes vote down vote up
private double updatePosX() {
	final ScrollPane sp = getSkinnable();
	double x = isReverseNodeOrientation() ? (hsb.getMax() - (posX - hsb.getMin())) : posX;
	double minX = Math.min((-x / (hsb.getMax() - hsb.getMin()) * (nodeWidth - contentWidth)), 0);
	viewContent.setLayoutX(snapPosition(minX));
	if (!sp.hvalueProperty().isBound())
		sp.setHvalue(Utils.clamp(sp.getHmin(), posX, sp.getHmax()));
	return posX;
}
 
Example 8
Source File: FxmlControl.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static void setScrollPane(ScrollPane scrollPane, double xOffset,
        double yOffset) {
    final Bounds visibleBounds = scrollPane.getViewportBounds();
    double scrollWidth = scrollPane.getContent().getBoundsInParent().getWidth() - visibleBounds.getWidth();
    double scrollHeight = scrollPane.getContent().getBoundsInParent().getHeight() - visibleBounds.getHeight();

    scrollPane.setHvalue(scrollPane.getHvalue() + xOffset / scrollWidth);
    scrollPane.setVvalue(scrollPane.getVvalue() + yOffset / scrollHeight);
}
 
Example 9
Source File: CircuitSim.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setScrollPosition(double x, double y) {
	CircuitManager manager = getCurrentCircuit();
	if(manager != null) {
		ScrollPane scrollPane = manager.getCanvasScrollPane();
		Canvas canvas = manager.getCanvas();
		
		scrollPane.setHvalue(scrollPane.getHmax() * x / canvas.getWidth());
		scrollPane.setVvalue(scrollPane.getVmax() * y / canvas.getHeight());
	}
}