Java Code Examples for javafx.geometry.Bounds#getMinY()

The following examples show how to use javafx.geometry.Bounds#getMinY() . 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: AutoScrollHandler.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Return the edge of the {@link ScrollPane} where the cursor exited.
 *
 * @param x The current cursor x position relative to the {@link ScrollPane}.
 * @param y The current cursor y position relative to the {@link ScrollPane}.
 * @return A {@link Edge} object, {code null} if the cursor is actually inside the {@link ScrollPane}.
 */
private Edge getEdge ( final double x, final double y ) {

    Bounds bounds = scrollPane.getBoundsInLocal();

    if ( x <= bounds.getMinX() ) {
        return Edge.LEFT;
    } else if ( x >= bounds.getMaxX() ) {
        return Edge.RIGHT;
    } else if ( y <= bounds.getMinY() ) {
        return Edge.TOP;
    } else if ( y >= bounds.getMaxY() ) {
        return Edge.BOTTOM;
    } else {
        // Inside
        return null;
    }

}
 
Example 2
Source File: TargetView.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
private void addResizeAnchors() {
	final Bounds localBounds = getTargetGroup().getBoundsInLocal();
	final double horizontalMiddle = localBounds.getMinX() + (localBounds.getWidth() / 2) - (ANCHOR_WIDTH / 2);
	final double verticleMiddle = localBounds.getMinY() + (localBounds.getHeight() / 2) - (ANCHOR_HEIGHT / 2);

	// Top left
	addAnchor(localBounds.getMinX(), localBounds.getMinY());
	// Top middle
	addAnchor(horizontalMiddle, localBounds.getMinY());
	// Top right
	addAnchor(localBounds.getMaxX() - ANCHOR_WIDTH, localBounds.getMinY());
	// Middle left
	addAnchor(localBounds.getMinX(), verticleMiddle);
	// Middle right
	addAnchor(localBounds.getMaxX() - ANCHOR_WIDTH, verticleMiddle);
	// Bottom left
	addAnchor(localBounds.getMinX(), localBounds.getMaxY() - ANCHOR_HEIGHT);
	// Bottom middle
	addAnchor(horizontalMiddle, localBounds.getMaxY() - ANCHOR_HEIGHT);
	// Bottom right
	addAnchor(localBounds.getMaxX() - ANCHOR_WIDTH, localBounds.getMaxY() - ANCHOR_HEIGHT);
}
 
Example 3
Source File: DockUIPanel.java    From AnchorFX with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void manageDragEvent(MouseEvent event) {
    if (!node.draggingProperty().get()) {

        if (!node.maximizingProperty().get()) {
            Bounds bounds = node.localToScreen(barPanel.getBoundsInLocal());

            deltaDragging = new Point2D(event.getScreenX() - bounds.getMinX(),
                                        event.getScreenY() - bounds.getMinY());

            node.enableDraggingOnPosition(event.getScreenX() - deltaDragging.getX(), event.getScreenY() - deltaDragging.getY());
        }

    }
    else {
        if (node.getFloatableStage() != null && !node.getFloatableStage().inResizing() && node.draggingProperty().get()) {

            if (!node.maximizingProperty().get()) {
                node.moveFloatable(event.getScreenX() - deltaDragging.getX(),
                                   event.getScreenY() - deltaDragging.getY());

                //node.stationProperty().get().searchTargetNode(event.getScreenX(), event.getScreenY());
                AnchorageSystem.searchTargetNode(event.getScreenX(), event.getScreenY());
            }
        }
    }
}
 
Example 4
Source File: InfiniteCanvas.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Computes and returns the bounds of the scrollable area within this
 * {@link InfiniteCanvas}.
 *
 * @return The bounds of the scrollable area, i.e.
 *         <code>[minx, miny, maxx, maxy]</code>.
 */
