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

The following examples show how to use javafx.geometry.Rectangle2D#getMinY() . 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: Notifications.java    From oim-fx with MIT License 6 votes vote down vote up
public void show(Notifications notification) {
    Window window;
    if (notification.owner == null) {
        /*
         * If the owner is not set, we work with the whole screen.
         */
        Rectangle2D screenBounds = notification.screen.getVisualBounds();
        startX = screenBounds.getMinX();
        startY = screenBounds.getMinY();
        screenWidth = screenBounds.getWidth();
        screenHeight = screenBounds.getHeight();

        window = Utils.getWindow(null);
    } else {
        /*
         * If the owner is set, we will make the notifications popup
         * inside its window.
         */
        startX = notification.owner.getX();
        startY = notification.owner.getY();
        screenWidth = notification.owner.getWidth();
        screenHeight = notification.owner.getHeight();
        window = notification.owner;
    }
    show(window, notification);
}
 
Example 2
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 3
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 4
Source File: PopOver.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @param owner_bounds Bounds of active owner
 *  @return Suggested Side for the popup
 */
private Side determineSide(final Bounds owner_bounds)
{
    // Determine center of active owner
    final double owner_x = owner_bounds.getMinX() + owner_bounds.getWidth()/2;
    final double owner_y = owner_bounds.getMinY() + owner_bounds.getHeight()/2;

    // Locate screen
    Rectangle2D screen_bounds = ScreenUtil.getScreenBounds(owner_x, owner_y);
    if (screen_bounds == null)
        return Side.BOTTOM;

    // left .. right as -0.5 .. +0.5
    double lr = (owner_x - screen_bounds.getMinX())/screen_bounds.getWidth() - 0.5;
    // top..buttom as -0.5 .. +0.5
    double tb = (owner_y - screen_bounds.getMinY())/screen_bounds.getHeight() - 0.5;

    // More left/right from center, or top/bottom from center of screen?
    if (Math.abs(lr) > Math.abs(tb))
        return (lr < 0) ? Side.RIGHT : Side.LEFT;
    else
        return (tb < 0) ? Side.BOTTOM : Side.TOP;
}
 
Example 5
Source File: UndecoratorController.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Under Windows, the undecorator Stage could be been dragged below the Task
 * bar and then no way to grab it again... On Mac, do not drag above the
 * menu bar
 *
 * @param y
 */
void setStageY(Stage stage, double y) {
    try {
        ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
        if (screensForRectangle.size() > 0) {
            Screen screen = screensForRectangle.get(0);
            Rectangle2D visualBounds = screen.getVisualBounds();
            if (y < visualBounds.getHeight() - 30 && y + SHADOW_WIDTH >= visualBounds.getMinY()) {
                stage.setY(y);
            }
        }
    } catch (Exception e) {
        Undecorator.LOGGER.log(Level.SEVERE, "setStageY issue", e);
    }
}
 
