Java Code Examples for javafx.geometry.Bounds#getMaxX()
The following examples show how to use
javafx.geometry.Bounds#getMaxX() .
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: InfiniteCanvas.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * Ensures that the specified child {@link Node} is visible to the user by * scrolling to its position. The effect and style of the node are taken * into consideration. After revealing a node, it will be fully visible if * it fits within the current viewport bounds. * <p> * When the child node's left side is left to the viewport, it will touch * the left border of the viewport after revealing. When the child node's * right side is right to the viewport, it will touch the right border of * the viewport after revealing. When the child node's top side is above the * viewport, it will touch the top border of the viewport after revealing. * When the child node's bottom side is below the viewport, it will touch * the bottom border of the viewport after revealing. * <p> * The top and left sides have preference over the bottom and right sides, * i.e. when the top side is aligned with the viewport, the bottom side will * not be aligned, and when the left side is aligned with the viewport, the * right side will not be aligned. * * @param child * The child {@link Node} to reveal. */ public void reveal(Node child) { Bounds bounds = sceneToLocal( child.localToScene(child.getBoundsInLocal())); if (bounds.getHeight() <= getHeight()) { if (bounds.getMinY() < 0) { setVerticalScrollOffset( getVerticalScrollOffset() - bounds.getMinY()); } else if (bounds.getMaxY() > getHeight()) { setVerticalScrollOffset(getVerticalScrollOffset() + getHeight() - bounds.getMaxY()); } } if (bounds.getWidth() <= getWidth()) { if (bounds.getMinX() < 0) { setHorizontalScrollOffset( getHorizontalScrollOffset() - bounds.getMinX()); } else if (bounds.getMaxX() > getWidth()) { setHorizontalScrollOffset(getHorizontalScrollOffset() + getWidth() - bounds.getMaxX()); } } }
Example 2
Source File: InfiniteCanvas.java From gef with Eclipse Public License 2.0 | 6 votes |
/** * 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 3
Source File: AutoScrollHandler.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** * 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 4
Source File: YRangeIndicator.java From chart-fx with Apache License 2.0 | 6 votes |
@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 5
Source File: XValueIndicator.java From chart-fx with Apache License 2.0 | 6 votes |
@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 double xPos = minX + getChart().getFirstAxis(Orientation.HORIZONTAL).getDisplayPosition(getValue()); if (xPos < minX || xPos > maxX) { getChartChildren().clear(); } else { layoutLine(xPos, minY, xPos, maxY); layoutMarker(xPos, minY + 1.5 * AbstractSingleValueIndicator.triangleHalfWidth, xPos, maxY); layoutLabel(new BoundingBox(xPos, minY, 0, maxY - minY), AbstractSingleValueIndicator.MIDDLE_POSITION, getLabelPosition()); } }
Example 6
Source File: YValueIndicator.java From chart-fx with Apache License 2.0 | 6 votes |
@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 double yPos = minY + getNumericAxis().getDisplayPosition(getValue()); if (yPos < minY || yPos > maxY) { getChartChildren().clear(); } else { layoutLine(minX, yPos, maxX, yPos); layoutMarker(maxX - 1.5 * AbstractSingleValueIndicator.triangleHalfWidth, yPos, minX, yPos); // + // 1.5*TRIANGLE_HALF_WIDTH layoutLabel(new BoundingBox(minX, yPos, maxX - minX, 0), getLabelPosition(), AbstractSingleValueIndicator.MIDDLE_POSITION); } }
Example 7
Source File: XRangeIndicator.java From chart-fx with Apache License 2.0 | 6 votes |
@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 xAxis = getNumericAxis(); final double value1 = xAxis.getDisplayPosition(getLowerBound()); final double value2 = xAxis.getDisplayPosition(getUpperBound()); final double startX = Math.max(minX, minX + Math.min(value1, value2)); final double endX = Math.min(maxX, minX + Math.max(value1, value2)); layout(new BoundingBox(startX, minY, endX - startX, maxY - minY)); }
Example 8
Source File: DoughnutChart.java From mars-sim with GNU General Public License v3.0 | 6 votes |
private void updateInnerCircleLayout() { double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE; for (PieChart.Data data: getData()) { Node node = data.getNode(); Bounds bounds = node.getBoundsInParent(); if (bounds.getMinX() < minX) { minX = bounds.getMinX(); } if (bounds.getMinY() < minY) { minY = bounds.getMinY(); } if (bounds.getMaxX() > maxX) { maxX = bounds.getMaxX(); } if (bounds.getMaxY() > maxY) { maxY = bounds.getMaxY(); } } innerCircle.setCenterX(minX + (maxX - minX) / 2); innerCircle.setCenterY(minY + (maxY - minY) / 2); innerCircle.setRadius((maxX - minX) / 4); }
Example 9
Source File: MouseUtils.java From chart-fx with Apache License 2.0 | 6 votes |
/** * * @param screenBounds boundary box in screen coordinates * @param mouseLoc mouse screen coordinate * @return maximum external distance (Manhattan-Norm) from the boundary rectangle */ public static double mouseOutsideBoundaryBoxDistance(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()) { minX = screenBounds.getMinX() - x; } else if (x > screenBounds.getMaxX()) { minX = x - screenBounds.getMaxX(); } else { minX = 0.0; } final double minY; if (y < screenBounds.getMinY()) { minY = screenBounds.getMinY() - y; } else if (y > screenBounds.getMaxY()) { minY = y - screenBounds.getMaxY(); } else { minY = 0.0; } return Math.max(minX, minY); }
Example 10
Source File: TestCanvasSelection.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test public void testClickInsideBOundsButOutsideShapeDoesNotSelectIt() { Cmds.of(addLines).execute(); final Bounds bounds = getPane().getChildren().get(0).getBoundsInParent(); final double x = canvas.getScene().getWindow().getX() + Canvas.ORIGIN.getX() + bounds.getMaxX() - 5; final double y = canvas.getScene().getWindow().getY() + Canvas.ORIGIN.getY() + bounds.getMinY() + 5; Cmds.of(() -> clickOn(x, y)).execute(); assertTrue(canvas.getDrawing().getSelection().isEmpty()); }
Example 11
Source File: AppUtils.java From OpenLabeler with Apache License 2.0 | 5 votes |
public static Bounds insetBounds(Bounds bounds, double amount) { return new BoundingBox( bounds.getMinX() + amount, bounds.getMinY() + amount, bounds.getMaxX() - amount, bounds.getMaxY() - amount); }
Example 12
Source File: NodeLayoutBehaviorTests.java From gef with Eclipse Public License 2.0 | 5 votes |
@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 13
Source File: MyBoxController.java From MyBox with Apache License 2.0 | 5 votes |
public void locateImage(Node region, boolean right) { if (!imageCheck.isSelected()) { imagePop.hide(); return; } Bounds bounds = region.localToScreen(region.getBoundsInLocal()); double x = right ? (bounds.getMaxX() + 200) : (bounds.getMinX() - 550); imagePop.show(region, x, bounds.getMinY() - 50); FxmlControl.refreshStyle(imagePop.getOwnerNode().getParent()); }
Example 14
Source File: WoodlandController.java From examples-javafx-repos1 with Apache License 2.0 | 5 votes |
private boolean isPicked(Node n, double sceneX, double sceneY) { Bounds bounds = n.getLayoutBounds(); Bounds boundsScene = n.localToScene( bounds ); if( (sceneX >= boundsScene.getMinX()) && (sceneY >= boundsScene.getMinY()) && (sceneX <= boundsScene.getMaxX()) && ( sceneY <= boundsScene.getMaxY() ) ) { return true; } return false; }
Example 15
Source File: ScrollBottomRightAction.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected Point determinePivotPoint(Bounds bounds) { return new Point(bounds.getMaxX(), bounds.getMaxY()); }
Example 16
Source File: NodeLayoutBehavior.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected void preLayout() { org.eclipse.gef.graph.Node content = getHost().getContent(); Node visual = getHost().getVisual(); Bounds hostBounds = visual.getLayoutBounds(); double minx = hostBounds.getMinX(); double miny = hostBounds.getMinY(); double maxx = hostBounds.getMaxX(); double maxy = hostBounds.getMaxY(); Affine transform = getHost().getVisualTransform(); // initialize size if (ZestProperties.getSize(content) != null) { // no model information available yet, use visual location preLayoutSize = ZestProperties.getSize(content).getCopy(); } else { preLayoutSize = new Dimension(maxx - minx, maxy - miny); } // constrain to visual's min-size { double minWidth = visual.minWidth(-1); double minHeight = visual.minHeight(-1); if (preLayoutSize.width < minWidth) { preLayoutSize.width = minWidth; } if (preLayoutSize.height < minHeight) { preLayoutSize.height = minHeight; } } // System.out.println("pre layout size of " + content + ": " + // preLayoutSize); LayoutProperties.setSize(content, preLayoutSize.getCopy()); // initialize location (layout location is center while visual position // is top-left) if (ZestProperties.getPosition(content) != null) { LayoutProperties.setLocation(content, ZestProperties.getPosition(content).getTranslated(preLayoutSize.getScaled(0.5))); } else { // no model information available yet, use visual location LayoutProperties.setLocation(content, new Point(transform.getTx() + minx + (maxx - minx) / 2, transform.getTy() + miny + (maxy - miny) / 2)); } // additional information inferred from visual LayoutProperties.setResizable(content, visual.isResizable()); }
Example 17
Source File: ScaleBarOverlayRenderer.java From paintera with GNU General Public License v2.0 | 4 votes |
@Override public synchronized void drawOverlays(GraphicsContext graphicsContext) { if (width > 0.0 && height > 0.0 && config.getIsShowing()) { double targetLength = Math.min(width, config.getTargetScaleBarLength()); double[] onePixelWidth = {1.0, 0.0, 0.0}; transform.applyInverse(onePixelWidth, onePixelWidth); final double globalCoordinateWidth = LinAlgHelpers.length(onePixelWidth); // length of scale bar in global coordinate system final double scaleBarWidth = targetLength * globalCoordinateWidth; final double pot = Math.floor( Math.log10( scaleBarWidth ) ); final double l2 = scaleBarWidth / Math.pow( 10, pot ); final int fracs = ( int ) ( 0.1 * l2 * subdivPerPowerOfTen ); final double scale1 = ( fracs > 0 ) ? Math.pow( 10, pot + 1 ) * fracs / subdivPerPowerOfTen : Math.pow( 10, pot ); final double scale2 = ( fracs == 3 ) ? Math.pow( 10, pot + 1 ) : Math.pow( 10, pot + 1 ) * ( fracs + 1 ) / subdivPerPowerOfTen; final double lB1 = scale1 / globalCoordinateWidth; final double lB2 = scale2 / globalCoordinateWidth; final double scale; final double scaleBarLength; if (Math.abs(lB1 - targetLength) < Math.abs(lB2 - targetLength)) { scale = scale1; scaleBarLength = lB1; } else { scale = scale2; scaleBarLength = lB2; } final double[] ratios = UNITS.stream().mapToDouble(unit -> config.getBaseUnit().getConverterTo(unit).convert(scale)).toArray(); int firstSmallerThanZeroIndex = 0; for (; firstSmallerThanZeroIndex < ratios.length; ++firstSmallerThanZeroIndex) { if (ratios[firstSmallerThanZeroIndex] < 1.0) break; } final int unitIndex = Math.max(firstSmallerThanZeroIndex - 1, 0); final Unit<Length> targetUnit = UNITS.get(unitIndex); final double targetScale = config.getBaseUnit().getConverterTo(targetUnit).convert(scale); final double x = 20; final double y = height - 30; final DecimalFormat format = new DecimalFormat(String.format("0.%s", String.join("", Collections.nCopies(config.getNumDecimals(), "#")))); final String scaleBarText = format.format(targetScale) + targetUnit.toString(); final Text text = new Text(scaleBarText); text.setFont(config.getOverlayFont()); final Bounds bounds = text.getBoundsInLocal(); final double tx = 20 + (scaleBarLength - bounds.getMaxX()) / 2; final double ty = y - 5; graphicsContext.setFill(config.getBackgroundColor()); // draw background graphicsContext.fillRect( x - 7, ty - bounds.getHeight() - 3, scaleBarLength + 14, bounds.getHeight() + 25 ); // draw scalebar graphicsContext.setFill(config.getForegroundColor()); graphicsContext.fillRect(x, y, ( int ) scaleBarLength, 10); // draw label graphicsContext.setFont(config.getOverlayFont()); graphicsContext.fillText(scaleBarText, tx, ty); } }
Example 18
Source File: DoublePolygon.java From MyBox with Apache License 2.0 | 4 votes |
@Override public DoubleRectangle getBound() { Bounds bound = polygon.getBoundsInLocal(); return new DoubleRectangle(bound.getMinX(), bound.getMinY(), bound.getMaxX(), bound.getMaxY()); }
Example 19
Source File: DoublePolyline.java From MyBox with Apache License 2.0 | 4 votes |
@Override public DoubleRectangle getBound() { Bounds bound = polyline.getBoundsInLocal(); return new DoubleRectangle(bound.getMinX(), bound.getMinY(), bound.getMaxX(), bound.getMaxY()); }
Example 20
Source File: JFXGeometryTools.java From phoebus with Eclipse Public License 1.0 | 3 votes |
/** 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); }