protected double[] computeScrollableBoundsInLocal() {
	double[] cb = Arrays.copyOf(contentBounds, contentBounds.length);
	Bounds db = getContentGroup().getBoundsInParent();

	// factor in the viewport extending the content bounds
	if (cb[0] < 0) {
		cb[0] = 0;
	}
	if (cb[1] < 0) {
		cb[1] = 0;
	}
	if (cb[2] > getWidth()) {
		cb[2] = 0;
	} else {
		cb[2] = getWidth() - cb[2];
	}
	if (cb[3] > getHeight()) {
		cb[3] = 0;
	} else {
		cb[3] = getHeight() - cb[3];
	}

	return new double[] { db.getMinX() - cb[0], db.getMinY() - cb[1],
			db.getMaxX() + cb[2], db.getMaxY() + cb[3] };
}
 
Example 5
Source File: MouseUtils.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param screenBounds boundary box in screen coordinates
 * @param mouseLoc mouse screen coordinate
 * @return minimum internal distance (Manhattan-Norm) from the boundary rectangle
 */
public static double mouseInsideBoundaryBoxDistance(final Bounds screenBounds, final Point2D mouseLoc) {
    if (!screenBounds.contains(mouseLoc)) {
        return 0;
    }
    final double x = mouseLoc.getX();
    final double y = mouseLoc.getY();
    final double minX;
    if (x > screenBounds.getMinX() && x < screenBounds.getMaxX()) {
        minX = Math.min(x - screenBounds.getMinX(), screenBounds.getMaxX() - x);
    } else {
        minX = 0.0;
    }
    final double minY;
    if (y > screenBounds.getMinY() && y < screenBounds.getMaxY()) {
        minY = Math.min(y - screenBounds.getMinY(), screenBounds.getMaxY() - y);
    } else {
        minY = 0.0;
    }

    return Math.min(minX, minY);
}
 
Example 6
Source File: Zoomer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
/**
 * take a snapshot of present view (needed for scroll zoom interactor
 */
private void makeSnapshotOfView() {
    final Bounds bounds = getChart().getBoundsInLocal();
    final double minX = bounds.getMinX();
    final double minY = bounds.getMinY();
    final double maxX = bounds.getMaxX();
    final double maxY = bounds.getMaxY();

    zoomRectangle.setX(bounds.getMinX());
    zoomRectangle.setY(bounds.getMinY());
    zoomRectangle.setWidth(maxX - minX);
    zoomRectangle.setHeight(maxY - minY);

    pushCurrentZoomWindows();
    performZoom(getZoomDataWindows(), true);
    zoomRectangle.setVisible(false);
}
 
Example 7
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Bounds getParagraphBoundsOnScreen(Cell<Paragraph<PS, SEG, S>, ParagraphBox<PS, SEG, S>> cell) {
    Bounds nodeLocal = cell.getNode().getBoundsInLocal();
    Bounds nodeScreen = cell.getNode().localToScreen(nodeLocal);
    Bounds areaLocal = getBoundsInLocal();
    Bounds areaScreen = localToScreen(areaLocal);

    // use area's minX if scrolled right and paragraph's left is not visible
    double minX = nodeScreen.getMinX() < areaScreen.getMinX()
            ? areaScreen.getMinX()
            : nodeScreen.getMinX();
    // use area's minY if scrolled down vertically and paragraph's top is not visible
    double minY = nodeScreen.getMinY() < areaScreen.getMinY()
            ? areaScreen.getMinY()
            : nodeScreen.getMinY();
    // use area's width whether paragraph spans outside of it or not
    // so that short or long paragraph takes up the entire space
    double width = areaScreen.getWidth();
    // use area's maxY if scrolled up vertically and paragraph's bottom is not visible
    double maxY = nodeScreen.getMaxY() < areaScreen.getMaxY()
            ? nodeScreen.getMaxY()
            : areaScreen.getMaxY();
    return new BoundingBox(minX, minY, width, maxY - minY);
}
 
Example 8
Source File: YRangeIndicator.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@Override
public void layoutChildren() {
    if (getChart() == null) {
        return;
    }

    final Bounds plotAreaBounds = getChart().getCanvas().getBoundsInLocal();
    final double minX = plotAreaBounds.getMinX();
    final double maxX = plotAreaBounds.getMaxX();
    final double minY = plotAreaBounds.getMinY();
    final double maxY = plotAreaBounds.getMaxY();

    final Axis yAxis = getNumericAxis();
    final double value1 = yAxis.getDisplayPosition(getLowerBound());
    final double value2 = yAxis.getDisplayPosition(getUpperBound());

    final double startY = Math.max(minY, minY + Math.min(value1, value2));
    final double endY = Math.min(maxY, minY + Math.max(value1, value2));

    layout(new BoundingBox(minX, startY, maxX - minX, endY - startY));
}
 