Example 6
Source File: SelectedWidgetUITracker.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void updateTrackerFromWidgets()
{
    if (updating)
        return;
    final Rectangle2D rect = GeometryTools.getDisplayBounds(widgets);
    updating = true;

    // Update overall tracker rectangle
    setPosition(rect);

    // Add a highlight to each selected widget
    // (tracker area may cover widgets that are not actually selected)
    // Only do that for 2 or more widgets.
    // For a single widget, the tracker rectangle is sufficient.
    widget_highlights.getChildren().clear();
    if (widgets.size() > 1)
        for (Widget widget : widgets)
        {
            final Rectangle2D bounds = GeometryTools.getDisplayBounds(widget);
            final Rectangle highlight = new Rectangle(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
            highlight.getStyleClass().add("tracker_highlight");
            // highlight is 'behind' rest of tracker, but still pass mouse clicks through to widgets
            highlight.setMouseTransparent(true);
            widget_highlights.getChildren().add(highlight);
        }

    updating = false;
}
 
Example 7
Source File: GemOverlay_Stage.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
public GemOverlay_Stage(Build build,boolean betaUi){

        generateLevels(build);
        betaUI = betaUi;
        this.setAlwaysOnTop(true);
        this.initStyle(StageStyle.TRANSPARENT);
        Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
        //double screenRightEdge = primScreenBounds.getMaxX() ;
        //if the settings are on default load the optimized settings based on screen measurements
        if(Preferences_Controller.gem_overlay_pos[0] == -200
                && Preferences_Controller.gem_overlay_pos[1] == -200){

            double screenRightEdge = primScreenBounds.getMinX();
            prefX = screenRightEdge;
            prefY = primScreenBounds.getMinY();

            Preferences_Controller.updateGemsPos(prefX, prefY);
        }else{
            prefX = Preferences_Controller.gem_overlay_pos[0];
            prefY = Preferences_Controller.gem_overlay_pos[1];
        }
        this.setX(prefX);
        this.setY(prefY);
        gemsOnThisLevel_local = new ArrayList<>();
        if(!betaUi)
            loadFXML();
        else
            loadFXMLBeta();

        this.setOnCloseRequest(event -> {
            System.out.println("Closing application from stage -> gem:: ");
            if(saveBuildsToMemory()){
                System.out.println("Successfully saved checkpoint");
            }else{
                System.out.println("Checkpoint save failed");
            }
            System.exit(11);
        });
    }
 
Example 8
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 9
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Rectangle getDisplayScreen(Stage stage){
    Screen crtScreen = getCrtScreen(stage);
    Rectangle2D rectangle2D = crtScreen.getBounds();
    return new Rectangle((int)rectangle2D.getMinX (), (int)rectangle2D.getMinY(),
            (int)rectangle2D.getWidth(),
            (int)rectangle2D.getHeight());
}
 
Example 10
Source File: MovingImageView.java    From neural-style-gui with GNU General Public License v3.0 5 votes vote down vote up
private Point2D imageViewToImage(Point2D imageViewCoordinates) {
    double xProportion = imageViewCoordinates.getX() / imageView.getBoundsInLocal().getWidth();
    double yProportion = imageViewCoordinates.getY() / imageView.getBoundsInLocal().getHeight();

    Rectangle2D viewport = imageView.getViewport();
    return new Point2D(
            viewport.getMinX() + xProportion * viewport.getWidth(),
            viewport.getMinY() + yProportion * viewport.getHeight());
}
 
Example 11
Source File: MnistImageView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Point2D getImageCoordinates(double eX, double eY) {
    double factorX = eX / this.getBoundsInLocal().getWidth();
    double factorY = eY / this.getBoundsInLocal().getHeight();
    Rectangle2D viewport = this.getViewport();
    return new Point2D(viewport.getMinX() + factorX * viewport.getWidth(), 
            viewport.getMinY() + factorY * viewport.getHeight());
}
 
Example 12
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 13
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 14
Source File: CustomStage.java    From JavaFX-Chat with GNU General Public License v3.0 5 votes vote down vote up
public CustomStage(AnchorPane ap, StageStyle style) {
    initStyle(style);

    setSize(ap.getPrefWidth(), ap.getPrefHeight());

    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    double x = screenBounds.getMinX() + screenBounds.getWidth() - ap.getPrefWidth() - 2;
    double y = screenBounds.getMinY() + screenBounds.getHeight() - ap.getPrefHeight() - 2;

    bottomRight = new Location(x,y);
}
 
Example 15
Source File: ViewGrid.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
private final void updatePath(final boolean withMainGrid, final boolean withSubGrid, final boolean withLabels) {
	final double minY = model.getGridMinY();
	final double maxY = model.getGridMaxY();
	final double minX = model.getGridMinX();
	final double maxX = model.getGridMaxX();
	final double unit = model.getUnit();
	double yStep = Shape.PPC * unit;
	double xStep = Shape.PPC * unit;
	xStep *= model.getGridEndX() < model.getGridStartX() ? -1d : 1d;
	yStep *= model.getGridEndY() < model.getGridStartY() ? -1d : 1d;
	final double posX = Math.min(model.getGridStartX(), model.getGridEndX()) * Shape.PPC * unit;
	final double posY = -Math.min(model.getGridStartY(), model.getGridEndY()) * Shape.PPC * unit;
	final double absStep = Math.abs(xStep);
	final Rectangle2D bounds = getGridBounds(posX, posY);
	final double tlx = bounds.getMinX();
	final double tly = bounds.getMinY();

	if(withSubGrid) {
		subgrid.getElements().clear();
		updatePathSubGrid(unit, minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, bounds.getMaxX(), bounds.getMaxY());
	}

	if(withMainGrid) {
		maingrid.getElements().clear();
		updatePathMainGrid(unit, minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, bounds.getMaxX(), bounds.getMaxY(), absStep);
	}

	if(withLabels) {
		cleanLabels();
		updatePathLabels(minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, absStep);
	}
}
 
Example 16
Source File: FxUtils.java    From stagedisplayviewer with MIT License 5 votes vote down vote up
private Rectangle2D getScreenBounds() {
  	// Uses property width/height if specified, or defaults to screen bounds.
  	Rectangle2D screen = getScreen().getBounds();
  	double width = Property.WIDTH.toDouble();
  	double height = Property.HEIGHT.toDouble();
  	return new Rectangle2D(screen.getMinX(), screen.getMinY(), 
	width > 0 ? width : screen.getWidth(), 
	height > 0 ? height : screen.getHeight()
);
  }
 
Example 17
Source File: SelectedWidgetUITracker.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** Updates widgets to current tracker location and size */
private void updateWidgetsFromTracker(final Rectangle2D original, final Rectangle2D current)
{
    if (updating)
        return;
    updating = true;
    try
    {
        group_handler.hide();

        final List<Rectangle2D> orig_position =
            widgets.stream().map(GeometryTools::getBounds).collect(Collectors.toList());

        // If there was only one widget, the tracker bounds represent
        // the desired widget location and size.
        // But tracker bounds can apply to one or more widgets, so need to
        // determine the change in tracker bounds, apply those to each widget.
        final double dx = current.getMinX()   - original.getMinX();
        final double dy = current.getMinY()   - original.getMinY();
        final double dw = current.getWidth()  - original.getWidth();
        final double dh = current.getHeight() - original.getHeight();
        final int N = orig_position.size();

        // Use compound action if there's more than one widget
        final CompoundUndoableAction compound = N>1
            ? new CompoundUndoableAction(Messages.UpdateWidgetLocation)
            : null;
        for (int i=0; i<N; ++i)
        {
            final Widget widget = widgets.get(i);
            final Rectangle2D orig = orig_position.get(i);

            final ChildrenProperty orig_parent_children = ChildrenProperty.getParentsChildren(widget);
            ChildrenProperty parent_children = group_handler.getActiveParentChildren();
            if (parent_children == null)
                parent_children = widget.getDisplayModel().runtimeChildren();

            final int orig_index;
            if (orig_parent_children == parent_children)
            {   // Slightly faster since parent stays the same
                if (! widget.propX().isUsingWidgetClass())
                    widget.propX().setValue((int) (orig.getMinX() + dx));
                if (! widget.propY().isUsingWidgetClass())
                    widget.propY().setValue((int) (orig.getMinY() + dy));
                orig_index = -1;
            }
            else
            {   // Update to new parent
                if (widget.getDisplayModel().isClassModel())
                {
                    logger.log(Level.WARNING, "Widget hierarchy is not permitted for class model");
                    return;
                }

                final Point2D old_offset = GeometryTools.getDisplayOffset(widget);
                orig_index = orig_parent_children.removeChild(widget);
                parent_children.addChild(widget);
                final Point2D new_offset = GeometryTools.getDisplayOffset(widget);

                logger.log(Level.FINE, "{0} moves from {1} ({2}) to {3} ({4})",
                           new Object[] { widget, orig_parent_children.getWidget(), old_offset,
                                                  parent_children.getWidget(), new_offset});
                // Account for old and new display offset
                if (! widget.propX().isUsingWidgetClass())
                    widget.propX().setValue((int) (orig.getMinX() + dx + old_offset.getX() - new_offset.getX()));
                if (! widget.propY().isUsingWidgetClass())
                    widget.propY().setValue((int) (orig.getMinY() + dy + old_offset.getY() - new_offset.getY()));
            }
            if (! widget.propWidth().isUsingWidgetClass())
                widget.propWidth().setValue((int) Math.max(1, orig.getWidth() + dw));
            if (! widget.propHeight().isUsingWidgetClass())
                widget.propHeight().setValue((int) Math.max(1, orig.getHeight() + dh));

            final UndoableAction step = new UpdateWidgetLocationAction(widget,
                                                                       orig_parent_children,
                                                                       parent_children,
                                                                       orig_index,
                                                                       (int) orig.getMinX(),  (int) orig.getMinY(),
                                                                       (int) orig.getWidth(), (int) orig.getHeight());
            if (compound == null)
                undo.add(step);
            else
                compound.add(step);
        }
        if (compound != null)
            undo.add(compound);
    }
    catch (Exception ex)
    {
        logger.log(Level.SEVERE, "Failed to move/resize widgets", ex);
    }
    finally
    {
        updating = false;
        updateTrackerFromWidgets();
    }
}
 
Example 18
Source File: ZoneOverlay_Stage.java    From Path-of-Leveling with MIT License 4 votes vote down vote up
public ZoneOverlay_Stage(){
    isVisible = false;
    this.setAlwaysOnTop(true);
    this.initStyle(StageStyle.TRANSPARENT);
    
    if(Preferences_Controller.zones_overlay_pos[0] == -200 
            && Preferences_Controller.zones_overlay_pos[1] == -200){
        
        Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
        primScreenBounds.getMinY();
        prefX = 200.0;
        prefY = primScreenBounds.getMinY();
        
        Preferences_Controller.updateZonesPos(prefX, prefY);
    }else{
        prefX = Preferences_Controller.zones_overlay_pos[0];
        prefY = Preferences_Controller.zones_overlay_pos[1];
    }
    
    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);
    });
    if(!Preferences_Controller.zones_toggle){
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/poe/level/fx/overlay/ZoneOverlay.fxml"));
        AnchorPane ap = null;
        try {
            ap = loader.load();
        } catch (IOException ex) {
            Logger.getLogger(ZoneOverlay_Stage.class.getName()).log(Level.SEVERE, null, ex);
        }
        controller = loader.<ZoneOverlay_Controller>getController();
        controller.playTown();
        Scene scene = new Scene(ap);
        scene.getStylesheets().add(getClass().getResource("/styles/style.css").toExternalForm());
        scene.setFill(Color.TRANSPARENT);
        bindKeyEvent(scene);
        this.setScene(scene);
        controller.hookStage(this);
        this.setX(prefX);
        this.setY(prefY);
        fadeIn();
    }
}
 
