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

The following examples show how to use javafx.geometry.Rectangle2D#getMaxY() . 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: 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 5
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 6
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 7
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 8
Source File: CardAppleMouse.java    From jace with GNU General Public License v2.0 5 votes vote down vote up
private void setClampWindowX(int min, int max) {
    // Fix for GEOS clamping funkiness
    if (max == 32767) {
        max = 560;
    }
    clampWindow = new Rectangle2D(min, clampWindow.getMinY(), max, clampWindow.getMaxY());
}
 
Example 9
Source File: LevelOverlay_Stage.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
public LevelOverlay_Stage(){
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/poe/level/fx/overlay/LevelOverlay.fxml"));
    AnchorPane ap = null;
    try {
        ap = loader.load();
    } catch (IOException ex) {
        Logger.getLogger(ZoneOverlay_Stage.class.getName()).log(Level.SEVERE, null, ex);
    }
    controller = loader.<LevelOverlay_Controller>getController();
    
    Scene scene = new Scene(ap);
    scene.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
    scene.setFill(Color.TRANSPARENT);
    this.setOnCloseRequest(event -> {
        System.out.println("Closing application from stage -> level:: ");
        if(saveBuildsToMemory()){
            System.out.println("Successfully saved checkpoint");
        }else{
            System.out.println("Checkpoint save failed");
        }
        System.exit(10);
    });
    
    this.setScene(scene);
    this.setAlwaysOnTop(true);
    this.initStyle(StageStyle.TRANSPARENT);
    
    if(Preferences_Controller.level_overlay_pos[0] == -200 
            && Preferences_Controller.level_overlay_pos[1] == -200){
        
        Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
        prefX = primScreenBounds.getWidth()/2 - 736/2;
        prefY = primScreenBounds.getMaxY() - 100;
        
        Preferences_Controller.updateLevelPos(prefX, prefY);
    }else{
        prefX = Preferences_Controller.level_overlay_pos[0];
        prefY = Preferences_Controller.level_overlay_pos[1];
    }
    
    this.setX(prefX);
    this.setY(prefY);
    
    controller.hookStage(this);
    controller.setPlayerLevel(Main_Stage.playerLevel);
    controller.reset(Main_Stage.playerLevel);
    this.show();
}