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

The following examples show how to use javafx.geometry.Bounds#getMaxY() . 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: 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 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 2
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 3
Source File: XValueIndicator.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 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 4
Source File: InfiniteCanvas.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Computes the bounds <code>[min-x, min-y, max-x, max-y]</code> surrounding
 * the {@link #getContentGroup() content group} within the coordinate system
 * of this {@link InfiniteCanvas}.
 *
 * @return The bounds <code>[min-x, min-y, max-x, max-y]</code> surrounding
 *         the {@link #getContentGroup() content group} within the
 *         coordinate system of this {@link InfiniteCanvas}.
 */
protected double[] computeContentBoundsInLocal() {
	Bounds contentBoundsInScrolledPane = getContentGroup()
			.getBoundsInParent();
	double minX = contentBoundsInScrolledPane.getMinX();
	double maxX = contentBoundsInScrolledPane.getMaxX();
	double minY = contentBoundsInScrolledPane.getMinY();
	double maxY = contentBoundsInScrolledPane.getMaxY();

	Point2D minInScrolled = getScrolledPane().localToParent(minX, minY);
	double realMinX = minInScrolled.getX();
	double realMinY = minInScrolled.getY();
	double realMaxX = realMinX + (maxX - minX);
	double realMaxY = realMinY + (maxY - minY);

	return new double[] { realMinX, realMinY, realMaxX, realMaxY };
}
 
Example 5
Source File: DoughnutChart.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: SortMeController.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@FXML
public void shuffle() {
	
	Bounds bounds = background.getLayoutBounds();
	
	double minx = bounds.getMinX();
	double miny = bounds.getMinY();

	Random random = new Random();
	
	for( Sprite sp : sprites ) {			
		double maxx = bounds.getMaxX() - sp.container.getWidth();
		double maxy = bounds.getMaxY() - sp.container.getHeight();
		double x = random.nextDouble() * (maxx - minx);
		double y = random.nextDouble() * (maxy - miny);
		sp.relocate(x, y);
	}
	
}
 
Example 7
Source File: WoodlandController.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
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 8
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 9
Source File: MarqueeOnDragHandler.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void showCaretAtBottom() {
    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.getMaxY();
    suspendVisibleParsWhile(() -> virtualFlow.showAtOffset(parIdx, getViewportHeight() - y));
}
 
Example 11
Source File: InputMethodRequestsObject.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Point2D getTextLocation(int offset) {
    // Method for supporting Pinyin input on Mac.
    // TODO: Apparently only tested on MacOS, so might need more testing.
    //  Doesn't seem to affect any other language input as far as I can tell.
    Optional<Bounds> caretPositionBounds = textArea.getCaretBounds();
    if (caretPositionBounds.isPresent()) {
        Bounds bounds = caretPositionBounds.get();
        return new Point2D(bounds.getMaxX() - 5, bounds.getMaxY());
    }

    throw new NullPointerException();
}
 
Example 12
Source File: ChargeSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
@Override protected void resize() {
    width  = gauge.getWidth() - gauge.getInsets().getLeft() - gauge.getInsets().getRight();
    height = gauge.getHeight() - gauge.getInsets().getTop() - gauge.getInsets().getBottom();

    if (aspectRatio * width > height) {
        width = 1 / (aspectRatio / height);
    } else if (1 / (aspectRatio / height) > width) {
        height = aspectRatio * width;
    }

    if (width > 0 && height > 0) {
        pane.setMaxSize(width, height);
        pane.setPrefSize(width, height);
        pane.relocate((gauge.getWidth() - width) * 0.5, (gauge.getHeight() - height) * 0.5);
        pane.setSpacing(width * 0.01960784);

        double barWidth = 0;
        for (int i = 0 ; i < 12 ; i++) {
            bars[i].setPrefSize(0.3030303 * height, (0.3030303 * height + i * 0.06060606 * height));
            Bounds bounds = bars[i].getLayoutBounds();
            barWidth      = bounds.getWidth();
            if (barWidth == 0) return;

            BarColor barColor;
            if (i < 2) {
                barColor = BarColor.RED;
            } else if (i < 9) {
                barColor = BarColor.ORANGE;
            } else {
                barColor = BarColor.GREEN;
            }
            barBackgrounds[i] = new Background(new BackgroundFill[] {
                new BackgroundFill(Color.WHITE, new CornerRadii(1024), Insets.EMPTY),
                new BackgroundFill(new LinearGradient(0, bounds.getMinY(), 0, bounds.getMaxY(), false, CycleMethod.NO_CYCLE, new Stop(0.0, barColor.COLOR_FROM), new Stop(1.0, barColor.COLOR_TO)), new CornerRadii(1024), new Insets(0.15 * barWidth))
            });
            barBackgrounds[i + 12] = new Background(new BackgroundFill[] {
                new BackgroundFill(Color.WHITE, new CornerRadii(1024), Insets.EMPTY),
                new BackgroundFill(new LinearGradient(0, bounds.getMinY(), 0, bounds.getMaxY(), false, CycleMethod.NO_CYCLE, new Stop(0.0, BarColor.GRAY.COLOR_FROM), new Stop(1.0, BarColor.GRAY.COLOR_TO)), new CornerRadii(1024), new Insets(0.15 * barWidth))
            });
        }
        barBorder = new Border(new BorderStroke(Color.rgb(102, 102, 102), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(0.05 * barWidth)));
    }
    redraw();
}
 
Example 13
Source File: ResizeTranslateFirstAnchorageOnHandleDragHandler.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void startDrag(MouseEvent e) {
	setTargetPart(determineTargetPart());
	invalidGesture = !isResizeTranslate(e);
	if (invalidGesture) {
		return;
	}
	ITransformableContentPart<? extends Node> targetPart = getTargetPart();
	storeAndDisableRefreshVisuals(targetPart);
	initialPointerLocation = new Point(e.getSceneX(), e.getSceneY());
	init(getResizePolicy());
	init(getTransformPolicy());
	translationIndex = getTransformPolicy().createPreTransform();
	// determine initial bounds in scene
	Bounds layoutBounds = targetPart.getVisual().getLayoutBounds();
	Bounds initialBoundsInScene = targetPart.getVisual()
			.localToScene(layoutBounds);
	// save moved vertex
	int segment = getHost().getSegmentIndex();
	if (segment == 0) {
		initialVertex = new Point(initialBoundsInScene.getMinX(),
				initialBoundsInScene.getMinY());
	} else if (segment == 1) {
		initialVertex = new Point(initialBoundsInScene.getMaxX(),
				initialBoundsInScene.getMinY());
	} else if (segment == 2) {
		initialVertex = new Point(initialBoundsInScene.getMaxX(),
				initialBoundsInScene.getMaxY());
	} else if (segment == 3) {
		initialVertex = new Point(initialBoundsInScene.getMinX(),
				initialBoundsInScene.getMaxY());
	}

	snapToSupport = targetPart.getViewer().getAdapter(SnapToSupport.class);
	if (snapToSupport != null) {
		SnappingLocation hssl = new SnappingLocation(targetPart,
				Orientation.HORIZONTAL, initialVertex.x);
		SnappingLocation vssl = new SnappingLocation(targetPart,
				Orientation.VERTICAL, initialVertex.y);
		snapToSupport.startSnapping(targetPart, Arrays.asList(hssl, vssl));
	}
}
 
Example 14
Source File: ScrollBottomLeftAction.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Point determinePivotPoint(Bounds bounds) {
	return new Point(bounds.getMinX(), bounds.getMaxY());
}
 
Example 15
Source File: DoublePolygon.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
public DoubleRectangle getBound() {
    Bounds bound = polygon.getBoundsInLocal();
    return new DoubleRectangle(bound.getMinX(), bound.getMinY(), bound.getMaxX(), bound.getMaxY());
}
 
Example 16
Source File: OnlyScrollPaneSkin.java    From oim-fx with MIT License 4 votes vote down vote up
void scrollBoundsIntoView(Bounds b) {
	double dx = 0.0;
	double dy = 0.0;
	if (b.getMaxX() > contentWidth) {
		dx = b.getMinX() - snappedLeftInset();
	}
	if (b.getMinX() < snappedLeftInset()) {
		dx = b.getMaxX() - contentWidth - snappedLeftInset();
	}
	if (b.getMaxY() > snappedTopInset() + contentHeight) {
		dy = b.getMinY() - snappedTopInset();
	}
	if (b.getMinY() < snappedTopInset()) {
		dy = b.getMaxY() - contentHeight - snappedTopInset();
	}
	// We want to move contentPanel's layoutX,Y by (dx,dy).
	// But to do this we have to set the scrollbars' values appropriately.

	if (dx != 0) {
		double sdx = dx * (hsb.getMax() - hsb.getMin()) / (nodeWidth - contentWidth);
		// Adjust back for some amount so that the Node border is not too
		// close to view border
		sdx += -1 * Math.signum(sdx) * hsb.getUnitIncrement() / 5; // This
																	// accounts
																	// to 2%
																	// of
																	// view
																	// width
		hsb.setValue(hsb.getValue() + sdx);
		getSkinnable().requestLayout();
	}
	if (dy != 0) {
		double sdy = dy * (vsb.getMax() - vsb.getMin()) / (nodeHeight - contentHeight);
		// Adjust back for some amount so that the Node border is not too
		// close to view border
		sdy += -1 * Math.signum(sdy) * vsb.getUnitIncrement() / 5; // This
																	// accounts
																	// to 2%
																	// of
																	// view
																	// height
		vsb.setValue(vsb.getValue() + sdy);
		getSkinnable().requestLayout();
	}

}
 
Example 17
Source File: DataPointTooltip.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
private void updateLabel(final MouseEvent event, final Bounds plotAreaBounds, final DataPoint dataPoint) {
    label.setText(formatLabel(dataPoint));
    final double mouseX = event.getX();
    final double spaceLeft = mouseX - plotAreaBounds.getMinX();
    final double spaceRight = plotAreaBounds.getWidth() - spaceLeft;
    double width = label.prefWidth(-1);
    boolean atSide = true; // set to false if we cannot print the tooltip beside the point

    double xLocation;
    if (spaceRight >= width + LABEL_X_OFFSET) { // place to right if enough space
        xLocation = mouseX + DataPointTooltip.LABEL_X_OFFSET;
    } else if (spaceLeft >= width + LABEL_X_OFFSET) { // place left if enough space
        xLocation = mouseX - DataPointTooltip.LABEL_X_OFFSET - width;
    } else if (width < plotAreaBounds.getWidth()) {
        xLocation = spaceLeft > spaceRight ? plotAreaBounds.getMaxX() - width : plotAreaBounds.getMinX();
        atSide = false;
    } else {
        width = plotAreaBounds.getWidth();
        xLocation = plotAreaBounds.getMinX();
        atSide = false;
    }

    final double mouseY = event.getY();
    final double spaceTop = mouseY - plotAreaBounds.getMinY();
    final double spaceBottom = plotAreaBounds.getHeight() - spaceTop;
    double height = label.prefHeight(width);

    double yLocation;
    if (height < spaceBottom) {
        yLocation = mouseY + DataPointTooltip.LABEL_Y_OFFSET;
    } else if (height < spaceTop) {
        yLocation = mouseY - DataPointTooltip.LABEL_Y_OFFSET - height;
    } else if (atSide && height < plotAreaBounds.getHeight()) {
        yLocation = spaceTop < spaceBottom ? plotAreaBounds.getMaxY() - height : plotAreaBounds.getMinY();
    } else if (atSide) {
        yLocation = plotAreaBounds.getMinY();
        height = plotAreaBounds.getHeight();
    } else if (spaceBottom > spaceTop) {
        yLocation = mouseY + DataPointTooltip.LABEL_Y_OFFSET;
        height = spaceBottom - LABEL_Y_OFFSET;
    } else {
        yLocation = plotAreaBounds.getMinY();
        height = spaceTop - LABEL_Y_OFFSET;
    }
    label.resizeRelocate(xLocation, yLocation, width, height);
}
 
Example 18
Source File: ScrollBottomRightAction.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Point determinePivotPoint(Bounds bounds) {
	return new Point(bounds.getMaxX(), bounds.getMaxY());
}
 
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: 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;
          
}