Example usage for javafx.fxml FXMLLoader getController

List of usage examples for javafx.fxml FXMLLoader getController

Introduction

In this page you can find the example usage for javafx.fxml FXMLLoader getController.

Prototype

@SuppressWarnings("unchecked")
public <T> T getController() 

Source Link

Document

Returns the controller associated with the root object.

Usage

From source file:acmi.l2.clientmod.xdat.XdatEditor.java

@Override
public void start(Stage primaryStage) throws Exception {
    this.stage = primaryStage;

    FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"), interfaceResources);
    loader.setClassLoader(getClass().getClassLoader());
    loader.setControllerFactory(param -> new Controller(XdatEditor.this));
    Parent root = loader.load();/*from  w  w  w  .  j a  va  2 s  . c o  m*/
    controller = loader.getController();

    primaryStage.setTitle("XDAT Editor");
    primaryStage.setScene(new Scene(root));
    primaryStage.show();

    postShow();
}

From source file:com.esri.geoevent.test.performance.ui.OrchestratorUI.java

@Override
public void start(Stage primaryStage) {

    Parameters parameters = getParameters();
    Map<String, String> args = parameters.getNamed();
    String modeStr = args.get("mode");
    if (modeStr == null) {
        modeStr = "Orchestrator";
    }/*from   ww w  . jav a2s .c o  m*/
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {

    case Orchestrator:
        fxmlFile = "Orchestrator.fxml";
        //controller = new OrchestratorController();
        break;
    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        // set the stage on the orchestrator
        if (loader.getController() instanceof OrchestratorController) {
            OrchestratorController orchestratorController = loader.getController();
            orchestratorController.setStage(primaryStage);
        }

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        OrchestratorUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:jlotoprint.MainViewController.java

@FXML
public void handleOpenTemplateDesigner(ActionEvent event) {

    try {//from w  w  w.j  a  va 2 s  .co m
        FXMLLoader dialog = new FXMLLoader(MainViewController.class.getResource("TemplateDesigner.fxml"));
        Parent root = (Parent) dialog.load();
        final Stage stage = new Stage();
        stage.setOnCloseRequest((WindowEvent windowEvent) -> {
            boolean shouldClose = ((TemplateDesignerController) dialog.getController()).showSaveChangesDialog();
            //cancel event
            if (!shouldClose) {
                windowEvent.consume();
            }
        });
        root.addEventHandler(TemplateDesignerEvent.CLOSE, actionEvent -> {
            stage.close();
        });
        stage.setScene(new Scene(root));
        stage.getIcons().add(new Image("file:resources/icon.png"));
        stage.setTitle("Template Designer");
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(JLotoPrint.stage.getScene().getWindow());
        stage.show();
    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java

public void handleSetupLayers(Event e) {
    try {/* w  w w  .j av  a  2 s  .  c  o m*/
        URL layersDialogFXML = getClass().getResource(LAYERS_DIALOG_FXML);
        FXMLLoader loader = new FXMLLoader(layersDialogFXML);
        Stage layersDialog = loader.load();
        ChromatogramLayersDialogController controller = loader.getController();
        controller.configure(datasets, this);
        layersDialog.initModality(Modality.APPLICATION_MODAL);
        layersDialog.show();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.bekwam.mavenpomupdater.Main.java

@Override
public void start(Stage primaryStage) throws Exception {

    ///*w ww .j  av  a 2  s  .c o  m*/
    // handle command line options
    //
    Application.Parameters params = getParameters();

    List<String> unnamedList = params.getUnnamed();

    Options options = new Options();
    options.addOption("help", false, "Print this message");
    options.addOption("hidpi", false, "Use high-DPI scaling");

    CommandLineParser p = new BasicParser();
    CommandLine cmd = p.parse(options, unnamedList.toArray(new String[0]));

    HelpFormatter formatter = new HelpFormatter();

    if (cmd.hasOption("help")) {
        if (log.isDebugEnabled()) {
            log.debug("[START] running as help command");
        }
        formatter.printHelp("Main", options);
        return;
    }

    AbstractModule module = null;
    if (runningAsJNLP()) {

        if (log.isInfoEnabled()) {
            log.info("using jnlp module and jnlp favorites store");
        }
        module = new MPUJNLPModule();
    } else {

        if (log.isInfoEnabled()) {
            log.info("using standalone module and in-memory favorites store");
        }
        module = new MPUStandaloneModule();
    }

    //
    // setup google guice
    //
    final Injector injector = Guice.createInjector(module);

    BuilderFactory builderFactory = new JavaFXBuilderFactory();

    Callback<Class<?>, Object> guiceControllerFactory = clazz -> injector.getInstance(clazz);

    //
    // setup icons
    //
    primaryStage.getIcons().add(new Image("images/mpu_icon_64.png"));

    //
    // load fxml and wire controllers
    //
    FXMLLoader mainViewLoader = new FXMLLoader(getClass().getResource("mavenpomupdater.fxml"), null,
            builderFactory, guiceControllerFactory);
    Parent mainView = mainViewLoader.load();
    MainViewController mainViewController = mainViewLoader.getController();

    FXMLLoader alertViewLoader = new FXMLLoader(getClass().getResource("alert.fxml"), null, builderFactory,
            guiceControllerFactory);
    Parent alertView = alertViewLoader.load();

    //
    // i'm continuing this manual wiring to 1) accommodate a potential
    // bi-directional reference problem and 2) to make sure that guice
    // doesn't return different object for the main -> alert and alert ->
    // main dependency injections
    //

    final AlertController alertController = alertViewLoader.getController();
    mainViewController.alertController = alertController;
    alertController.mainViewControllerRef = new WeakReference<MainViewController>(mainViewController);

    //
    // add FlowPane, StackPane objects (defined in program and outside of 
    // FXML)
    //
    final FlowPane fp = new FlowPane();
    fp.setAlignment(Pos.CENTER);
    fp.getChildren().add(alertView);
    fp.getStyleClass().add("alert-background-pane");

    final StackPane sp = new StackPane();
    sp.getChildren().add(fp); // initially hide the alert
    sp.getChildren().add(mainView);

    //
    // setup scene
    //
    Scene scene = new Scene(sp);
    scene.getStylesheets().add("com/bekwam/mavenpomupdater/mpu.css");

    scene.setOnKeyPressed(keyEvent -> {
        KeyCode key = keyEvent.getCode();
        if (key == KeyCode.ESCAPE && (sp.getChildren().get(1) == fp)) {
            if (log.isDebugEnabled()) {
                log.debug("[ESCAPE]");
            }
            alertController.action();
        }
    });

    //
    // setup stage
    //
    primaryStage.setTitle("Maven POM Version Updater");
    primaryStage.setScene(scene);

    if (cmd.hasOption("hidpi")) {

        if (log.isInfoEnabled()) {
            log.info("running in Hi-DPI display mode");
        }
        primaryStage.setWidth(2560.0);
        primaryStage.setHeight(1440.0);
        primaryStage.setMinWidth(1920.0);
        primaryStage.setMinHeight(1080.0);

        mainViewController.adjustForHiDPI();

    } else {
        if (log.isInfoEnabled()) {
            log.info("running in normal display mode");
        }

        primaryStage.setWidth(1280.0);
        primaryStage.setHeight(800.0);
        primaryStage.setMinWidth(1024.0);
        primaryStage.setMinHeight(768.0);

    }

    primaryStage.show();
}

From source file:net.rptools.tokentool.client.TokenTool.java

@Override
public void start(Stage primaryStage) throws IOException {
    stage = primaryStage;/*from   w  w w  .j  a  v a  2 s . c  om*/
    setUserAgentStylesheet(STYLESHEET_MODENA); // Setting the style back to the new Modena
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(AppConstants.TOKEN_TOOL_FXML),
            ResourceBundle.getBundle(AppConstants.TOKEN_TOOL_BUNDLE));
    root = fxmlLoader.load();
    tokentool_Controller = (TokenTool_Controller) fxmlLoader.getController();

    Scene scene = new Scene(root);
    primaryStage.setTitle(I18N.getString("TokenTool.stage.title"));
    primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(AppConstants.TOKEN_TOOL_ICON)));
    primaryStage.setScene(scene);

    primaryStage.widthProperty().addListener((obs, oldVal, newVal) -> {
        if (Double.isNaN(oldVal.doubleValue()))
            return;

        deltaX += newVal.doubleValue() - oldVal.doubleValue();

        // Only adjust on even width adjustments
        if (deltaX > 1 || deltaX < -1) {
            if (deltaX % 2 == 0) {
                tokentool_Controller.updatePortraitLocation(deltaX, 0);
                deltaX = 0;
            } else {
                tokentool_Controller.updatePortraitLocation(deltaX - 1, 0);
                deltaX = 1;
            }
        }
    });

    primaryStage.heightProperty().addListener((obs, oldVal, newVal) -> {
        if (Double.isNaN(oldVal.doubleValue()))
            return;

        deltaY += newVal.doubleValue() - oldVal.doubleValue();

        // Only adjust on even width adjustments
        if (deltaY > 1 || deltaY < -1) {
            if (deltaY % 2 == 0) {
                tokentool_Controller.updatePortraitLocation(0, deltaY);
                deltaY = 0;
            } else {
                tokentool_Controller.updatePortraitLocation(0, deltaY - 1);
                deltaY = 1;
            }
        }
    });

    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            tokentool_Controller.exitApplication();
        }
    });

    // Load all the overlays into the treeview
    tokentool_Controller.updateOverlayTreeview(overlayTreeItems);

    // Restore saved settings
    AppPreferences.restorePreferences(tokentool_Controller);

    // Add recent list to treeview
    tokentool_Controller.updateOverlayTreeViewRecentFolder(true);

    // Set the Overlay Options accordion to be default open view
    tokentool_Controller.expandOverlayOptionsPane(true);

    primaryStage.show();

    // Finally, update token preview image after everything is done loading
    Platform.runLater(() -> tokentool_Controller.updateTokenPreviewImageView());
}

