Example usage for javafx.fxml FXMLLoader load

List of usage examples for javafx.fxml FXMLLoader load

Introduction

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

Prototype

public <T> T load() throws IOException 

Source Link

Document

Loads an object hierarchy from a FXML document.

Usage

From source file:org.cryptomator.ui.MainApplication.java

@Override
public void start(final Stage primaryStage) throws IOException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    Platform.runLater(() -> {//from ww w  .  jav a 2 s  . c  om
        /*
         * This fixes a bug on OSX where the magic file open handler leads
         * to no context class loader being set in the AppKit (event) thread
         * if the application is not started opening a file.
         */
        if (Thread.currentThread().getContextClassLoader() == null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    });

    Runtime.getRuntime().addShutdownHook(MainApplication.CLEAN_SHUTDOWN_PERFORMER);

    executorService = Executors.newCachedThreadPool();
    addShutdownTask(() -> {
        executorService.shutdown();
    });

    WebDavServer.getInstance().start();
    chooseNativeStylesheet();
    final ResourceBundle rb = ResourceBundle.getBundle("localization");
    final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"), rb);
    final Parent root = loader.load();
    final MainController ctrl = loader.getController();
    ctrl.setStage(primaryStage);
    final Scene scene = new Scene(root);
    primaryStage.setTitle(rb.getString("app.name"));
    primaryStage.setScene(scene);
    primaryStage.sizeToScene();
    primaryStage.setResizable(false);
    primaryStage.show();
    ActiveWindowStyleSupport.startObservingFocus(primaryStage);
    TrayIconUtil.init(primaryStage, rb, () -> {
        quit();
    });

    for (String arg : getParameters().getUnnamed()) {
        handleCommandLineArg(ctrl, arg);
    }

    if (org.controlsfx.tools.Platform.getCurrent().equals(org.controlsfx.tools.Platform.OSX)) {
        Main.OPEN_FILE_HANDLER.complete(file -> handleCommandLineArg(ctrl, file.getAbsolutePath()));
    }

    LocalInstance cryptomatorGuiInstance = SingleInstanceManager.startLocalInstance(APPLICATION_KEY,
            executorService);
    addShutdownTask(() -> {
        cryptomatorGuiInstance.close();
    });

    cryptomatorGuiInstance.registerListener(arg -> handleCommandLineArg(ctrl, arg));
}

From source file:context.ui.control.codebooknetwork.CodebookNetworkController.java

/**
 *
 */// ww w  . j  a v  a2 s  .co  m
public CodebookNetworkController() {
    super();
    try {
        setTaskname(NamingPolicy.generateTaskName(CodebookNetworkTaskInstance.class));
        setTaskInstance(new CodebookApplicationTaskInstance(getTaskname()));

        FXMLLoader loader2 = new FXMLLoader(
                getClass().getResource(CodebookNetworkConfigurationController.path));
        Parent s2Content = (Parent) loader2.load();
        configurationController = (CodebookNetworkConfigurationController) loader2.getController();

        setStep2Content(s2Content);

        super.postInitialize();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

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

@Override
public void start(Stage primaryStage) {
    String modeStr = "Producer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();/* w  w w  .ja va  2s . c om*/
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {
    case Producer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ProducerController();
        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);

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

From source file:io.github.mzmine.util.jfreechart.ManualZoomDialog.java

/**
 * Constructor/* ww w  . ja v a  2s . c o  m*/
 */
public ManualZoomDialog(Window parent, XYPlot plot) {

    initOwner(parent);

    setTitle("Manual zoom");

    setGraphic(new ImageView("file:icons/axesicon.png"));

    getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    xAxis = (NumberAxis) plot.getDomainAxis();
    yAxis = (NumberAxis) plot.getRangeAxis();

    try {
        URL layersDialogFXML = getClass().getResource(DIALOG_FXML);
        FXMLLoader loader = new FXMLLoader(layersDialogFXML);
        loader.setController(this);
        GridPane grid = loader.load();
        getDialogPane().setContent(grid);
    } catch (Exception e) {
        e.printStackTrace();
    }

    final Button btOk = (Button) getDialogPane().lookupButton(ButtonType.OK);
    btOk.addEventFilter(ActionEvent.ACTION, event -> {
        commitChanges(event);
    });

}

From source file:ninja.eivind.hotsreplayuploader.window.nodes.HotsLogsNode.java

public HotsLogsNode(FXMLLoaderFactory factory) throws IOException {
    super();/* w  ww  . j  a v  a 2 s . c  o  m*/
    URL resource = getClass().getResource("HotsLogsNode.fxml");
    FXMLLoader loader = factory.get();
    loader.setLocation(resource);
    loader.setRoot(this);
    loader.setController(this);
    loader.load();
}

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

@Override
public void start(Stage primaryStage) {

    String modeStr = "Consumer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();//from   w  ww  .  ja va  2s. co  m
        System.exit(0);
        return;
    }

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

    case Consumer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ConsumerController();
        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);

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

From source file:com.github.drbookings.DrBookingsApplication.java

private void startGUI(final Stage stage) throws IOException {
    final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MainView.fxml"));
    final Parent root = loader.load();
    final Scene scene = new Scene(root, 900, 800);
    mainController = loader.getController();
    String s = getClass().getPackage().getImplementationVersion();
    if (s == null) {
        s = "dev version";
    }//  www.  ja va  2s  .  c  o m
    stage.setTitle("Dr.Bookings " + s);
    stage.setScene(scene);
    stage.setOnCloseRequest(new CloseRequestEventHandler());
    stage.show();
    mainController.readDataFile(SettingsManager.getInstance().getDataFile());

}

From source file:de.tmosebach.mm.jfxui.SpringFXMLLoader.java

public Node load(URL url) {
    try {/*  w  w  w.j  a  v  a  2  s  . c o  m*/
        FXMLLoader loader = new FXMLLoader(url);
        loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> aClass) {
                return context.getBean(aClass);
            }
        });
        return loader.load();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(String.format("Failed to load FXML file '%s'", url));
    }
}

From source file:com.coolchick.translatortemplater.Main.java

/**
 * Shows the person overview inside the root layout.
 *//*  w  w  w. j  a v  a 2s  .  c  o m*/
public void showTranslatorOverview() {
    try {
        // Load person overview.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Main.class.getResource("PersonOverview.fxml"));
        StackPane personOverview = loader.load();
        PersonOverviewController controller = loader.getController();
        controller.setMain(this);
        controller.setTranslators(getTranslators());
        primaryStage.setScene(new Scene(personOverview, 800, 600));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:gov.va.isaac.gui.listview.operations.FindAndReplace.java

@Override
public void init(ObservableList<SimpleDisplayConcept> conceptList) {
    super.init(conceptList);
    try {/* w  ww.  j a  va2s  . c  om*/
        URL resource = FindAndReplace.class.getResource("FindAndReplaceController.fxml");
        FXMLLoader loader = new FXMLLoader(resource);
        loader.load();
        frc_ = loader.getController();
        super.root_ = frc_.getRoot();
    } catch (IOException e) {
        logger_.error("Unexpected error building panel", e);
        throw new RuntimeException("Error building panel");
    }
}