Java Code Examples for javafx.geometry.Bounds#getMinX()
The following examples show how to use
javafx.geometry.Bounds#getMinX() .
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: 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 2
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 3
Source File: FXEventQueueDevice.java From marathonv5 with Apache License 2.0 | 6 votes |
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 4
Source File: DockUIPanel.java From AnchorFX with GNU Lesser General Public License v3.0 | 6 votes |
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 5
Source File: ShapeConverter.java From Enzo with Apache License 2.0 | 5 votes |
public static String convertRectangle(final Rectangle RECTANGLE) { final StringBuilder fxPath = new StringBuilder(); final Bounds bounds = RECTANGLE.getBoundsInLocal(); if (Double.compare(RECTANGLE.getArcWidth(), 0.0) == 0 && Double.compare(RECTANGLE.getArcHeight(), 0.0) == 0) { fxPath.append("M ").append(bounds.getMinX()).append(" ").append(bounds.getMinY()).append(" ") .append("H ").append(bounds.getMaxX()).append(" ") .append("V ").append(bounds.getMaxY()).append(" ") .append("H ").append(bounds.getMinX()).append(" ") .append("V ").append(bounds.getMinY()).append(" ") .append("Z"); } else { double x = bounds.getMinX(); double y = bounds.getMinY(); double width = bounds.getWidth(); double height = bounds.getHeight(); double arcWidth = RECTANGLE.getArcWidth(); double arcHeight = RECTANGLE.getArcHeight(); double r = x + width; double b = y + height; fxPath.append("M ").append(x + arcWidth).append(" ").append(y).append(" ") .append("L ").append(r - arcWidth).append(" ").append(y).append(" ") .append("Q ").append(r).append(" ").append(y).append(" ").append(r).append(" ").append(y + arcHeight).append(" ") .append("L ").append(r).append(" ").append(y + height - arcHeight).append(" ") .append("Q ").append(r).append(" ").append(b).append(" ").append(r - arcWidth).append(" ").append(b).append(" ") .append("L ").append(x + arcWidth).append(" ").append(b).append(" ") .append("Q ").append(x).append(" ").append(b).append(" ").append(x).append(" ").append(b - arcHeight).append(" ") .append("L ").append(x).append(" ").append(y + arcHeight).append(" ") .append("Q ").append(x).append(" ").append(y).append(" ").append(x + arcWidth).append(" ").append(y).append(" ") .append("Z"); } return fxPath.toString(); }
Example 6
Source File: SelectionStripSkin.java From WorkbenchFX with Apache License 2.0 | 5 votes |
private void scrollTo(T item) { Node node = nodeMap.get(item); if (node != null) { SelectionStrip strip = getSkinnable(); strip.getProperties().remove(SCROLL_TO_KEY); final Bounds nodeBounds = node.localToParent(node.getLayoutBounds()); final double x = -nodeBounds.getMinX() + strip.getWidth() / 2 - nodeBounds.getWidth() / 2; final double x1 = -translateX.get(); final double x2 = x1 + strip.getLayoutBounds().getWidth(); if (x1 > nodeBounds.getMinX() || x2 < nodeBounds.getMaxX()) { if (strip.isAnimateScrolling()) { KeyValue keyValue = new KeyValue(translateX, x); KeyFrame keyFrame = new KeyFrame(strip.getAnimationDuration(), keyValue); Timeline timeline = new Timeline(keyFrame); timeline.play(); } else { translateX.set(x); } } } }
Example 7
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 8
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 9
Source File: TestCanvasSelection.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test public void testDnDToSelectShapeSelectsIt() { Cmds.of(addLines).execute(); final Bounds bounds = getPane().getChildren().get(0).getBoundsInParent(); final double x = canvas.getScene().getWindow().getX() + Canvas.ORIGIN.getX() + bounds.getMinX() + bounds.getWidth() / 2d - 20d; final double y = canvas.getScene().getWindow().getY() + Canvas.ORIGIN.getY() + bounds.getMinY() + bounds.getHeight() / 2d; Cmds.of(() -> clickOn(x, y), () -> drag(x + 10, y + 10), () -> drag(x + 50, y), () -> drag(x + 100, y)).execute(); assertEquals(1, canvas.getDrawing().getSelection().size()); assertSame(addedPolyline, canvas.getDrawing().getSelection().getShapeAt(0).orElseThrow()); }
Example 10
Source File: TestCanvasSelection.java From latexdraw with GNU General Public License v3.0 | 5 votes |
@Test public void testDnDToSelectRecOutToIn() { Cmds.of(addRec).execute(); final Bounds bounds = getPane().getChildren().get(0).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(() -> clickOn(x, y), () -> drag(x + 10, y + 20), () -> drag(x + 50, y + 20), () -> drag(x + 100, y + 20)).execute(); assertEquals(1, canvas.getDrawing().getSelection().size()); assertSame(addedRec, canvas.getDrawing().getSelection().getShapeAt(0).orElseThrow()); }
Example 11
Source File: MarqueeOnDragHandler.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Returns a {@link List} of all {@link Node}s that are descendants of the * given root {@link Node} and fully contained within the bounds specified * by <code>[x0, y0, x1, y1]</code>. * * @param root * The root {@link Node}. * @param x0 * The minimum x-coordinate. * @param y0 * The minimum y-coordinate. * @param x1 * The maximum x-coordinate. * @param y1 * The maximum y-coordinate. * @return A {@link List} containing all {@link Node}s that are descendants * of the given root {@link Node} and fully contained within the * specified bounds. */ // TODO: move to utility public static List<Node> findContainedNodes(Node root, double x0, double y0, double x1, double y1) { Bounds bounds; double bx1, bx0, by1, by0; List<Node> containedNodes = new ArrayList<>(); Queue<Node> nodes = new LinkedList<>(); nodes.add(root); while (!nodes.isEmpty()) { Node current = nodes.remove(); bounds = current.getBoundsInLocal(); bounds = current.localToScene(bounds); bx1 = bounds.getMaxX(); bx0 = bounds.getMinX(); by1 = bounds.getMaxY(); by0 = bounds.getMinY(); if (bx1 < x0 || bx0 > x1 || by1 < y0 || by0 > y1) { // current node is outside of marquee bounds => dont collect } else { if (bx0 >= x0 && bx1 <= x1 && by0 >= y0 && by1 <= y1) { // current node is fully contained within marquee bounds containedNodes.add(current); } if (current instanceof Parent) { // add all children to nodes Parent p = (Parent) current; nodes.addAll(p.getChildrenUnmodifiable()); } } } return containedNodes; }
Example 12
Source File: EditDataSet.java From chart-fx with Apache License 2.0 | 5 votes |
protected void addPoint(final double x, final double y) { if (!(getChart() instanceof XYChart)) { return; } final XYChart xyChart = (XYChart) getChart(); // TODO: tidy up code and make it compatible with multiple renderer // find data set closes to screen coordinate x & y final Pane pane = getChart().getCanvasForeground(); final Bounds bounds = pane.getBoundsInLocal(); final Bounds screenBounds = pane.localToScreen(bounds); final int x0 = (int) screenBounds.getMinX(); final int y0 = (int) screenBounds.getMinY(); final DataPoint dataPoint = findNearestDataPoint(getChart(), new Point2D(x - x0, y - y0)); if (dataPoint != null && (dataPoint.getDataSet() instanceof EditableDataSet)) { final Axis xAxis = xyChart.getFirstAxis(Orientation.HORIZONTAL); final Axis yAxis = xyChart.getFirstAxis(Orientation.VERTICAL); final int index = dataPoint.getIndex(); final double newValX = xAxis.getValueForDisplay(x - x0); final double newValY = yAxis.getValueForDisplay(y - y0); final EditableDataSet ds = (EditableDataSet) (dataPoint.getDataSet()); final double oldValX = ds.get(DataSet.DIM_X, index); if (oldValX <= newValX) { ds.add(index, newValX, newValY); } else { ds.add(index - 1, newValX, newValY); } } updateMarker(); }
Example 13
Source File: ScrollCenterAction.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected Point determinePivotPoint(Bounds bounds) { return new Point(bounds.getMinX() + bounds.getWidth() / 2, bounds.getMinY() + bounds.getHeight() / 2); }
Example 14
Source File: AutoScalingGroup.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void layoutChildren() { if (autoScale) { List<Node> children = getChildren(); double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE, minZ = Double.MAX_VALUE; double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE, maxZ = Double.MIN_VALUE; boolean first = true; for (int i=0, max=children.size(); i<max; i++) { final Node node = children.get(i); if (node.isVisible()) { Bounds bounds = node.getBoundsInLocal(); // if the bounds of the child are invalid, we don't want // to use those in the remaining computations. if (bounds.isEmpty()) continue; if (first) { minX = bounds.getMinX(); minY = bounds.getMinY(); minZ = bounds.getMinZ(); maxX = bounds.getMaxX(); maxY = bounds.getMaxY(); maxZ = bounds.getMaxZ(); first = false; } else { minX = Math.min(bounds.getMinX(), minX); minY = Math.min(bounds.getMinY(), minY); minZ = Math.min(bounds.getMinZ(), minZ); maxX = Math.max(bounds.getMaxX(), maxX); maxY = Math.max(bounds.getMaxY(), maxY); maxZ = Math.max(bounds.getMaxZ(), maxZ); } } } final double w = maxX-minX; final double h = maxY-minY; final double d = maxZ-minZ; final double centerX = minX + (w/2); final double centerY = minY + (h/2); final double centerZ = minZ + (d/2); double scaleX = twoSize/w; double scaleY = twoSize/h; double scaleZ = twoSize/d; double scale = Math.min(scaleX, Math.min(scaleY,scaleZ)); this.scale.setX(scale); this.scale.setY(scale); this.scale.setZ(scale); this.translate.setX(-centerX); this.translate.setY(-centerY); } }
Example 15
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 16
Source File: InfiniteCanvas.java From gef with Eclipse Public License 2.0 | 4 votes |
/** * 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() > 0 && infiniteCanvas.getHeight() > 0 * && infiniteCanvas.getContentBounds().getWidth() > 0 * && infiniteCanvas.getContentBounds().getHeight() > 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 17
Source File: DragResizerUtil.java From chart-fx with Apache License 2.0 | 4 votes |
protected void mouseDragged(final MouseEvent event) { // NOPMD final Bounds bounds = node.getBoundsInParent(); final double mouseX = bounds.getMinX() + event.getX(); final double mouseY = bounds.getMinY() + event.getY(); if (state == DragDirection.DRAG) { listener.onDrag(node, mouseX - clickX, mouseY - clickY, nodeWidth, nodeHeight); return; } if (state == DragDirection.DEFAULT) { return; } // resizing double newX = nodePositionX; double newY = nodePositionY; double newHeight = nodeHeight; double newWidth = nodeWidth; // right resize if (state.isEast()) { newWidth = mouseX - nodePositionX; } // left resize if (state.isWest()) { newX = mouseX; newWidth = nodeWidth + nodePositionX - newX; } // bottom resize if (state.isSouth()) { newHeight = mouseY - nodePositionY; } // top resize if (state.isNorth()) { newY = mouseY; newHeight = nodeHeight + nodePositionY - newY; } // min valid rect size check if (newWidth < MIN_WIDTH) { if (state == DragDirection.W_RESIZE || state == DragDirection.NW_RESIZE || state == DragDirection.SW_RESIZE) { newX = newX - MIN_WIDTH + newWidth; } newWidth = MIN_WIDTH; } if (newHeight < MIN_HEIGHT) { if (state == DragDirection.N_RESIZE || state == DragDirection.NW_RESIZE || state == DragDirection.NE_RESIZE) { newY = newY + newHeight - MIN_HEIGHT; } newHeight = MIN_HEIGHT; } listener.onResize(node, newX, newY, newWidth, newHeight); }
Example 18
Source File: ScrollBottomLeftAction.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override protected Point determinePivotPoint(Bounds bounds) { return new Point(bounds.getMinX(), bounds.getMaxY()); }
Example 19
Source File: LiveMapLocate.java From marathonv5 with Apache License 2.0 | 3 votes |
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: LiveMapLocate.java From marathonv5 with Apache License 2.0 | 3 votes |
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; }