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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations