Example usage for javafx.stage Screen getPrimary

List of usage examples for javafx.stage Screen getPrimary

Introduction

In this page you can find the example usage for javafx.stage Screen getPrimary.

Prototype

public static Screen getPrimary() 

Source Link

Document

The primary Screen .

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Group root = new Group();
    Scene scene = new Scene(root, 500, 200);
    stage.setScene(scene);/*from   w ww  .  j a v  a2 s . co m*/

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

    //set Stage boundaries to visible bounds of the main screen
    stage.setX(primaryScreenBounds.getMinX());
    stage.setY(primaryScreenBounds.getMinY());
    stage.setWidth(primaryScreenBounds.getWidth());
    stage.setHeight(primaryScreenBounds.getHeight());

    stage.show();

}

From source file:com.toyota.carservice.controller.CarMenuManagement.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    ApplicationContext appContex = config.getInstance().getApplicationContext();
    rec2 = Screen.getPrimary().getVisualBounds();
    w = 0.1;/*from www .j  a va2s .com*/
    h = 0.1;
    Platform.runLater(() -> {
        stage = (Stage) maximize.getScene().getWindow();
        stage.setMaximized(true);
        stage.setHeight(rec2.getHeight());
        maximize.getStyleClass().add("decoration-button-restore");
        resize.setVisible(false);
        loadMenu();
    });
}

From source file:com.fishbeans.app.FXMLComponentBase.java

public Parent getRootNode() {

    setupFxmlReloader();/*from   w w w .j a va 2s  . c  om*/

    Parent parent = fxmlLoader.getRoot();
    Screen screen = Screen.getPrimary();
    Rectangle2D bounds = screen.getVisualBounds();
    ViewController controller = (ViewController) fxmlLoader.getController();
    controller.set2DBounds(bounds);

    return parent;
}

From source file:de.unibw.inf2.fishification.Launch.java

@Override
public void start(Stage primaryStage) {

    m_log.info("Fishification launched.");

    // Store JavaFx stage for thread-safe access
    StageSingleton.injectStage(primaryStage);

    boolean fullScreenMode = true;
    int serverPort = 8088;
    String serverEndpoint = "fishworld";
    try {//from   www . ja  va 2 s . c  o m
        // Load configuration
        PropertiesConfiguration config = new PropertiesConfiguration("app.properties");

        // Assign properties
        m_serverMode = config.getBoolean("fishification.server.active");
        fullScreenMode = config.getBoolean("fishification.fullscreen");
        serverPort = config.getInt("fishification.server.port");
        serverEndpoint = config.getString("fishification.server.endpoint");

    } catch (ConfigurationException e) {
        m_log.warn(MarkerManager.getMarker("EXCEPTION"), "Error reading configuration.", e);
    }

    // Init Server ?
    if (!m_serverMode) {

        m_log.info(String.format("Starting in client mode with fullscreen: '%b'", fullScreenMode));

        // Create World
        m_world = new FishWorld();

        // Init World
        Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
        m_world.initialize(screenBounds.getWidth(), screenBounds.getHeight());

        // Let's go
        m_world.launch();

    } else {

        // Launch Server
        m_log.info(String.format("Starting server with port: '%d' endpoint: '%s' fullscreen: '%b'", serverPort,
                serverEndpoint, fullScreenMode));

        try {
            // Set up server
            FishificationServer.launch(serverPort, serverEndpoint);

        } catch (Exception e) {
            m_log.error(MarkerManager.getMarker("EXCEPTION"), "Error launching the server. Exit application.",
                    e);
            Platform.exit();
        }
    }

    // Focus window
    primaryStage.show();

    // Full Screen mode
    if (fullScreenMode) {
        primaryStage.setFullScreen(true);
    }

}

From source file:org.dataconservancy.packaging.gui.App.java

