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

The following examples show how to use javafx.geometry.Rectangle2D#getHeight() . 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: MnistImageView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void zoom(double factor, double pivotX, double pivotY) {
    Rectangle2D viewport = this.getViewport();
    double scale = clamp(factor,
        Math.min(MIN_SIZE / viewport.getWidth(), MIN_SIZE / viewport.getHeight()),
        Math.max(INNER_WIDTH / viewport.getWidth(), INNER_HEIGHT / viewport.getHeight()));
    Point2D pivot = getImageCoordinates(pivotX, pivotY);

    double newWidth = viewport.getWidth() * scale;
    double newHeight = viewport.getHeight() * scale;

    // to zoom over the pivot, we have for x, y:
    // (x - newMinX) / (x - viewport.getMinX()) = scale
    // solving for newMinX, newMinY:
    double newMinX = clamp(pivot.getX() - (pivot.getX() - viewport.getMinX()) * scale, 
            0, IMAGE_WIDTH - newWidth);
    double newMinY = clamp(pivot.getY() - (pivot.getY() - viewport.getMinY()) * scale, 
            0, IMAGE_HEIGHT - newHeight);

    this.setViewport(new Rectangle2D(newMinX, newMinY, newWidth, newHeight));
}
 
Example 2
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 3
Source File: AlgorithmBenchmarker.java    From JImageHash with MIT License 6 votes vote down vote up
/**
 * Spawn a full screen windows with a webview displaying the html content
 * 
 * @param stage       of the window
 * @param htmlContent the content to display
 */
private void spawnNewWindow(Stage stage, String htmlContent) {

	WebView webView = new WebView();
	webView.getEngine().loadContent(htmlContent);

	// Fullscreen

	Rectangle2D screen = Screen.getPrimary().getVisualBounds();

	double w = screen.getWidth();
	double h = screen.getHeight();
	Scene scene = new Scene(webView, w, h);
	stage.setTitle("Image Hash Benchmarker");
	stage.getIcons().add(new Image("imageHashLogo.png"));
	stage.setScene(scene);
	stage.show();
}
 
Example 4
Source File: EnvironmentManagerImpl.java    From VocabHunter with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isVisible(final Placement placement) {
    ObservableList<Screen> screens = Screen.getScreensForRectangle(rectangle(placement));

    if (screens.size() == 1) {
        Screen screen = screens.get(0);
        Rectangle2D bounds = screen.getVisualBounds();

        if (placement.isPositioned()) {
            return bounds.contains(placement.getX(), placement.getY(), placement.getWidth(), placement.getHeight());
        } else {
            return bounds.getWidth() >= placement.getWidth() && bounds.getHeight() >= placement.getHeight();
        }
    } else {
        return false;
    }
}
 
Example 5
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 6
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 7
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 8
Source File: Callout.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
protected Animation buildSubtitleRectAnim(HBox mainTitleBackground, Rectangle subTitleRect) {

        // Small rectangle (prompt)
        // Calculate main title width and height upfront
        Rectangle2D mainTitleBounds = getBoundsUpfront(mainTitleBackground);

        double mainTitleWidth = mainTitleBounds.getWidth();
        double mainTitleHeight = mainTitleBounds.getHeight();

        // Position of the end
        Point2D endPointLL = calcEndPointOfLeaderLine();
        double x = endPointLL.getX();
        double y = endPointLL.getY();

        int direction = getEndLeaderLineDirection();
        if (direction == LEFT) {
            subTitleRect.setLayoutX( x + (subTitleRect.getWidth() * direction));
        } else {
            subTitleRect.setLayoutX( x );
        }


        subTitleRect.setLayoutY( y + (mainTitleHeight/2) + 2);

        return new Timeline(
                new KeyFrame(Duration.millis(1),
                        new KeyValue(subTitleRect.visibleProperty(), true),
                        new KeyValue(subTitleRect.heightProperty(), 0)), // show
                new KeyFrame(Duration.millis(300),
                        new KeyValue(subTitleRect.heightProperty(), 20)
                )
        );
    }
 
Example 9
Source File: FxUtils.java    From stagedisplayviewer with MIT License 5 votes vote down vote up
public Scene createScene(Text lowerKey) {
    Rectangle2D bounds = getScreenBounds();
    Scene scene = new Scene(createRoot(lowerKey), bounds.getWidth(), bounds.getHeight());
    scene.getStylesheets().add("styles.css");
    try {
        scene.getStylesheets().add(new File("styles.css").toURI().toURL().toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return scene;
}
 
Example 10
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 11
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 12
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 13
Source File: WebBrowser.java    From yfiton with Apache License 2.0 4 votes vote down vote up
@Override
public void start(final Stage stage) throws Exception {
    // required to allow CORS
    System.setProperty("sun.net.http.allowRestrictedHeaders", "true");

    BorderPane borderPane = new BorderPane();

    WebView browser = new WebView();
    WebEngine webEngine = browser.getEngine();
    webEngine.setUserAgent("Yfiton");

    Map<String, String> parameters = getParameters().getNamed();
    borderPane.setCenter(browser);
    webEngine.documentProperty().addListener((prop, oldDoc, newDoc) -> {
        String debugMode = parameters.get("debug");
        if (debugMode != null && debugMode.equalsIgnoreCase("true")) {
            enableFirebug(webEngine);
        }
    });
    webEngine.load(parameters.get("authorization-url"));

    Class<?> listenerClass = Class.forName(parameters.get("webengine-listener-class"));

    WebEngineListener listener =
            (WebEngineListener) listenerClass.getConstructor(
                    WebEngine.class, String.class, String.class).newInstance(
                    webEngine, parameters.get("authorization-file"), parameters.get("authorization-code-parameter-name"));

    webEngine.getLoadWorker().stateProperty().addListener(listener);

    stage.setTitle("Yfiton");

    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();

    scene =
            new Scene(
                    borderPane,
                    primaryScreenBounds.getWidth() * 0.55,
                    primaryScreenBounds.getHeight() * 0.65);

    stage.setScene(scene);
    stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/yfiton-icon.png")));
    stage.show();
    stage.setOnCloseRequest(event -> System.exit(EXIT_CODE_ON_CLOSE));
}
 
Example 14
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 15
Source File: Callout.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
protected Animation buildMainTitleAnim(HBox mainTitleBackground) {

        // main title box
        // Calculate main title width and height upfront
        Rectangle2D mainTitleBounds = getBoundsUpfront(mainTitleBackground);

        double mainTitleWidth = mainTitleBounds.getWidth();
        double mainTitleHeight = mainTitleBounds.getHeight();

        // Position mainTitleText background beside the end part of the leader line.
        Point2D endPointLLine = calcEndPointOfLeaderLine();
        double x = endPointLLine.getX();
        double y = endPointLLine.getY();

        // Viewport to make main title appear to scroll
        Rectangle mainTitleViewPort = new Rectangle();
        mainTitleViewPort.setWidth(0);
        mainTitleViewPort.setHeight(mainTitleHeight);

        mainTitleBackground.setClip(mainTitleViewPort);
        mainTitleBackground.setLayoutX(x);
        mainTitleBackground.setLayoutY(y - (mainTitleHeight/2));

        // Animate main title from end point to the left.
        if (LEFT == getEndLeaderLineDirection()) {
            // animate layout x and width
            return new Timeline(
                    new KeyFrame(Duration.millis(1),
                            new KeyValue(mainTitleBackground.visibleProperty(), true),
                            new KeyValue(mainTitleBackground.layoutXProperty(), x)
                    ), // show
                    new KeyFrame(Duration.millis(200),
                            new KeyValue(mainTitleBackground.layoutXProperty(), x - mainTitleWidth),
                            new KeyValue(mainTitleViewPort.widthProperty(), mainTitleWidth)
                    )
            );
        }

        // Animate main title from end point to the right
        return new Timeline(
                new KeyFrame(Duration.millis(1),
                        new KeyValue(mainTitleBackground.visibleProperty(), true)), // show
                new KeyFrame(Duration.millis(200),
                        new KeyValue(mainTitleViewPort.widthProperty(), mainTitleWidth)
                )
        );
    }
 
Example 16
Source File: ColorPaletteController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public void init(BaseController parent, Control control, String title,
            boolean pickColor) {
        parentController = parent;
        this.control = control;
//        logger.debug(control.getClass() + " " + control.getId());
        Rectangle2D screenBounds = FxmlControl.getScreen();
        double controlX = FxmlControl.getX(control);
        double controlY = FxmlControl.getY(control);
        int offset = 20;
//        logger.debug(control.getClass() + " " + control.getId() + " " + controlX + " " + controlY);
        if (controlX + control.getWidth() + getMyStage().getWidth() > screenBounds.getWidth()) {
            getMyStage().setX(Math.max(0, controlX - getMyStage().getWidth() - offset));
        } else {
            getMyStage().setX(Math.min(screenBounds.getWidth() - offset, controlX + control.getWidth() + offset));
        }
        if (controlY + getMyStage().getHeight() > screenBounds.getHeight()) {
            getMyStage().setY(Math.max(0, screenBounds.getHeight() - getMyStage().getHeight()));
        } else {
            getMyStage().setY(Math.max(0, controlY - offset));
        }
        titleLabel.setText(title);

        if (pickColor) {
            pickColorButton.setVisible(true);
            isPickingColor.bind(pickColorButton.selectedProperty());
            isPickingColor.addListener(new ChangeListener<Boolean>() {
                @Override
                public void changed(ObservableValue<? extends Boolean> ov,
                        Boolean oldVal, Boolean newVal) {
                    if (newVal) {
                        promptLabel.setText(AppVariables.message("PickingColorsNow"));
                    } else {
                        promptLabel.setText("");
                    }
                }
            });
            parentController.getIsPickingColor().bind(isPickingColor);
        } else {
            parentController.getIsPickingColor().unbind();
            pickColorButton.setVisible(false);
        }
    }
 
Example 17
Source File: EnvironmentManagerImpl.java    From VocabHunter with Apache License 2.0 4 votes vote down vote up
@Override
public Placement getScreenSize() {
    Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();

    return new Placement(visualBounds.getWidth(), visualBounds.getHeight());
}
 
Example 18
Source File: DesktopDisplayService.java    From attach with GNU General Public License v3.0 4 votes vote down vote up
public DesktopDisplayService() {
    Rectangle2D bounds = Screen.getPrimary().getBounds();
    dimensions = new Dimension2D(bounds.getWidth(), bounds.getHeight());
}
 
Example 19
Source File: JavaFXNES.java    From halfnes with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    this.stage = stage;
    //Rectangle2D bounds = Screen.getPrimary().getBounds();
    Rectangle2D bounds = new Rectangle2D(0,0,640,480);
    gameCanvas = new Canvas(256, 240);
    stage.addEventHandler(javafx.stage.WindowEvent.WINDOW_CLOSE_REQUEST, e -> nes.quit());
    menu = new OnScreenMenu(this);
    //menu.setPadding(extraOverscan);
    menu.setPrefWidth(256);
    menu.setPrefHeight(240);
    Group root = new Group(gameCanvas, menu);
    Scene scene = new Scene(root, bounds.getWidth(), bounds.getHeight(), Color.BLACK);
    stage.setScene(scene);
    //stage.setFullScreen(true);
    stage.setFullScreenExitKeyCombination(KeyCombination.valueOf("F11"));
    stage.addEventHandler(javafx.scene.input.KeyEvent.KEY_PRESSED, e -> {
        if (e.getCode().equals(KeyCode.ESCAPE)) {
            menu.show();
        }
    });
    root.setLayoutX(overscan.getRight() - overscan.getLeft() - extraOverscan.getLeft() * bounds.getWidth() / 256);
    root.setLayoutY(overscan.getBottom() - overscan.getTop() - extraOverscan.getTop() * bounds.getHeight() / 240);
    root.getTransforms().add(new Scale(
        (bounds.getWidth() - (overscan.getRight() - overscan.getLeft())) / (256 - extraOverscan.getLeft() - extraOverscan.getRight()),
        (bounds.getHeight() - (overscan.getBottom() - overscan.getTop())) / (240 - extraOverscan.getTop() - extraOverscan.getBottom())));
    nes = new NES(this);
    ControllerImpl padController1 = new ControllerImpl(scene, 0);
    ControllerImpl padController2 = new ControllerImpl(scene, 1);
    padController1.startEventQueue();
    padController2.startEventQueue();
    nes.setControllers(padController1, padController2);
    final List<String> params = getParameters().getRaw();
    new Thread(() -> {
        if (params.isEmpty()) {
            nes.run();
        } else {
            nes.run(params.get(0));
        }
    }, "Game Thread").start();
}
 
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());
}