Example 9
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void showCaretAtTop() {
    int parIdx = getCurrentParagraph();
    Cell<Paragraph<PS, SEG, S>, ParagraphBox<PS, SEG, S>> cell = virtualFlow.getCell(parIdx);
    Bounds caretBounds = cell.getNode().getCaretBounds(caretSelectionBind.getUnderlyingCaret());
    double y = caretBounds.getMinY();
    suspendVisibleParsWhile(() -> virtualFlow.showAtOffset(parIdx, -y));
}
 
Example 10
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static Bounds extendLeft(Bounds b, double w) {
    if(w == 0) {
        return b;
    } else {
        return new BoundingBox(
                b.getMinX() - w, b.getMinY(),
                b.getWidth() + w, b.getHeight());
    }
}
 
Example 11
Source File: NodeLayoutBehaviorTests.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void test_provide() throws Exception {
	final Point location = new Point(10, 20);

	// setup with non-resizable figure
	Node nodeLayout = createNode();
	NodeLayoutBehavior behavior = createNodeLayoutBehavior(location, null, nodeLayout);
	Group visual = behavior.getHost().getVisual();

	// preLayout
	Method method = NodeLayoutBehavior.class.getDeclaredMethod("preLayout", new Class[] {});
	method.setAccessible(true);
	method.invoke(behavior, new Object[] {});

	assertEquals(visual.isResizable(), LayoutProperties.isResizable(nodeLayout));

	// zest position is top-left, while layout location is center
	Bounds layoutBounds = visual.getLayoutBounds();
	double minX = layoutBounds.getMinX();
	double minY = layoutBounds.getMinY();
	double maxX = layoutBounds.getMaxX();
	double maxY = layoutBounds.getMaxY();
	assertEquals(location, LayoutProperties.getLocation(nodeLayout).translate(-minX - ((maxX - minX) / 2),
			-minY - ((maxY - minY) / 2)));
	assertEquals(new Dimension(layoutBounds.getWidth(), layoutBounds.getHeight()),
			LayoutProperties.getSize(nodeLayout));
}
 
Example 12
Source File: TestCanvasSelection.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDnDToSelectShapeSelectsIt2() {
	Cmds.of(addLines).execute();
	final Bounds bounds = getPane().getChildren().get(0).getBoundsInParent();
	final double x = canvas.getScene().getWindow().getX() + Canvas.ORIGIN.getX() + bounds.getMinX() - 10d;
	final double y = canvas.getScene().getWindow().getY() + Canvas.ORIGIN.getY() + bounds.getMinY();
	Cmds.of(() -> clickOn(x, y), () -> drag(x + 10, y + 10),
		() -> drag(x + 60, y + 10), () -> drag(x + 70, y + 10)).execute();
	assertEquals(1, canvas.getDrawing().getSelection().size());
	assertSame(addedPolyline, canvas.getDrawing().getSelection().getShapeAt(0).orElseThrow());
}
 
Example 13
Source File: DragResizerUtil.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected void setNewInitialEventCoordinates(final MouseEvent event) {
    final Bounds bounds = node.getBoundsInParent();
    nodePositionX = bounds.getMinX();
    nodePositionY = bounds.getMinY();
    nodeHeight = bounds.getHeight();
    nodeWidth = bounds.getWidth();
    clickX = event.getX();
    clickY = event.getY();
}
 
Example 14
Source File: TestCanvasSelection.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDnDToSelectGridWithShift() {
	assumeFalse(GraphicsEnvironment.isHeadless());
	Cmds.of(addRec, addRec2, clickOnAddedFirstShape, ctrlClickOnAddedRec2).execute();
	final Bounds bounds = getPane().getChildren().get(1).getBoundsInParent();
	final double x = canvas.getScene().getWindow().getX() + Canvas.ORIGIN.getX() + bounds.getMinX() - 20d;
	final double y = canvas.getScene().getWindow().getY() + Canvas.ORIGIN.getY() + bounds.getMinY();
	Cmds.of(() -> press(KeyCode.SHIFT),
		() -> clickOn(x, y),
		() -> drag(x + 10, y + 20),
		() -> drag(x + 50, y + 20),
		() -> drag(x + 60, y + 20)).execute();
	assertEquals(1, canvas.getDrawing().getSelection().size());
	assertSame(addedRec, canvas.getDrawing().getSelection().getShapeAt(0).orElseThrow());
}
 
