Rectangle2D bounds = Screen.getScreens().get(0).getBounds(); width = bounds.getWidth() / 2.5; height = bounds.getHeight() / 1.35; }catch (Exception e){ }
bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
private void defaultStageStatus() { Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds(); stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2); stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 4); stage.setMaximized(true); }
public static double getScreenHeight() { return Screen.getPrimary().getVisualBounds().getHeight(); }
/** * Indicates whether the specified selection has the correct ratio (which depends on whether the ratio is even * {@link #selectionRatioFixedProperty() fixed}). * * @param selection * the selection to check as a {@link Rectangle2D} * @return {@code true} if the selection has the correct ratio. */ private boolean hasCorrectRatio(Rectangle2D selection) { if (!isSelectionRatioFixed()) { return true; } double ratio = selection.getWidth() / selection.getHeight(); // compute the divergence relative to the fixed selection ratio double ratioDivergence = Math.abs(1 - ratio / getFixedSelectionRatio()); return ratioDivergence <= MAX_SELECTION_RATIO_DIVERGENCE; }
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; }
/** * Calculates the location of a window so that it will be centered on the screen. * * @param window the window * @return the location (top left corner) */ public Point2D determineCenteredLocation(Window window) { Rectangle2D screenSize = Screen.getPrimary().getVisualBounds(); // align sizes (for computation below) double windowWidth = window.getWidth(); double windowHeight = window.getHeight(); if (window.getWidth() > screenSize.getWidth()) { windowWidth = screenSize.getWidth(); } if (windowHeight > screenSize.getHeight()) { windowHeight = screenSize.getHeight(); } return new Point2D((screenSize.getWidth() - windowWidth) / 2.0, (screenSize.getHeight() - windowHeight) / 2.0); }
/** * 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); }
@Override public String getAsText() { if (null == getValue()) return null; Rectangle2D r = (Rectangle2D) getValue(); return r.getMinX() + ", " + r.getMinY() + ", " + r.getWidth() + ", " + r.getHeight(); }
/** * 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()); }
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; }
/** * 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(); } }
/** * 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(); }
private void _resize(final double width, final double height) { Window window = container.getScene().getWindow(); // size difference between root node and window depends on OS and Decorations double diffY = window.getHeight() - container.getHeight(); double diffX = window.getWidth() - container.getWidth(); webView.setMaxWidth(width); webView.setMaxHeight(height); webView.setMinWidth(width); webView.setMinHeight(height); javafx.geometry.Rectangle2D screenBounds = Screen.getPrimary().getBounds(); double scaleX = screenBounds.getWidth() / ( width + diffX ); double scaleY = screenBounds.getHeight() / ( height + diffY ); // calculate scale factor if too big for device, the .1 adds some padding double scale = Math.min(Math.min(scaleX, scaleY), 1.1) - .1; webView.setScaleX(scale); webView.setScaleY(scale); container.getScene().setRoot(new Group()); ((Stage)window).setScene(new Scene(container, width * scale, height * scale)); }
/** * 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 the window */ protected void maximize() { // We are bound to the stage if (!isLightweight()) { Stage stage = getStage(); final double stageY = stage.getY(); final Screen screen = Screen.getScreensForRectangle(stage.getX(), stageY, 1, 1).get(0); this.backupWindowBounds = new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight()); final double newStageY = screen.getVisualBounds().getMinY(); stage.setX(screen.getVisualBounds().getMinX()); stage.setY(newStageY); stage.setWidth(screen.getVisualBounds().getWidth()); stage.setHeight(screen.getVisualBounds().getHeight()); getStyleClass().add("window-maximized"); //$NON-NLS-1$ // stage.setMaximized(true); this.maximized.set(true); } else { // We are embedded into a container do nothing } }
/** * 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; }