Java Code Examples for javafx.geometry.Rectangle2D#getMaxX()

The following examples show how to use javafx.geometry.Rectangle2D#getMaxX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StageControllerImpl.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
public void placeStage(final Stage stage) {
    if (targetWindow != null) {
        stage.setX(targetWindow.getX() + targetWindow.getWidth());
        stage.setY(targetWindow.getY());
        try {
            // Prevents putting the stage out of the screen
            final Screen primary = Screen.getPrimary();
            if (primary != null) {
                final Rectangle2D rect = primary.getVisualBounds();
                if (stage.getX() + stage.getWidth() > rect.getMaxX()) {
                    stage.setX(rect.getMaxX() - stage.getWidth());
                }
                if (stage.getY() + stage.getHeight() > rect.getMaxY()) {
                    stage.setX(rect.getMaxY() - stage.getHeight());
                }
            }
        } catch (final Exception e) {
            ExceptionLogger.submitException(e);
        }
    }
}
 
Example 2
Source File: MovablePane.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Rectangle2D anchorToEdges(Rectangle2D bounds, Rectangle2D screenBounds) {
	double x1 = bounds.getMinX(), y1 = bounds.getMinY();
	double x2 = bounds.getMaxX(), y2 = bounds.getMaxY();
	if (Math.abs(x1 - screenBounds.getMinX()) < SNAP_DISTANCE) {
		x1 = screenBounds.getMinX();
	}
	if (Math.abs(y1 - screenBounds.getMinY()) < SNAP_DISTANCE) {
		y1 = screenBounds.getMinY();
	}
	if (Math.abs(x2 - screenBounds.getMaxX()) < SNAP_DISTANCE) {
		x1 = screenBounds.getMaxX() - bounds.getWidth();
	}
	if (Math.abs(y2 - screenBounds.getMaxY()) < SNAP_DISTANCE) {
		y1 = screenBounds.getMaxY() - bounds.getHeight();
	}
	return new Rectangle2D(x1, y1, bounds.getWidth(), bounds.getHeight());
}
 
Example 3
Source File: OverlayStage.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Rectangle2D getDesktopSize() {
	Rectangle2D rect = Screen.getPrimary().getBounds();
	double minX = rect.getMinX(), minY = rect.getMinY();
	double maxX = rect.getMaxX(), maxY = rect.getMaxY();
	for (Screen screen : Screen.getScreens()) {
		Rectangle2D screenRect = screen.getBounds();
		if (minX > screenRect.getMinX()) {
			minX = screenRect.getMinX();
		}
		if (minY > screenRect.getMinY()) {
			minY = screenRect.getMinY();
		}
		if (maxX < screenRect.getMaxX()) {
			maxX = screenRect.getMaxX();
		}
		if (maxY < screenRect.getMaxY()) {
			maxY = screenRect.getMaxY();
		}
	}
	return new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
}
 
Example 4
Source File: JFXCustomColorPickerDialog.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Screen getCrtScreen(Stage stage) {
    double x = stage.getX();
    Screen crtScreen = null;
    for (Screen screen : Screen.getScreens()) {
        crtScreen = screen;
        Rectangle2D bounds = screen.getBounds();
        if (bounds.getMaxX() > x) {
            break;
        }
    }
    return crtScreen;
}
 
Example 6
Source File: ScreenUtil.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param x Screen coordinates
 *  @param y Screen coordinates
 *  @return Bounds of screen that contains the point, or <code>null</code> if no screen found
 */
public static Rectangle2D getScreenBounds(final double x, final double y)
{
    for (Screen screen : Screen.getScreens())
    {
        final Rectangle2D check = screen.getVisualBounds();
        // contains(x, y) would include the right edge
        if (x >= check.getMinX()  &&  x <  check.getMaxX()  &&
            y >= check.getMinY()  &&  y <  check.getMaxY())
            return check;
    }
    return null;
}
 
Example 7
Source File: MovablePane.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Point2D relocateByKey(Point2D pos, Rectangle2D screen, String key, int value){
	switch (key){
		case "top": return new Point2D(pos.getX(), value);
		case "left": return new Point2D(value, pos.getY());
		case "right": return new Point2D(screen.getMaxX() - getWidth() - value, pos.getY());
		case "bottom": return new Point2D(pos.getX(), screen.getMaxY() - getHeight() - value);
		case "verticalPercent": return new Point2D(pos.getX(), (screen.getMaxY() - getHeight()) * value / 100);
		case "horizontalPercent": return new Point2D((screen.getMaxX() - getWidth()) * value / 100, pos.getY());
	}
	return pos;
}
 
