Java Code Examples for javafx.stage.Screen#getScreens()

The following examples show how to use javafx.stage.Screen#getScreens() . 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: UndecoratorController.java    From DevToolBox with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Based on mouse position returns dock side
 *
 * @param mouseEvent
 * @return DOCK_LEFT,DOCK_RIGHT,DOCK_TOP
 */
int getDockSide(MouseEvent mouseEvent) {
    double minX = Double.POSITIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxX = 0;
    double maxY = 0;
    // Get "big" screen bounds
    ObservableList<Screen> screens = Screen.getScreens();
    for (Screen screen : screens) {
        Rectangle2D visualBounds = screen.getVisualBounds();
        minX = Math.min(minX, visualBounds.getMinX());
        minY = Math.min(minY, visualBounds.getMinY());
        maxX = Math.max(maxX, visualBounds.getMaxX());
        maxY = Math.max(maxY, visualBounds.getMaxY());
    }
    // Dock Left
    if (mouseEvent.getScreenX() == minX) {
        return DOCK_LEFT;
    } else if (mouseEvent.getScreenX() >= maxX - 1) { // MaxX returns the width? Not width -1 ?!
        return DOCK_RIGHT;
    } else if (mouseEvent.getScreenY() <= minY) {   // Mac menu bar
        return DOCK_TOP;
    }
    return 0;
}
 
Example 2
Source File: MovablePane.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setPosition(Point2D topLeft) {
	if (topLeft == null) {
		setDefaultPosition();
		return;
	}
	Bounds bounds = getLayoutBounds();
	Rectangle2D rect = new Rectangle2D(topLeft.getX(), topLeft.getY(),
			bounds.getWidth(), bounds.getHeight());

	// Anchoring to screen edges if pane is too hide to edge
	for (Screen screen : Screen.getScreens()) {
		rect = anchorToEdges(rect, screen.getBounds());
		rect = anchorToEdges(rect, screen.getVisualBounds());
	}
	relocate(rect.getMinX(), rect.getMinY());
}
 
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: ProjectorArenaPane.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
private Optional<Screen> findSmallestScreen() {
	Screen smallest = null;

	// Find screen with the smallest area
	for (final Screen screen : Screen.getScreens()) {
		if (smallest == null) {
			smallest = screen;
		} else {
			if (screen.getBounds().getHeight() * screen.getBounds().getWidth() < smallest.getBounds().getHeight()
					* smallest.getBounds().getWidth()) {
				smallest = screen;
			}
		}
	}

	return Optional.ofNullable(smallest);
}
 
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: SplashStage.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new splash window.
 */
public SplashStage() {
    initModality(Modality.APPLICATION_MODAL);
    initStyle(StageStyle.UNDECORATED);
    Utils.addIconsToStage(this);
    setTitle("Quelea " + LabelGrabber.INSTANCE.getLabel("loading.text") + "...");
    Image splashImage = new Image(new File(QueleaProperties.VERSION.getUnstableName().getSplashPath()).getAbsoluteFile().toURI().toString());
    ImageView imageView = new ImageView(splashImage);
    Group mainPane = new Group();
    mainPane.getChildren().add(imageView);
    Scene scene = new Scene(mainPane);
    if (QueleaProperties.get().getUseDarkTheme()) {
        scene.getStylesheets().add("org/modena_dark.css");
    }
    setScene(scene);

    ObservableList<Screen> monitors = Screen.getScreens();
    Screen screen;
    int controlScreenProp = QueleaProperties.get().getControlScreen();
    if (controlScreenProp < monitors.size() && controlScreenProp >= 0) {
        screen = monitors.get(controlScreenProp);
    } else {
        screen = Screen.getPrimary();
    }

    Rectangle2D bounds = screen.getVisualBounds();
    setX(bounds.getMinX() + ((bounds.getWidth() / 2) - splashImage.getWidth() / 2));
    setY(bounds.getMinY() + ((bounds.getHeight() / 2) - splashImage.getHeight() / 2));
}
 
Example 7
Source File: DisplayGroup.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a list model describing the available graphical devices.
 *
 * @return a list model describing the available graphical devices.
 */
private ObservableList<String> getAvailableScreens(boolean none) {
    ObservableList<Screen> monitors = Screen.getScreens();

    ObservableList<String> descriptions = FXCollections.<String>observableArrayList();
    if (none) {
        descriptions.add(LabelGrabber.INSTANCE.getLabel("none.text"));
    }
    for (int i = 0; i < monitors.size(); i++) {
        descriptions.add(LabelGrabber.INSTANCE.getLabel("output.text") + " " + (i + 1));
    }
    return descriptions;
}
 
