private void fixPosition() { Window w = dialog.getOwner(); Screen s = com.sun.javafx.util.Utils.getScreen(w); Rectangle2D sb = s.getBounds(); double xR = w.getX() + w.getWidth(); double xL = w.getX() - dialog.getWidth(); double x; double y; if (sb.getMaxX() >= xR + dialog.getWidth()) { x = xR; } else if (sb.getMinX() <= xL) { x = xL; } else { x = Math.max(sb.getMinX(), sb.getMaxX() - dialog.getWidth()); } y = Math.max(sb.getMinY(), Math.min(sb.getMaxY() - dialog.getHeight(), w.getY())); dialog.setX(x); dialog.setY(y); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the southwest. The given * {@code ratio} is enforced when indicated by {@code ratioFixed}. * * @param original * the original rectangle * @param ratioFixed * indicates whether the rectangle's ratio will be fixed to the {@code ratio} * @param ratio * the possibly fixed ratio of the rectangle created by this strategy * @param bounds * the bounds within which the new rectangle must be contained */ public ToSouthwestChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); northeasternCorner = new Point2D(original.getMaxX(), original.getMinY()); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the northwest. The given * {@code ratio} is enforced when indicated by {@code ratioFixed}. * * @param original * the original rectangle * @param ratioFixed * indicates whether the rectangle's ratio will be fixed to the {@code ratio} * @param ratio * the possibly fixed ratio of the rectangle created by this strategy * @param bounds * the bounds within which the new rectangle must be contained */ public ToNorthwestChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); southeasternCorner = new Point2D(original.getMaxX(), original.getMaxY()); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the north. The given * {@code ratio} is enforced when indicated by {@code ratioFixed}. * * @param original * the original rectangle * @param ratioFixed * indicates whether the rectangle's ratio will be fixed to the {@code ratio} * @param ratio * the possibly fixed ratio of the rectangle created by this strategy * @param bounds * the bounds within which the rectangle can be resized */ public ToNorthChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); Point2D edgeCenterPoint = new Point2D((original.getMinX() + original.getMaxX()) / 2, original.getMaxY()); southernEdge = new Edge2D(edgeCenterPoint, Orientation.HORIZONTAL, original.getMaxX() - original.getMinX()); }
/** * Returns the rectangle which represents the intersection of the two specified rectangles. * * @param a * a {@link Rectangle2D} * @param b * another {@link Rectangle2D} * @return a {@link Rectangle2D} which is the intersection of {@code a} and {@code b}; possible * {@link Rectangle2D#EMPTY}. */ public static Rectangle2D intersection(Rectangle2D a, Rectangle2D b) { Objects.requireNonNull(a, "The argument 'a' must not be null."); //$NON-NLS-1$ Objects.requireNonNull(b, "The argument 'b' must not be null."); //$NON-NLS-1$ if (a.intersects(b)) { double intersectionMinX = Math.max(a.getMinX(), b.getMinX()); double intersectionMaxX = Math.min(a.getMaxX(), b.getMaxX()); double intersectionWidth = intersectionMaxX - intersectionMinX; double intersectionMinY = Math.max(a.getMinY(), b.getMinY()); double intersectionMaxY = Math.min(a.getMaxY(), b.getMaxY()); double intersectionHeight = intersectionMaxY - intersectionMinY; return new Rectangle2D(intersectionMinX, intersectionMinY, intersectionWidth, intersectionHeight); } else { return Rectangle2D.EMPTY; } }
/** * Returns the center of the specified rectangle as a point. * * @param rectangle * the {@link Rectangle2D} whose center point will be returned * @return the {@link Point2D} whose x/y coordinates lie at {@code (min + max) / 2}. */ public static Point2D getCenterPoint(Rectangle2D rectangle) { Objects.requireNonNull(rectangle, "The argument 'rectangle' must not be null."); //$NON-NLS-1$ double centerX = (rectangle.getMinX() + rectangle.getMaxX()) / 2; double centerY = (rectangle.getMinY() + rectangle.getMaxY()) / 2; return new Point2D(centerX, centerY); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the south. The given * {@code ratio} is enforced when indicated by {@code ratioFixed}. * * @param original * the original rectangle * @param ratioFixed * indicates whether the rectangle's ratio will be fixed to the {@code ratio} * @param ratio * the possibly fixed ratio of the rectangle created by this strategy * @param bounds * the bounds within which the rectangle can be resized */ public ToSouthChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); Point2D edgeCenterPoint = new Point2D((original.getMinX() + original.getMaxX()) / 2, original.getMinY()); northernEdge = new Edge2D(edgeCenterPoint, Orientation.HORIZONTAL, original.getMaxX() - original.getMinX()); }
private void onMouseDragged( MouseEvent mouseEvent ) { if ( !selecting.get() ) return; Rectangle2D plotArea = chartInfo.getPlotArea(); if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Horizontal ) { double x = mouseEvent.getX(); //Clamp to the selection start x = Math.max( x, selectRect.getTranslateX() ); //Clamp to plot area x = Math.min( x, plotArea.getMaxX() ); rectX.set( x ); } if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Vertical ) { double y = mouseEvent.getY(); //Clamp to the selection start y = Math.max( y, selectRect.getTranslateY() ); //Clamp to plot area y = Math.min( y, plotArea.getMaxY() ); rectY.set( y ); } }
minX = Math.min(minX, visualBounds.getMinX()); minY = Math.min(minY, visualBounds.getMinY()); maxX = Math.max(maxX, visualBounds.getMaxX()); maxY = Math.max(maxY, visualBounds.getMaxY());
/** * @return random point within given bounds (minX <= x < maxX, minY <= y < maxY) */ public static Point2D randomPoint(Rectangle2D bounds) { return new Point2D( random(bounds.getMinX(), bounds.getMaxX()), random(bounds.getMinY(), bounds.getMaxY()) ); }
&& point.getX() < rectangle.getMaxX() + edgeTolerance; if (xCloseToHorizontal) { if (yCloseToUpper) {
double xDistanceToRight = Math.abs(point.getX() - rectangle.getMaxX()); boolean xCloseToLeft = xDistanceToLeft < edgeTolerance && xDistanceToLeft < xDistanceToRight; boolean xCloseToRight = xDistanceToRight < edgeTolerance && xDistanceToRight < xDistanceToLeft;
private void fixPosition() { Window w = dialog.getOwner(); Screen s = com.sun.javafx.util.Utils.getScreen(w); Rectangle2D sb = s.getBounds(); double xR = w.getX() + w.getWidth(); double xL = w.getX() - dialog.getWidth(); double x; double y; if (sb.getMaxX() >= xR + dialog.getWidth()) { x = xR; } else if (sb.getMinX() <= xL) { x = xL; } else { x = Math.max(sb.getMinX(), sb.getMaxX() - dialog.getWidth()); } y = Math.max(sb.getMinY(), Math.min(sb.getMaxY() - dialog.getHeight(), w.getY())); dialog.setX(x); dialog.setY(y); }
/** * Moves the specified point into the specified rectangle. If the point is already with the rectangle, it is * returned. Otherwise the point in the rectangle which is closest to the specified one is returned. * * @param rectangle * the {@link Rectangle2D} into which the point should be moved * @param point * the {@link Point2D} which is checked * @return either the specified {@code point} or the {@link Point2D} which is closest to it while still being * contained on the {@code rectangle} */ public static Point2D inRectangle(Rectangle2D rectangle, Point2D point) { Objects.requireNonNull(rectangle, "The argument 'rectangle' must not be null."); //$NON-NLS-1$ Objects.requireNonNull(point, "The argument 'point' must not be null."); //$NON-NLS-1$ if (rectangle.contains(point)) { return point; } // force the x and y coordinate into the rectangle double newX = MathTools.inInterval(rectangle.getMinX(), point.getX(), rectangle.getMaxX()); double newY = MathTools.inInterval(rectangle.getMinY(), point.getY(), rectangle.getMaxY()); return new Point2D(newX, newY); }
/** * Indicates whether the specified selection is inside the specified bounds. * * @param selection * the selection as a {@link Rectangle2D} * @param bounds * the {@link Bounds} to check the selection against * @return {@code true} if the selection is fully contained in the bounds; otherwise {@code false} */ private static boolean inBounds(Rectangle2D selection, Bounds bounds) { return bounds.getMinX() <= selection.getMinX() && bounds.getMinY() <= selection.getMinY() && selection.getMaxX() <= bounds.getMaxX() && selection.getMaxY() <= bounds.getMaxY(); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the west. The given * {@code ratio} is enforced when indicated by {@code ratioFixed}. * * @param original * the original rectangle * @param ratioFixed * indicates whether the rectangle's ratio will be fixed to the {@code ratio} * @param ratio * the possibly fixed ratio of the rectangle created by this strategy * @param bounds * the bounds within which the rectangle can be resized */ public ToWestChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); Point2D edgeCenterPoint = new Point2D(original.getMaxX(), (original.getMinY() + original.getMaxY()) / 2); easternEdge = new Edge2D(edgeCenterPoint, Orientation.VERTICAL, original.getMaxY() - original.getMinY()); }
/** * Returns either the specified point if if the specified bounds {@link Rectangle2D#contains(Point2D) contain} it or * a point whose X and/or Y coordinates are moved into the bounds. * * @param point * the point to move into the {@code bounds} * @param bounds * the bounds into which the {@code point} will be moved * @return either {@code point} or a new {@link Point2D} whose coordinates were changed so that it lies within the * {@code bounds} */ private static Point2D movePointIntoBounds(Point2D point, Rectangle2D bounds) { if (bounds.contains(point)) { return point; } else { double boundedPointX = MathTools.inInterval(bounds.getMinX(), point.getX(), bounds.getMaxX()); double boundedPointY = MathTools.inInterval(bounds.getMinY(), point.getY(), bounds.getMaxY()); return new Point2D(boundedPointX, boundedPointY); } }
private void onMousePressed( MouseEvent mouseEvent ) { double x = mouseEvent.getX(); double y = mouseEvent.getY(); Rectangle2D plotArea = chartInfo.getPlotArea(); DefaultChartInputContext context = new DefaultChartInputContext( chartInfo, x, y ); zoomMode = axisConstraintStrategy.getConstraint(context); if ( zoomMode == AxisConstraint.Both ) { selectRect.setTranslateX( x ); selectRect.setTranslateY( y ); rectX.set( x ); rectY.set( y ); } else if ( zoomMode == AxisConstraint.Horizontal ) { selectRect.setTranslateX( x ); selectRect.setTranslateY( plotArea.getMinY() ); rectX.set( x ); rectY.set( plotArea.getMaxY() ); } else if ( zoomMode == AxisConstraint.Vertical ) { selectRect.setTranslateX( plotArea.getMinX() ); selectRect.setTranslateY( y ); rectX.set( plotArea.getMaxX() ); rectY.set( y ); } }
double maxX = bounds.getMaxX() - getPrevious().getWidth(); double maxY = bounds.getMaxY() - getPrevious().getHeight();
new KeyFrame( Duration.millis( zoomDurationMillis.get() ), new KeyValue( xAxis.lowerBoundProperty(), zoomWindow.getMinX() ), new KeyValue( xAxis.upperBoundProperty(), zoomWindow.getMaxX() ), new KeyValue( yAxis.lowerBoundProperty(), zoomWindow.getMinY() ), new KeyValue( yAxis.upperBoundProperty(), zoomWindow.getMaxY() ) zoomAnimation.stop(); xAxis.setLowerBound( zoomWindow.getMinX() ); xAxis.setUpperBound( zoomWindow.getMaxX() ); yAxis.setLowerBound( zoomWindow.getMinY() ); yAxis.setUpperBound( zoomWindow.getMaxY() );