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

The following examples show how to use javafx.geometry.Rectangle2D#getWidth() . 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: 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 2
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 3
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 4
Source File: Main.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    new Thread(() -> {
        try {
            SVGGlyphLoader.loadGlyphsFont(Main.class.getResourceAsStream("/fonts/icomoon.svg"),
                    "icomoon.svg");
        } catch (IOException ioExc) {
            ioExc.printStackTrace();
        }
    }).start();

    Flow flow = new Flow(XToolsController.class);
    DefaultFlowContainer container = new DefaultFlowContainer();
    flowContext = new ViewFlowContext();
    flowContext.register("Stage", stage);
    flow.createHandler(flowContext).start(container);

    JFXDecorator decorator = new JFXDecorator(stage, container.getView());
    decorator.setCustomMaximize(true);
    decorator.setGraphic(new SVGGlyph(""));

    stage.setTitle("JFoenix Demo");

    double width = 800;
    double height = 600;
    try {
        Rectangle2D bounds = Screen.getScreens().get(0).getBounds();
        width = bounds.getWidth() / 2.5;
        height = bounds.getHeight() / 1.35;
    }catch (Exception e){ }

    Scene scene = new Scene(decorator, width, height);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
            JFoenixResources.load("css/jfoenix-design.css").toExternalForm(),
            Main.class.getResource("/css/jfoenix-main-demo.css").toExternalForm());
    stage.setScene(scene);
    stage.show();
}
 
Example 5
Source File: AndroidDisplayService.java    From attach with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dimension2D getDefaultDimensions() {
    Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
    Dimension2D dimension2D = new Dimension2D(visualBounds.getWidth(), visualBounds.getHeight());
    if (debug) {
        LOG.log(Level.INFO, "Screen default dimensions: " + dimension2D);
    }
    return dimension2D;
}
 
Example 6
Source File: MainDemo.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    new Thread(() -> {
        try {
            SVGGlyphLoader.loadGlyphsFont(MainDemo.class.getResourceAsStream("/fonts/icomoon.svg"),
                "icomoon.svg");
        } catch (IOException ioExc) {
            ioExc.printStackTrace();
        }
    }).start();

    Flow flow = new Flow(MainController.class);
    DefaultFlowContainer container = new DefaultFlowContainer();
    flowContext = new ViewFlowContext();
    flowContext.register("Stage", stage);
    flow.createHandler(flowContext).start(container);

    JFXDecorator decorator = new JFXDecorator(stage, container.getView());
    decorator.setCustomMaximize(true);
    decorator.setGraphic(new SVGGlyph(""));

    stage.setTitle("JFoenix Demo");

    double width = 800;
    double height = 600;
    try {
        Rectangle2D bounds = Screen.getScreens().get(0).getBounds();
        width = bounds.getWidth() / 2.5;
        height = bounds.getHeight() / 1.35;
    }catch (Exception e){ }

    Scene scene = new Scene(decorator, width, height);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
                       JFoenixResources.load("css/jfoenix-design.css").toExternalForm(),
                       MainDemo.class.getResource("/css/jfoenix-main-demo.css").toExternalForm());
    stage.setScene(scene);
    stage.show();
}
 
Example 7
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 8
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 9
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 10
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 11
Source File: TacWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Inject
public TacWindow() {
    type = Type.Attention;

    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
    final double primaryScreenBoundsWidth = primaryScreenBounds.getWidth();
    smallScreen = primaryScreenBoundsWidth < 1024;
    if (smallScreen) {
        this.width = primaryScreenBoundsWidth * 0.8;
        log.warn("Very small screen: primaryScreenBounds=" + primaryScreenBounds.toString());
    } else {
        width = 1100;
    }
}
 
Example 12
Source File: Callout.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
protected Animation buildSubTitleAnim(HBox mainTitle, HBox subTitle) {

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

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

        Pos textPos = (LEFT == getEndLeaderLineDirection()) ? Pos.CENTER_LEFT : Pos.CENTER_RIGHT;
        subTitle.setAlignment(textPos);

        Rectangle2D subTitleBounds = getBoundsUpfront(subTitle);

        double subTitleTextWidth = subTitleBounds.getWidth();
        double subTitleTextHeight = subTitleBounds.getHeight();

        Point2D endPointLL = calcEndPointOfLeaderLine();
        int direction = getEndLeaderLineDirection();
        double x = endPointLL.getX() + (5 * direction);
        double y = endPointLL.getY();
        subTitle.setLayoutX( x );
        subTitle.setLayoutY( y + (mainTitleHeight/2) + 4);

        Rectangle subTitleViewPort = new Rectangle();
        subTitleViewPort.setWidth(0);
        subTitleViewPort.setHeight(subTitleTextHeight);
        subTitle.setClip(subTitleViewPort);

        // Animate subtitle from end point to the left.
        if (LEFT == getEndLeaderLineDirection()) {
            return new Timeline(
                    new KeyFrame(Duration.millis(1),
                            new KeyValue(subTitle.visibleProperty(), true),
                            new KeyValue(subTitle.layoutXProperty(), x)), // show
                    new KeyFrame(Duration.millis(200),

                            new KeyValue(subTitle.layoutXProperty(), x - subTitleTextWidth),
                            new KeyValue(subTitleViewPort.widthProperty(), subTitleTextWidth))
            );
        }

        // Animate subtitle from end point to the right.
        return new Timeline(
                new KeyFrame(Duration.millis(1),
                        new KeyValue(subTitle.visibleProperty(), true)), // show
                new KeyFrame(Duration.millis(200),
                        new KeyValue(subTitleViewPort.widthProperty(), subTitleTextWidth))
        );
    }
 
Example 13
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 14
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 15
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 16
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 17
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 18
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 19
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 20
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());
}