Search in sources :

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

Example 72 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 (!Precision.equals(stage.getMinWidth(), stage.getMaxWidth())) {
                    // width may be locked
                    final double width = rectangle.getWidth();
                    if (stage.isShowing()) {
                        JavaFXUtils.runNow(() -> stage.setWidth(width));
                    } else {
                        stage.setWidth(width);
                    }
                }
                if (!Precision.equals(stage.getMinHeight(), stage.getMaxHeight())) {
                    // height may be locked
                    final double height = rectangle.getHeight();
                    if (stage.isShowing()) {
                        JavaFXUtils.runNow(() -> 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 73 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);
        }
    }
    return rectangle;
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D)

Example 74 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)

Example 75 with Rectangle2D

use of javafx.geometry.Rectangle2D in project Labyrinthe3d by FauconFan.

the class Main method start.

@Override
public void start(Stage primaryStage) {
    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
    primaryStage.setX(primaryScreenBounds.getMinX());
    primaryStage.setY(primaryScreenBounds.getMinY());
    primaryStage.setWidth(primaryScreenBounds.getWidth());
    primaryStage.setHeight(primaryScreenBounds.getHeight());
    Controller c = new Controller();
    View v = new View(primaryStage, c);
    c.initView(v);
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) Controller(src.controller.Controller) View(src.view.View)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)96 Image (javafx.scene.image.Image)14 Point2D (javafx.geometry.Point2D)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 Screen (javafx.stage.Screen)11 List (java.util.List)8 IOException (java.io.IOException)7 Rectangle (javafx.scene.shape.Rectangle)7 Stage (javafx.stage.Stage)7 GameApplication (com.almasb.fxgl.app.GameApplication)6 GameSettings (com.almasb.fxgl.app.GameSettings)6 FXGL (com.almasb.fxgl.dsl.FXGL)6 KeyCode (javafx.scene.input.KeyCode)6 Duration (javafx.util.Duration)6 Interpolators (com.almasb.fxgl.animation.Interpolators)4 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)4 Entity (com.almasb.fxgl.entity.Entity)4 BufferedImage (java.awt.image.BufferedImage)4 Collectors (java.util.stream.Collectors)4