Example 8
Source File: MovablePane.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void loadPositionFromStorage() {
	try {
		final String key = getCurrentPositionStorageKey();
		if (key != null) {
			final String value = Main.getProperties().getString(key);
			if (value != null) {
				String[] coords = value.split(";");
				if (coords.length == 2) {
					double x = Double.parseDouble(coords[0]);
					double y = Double.parseDouble(coords[1]);
					Rectangle2D desktop = OverlayStage.getDesktopSize();
					if(desktop.getWidth() == 0 || desktop.getHeight() == 0) return;

					// fix if character position is outside the screen
					if (x + getHeight() > desktop.getMaxX() || x < -getHeight())
						x = desktop.getMaxX() - getHeight();
					if (y + getWidth() > desktop.getMaxY() || y < -getWidth())
						y = desktop.getMaxY() - getWidth();

					setPosition(new Point2D(x, y));
					return;
				}
			}
		}
	} catch (Exception e){ Main.log(e); }
	setDefaultPosition();
}
 
Example 9
Source File: StartUpLocation.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get Top Left X and Y Positions for a Window to centre it on the
 * currently active screen at application startup
 * @param windowWidth - Window Width
 * @param windowHeight - Window Height
 */
public StartUpLocation(double windowWidth, double windowHeight) {
 
 //System.out.println("(" + windowWidth + ", " + windowHeight + ")");
    // Get X Y of start-up location on Active Screen
    // simple_JavaFX_App
    try {
        // Get current mouse location, could return null if mouse is moving Super-Man fast
        Point p = MouseInfo.getPointerInfo().getLocation();
        // Get list of available screens
        List<Screen> screens = Screen.getScreens();
        if (p != null && screens != null && screens.size() > 1) {
     	   // in order for xPos != 0 and yPos != 0 in startUpLocation, there has to be more than 1 screen
            // Screen bounds as rectangle
            Rectangle2D screenBounds;
            // Go through each screen to see if the mouse is currently on that screen
            for (Screen screen : screens) {
                screenBounds = screen.getVisualBounds();
                // Trying to compute Left Top X-Y position for the Applcation Window
                // If the Point p is in the Bounds
                if (screenBounds.contains(p.x, p.y)) {
                    // Fixed Size Window Width and Height
                    xPos = screenBounds.getMinX() + ((screenBounds.getMaxX() - screenBounds.getMinX() - windowWidth) / 2);
                    yPos = screenBounds.getMinY() + ((screenBounds.getMaxY() - screenBounds.getMinY() - windowHeight) / 2);
                    return;
                }
            }
        }
    } catch (HeadlessException headlessException) {
        // Catch and report exceptions
        headlessException.printStackTrace();
    }
    
}
 
Example 10
Source File: CardAppleMouse.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void setClampWindowY(int min, int max) {
    // Fix for GEOS clamping funkiness
    if (max == 32767) {
        max = 192;
    }
    clampWindow = new Rectangle2D(clampWindow.getMinX(), min, clampWindow.getMaxX(), max);
}
 
Example 11
Source File: AutocompletePopup.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
public void show(final TextInputControl field)
{
    active_field = new WeakReference<>(field);

    // Back when using a ContextMenu,
    //   menu.show(field, Side.BOTTOM, 0, 0);
    // held an `ownerNode` reference,
    // so not passing the field sped up GC.
    final Bounds bounds = field.localToScreen(field.getLayoutBounds());
    if (bounds == null)
    {
        logger.log(Level.WARNING, "Cannot show popup", new Exception("No window"));
        return;
    }

    // Min. width of 620 is useful for long sim PVs
    final double width = Math.max(620, bounds.getWidth());
    ((ListView<?>) skin.getNode()).setPrefWidth(width);

    // Position popup under the field
    double x = bounds.getMinX();
    double y = bounds.getMaxY();

    // But check if that would move it off-screen
    Rectangle2D screen_bounds = ScreenUtil.getScreenBounds(x, y);
    if (screen_bounds != null)
    {
        // Move left to avoid dropping off right screen edge
        if (x + width > screen_bounds.getMaxX())
            x = screen_bounds.getMaxX() - width;
        // Currently not adjusting Y coordinate.
        // Doing that would require listening to height changes
        // as the list is populated.
        // So if list is too long, it will drop below the bottom
        // of the screen.
        // User can still see the text field, and as more is entered,
        // the list tends to show better matches i.e. fewer entries.
    }

    final Window window = field.getScene().getWindow();
    show(window, x, y);
}