public void start(Stage stage) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath*:org/dataconservancy/config/applicationContext.xml",
            "classpath*:org/dataconservancy/packaging/tool/ser/config/applicationContext.xml",
            "classpath*:applicationContext.xml");

    // min supported size is 800x600
    stage.setMinWidth(800);/*w  ww  .  ja  v  a 2s .c o m*/
    stage.setMinHeight(550);
    Factory factory = (Factory) context.getBean("factory");
    factory.setStage(stage);

    Font.loadFont(App.class.getResource("/fonts/OpenSans-Regular.ttf").toExternalForm(), 14);
    Font.loadFont(App.class.getResource("/fonts/OpenSans-Italic.ttf").toExternalForm(), 14);
    Font.loadFont(App.class.getResource("/fonts/OpenSans-Bold.ttf").toExternalForm(), 14);

    Configuration config = factory.getConfiguration();
    CmdLineParser parser = new CmdLineParser(config);

    try {
        List<String> raw = getParameters().getRaw();
        parser.parseArgument(raw.toArray(new String[raw.size()]));
    } catch (CmdLineException e) {
        System.out.println(e.getMessage());
        log.error(e.getMessage());
        Platform.exit();
        return;
    }

    Controller controller = factory.getController();
    controller.setApplicationHostServices(getHostServices());

    controller.startApp();

    // Default size to 800x800, but shrink if screen is too small
    double sceneHeight = 800;

    Rectangle2D screen = Screen.getPrimary().getVisualBounds();
    if (screen.getHeight() < 800) {
        sceneHeight = screen.getHeight() - 50;
        if (sceneHeight < 550)
            sceneHeight = 550;
    }

    Scene scene = new Scene(controller.asParent(), 800, sceneHeight);
    scene.getStylesheets().add("/css/app.css");

    stage.getIcons().add(new Image("/images/DCPackageTool-icon.png"));
    stage.setTitle("DC Package Tool");
    stage.setScene(scene);
    stage.show();

}

From source file:com.deicos.lince.Initializer.java

@Override
public void start(Stage stage) throws Exception {
    /*AppPreloader preloader = new AppPreloader();
    preloader.start(stage);*///from ww w .  j  av  a2  s.  c om
    notifyPreloader(new Preloader.StateChangeNotification(Preloader.StateChangeNotification.Type.BEFORE_START));
    stage.setTitle(windowTitle);
    //stage.setScene(new Scene(mainLayout));

    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    Browser browser = new Browser(BrowserType.HEAVYWEIGHT);
    BrowserView view = new BrowserView(browser);
    //String url = getClass().getClassLoader().getResource("app-lince.html").toString();
    String url = getServerURL();
    browser.loadURL(url);
    String remoteDebuggingURL = browser.getRemoteDebuggingURL();
    logger.info("==============================================================================");
    logger.info("   Remote debug   :" + remoteDebuggingURL);
    logger.info("   Remote uri     :" + url);
    logger.info("==============================================================================");
    Scene scene = new Scene(new BorderPane(view), screenBounds.getWidth() - 20, screenBounds.getHeight() - 40);
    stage.setScene(scene);
    stage.setResizable(true);
    stage.centerOnScreen();
    stage.show();
    stage.setOnCloseRequest(this);
}

From source file:wpdisplaytest.WPDisplayTest.java

private void moveToSecondaryIfExists(Stage stage) {
    Screen secondary;/*from  w ww.  ja v a  2  s  . co  m*/
    try {
        secondary = Screen.getScreens().stream().filter(E -> {
            return !E.equals(Screen.getPrimary());
        }).findFirst().get();
        Rectangle2D bounds = secondary.getVisualBounds();
        stage.setX(bounds.getMinX());
        stage.setY(bounds.getMinY());
        stage.centerOnScreen();
    } catch (NoSuchElementException ex) {
        //There is no secondary viewport, fail silently
    }

}

From source file:org.jevis.jeconfig.JEConfig.java

/**
 * Build an new JEConfig Login and main frame/stage
 *
 * @param primaryStage//from w  w w  .j  av  a2s.com
 */
