Search in sources :

Example 31 with Rectangle2D

use of javafx.geometry.Rectangle2D in project sakuli by ConSol.

the class UiTestApplication method run.

@Override
public void run() {
    Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
    // create Login scene
    Scene loginScene = gotoLogin();
    width = bounds.getWidth();
    height = bounds.getHeight() * HEIGHT_PERCENTAGE;
    Stage stage = StageBuilder.create().x(0).y(0).width(width).height(height).title("Sakuli Login Sample").scene(loginScene).onCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            LOGGER.info("PLATFORM exit!");
        }
    }).build();
    LOGGER.info("set width '{}' and height '{}'", width, height);
    start(stage);
}
Also used : WindowEvent(javafx.stage.WindowEvent) Rectangle2D(javafx.geometry.Rectangle2D) Stage(javafx.stage.Stage) EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene)

Example 32 with Rectangle2D

use of javafx.geometry.Rectangle2D in project JFoenix by jfoenixadmin.

the class JFXCustomColorPickerDialog method fixPosition.

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, 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);
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D)

Example 33 with Rectangle2D

use of javafx.geometry.Rectangle2D in project jgnash by ccavanaugh.

the class StageUtils method addBoundsListener.

public static void addBoundsListener(final Stage stage, final String prefNode, @Nullable final Stage parent) {
    final String bounds = Preferences.userRoot().node(prefNode).get(DEFAULT_KEY, null);
    if (bounds != null) {
        // restore to previous size and position
        Rectangle2D rectangle = decodeRectangle(bounds);
        // relative window placement requested.  Modify the coordinates to the current parent placement
        if (parent != null) {
            rectangle = new Rectangle2D(rectangle.getMinX() + parent.getX(), rectangle.getMinY() + parent.getY(), rectangle.getWidth(), rectangle.getHeight());
        }
        // Do not try to restore bounds if they exceed available screen space.. user dropped a monitor
        if (getMaxVisualBounds().contains(rectangle)) {
            final boolean resizable = stage.isResizable();
            // Stage will not reposition if resizable is false... JavaFx bug?
            stage.setResizable(false);
            stage.setX(rectangle.getMinX());
            stage.setY(rectangle.getMinY());
            if (resizable) {
                // don't resize if originally false
                if (stage.getMinWidth() != stage.getMaxWidth()) {
                    // width may be locked
                    final double width = rectangle.getWidth();
                    if (stage.isShowing()) {
                        Platform.runLater(() -> stage.setWidth(width));
                    } else {
                        stage.setWidth(width);
                    }
                }
                if (stage.getMinHeight() != stage.getMaxHeight()) {
                    // height may be locked
                    final double height = rectangle.getHeight();
                    if (stage.isShowing()) {
                        Platform.runLater(() -> stage.setHeight(height));
                    } else {
                        stage.setHeight(height);
                    }
                }
            }
            // restore the resize property
            stage.setResizable(resizable);
        }
    }
    final ChangeListener<Number> boundsListener = new BoundsListener(stage, prefNode, parent);
    stage.widthProperty().addListener(boundsListener);
    stage.heightProperty().addListener(boundsListener);
    stage.xProperty().addListener(boundsListener);
    stage.yProperty().addListener(boundsListener);
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D)

Example 34 with Rectangle2D

use of javafx.geometry.Rectangle2D in project jgnash by ccavanaugh.

the class StageUtils method decodeRectangle.

private static Rectangle2D decodeRectangle(final String bounds) {
    if (bounds == null) {
        return null;
    }
    Rectangle2D rectangle = null;
    final String[] array = bounds.split(String.valueOf(COMMA_DELIMITER));
    if (array.length == 4) {
        try {
            rectangle = new Rectangle2D(Double.parseDouble(array[X]), Double.parseDouble(array[Y]), Double.parseDouble(array[WIDTH]), Double.parseDouble(array[HEIGHT]));
        } catch (final NumberFormatException nfe) {
            Logger.getLogger(StageUtils.class.getName()).log(Level.SEVERE, null, nfe);
            rectangle = null;
        }
    }
    return rectangle;
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D)

Example 35 with Rectangle2D

use of javafx.geometry.Rectangle2D in project jgnash by ccavanaugh.

the class StageUtils method getMaxVisualBounds.

/**
     * Returns the maximum visual bounds of the users desktop.
     *
     * @return maximum usable desktop bounds
     */
private static Rectangle2D getMaxVisualBounds() {
    double maxX = 0;
    double maxY = 0;
    double minX = Double.MAX_VALUE;
    double minY = Double.MAX_VALUE;
    for (final Screen screen : Screen.getScreens()) {
        minX = Math.min(minX, screen.getVisualBounds().getMinX());
        minY = Math.min(minY, screen.getVisualBounds().getMinY());
        maxX = Math.max(maxX, screen.getVisualBounds().getMaxX());
        maxY = Math.max(maxY, screen.getVisualBounds().getMaxY());
    }
    return new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
}
Also used : Screen(javafx.stage.Screen) Rectangle2D(javafx.geometry.Rectangle2D)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)76 Image (javafx.scene.image.Image)14 Scene (javafx.scene.Scene)10 Screen (javafx.stage.Screen)10 Stage (javafx.stage.Stage)7 Point2D (javafx.geometry.Point2D)6 IOException (java.io.IOException)5 ImageView (javafx.scene.image.ImageView)5 BufferedImage (java.awt.image.BufferedImage)4 File (java.io.File)4 List (java.util.List)4 Color (javafx.scene.paint.Color)4 Optional (java.util.Optional)3 Level (java.util.logging.Level)3 Application (javafx.application.Application)3 Platform (javafx.application.Platform)3 Menu (javafx.scene.control.Menu)3 MenuBar (javafx.scene.control.MenuBar)3 MenuItem (javafx.scene.control.MenuItem)3 Pane (javafx.scene.layout.Pane)3