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

The following examples show how to use javafx.scene.control.ScrollPane#getHvalue() . 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: TestLaTeXDraw.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMoveViewPort(final FxRobot robot) {
	Platform.runLater(() -> {
		try {
			app.getMainStage().showAndWait();
		}catch(final IllegalStateException ignored) {
			// Already visible
		}
	});
	WaitForAsyncUtils.waitForFxEvents();
	final ScrollPane pane = robot.lookup("#scrollPane").query();
	final double hvalue = pane.getHvalue();
	final double vvalue = pane.getVvalue();
	robot.drag("#canvas", MouseButton.MIDDLE).dropBy(100d, 200d);
	WaitForAsyncUtils.waitForFxEvents();
	assertThat(hvalue).isGreaterThan(pane.getHvalue());
	assertThat(vvalue).isGreaterThan(pane.getVvalue());
}
 
Example 3
Source File: ZoomPane.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
private static Point2D figureScrollOffset(Node scrollContent, ScrollPane scroller) {
	double extraWidth = scrollContent.getLayoutBounds().getWidth() - scroller.getViewportBounds().getWidth();
	double hScrollProportion = (scroller.getHvalue() - scroller.getHmin())
			/ (scroller.getHmax() - scroller.getHmin());
	double scrollXOffset = hScrollProportion * Math.max(0, extraWidth);
	double extraHeight = scrollContent.getLayoutBounds().getHeight() - scroller.getViewportBounds().getHeight();
	double vScrollProportion = (scroller.getVvalue() - scroller.getVmin())
			/ (scroller.getVmax() - scroller.getVmin());
	double scrollYOffset = vScrollProportion * Math.max(0, extraHeight);
	return new Point2D(scrollXOffset, scrollYOffset);
}
 
Example 4
Source File: JFXRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Ctrl-Wheel zoom gesture help function
 *  Store scroll offset of scrollContent (scroll_body Group) in a scroller (model_root ScrollPane) before zoom
 */
private Point2D figureScrollOffset(final Node scrollContent, final ScrollPane scroller)
{
    double extraWidth = scrollContent.getLayoutBounds().getWidth() - scroller.getViewportBounds().getWidth();
    double hScrollProportion = (scroller.getHvalue() - scroller.getHmin()) / (scroller.getHmax() - scroller.getHmin());
    double scrollXOffset = hScrollProportion * Math.max(0, extraWidth);
    double extraHeight = scrollContent.getLayoutBounds().getHeight() - scroller.getViewportBounds().getHeight();
    double vScrollProportion = (scroller.getVvalue() - scroller.getVmin()) / (scroller.getVmax() - scroller.getVmin());
    double scrollYOffset = vScrollProportion * Math.max(0, extraHeight);
    return new Point2D(scrollXOffset, scrollYOffset);
}
 
Example 5
Source File: DiagramTab.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private ViewportProjection getViewportProjection()
{
	ScrollPane scrollPane = (ScrollPane)((BorderPane)getContent()).getCenter();
	Bounds bounds = scrollPane.getViewportBounds();
	// Because, when the scrollbars are not displayed, the Scrollpane will increase
	// the viewport size beyond the canvas size, it's necessary to max out the dimensions
	// at the size of the canvas.
	int viewportWidth = Math.min((int) bounds.getWidth(), (int) aDiagramCanvas.getWidth());
	int viewportHeight = Math.min((int) bounds.getHeight(), (int) aDiagramCanvas.getHeight());
	return new ViewportProjection(viewportWidth, viewportHeight, 
			(int) aDiagramCanvas.getWidth(), (int) aDiagramCanvas.getHeight(), 
			scrollPane.getHvalue(), scrollPane.getVvalue());
}
 
Example 6
Source File: JFXGeometryTools.java    From phoebus with Eclipse Public License 1.0 3 votes vote down vote up
/** Get origin of a ScrollPane
 *
 *  <p>If the content is smaller than the scroll pane,
 *  the upper left corner of the scroll pane will show point (0, 0)
 *  of the content.
 *
 *  <p>As the content gets larger than the scroll pane,
 *  scroll bars allow panning and this method
 *  then determines which (x, y) of the content is displayed
 *  in the upper left corner of the scroll pane.
 *
 *  @param scroll_pane {@link ScrollPane}
 *  @return Coordinates content in upper left corner
 */
public static Point2D getContentOrigin(final ScrollPane scroll_pane)
{
    final Bounds viewport = scroll_pane.getViewportBounds();
    final Bounds content = scroll_pane.getContent().getBoundsInLocal();
    // Tried contentgetWidth() but note that content.getMinX() may be < 0.
    // Using content.getMaxX() works in all cases.
    final double x = (content.getMaxX() - viewport.getWidth()) * scroll_pane.getHvalue();
    final double y = (content.getMaxY() - viewport.getHeight()) * scroll_pane.getVvalue();
    return new Point2D(x, y);
}