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); }
double upperLeftX = getPrevious().getMinX() + xMove; double upperLeftY = getPrevious().getMinY() + yMove; double maxX = bounds.getMaxX() - getPrevious().getWidth(); double maxY = bounds.getMaxY() - getPrevious().getHeight(); double correctedUpperLeftX = MathTools.inInterval(bounds.getMinX(), upperLeftX, maxX); double correctedUpperLeftY = MathTools.inInterval(bounds.getMinY(), upperLeftY, maxY); return new Rectangle2D( correctedUpperLeftX, correctedUpperLeftY, getPrevious().getWidth(), getPrevious().getHeight());
/** * 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; } }
javafx.geometry.Rectangle2D r = new javafx.geometry.Rectangle2D(0, 0, 1, 1); ObservableList<Screen> screens = Screen.getScreensForRectangle(r); if (screens != null && screens.size() > 0) { javafx.geometry.Rectangle2D rc = screens.get(0).getBounds(); }
/** * Creates a new change strategy which moves the specified rectangle within the specified bounds defined by the * rectangle from {@code (0, 0)} to {@code (maxX, maxY)}. * * @param previous * the previous rectangle this move is based on * @param maxX * the maximal x-coordinate of the right edge of the created rectangles; must be greater than or equal to * the previous rectangle's width * @param maxY * the maximal y-coordinate of the lower edge of the created rectangles; must be greater than or equal to * the previous rectangle's height */ public MoveChangeStrategy(Rectangle2D previous, double maxX, double maxY) { super(previous, false, 0); if (maxX < previous.getWidth()) { throw new IllegalArgumentException( "The specified maximal x-coordinate must be greater than or equal to the previous rectangle's width."); //$NON-NLS-1$ } if (maxY < previous.getHeight()) { throw new IllegalArgumentException( "The specified maximal y-coordinate must be greater than or equal to the previous rectangle's height."); //$NON-NLS-1$ } bounds = new Rectangle2D(0, 0, maxX, maxY); }
/** * Creates a new rectangle with the same center point and area as the specified {@code original} rectangle with the * specified {@code ratio} and respecting the specified {@code bounds} (if not-{@code null}). * * @param original * the original rectangle * @param ratio * the new ratio * @param bounds * the bounds within which the new rectangle will be located; might be {@code null} * @return a new {@link Rectangle2D} with the same center point as the {@code original} and the specified * {@code ratio}; it has the same area as the {@code original} unless this would violate the bounds; in this * case it is as large as possible while still staying within the bounds * @throws IllegalArgumentException * if the {@code original} rectangle's center point is out of the {@code bounds} */ private static Rectangle2D createWithFixedRatioWithinBounds(Rectangle2D original, double ratio, Rectangle2D bounds) { Point2D centerPoint = getCenterPoint(original); boolean centerPointInBounds = bounds == null || bounds.contains(centerPoint); if (!centerPointInBounds) { throw new IllegalArgumentException("The center point " + centerPoint //$NON-NLS-1$ + " of the original rectangle is out of the specified bounds."); //$NON-NLS-1$ } double area = original.getWidth() * original.getHeight(); return createForCenterAreaAndRatioWithinBounds(centerPoint, area, ratio, bounds); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the east. 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 ToEastChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); Point2D edgeCenterPoint = new Point2D(original.getMinX(), (original.getMinY() + original.getMaxY()) / 2); westernEdge = new Edge2D(edgeCenterPoint, Orientation.VERTICAL, original.getMaxY() - original.getMinY()); }
/** * 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()); }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the southeast. 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 ToSoutheastChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); northwesternCorner = new Point2D(original.getMinX(), original.getMinY()); }
/** * 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()); }
/** * 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()); }
/** * Under Windows, the undecorator Stage could be been dragged below the Task bar and then no way to * grab it again... On Mac, do not drag above the menu bar * * @param y */ void setStageY(Stage stage, double y) { try { ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); if (screensForRectangle.size() > 0) { Screen screen = screensForRectangle.get(0); Rectangle2D visualBounds = screen.getVisualBounds(); if (y < visualBounds.getHeight() - 30 && y + SHADOW_WIDTH >= visualBounds.getMinY()) { stage.setY(y); } } } catch (Exception e) { e.printStackTrace(); } }
/** * Creates a new change strategy which enlarges the specified {@code original} rectangle to the northeast. 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 ToNortheastChangeStrategy(Rectangle2D original, boolean ratioFixed, double ratio, Rectangle2D bounds) { super(ratioFixed, ratio, bounds); southwesternCorner = new Point2D(original.getMinX(), original.getMaxY()); }
/** * 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()); }
public HelpPopup(Region content) { getStyleClass().setAll("pdfsam-help-popup"); setAutoHide(true); setHideOnEscape(true); setAutoFix(true); this.content = content; this.content.setMaxWidth(Screen.getPrimary().getVisualBounds().getWidth() / 3); }
@Subscribe public void handleShipLeavesCity(ShipLeavingPort event) { ICity city = event.getCity(); final IShipOwner owner = event.getShip().getOwner(); if (owner instanceof IHumanPlayer && owner.equals(viewState.getPlayer())) { List<INavigableVessel> ships = ((IHumanPlayer)owner).findShips(city); if (ships.isEmpty()) { double cityX = (int) Math.rint(city.getCoordinates().getX()) * scale; double cityY = (int) Math.rint(city.getCoordinates().getY()) * scale; double viewportOffset = imgView.getViewport().getMinX() * scale; for (Iterator<Node> iterator = mapPane.getChildren().iterator(); iterator.hasNext(); ) { Node node = iterator.next(); if (node instanceof Circle) { Circle c = (Circle) node; if (c.getCenterX() + viewportOffset == cityX && c.getCenterY() == cityY) { Platform.runLater(iterator::remove); break; } } } } } } @Subscribe
public static double getScreenHeight() { return Screen.getPrimary().getVisualBounds().getHeight(); }
/** * 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()); }