Example 19
Source File: JFXDecorator.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
private void maximize(SVGGlyph resizeMin, SVGGlyph resizeMax) {
    if (!isCustomMaximize()) {
        primaryStage.setMaximized(!primaryStage.isMaximized());
        maximized = primaryStage.isMaximized();
        if (primaryStage.isMaximized()) {
            btnMax.setGraphic(resizeMin);
            btnMax.setTooltip(new Tooltip("Restore Down"));
        } else {
            btnMax.setGraphic(resizeMax);
            btnMax.setTooltip(new Tooltip("Maximize"));
        }
    } else {
        if (!maximized) {
            // store original bounds
            originalBox = new BoundingBox(primaryStage.getX(), primaryStage.getY(), primaryStage.getWidth(), primaryStage.getHeight());
            // get the max stage bounds
            Screen screen = Screen.getScreensForRectangle(primaryStage.getX(),
                primaryStage.getY(),
                primaryStage.getWidth(),
                primaryStage.getHeight()).get(0);
            Rectangle2D bounds = screen.getVisualBounds();
            maximizedBox = new BoundingBox(bounds.getMinX(),
                bounds.getMinY(),
                bounds.getWidth(),
                bounds.getHeight());
            // maximized the stage
            primaryStage.setX(maximizedBox.getMinX());
            primaryStage.setY(maximizedBox.getMinY());
            primaryStage.setWidth(maximizedBox.getWidth());
            primaryStage.setHeight(maximizedBox.getHeight());
            btnMax.setGraphic(resizeMin);
            btnMax.setTooltip(new Tooltip("Restore Down"));
        } else {
            // restore stage to its original size
            primaryStage.setX(originalBox.getMinX());
            primaryStage.setY(originalBox.getMinY());
            primaryStage.setWidth(originalBox.getWidth());
            primaryStage.setHeight(originalBox.getHeight());
            originalBox = null;
            btnMax.setGraphic(resizeMax);
            btnMax.setTooltip(new Tooltip("Maximize"));
        }
        maximized = !maximized;
    }
}
 
Example 20
Source File: Utils.java    From Quelea with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Converts a JavaFX Rectangle2D to a JavaFX bounds object.
 * <p/>
 * @param rect the Rectangle2D to convert.
 * @return the equivalent bounds.
 * <p/>
 */
public static Bounds getBoundsFromRect2D(Rectangle2D rect) {
	return new BoundingBox(rect.getMinX(), rect.getMinY(), rect.getWidth(), rect.getHeight());
}