//AITBilal - Login  
private void initGUI(Stage primaryStage) {
    Scene scene;
    LoginGlass login = new LoginGlass(primaryStage);

    AnchorPane jeconfigRoot = new AnchorPane();
    AnchorPane.setTopAnchor(jeconfigRoot, 0.0);
    AnchorPane.setRightAnchor(jeconfigRoot, 0.0);
    AnchorPane.setLeftAnchor(jeconfigRoot, 0.0);
    AnchorPane.setBottomAnchor(jeconfigRoot, 0.0);
    //        jeconfigRoot.setStyle("-fx-background-color: white;");
    //        jeconfigRoot.getChildren().setAll(new Label("sodfhsdhdsofhdshdsfdshfjf"));

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

    // @AITBilal - Main frame elemente wird aufgerufen nachdem man sich eingeloggt hat.
    login.getLoginStatus().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (newValue) {
                System.out.println("after request");
                _mainDS = login.getDataSource();
                ds = _mainDS;

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        FadeTransition ft = new FadeTransition(Duration.millis(1500), login);
                        ft.setFromValue(1.0);
                        ft.setToValue(0);
                        ft.setCycleCount(1);
                        ft.play();
                    }
                });

                JEConfig.PROGRAMM_INFO.setJEVisAPI(ds.getInfo());
                JEConfig.PROGRAMM_INFO.addLibrary(org.jevis.commons.application.Info.INFO);
                JEConfig.PROGRAMM_INFO.addLibrary(org.jevis.application.Info.INFO);

                preLodedClasses = login.getAllClasses();
                preLodedRootObjects = login.getRootObjects();

                PluginManager pMan = new PluginManager(ds);
                //@AITBilal - Toolbar fr save, newB, delete, sep1, form
                GlobalToolBar toolbar = new GlobalToolBar(pMan);
                pMan.addPluginsByUserSetting(null);

                //                    StackPane root = new StackPane();
                //                    root.setId("mainpane");
                BorderPane border = new BorderPane();
                VBox vbox = new VBox();
                vbox.getChildren().addAll(new TopMenu(), toolbar.ToolBarFactory());
                border.setTop(vbox);
                //@AITBilal - Alle Plugins Inhalt fr JEConfig (Resources... | System | Attribute)
                border.setCenter(pMan.getView());

                Statusbar statusBar = new Statusbar(ds);

                border.setBottom(statusBar);

                System.out.println("show welcome");

                //Disable GUI is StatusBar note an disconnect
                border.disableProperty().bind(statusBar.connectedProperty.not());

                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        AnchorPane.setTopAnchor(border, 0.0);
                        AnchorPane.setRightAnchor(border, 0.0);
                        AnchorPane.setLeftAnchor(border, 0.0);
                        AnchorPane.setBottomAnchor(border, 0.0);

                        jeconfigRoot.getChildren().setAll(border);
                        //                            try {
                        //            WelcomePage welcome = new WelcomePage(primaryStage, new URI("http://coffee-project.eu/"));
                        //            WelcomePage welcome = new WelcomePage(primaryStage, new URI("http://openjevis.org/projects/openjevis/wiki/JEConfig3#JEConfig-Version-3"));

                        //                            Task<Void> showWelcome = new Task<Void>() {
                        //                                @Override
                        //                                protected Void call() throws Exception {
                        try {
                            WelcomePage welcome = new WelcomePage(primaryStage, _config.getWelcomeURL());
                        } catch (URISyntaxException ex) {
                            Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (MalformedURLException ex) {
                            Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        //                                    return null;
                        //                                }
                        //                            };
                        //                            new Thread(showWelcome).start();

                        //                                WelcomePage welcome = new WelcomePage(primaryStage, _config.getWelcomeURL());
                        //                            } catch (URISyntaxException ex) {
                        //                                Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
                        //                            } catch (MalformedURLException ex) {
                        //                                Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
                        //                            }
                    }
                });
            }

        }
    });

    AnchorPane.setTopAnchor(login, 0.0);
    AnchorPane.setRightAnchor(login, 0.0);
    AnchorPane.setLeftAnchor(login, 0.0);
    AnchorPane.setBottomAnchor(login, 0.0);
    //@AITBilal - Login Dialog
    scene = new Scene(jeconfigRoot, bounds.getWidth(), bounds.getHeight());
    scene.getStylesheets().add("/styles/Styles.css");
    primaryStage.getIcons().add(getImage("1393354629_Config-Tools.png"));
    primaryStage.setTitle("JEConfig");
    primaryStage.setScene(scene);
    maximize(primaryStage);
    primaryStage.show();

    //        Platform.runLater(new Runnable() {
    //            @Override
    //            public void run() {
    //@AITBilal - Inhalt bzw. die Elemente von LoginDialog
    jeconfigRoot.getChildren().setAll(login);
    //            }
    //        });

    primaryStage.onCloseRequestProperty().addListener(new ChangeListener<EventHandler<WindowEvent>>() {

        @Override
        public void changed(ObservableValue<? extends EventHandler<WindowEvent>> ov,
                EventHandler<WindowEvent> t, EventHandler<WindowEvent> t1) {
            try {
                System.out.println("Disconnect");
                ds.disconnect();
            } catch (JEVisException ex) {
                Logger.getLogger(JEConfig.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

public static double getNonFullScreenHeight(double potentialHeight) {
    Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
    final double screenHeight = screenBounds.getHeight();
    if (potentialHeight < screenHeight)
        return potentialHeight;

    //NOTE mac allows full screen of app and will save full screen height.  However app cannot be restored in full screen height. 
    final double maxHeight = screenHeight - screenBounds.getMinY();
    return maxHeight;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    BorderPane root = new BorderPane();

    Pane parentContainer = new Pane();
    parentContainer.setPrefSize(500, 500);
    parentContainer.setPickOnBounds(false);

    //Pane parent = new Pane();
    Group parent = new Group();
    boundsLayoutNode = parent;/*from  w w w  .  j  a v a  2s.  c  o m*/
    //parent.setPrefSize(300, 200);
    parent.setLayoutX(200);
    parent.setLayoutY(200);
    parent.setStyle("-fx-background-color:white;");
    parent.getChildren().addAll(new Group(localXAxisGroup, localYAxisGroup),
            new Group(parentXAxisGroup, parentYAxisGroup),
            new Group(parentBoundsRect, PARENT_BOUNDS_PATH_CIRCLE),
            new Group(localBoundsRect, LOCAL_BOUNDS_PATH_CIRCLE),
            new Group(layoutBoundsRect, LAYOUT_BOUNDS_PATH_CIRCLE), new Group(mainRect));

    parentContainer.getChildren().addAll(parent);

    VBox transformsControls = getTransformationControls();
    VBox resultsControls = getResultsControls();

    BorderPane nestedPane = new BorderPane();
    nestedPane.setCenter(parentContainer);
    nestedPane.setBottom(resultsControls);
    //nestedPane.setTop(printDataTextArea);
    //printDataTextArea.setPrefColumnCount(40);
    //printDataTextArea.setPrefRowCount(3);
    root.setCenter(nestedPane);

    root.setRight(transformsControls);
    //root.setBottom(resultsControls);
    //root.setCenter(parentContainer);

    // Attach event handlers
    attachEventHandlers();

    Scene scene = new Scene(root); //, 600, 400);
    stage.setScene(scene);
    stage.setTitle("Bounds of a Node");
    Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
    stage.setX(visualBounds.getMinX());
    stage.setY(visualBounds.getMinY());
    stage.setWidth(visualBounds.getWidth());
    stage.setHeight(visualBounds.getHeight());
    stage.show();

    // Make sure everything is in sync
    relayout();
}