Example 15
Source File: InifinteCanvasSnippet.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Scene createScene() {
	BorderPane root = new BorderPane();

	infiniteCanvas = new InfiniteCanvas();
	root.setCenter(infiniteCanvas);
	infiniteCanvas.getContentGroup().getChildren().addAll(
			rect(25, 25, 100, 50, Color.BLUE),
			rect(25, 200, 25, 50, Color.BLUE),
			rect(150, 100, 75, 75, Color.BLUE),
			rect(-100, -100, 30, 60, Color.CYAN),
			rect(75, 75, 150, 150, Color.RED));

	// translate to top-left most content node
	Bounds canvasBounds = infiniteCanvas.getContentBounds();
	double minx = canvasBounds.getMinX();
	double miny = canvasBounds.getMinY();
	infiniteCanvas.setHorizontalScrollOffset(-minx);
	infiniteCanvas.setVerticalScrollOffset(-miny);

	infiniteCanvas.setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			if (MouseButton.SECONDARY.equals(event.getButton())) {
				// determine pivot in content group
				Group contentGroup = infiniteCanvas.getContentGroup();
				Point2D contentPivot = contentGroup
						.sceneToLocal(event.getSceneX(), event.getSceneY());
				double zoomFactor = event.isControlDown() ? 4d / 5 : 5d / 4;

				// compute zoom transformation
				Affine tx = infiniteCanvas.getContentTransform();
				AffineTransform at = FX2Geometry.toAffineTransform(tx);
				at.concatenate(new AffineTransform()
						.translate(contentPivot.getX(), contentPivot.getY())
						.scale(zoomFactor, zoomFactor)
						.translate(-contentPivot.getX(),
								-contentPivot.getY()));
				Affine affine = Transform.affine(at.getM00(), at.getM01(),
						at.getM10(), at.getM11(), at.getTranslateX(),
						at.getTranslateY());
				infiniteCanvas.setContentTransform(affine);
			}
		}
	});

	return new Scene(root, 400, 300);
}
 
Example 16
Source File: AbstractEdgeViewer.java    From JetUML with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Rectangle getBounds(Edge pEdge)
{
	Bounds bounds = getShape(pEdge).getBoundsInLocal();
	return new Rectangle((int)bounds.getMinX(), (int)bounds.getMinY(), (int)bounds.getWidth(), (int)bounds.getHeight());
}
 
