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); }
primaryStage.getHeight()).get(0); Rectangle2D bounds = screen.getVisualBounds(); maximizedBox = new BoundingBox(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(),
/** * 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 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()); }
/** * 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); }
@Override public String getAsText() { if (null == getValue()) return null; Rectangle2D r = (Rectangle2D) getValue(); return r.getMinX() + ", " + r.getMinY() + ", " + r.getWidth() + ", " + r.getHeight(); }
/** * @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()) ); }
/** * Indicates whether the specified selection has only finite values (e.g. width and height). * * @param selection * the selection as a {@link Rectangle2D} * @return {@code true} if the selection has only finite values. */ private static boolean valuesFinite(Rectangle2D selection) { return Double.isFinite(selection.getMinX()) && Double.isFinite(selection.getMinY()) && Double.isFinite(selection.getWidth()) && Double.isFinite(selection.getHeight()); }
/** * 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(); }
@Subscribe public void handleShipEntersPort(ShipEntersPortEvent 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.size() == 1) { Dimension2D dim = map.getDimension(); scale = 192 / dim.getHeight(); double viewportOffset = imgView.getViewport().getMinX(); Platform.runLater(() -> drawShipPresenceInCity(city, viewportOffset)); if (shouldSwitchToCity(city)) { clientEventBus.post(new SwitchCity(city)); } } } } private boolean shouldSwitchToCity(ICity toCity) {
/** * 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()); }
public static Image clipImage(Image image, Rectangle2D clip) { WritableImage clippedImage = new WritableImage((int) clip.getWidth(), (int) clip.getHeight()); int[] rgbaValues = getRGB(image, (int) clip.getMinX(), (int) clip.getMinY(), (int) clip.getWidth(), (int) clip.getHeight()); setRGB(clippedImage, rgbaValues); return clippedImage; }
public Node createReplacement(Node node) { Rectangle2D b = getBounds(node); Node replNode = new ImageView(node.snapshot(new SnapshotParameters(), null)); replacedNodeMap.put(node, replNode); replNode.setUserData(node); replNode.setManaged(false); replNode.setId(ANIM_REPLACE_ID); replNode.resizeRelocate(b.getMinX(), b.getMinY(), b.getWidth(), b.getHeight()); return replNode; }
/** * Restore the window to original size */ protected void restore() { if (!isLightweight()) { if (this.backupWindowBounds != null) { Stage stage = getStage(); stage.setX(this.backupWindowBounds.getMinX()); stage.setY(this.backupWindowBounds.getMinY()); stage.setWidth(this.backupWindowBounds.getWidth()); stage.setHeight(this.backupWindowBounds.getHeight()); stage.setMaximized(false); this.backupWindowBounds = null; } } }
/** * Restore the window to original size */ protected void restore() { if (!isLightweight()) { if (this.backupWindowBounds != null) { Stage stage = getStage(); stage.setX(this.backupWindowBounds.getMinX()); stage.setY(this.backupWindowBounds.getMinY()); stage.setWidth(this.backupWindowBounds.getWidth()); stage.setHeight(this.backupWindowBounds.getHeight()); stage.setMaximized(false); this.backupWindowBounds = null; } } }
/** * Updates the position and size of {@link #selectedArea} (and by binding that of {@link #unselectedArea}) to a * changed selection. */ private void updateSelection() { boolean showSelection = getSkinnable().hasSelection() && getSkinnable().isSelectionActive(); if (showSelection) { // the selection can be properly displayed Rectangle2D selection = getSkinnable().getSelection(); setSelection(selection.getMinX(), selection.getMinY(), selection.getWidth(), selection.getHeight()); } else { // in this case the selection areas are invisible, // so the only thing left to do is to make sure their coordinates are not all over the place // (this is not strictly necessary but makes the skin's state cleaner) setSelection(0, 0, 0, 0); } }
@Override public void start(Stage stage) { super.start(stage); stage.setTitle(title); Rectangle2D sceneBounds=super.getSceneBounds(screenPercent,divX,divY); setScene(new Scene(region, sceneBounds.getWidth(), sceneBounds.getHeight())); stage.setScene(getScene()); stage.setX(sceneBounds.getMinX()); stage.setY(sceneBounds.getMinY()); stage.show(); }
/** * setup the GUI * * @param stage */ private void setup(Stage stage) { stage.setTitle(title); Rectangle2D sceneBounds = super.getSceneBounds(screenPercent, divX, divY); dropTarget = new DropTarget(); setScene( new Scene(dropTarget, sceneBounds.getWidth(), sceneBounds.getHeight())); stage.setScene(getScene()); scene.setFill(Color.LIGHTGRAY); stage.setX(super.getScreenWidth() - sceneBounds.getMinX()); stage.setY(super.getScreenHeight() - sceneBounds.getMinY()); stage.show(); }
/** * Maximize and ajust the window to screen size. */ public void maximize() { Stage stage = undecorator.getStage(); ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); Screen screen = screensForRectangle.get(0); Rectangle2D visualBounds = screen.getVisualBounds(); // save bounds before maximizing in order to restore later savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); undecorator.setShadow(false); // effectivly maximize stage.setX(visualBounds.getMinX()); stage.setY(visualBounds.getMinY()); stage.setWidth(visualBounds.getWidth()); stage.setHeight(visualBounds.getHeight()); maximized = true; }