Example 8
Source File: Utils.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isOffscreen(SceneInfo info) {
	for (Screen screen : Screen.getScreens()) {
		if (screen.getBounds().intersects(info.getBounds())) {
			return false;
		}
	}
	return true;
}
 
Example 9
Source File: DataBrowserInstance.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
public DataBrowserInstance(final DataBrowserApp app, final boolean minimal)
{
    this.app = app;

    // Determine width of widest monitor
    if (display_pixel_width == 0)
    {
        for (Screen screen : Screen.getScreens())
        {
            final int width = (int) screen.getBounds().getWidth();
            if (width > display_pixel_width)
                display_pixel_width = width;
        }
        if (display_pixel_width <= 0)
        {
            logger.log(Level.WARNING, "Cannot determine display pixel width, using 1000");
            display_pixel_width = 1000;
        }
    }

    perspective = new Perspective(minimal);

    dock_item = new DockItemWithInput(this, perspective, null, file_extensions, this::doSave);
    DockPane.getActiveDockPane().addTab(dock_item);

    dock_item.addCloseCheck(() ->
    {
        dispose();
        return true;
    });

    perspective.getModel().addListener(model_listener);
}
 
Example 10
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 11
Source File: SvgImageLoader.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public float calculateMaxRenderScale() {

    var maxRenderScale = 0F;
    var accessor = ScreenHelper.getScreenAccessor();

    for (var screen : Screen.getScreens()) {
        maxRenderScale = Math.max(maxRenderScale, accessor.getRenderScale(screen));
    }

    return maxRenderScale;
}
 
Example 12
Source File: FX.java    From FxDock with Apache License 2.0 5 votes vote down vote up
/** returns true if the coordinates belong to one of the Screens */
public static boolean isValidCoordinates(double x, double y)
{
	for(Screen screen: Screen.getScreens())
	{
		Rectangle2D r = screen.getVisualBounds();
		if(r.contains(x, y))
		{
			return true;
		}
	}
	return false;
}
 
Example 13
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 14
Source File: SvgImageLoader.java    From javafxsvg with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public float calculateMaxRenderScale() {
	float maxRenderScale = 0;
	ScreenHelper.ScreenAccessor accessor = ScreenHelper.getScreenAccessor();
	for (Screen screen : Screen.getScreens()) {
		maxRenderScale = Math.max(maxRenderScale, accessor.getRenderScale(screen));
	}
	return maxRenderScale;
}
 
Example 15
Source File: PopOver.java    From logbook-kai with MIT License 4 votes vote down vote up
/**
 * ポップアップの表示位置を設定します
 *
 * @param popup ポップアップ
 * @param anchorNode アンカーノード
 * @param event {@link MouseEvent}
 */
protected void setLocation(Popup popup, Node anchorNode, MouseEvent event) {
    double x = event.getScreenX();
    double y = event.getScreenY();
    double width = popup.getWidth();
    double height = popup.getHeight();
    double gapSize = this.getGapSize();

    PopupWindow.AnchorLocation anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT;
    double gapX = gapSize;
    double gapY = gapSize;

    for (Screen screen : Screen.getScreens()) {
        Rectangle2D screenRect = screen.getVisualBounds();

        // 右下 に表示可能であれば
        if (screenRect.contains(x + gapSize, y + gapSize, width, height)) {
            // PopupWindow視点でアンカーノードがTOP_LEFTの位置
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT;
            gapX = gapSize;
            gapY = gapSize;
            break;
        }
        // 左下
        if (screenRect.contains(x - gapSize - width, y + gapSize, width, height)) {
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_RIGHT;
            gapX = -gapSize;
            gapY = gapSize;
            break;
        }
        // 右上
        if (screenRect.contains(x + gapSize, y - gapSize - height, width, height)) {
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_LEFT;
            gapX = gapSize;
            gapY = -gapSize;
            break;
        }
        // 左上
        if (screenRect.contains(x - gapSize - width, y - gapSize - height, width, height)) {
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_RIGHT;
            gapX = -gapSize;
            gapY = -gapSize;
            break;
        }
    }

    popup.setAnchorLocation(anchorLocation);
    popup.setAnchorX(x + gapX);
    popup.setAnchorY(y + gapY);
}