Example 17
Source File: InfiniteCanvas.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Adjusts the {@link #horizontalScrollOffsetProperty()}, the
 * {@link #verticalScrollOffsetProperty()}, and the
 * {@link #contentTransformProperty()}, so that the
 * {@link #getContentGroup()} is fully visible within the bounds of this
 * {@link InfiniteCanvas} if possible. The content will be centered, but the
 * given <i>zoomMin</i> and <i>zoomMax</i> values restrict the zoom factor,
 * so that the content might exceed the canvas, or does not fill it
 * completely.
 * <p>
 * Note, that the {@link #contentTransformProperty()} is set to a pure scale
 * transformation by this method.
 * <p>
 * Note, that fit-to-size cannot be performed in all situations. If the
 * content area is 0 or the canvas area is 0, then this method cannot fit
 * the content to the canvas size, and therefore, throws an
 * {@link IllegalStateException}. The following condition can be used to
 * test if fit-to-size can be performed:
 *
 * <pre>
 * if (infiniteCanvas.getWidth() &gt; 0 &amp;&amp; infiniteCanvas.getHeight() &gt; 0
 * 		&amp;&amp; infiniteCanvas.getContentBounds().getWidth() &gt; 0
 * 		&amp;&amp; infiniteCanvas.getContentBounds().getHeight() &gt; 0) {
 * 	// save to call fit-to-size here
 * 	infiniteCanvas.fitToSize();
 * }
 * </pre>
 *
 * @param zoomMin
 *            The minimum zoom level.
 * @param zoomMax
 *            The maximum zoom level.
 * @throws IllegalStateException
 *             when the content area is zero or the canvas area is zero.
 */
public void fitToSize(double zoomMin, double zoomMax) {
	// validate content size is not 0
	Bounds contentBounds = getContentBounds();
	double contentWidth = contentBounds.getWidth();
	if (Double.isNaN(contentWidth) || Double.isInfinite(contentWidth)
			|| contentWidth <= 0) {
		throw new IllegalStateException("Content area is zero.");
	}
	double contentHeight = contentBounds.getHeight();
	if (Double.isNaN(contentHeight) || Double.isInfinite(contentHeight)
			|| contentHeight <= 0) {
		throw new IllegalStateException("Content area is zero.");
	}

	// validate canvas size is not 0
	if (getWidth() <= 0 || getHeight() <= 0) {
		throw new IllegalStateException("Canvas area is zero.");
	}

	// compute zoom factor
	double zf = Math.min(getWidth() / contentWidth,
			getHeight() / contentHeight);

	// validate zoom factor
	if (Double.isInfinite(zf) || Double.isNaN(zf) || zf <= 0) {
		throw new IllegalStateException("Invalid zoom factor.");
	}

	// compute content center
	double cx = contentBounds.getMinX() + contentBounds.getWidth() / 2;
	double cy = contentBounds.getMinY() + contentBounds.getHeight() / 2;

	// compute visible area center
	double vx = getWidth() / 2;
	double vy = getHeight() / 2;

	// scroll to center position
	setHorizontalScrollOffset(getHorizontalScrollOffset() + vx - cx);
	setVerticalScrollOffset(getVerticalScrollOffset() + vy - cy);

	// compute pivot point for zoom within content coordinates
	Point2D pivot = getContentGroup().sceneToLocal(vx, vy);

	// restrict zoom factor to [zoomMin, zoomMax] range
	AffineTransform contentTransform = FX2Geometry
			.toAffineTransform(getContentTransform());
	double realZoomFactor = contentTransform.getScaleX() * zf;
	if (realZoomFactor > zoomMax) {
		zf = zoomMax / contentTransform.getScaleX();
	}
	if (realZoomFactor < zoomMin) {
		zf = zoomMin / contentTransform.getScaleX();
	}

	// compute scale transformation (around visible center)
	AffineTransform scaleTransform = new AffineTransform()
			.translate(pivot.getX(), pivot.getY()).scale(zf, zf)
			.translate(-pivot.getX(), -pivot.getY());

	// concatenate old transformation and scale transformation to yield the
	// new transformation
	AffineTransform newTransform = contentTransform
			.concatenate(scaleTransform);
	setContentTransform(Geometry2FX.toFXAffine(newTransform));
}
 
Example 18
Source File: Tile3D.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
private Bounds localetoRoot(SVNode sv) {
    Node n = sv.getImpl();
    Bounds node = n.localToScene(n.getLayoutBounds());
    Bounds root = currentRoot2D.getImpl().localToScene(currentRoot2D.getImpl().getLayoutBounds());
    return new BoundingBox(node.getMinX() - root.getMinX(), node.getMinY() - root.getMinY(), node.getWidth(), node.getHeight());
}
 
Example 19
Source File: LiveMapLocate.java    From marathonv5 with Apache License 2.0 3 votes vote down vote up
public LiveMapLocate(Group group, Bounds bounds){
    
    rangeX = bounds.getMinX() - bounds.getMaxX();
    rangeY = bounds.getMinY() - bounds.getMaxY();
    
    scaleLongToX = rangeX/rangeLong;
    scaleLatToY = rangeY/rangeLat;
    
    this.bounds = bounds;
    this.group = group;
          
}
 
Example 20
Source File: FX2Geometry.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Converts the given JavaFX {@link Bounds} to a {@link Rectangle}.
 * 
 * @param b
 *            The JavaFX {@link Bounds} to convert.
 * @return The new {@link Rectangle}.
 */
public static final Rectangle toRectangle(Bounds b) {
	return new Rectangle(b.getMinX(), b.getMinY(), b.getWidth(), b.getHeight());
}