public void show(Window window, double x, double y, PopupVPosition vAlign, PopupHPosition hAlign, double initOffsetX, double initOffsetY) { if (!isShowing()) { if (window == null) { throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); } Window parent = window; final double anchorX = parent.getX() + x + initOffsetX; final double anchorY = parent.getY() + y + initOffsetY; this.show(parent, anchorX, anchorY); ((JFXPopupSkin) getSkin()).reset(vAlign, hAlign, initOffsetX, initOffsetY); Platform.runLater(() -> ((JFXPopupSkin) getSkin()).animate()); } }
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); }
@Override protected double computePrefHeight(double width) { Window owner = getOwner(); if (owner != null) { return owner.getHeight(); } else { return super.computePrefHeight(width); } }
private void addLayoutListeners() { Window stage = getOwner(); if (stage != null) { if (widthListener == null) { throw new RuntimeException("Owner can only be set using the constructor"); } stage.getScene().widthProperty().addListener(widthListener); stage.getScene().heightProperty().addListener(heightListener); stage.xProperty().addListener(xListener); stage.yProperty().addListener(yListener); } }
@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; }
/** 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); }
if( getScene() != null && getScene().getWindow() != null ) { Window w = getScene().getWindow(); getScene().getWindow().setWidth(Util.unsignedConstraintValue(w.getWidth(), getMinWidth(), getMaxWidth())); if( getScene() != null && getScene().getWindow() != null ) { Window w = getScene().getWindow(); getScene().getWindow().setHeight(Util.unsignedConstraintValue(w.getHeight(), getMinHeight(), getMaxHeight())); this.windowProperty.addListener((o, oldV, newV) -> { if (oldV != null) { oldV.widthProperty().removeListener(this::handleStageChange); oldV.heightProperty().removeListener(this::handleStageChange); oldV.xProperty().removeListener(this::handleStageChange); oldV.yProperty().removeListener(this::handleStageChange); newV.widthProperty().addListener(this::handleStageChange); newV.heightProperty().addListener(this::handleStageChange); newV.xProperty().addListener(this::handleStageChange); newV.yProperty().addListener(this::handleStageChange);
private void showPasswordFieldPopup() { Scene scene = this.getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing()) { Point2D nodeCoord = encryptionIndicator.localToScene(encryptionIndicator.getWidth() / 2, encryptionIndicator.getHeight() / 1.5); double anchorX = Math.round(owner.getX() + scene.getX() + nodeCoord.getX() + 2); double anchorY = Math.round(owner.getY() + scene.getY() + nodeCoord.getY() + 2); passwordPopup.showFor(this, descriptor, anchorX, anchorY); } } }
getPopupWindow().xProperty().addListener(updatePathListener); getPopupWindow().yProperty().addListener(updatePathListener); popOver.arrowLocationProperty().addListener(updatePathListener); popOver.contentNodeProperty().addListener( window.setX(window.getX() + deltaX); window.setY(window.getY() + deltaY);
@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(); }
private void updateWidth() { Window stage = getOwner(); setWidth(stage.getScene().getWidth()); }
/** * 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); }
ownerWindow.xProperty().removeListener(weakXListener); ownerWindow.yProperty().removeListener(weakYListener); ownerWindow.widthProperty().removeListener(weakHideListener); ownerWindow.heightProperty().removeListener(weakHideListener); ownerWindow.xProperty().addListener(weakXListener); ownerWindow.yProperty().addListener(weakYListener); ownerWindow.widthProperty().addListener(weakHideListener); ownerWindow.heightProperty().addListener(weakHideListener); ownerWindow.addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, closePopOverOnOwnerWindowClose); ownerWindow.addEventFilter(WindowEvent.WINDOW_HIDING, closePopOverOnOwnerWindowClose);
/** * * @param node * @return The Y screen coordinate of the node. */ static public double screenY(Node node) { return sceneY(node) + node.getScene().getWindow().getY(); }
/** * * @param node * @return The X screen coordinate of the node. */ static public double screenX(Node node) { return sceneX(node) + node.getScene().getWindow().getX(); }
@Override protected double computePrefWidth(double height) { Window owner = getOwner(); if (owner != null) { return owner.getWidth(); } else { return super.computePrefWidth(height); } }
public static void bindStyleSheetToWindow(Window window, StringProperty stylesheet) { window.sceneProperty().addListener(e -> { if (window.getScene() != null) { window.getScene().getStylesheets().add(stylesheet.get()); } }); if (window.getScene() != null) { window.getScene().getStylesheets().add(stylesheet.get()); } stylesheet.addListener((obs, o, n) -> { if (window.getScene() != null) { int oldPos = -1; if (o != null) { oldPos = window.getScene().getStylesheets().indexOf(o); window.getScene().getStylesheets().remove(o); } if (n != null) { if (oldPos >= 0) { window.getScene().getStylesheets().add(oldPos, n); } else { window.getScene().getStylesheets().add(n); } } } }); } }