From source file:pl.mcpg.nbtjeditor.Start.java

@Override
public void start(Stage stage) {
    Parent parent = null;/*from  w  w  w  .  j a  va2  s .c  om*/
    FXMLLoader loader = new FXMLLoader();
    try {
        parent = loader.load(getClass().getResourceAsStream("/main.fxml"));
    } catch (Exception e) {
        displayError("Couldn't load main FXML file! Application will\nnow close.", e);
        e.printStackTrace();
        System.exit(1);
    }
    stage.setMinWidth(150);
    stage.setMinHeight(150);
    stage.setTitle(APP_TITLE);
    stage.setScene(new Scene(parent, 640, 480));
    ((MainController) loader.getController()).setStage(stage);
    stage.show();
    if (fileToOpen != null && fileToOpen.exists()) {
        ((MainController) loader.getController()).open(null);
    }
}

From source file:gmailclientfx.controllers.SpamController.java

public void fetchSpam() {
    ObservableList<MyMessage> data = FXCollections.observableArrayList();
    stupacId.setCellValueFactory(new PropertyValueFactory<MyMessage, Integer>("TblId"));
    stupacNaslov.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Subject"));
    stupacFrom.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("Sender"));
    stupacDatum.setCellValueFactory(new PropertyValueFactory<MyMessage, String>("DateReceived"));

    spamTable.setItems(data);//from ww  w  .  ja v  a2  s . co  m
    spamTable.setOnMousePressed(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
                MyMessage selectedMsg = spamTable.getSelectionModel().getSelectedItem();
                PregledEmailaHelper.setMsg(selectedMsg);
                try {
                    Parent root;
                    FXMLLoader loader = new FXMLLoader();
                    loader.setLocation(
                            getClass().getClassLoader().getResource("gmailclientfx/views/pregledEmaila.fxml"));
                    root = loader.load();
                    Stage stage = new Stage();
                    stage.setScene(new Scene(root));
                    PregledEmailaController pgec = loader.getController();
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent event) {
                            pgec.bodyWebViewEngine.load(null);
                            System.out.println("Closing form!");
                        }

                    });
                    stage.setTitle(PregledEmailaHelper.getMsg().getSubject() + " - "
                            + PregledEmailaHelper.getMsg().getSender());
                    stage.show();
                } catch (IOException ex) {
                    Logger.getLogger(InboxController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    });
    try {
        IMAPStore store = OAuth2Authenticator.connectToImap("imap.gmail.com", 993, GmailClient.getEmail(),
                GmailClient.getAccesToken(), true);
        Folder spam = null;
        Folder[] folders = store.getDefaultFolder().list("*");
        for (Folder f : folders) {
            IMAPFolder imapFolder = (IMAPFolder) f;
            for (String att : imapFolder.getAttributes()) {
                if ("\\Junk".equals(att)) {
                    spam = f;
                }
            }
        }
        spam.open(Folder.READ_WRITE);

        MimeMessage[] seenMessages = (MimeMessage[]) spam
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
        for (int i = 0; i < seenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(seenMessages[i], i + 1, "SPAM");
            data.add(msg);
        }
        MimeMessage[] unseenMessages = (MimeMessage[]) spam
                .search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
        for (int i = 0; i < unseenMessages.length; i++) {
            MyMessage msg = GmailClient.fetchMessage(unseenMessages[i], i + 1, "SPAM");
            data.add(msg);
        }
        spam.close(false);
        store.close();
    } catch (Exception ex) {
        Logger.getLogger(SpamController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ubicrypt.ui.StackNavigator.java

public <R> Parent loadFrom(final Optional<R> data) {
    log.debug("fxml:{}", levels.peek());
    final FXMLLoader loader = new FXMLLoader(
            StackNavigator.class.getResource(format("/fxml/%s.fxml", levels.peek())), bundle);
    loader.setControllerFactory(controllerFactory);
    try {//from w w w .  j  av  a2 s.co m
        Parent parent;
        if (root != null) {
            root.getChildren().setAll((Node) loader.load());
            parent = (Parent) root.getChildren().get(0);
        } else {
            parent = loader.load();
        }
        Object controller = loader.getController();
        stream(getAllFields(controller.getClass())).filter(field -> field.getType() == StackNavigator.class)
                .forEach(field -> {
                    try {
                        writeField(field, controller, this, true);
                    } catch (IllegalAccessException e) {
                        log.error("error setting field:{} in:{}", field, controller);
                        Throwables.propagate(e);
                    }
                    log.debug("{} inject stack navigator", controller.getClass().getSimpleName());
                });
        if (Consumer.class.isAssignableFrom(controller.getClass())) {
            data.ifPresent(((Consumer<R>) controller)::accept);
        }
        return parent;
    } catch (final IOException e) {
        Throwables.propagate(e);
    }
    return null;
}

From source file:calendarioSeries.vistas.MainViewController.java

@FXML
private void addNewSerie() {
    Parent root;//from ww w .j ava  2  s .  c  o m
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainViewController.class.getResource("NewSerieView.fxml"));
        root = loader.load();

        NewSerieController controller = loader.getController();
        controller.setMainController(this);

        Stage stage = new Stage();
        stage.setTitle("Aade una nueva serie");
        stage.setScene(new Scene(root));
        stage.setMinHeight(650);
        stage.setMinWidth(600);
        stage.setResizable(false);
        stage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}