@Override protected double computePrefHeight(double width) { Window owner = getOwner(); if (owner != null) { return owner.getHeight(); } else { return super.computePrefHeight(width); } }
@Override protected double computePrefHeight(double width) { Window owner = getOwner(); if (owner != null) { return owner.getHeight(); } else { return super.computePrefHeight(width); } }
/** * Determine the pixels-per-inch of the screen we are on * @return */ double determinePPI() { if (ppi != null) { return ppi; } // Use command line value if (System.getProperties().containsKey(PPI_SYSTEM_PROPERTY)) { ppi = Double.valueOf(System.getProperty(PPI_SYSTEM_PROPERTY)); if (getTrace()) System.out.println("Using command line " + PPI_SYSTEM_PROPERTY + "=" + ppi); return ppi; } // determine the DPI factor, so the thresholds become larger on screens with a higher DPI ppi = 100.0; // average dpi Window window = getScene().getWindow(); ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(window.getX(), window.getY(), window.getWidth(), window.getHeight()); if (screensForRectangle.size() > 0) { Screen lScreen = screensForRectangle.get(0); // we just use the first screen ppi = lScreen.getDpi(); if (getTrace()) System.out.println("screens of scene: " + screensForRectangle + ", using the first then PPI=" + ppi); } return ppi; } Double ppi;
if (w != null && new BoundingBox(w.getX(), w.getY(), w.getWidth(), w.getHeight()).contains(screenX, screenY)) { return findNode(w.getScene().getRoot(), screenX, screenY); if (!FIND_NODE_EXCLUDE.equals(window.getUserData()) && new BoundingBox(window.getX(), window.getY(), window.getWidth(), window.getHeight()).contains(screenX, screenY)) { return findNode(window.getScene().getRoot(), screenX, screenY);
@Override public void run() { Window dialog = previewPane.getScene().getWindow(); double currWidth = dialog.getWidth(); double currHeight = dialog.getHeight(); dialog.setWidth(Math.max(currWidth, 20 + previewPane.getLayoutX() + previewPane.getPrefWidth())); dialog.setHeight(20 + currHeight + previewPane.getPrefHeight()); updatePreview(); }
@Override public void handle(WindowEvent event) { Window window = (Window) event.getSource(); prefs.putDouble("x", window.getX()); // NOI18N prefs.putDouble("y", window.getY()); // NOI18N prefs.putDouble("width", window.getWidth()); // NOI18N prefs.putDouble("height", window.getHeight()); // NOI18N } };
/** * Find a node in all windows * * @param w * the preferred window * @param screenX * the screen x * @param screenY * the screen y * @return the node or <code>null</code> */ @SuppressWarnings("deprecation") public static Node findNode(Window w, double screenX, double screenY) { // First check the owner if (new BoundingBox(w.getX(), w.getY(), w.getWidth(), w.getHeight()).contains(screenX, screenY)) { return findNode(w.getScene().getRoot(), screenX, screenY); } // FIXME If multiple match take the closest Iterator<Window> impl_getWindows = Window.impl_getWindows(); while (impl_getWindows.hasNext()) { Window window = impl_getWindows.next(); if (!FIND_NODE_EXCLUDE.equals(window.getUserData()) && new BoundingBox(window.getX(), window.getY(), window.getWidth(), window.getHeight()).contains(screenX, screenY)) { return findNode(window.getScene().getRoot(), screenX, screenY); } } return null; }
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)); }
/** * 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); }
public void show(Notifications notification) { Window window; if (notification.owner == null) { /* * If the owner is not set, we work with the whole screen. */ Rectangle2D screenBounds = notification.screen.getVisualBounds(); startX = screenBounds.getMinX(); startY = screenBounds.getMinY(); screenWidth = screenBounds.getWidth(); screenHeight = screenBounds.getHeight(); window = Utils.getWindow(null); } else { /* * If the owner is set, we will make the notifications popup * inside its window. */ startX = notification.owner.getX(); startY = notification.owner.getY(); screenWidth = notification.owner.getWidth(); screenHeight = notification.owner.getHeight(); window = notification.owner; } show(window, notification); }
/** * Calculates the position of a stage on the screen so that * it is being display in an optimal manner. * * @param stage the stage to be positioned on the screen * @return the location */ public Point2D determinePreferredStageLocation(Stage stage) { Point2D location = new Point2D(stage.getX(), stage.getY()); if (location.getX() == 0.0 && location.getY() == 0.0) { // if no position yet // place in the middle of the owner if possibe Window owner = stage.getOwner(); if (owner != null) { location = new Point2D(owner.getX() + (owner.getWidth() - stage.getWidth()) / 2.0, owner.getY() + (owner.getHeight() - stage.getHeight()) / 2.0); } else { // not much we can do: center it location = determineCenteredLocation(stage); } } return determineAlignedStageLocation(stage, location); }
double centerY = owner.getY()+owner.getHeight()/2; Screen screen = Screen.getScreens().stream().filter(s->s.getBounds().contains(centerX,centerY)).findFirst().orElse(Screen.getPrimary()); Rectangle2D screenBounds = screen.getBounds();
/** Checks the parent window/popup if its size is within parameters as set by the LC. */ private void adjustWindowSize() { BoundSize wBounds = layoutConstraints.getPackWidth(); BoundSize hBounds = layoutConstraints.getPackHeight(); Scene scene = getScene(); Window window = scene != null ? scene.getWindow() : null; if (window == null || wBounds == BoundSize.NULL_SIZE && hBounds == BoundSize.NULL_SIZE) return; Parent root = scene.getRoot(); double winWidth = window.getWidth(); double winHeight = window.getHeight(); double prefWidth = root.prefWidth(-1); double prefHeight = root.prefHeight(-1); FXContainerWrapper container = new FXContainerWrapper(root); double horIns = winWidth - scene.getWidth(); double verIns = winHeight - scene.getHeight(); double targetW = constrain(container, winWidth, prefWidth, wBounds) + horIns; double targetH = constrain(container, winHeight, prefHeight, hBounds) + verIns; double x = window.getX() - ((targetW - winWidth) * (1 - layoutConstraints.getPackWidthAlign())); double y = window.getY() - ((targetH - winHeight) * (1 - layoutConstraints.getPackHeightAlign())); window.setX(x); window.setY(y); window.setWidth(targetW); window.setHeight(targetH); }
return pointFor( new BoundingBox( window.getX(), window.getY(), window.getWidth(), window.getHeight() ) );
if( getScene() != null && getScene().getWindow() != null ) { Window w = getScene().getWindow(); getScene().getWindow().setHeight(Util.unsignedConstraintValue(w.getHeight(), getMinHeight(), getMaxHeight()));
if( getScene() != null && getScene().getWindow() != null ) { Window w = getScene().getWindow(); getScene().getWindow().setHeight(Util.unsignedConstraintValue(w.getHeight(), getMinHeight(), getMaxHeight()));