List of usage examples for javafx.fxml FXMLLoader getController
@SuppressWarnings("unchecked") public <T> T getController()
From source file:mesclasses.view.JourneeController.java
@FXML public void openPostIt() { try {// www . j a v a 2s .co m // Load the fxml file and create a new stage for the popup dialog. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource(Constants.POSTIT_DIALOG)); AnchorPane page = (AnchorPane) loader.load(); // Create the dialog Stage. Stage dialogStage = new Stage(); dialogStage.setTitle("Post-It"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.initOwner(primaryStage); Scene scene = new Scene(page); dialogStage.setScene(scene); // Set the person into the controller. PostItDialogController controller = loader.getController(); controller.setDialogStage(dialogStage); controller.setClasse(seanceSelect.getValue().getClasse()); // Show the dialog and wait until the user closes it dialogStage.showAndWait(); } catch (IOException e) { LOG.error(e); } }
From source file:mesclasses.view.JourneeController.java
@FXML public void openActions() { try {//from ww w .j ava 2s .c o m // Load the fxml file and create a new stage for the popup dialog. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource(Constants.ACTIONS_DIALOG)); AnchorPane page = (AnchorPane) loader.load(); // Create the dialog Stage. Stage dialogStage = new Stage(); dialogStage.setTitle("Actions faire"); dialogStage.initModality(Modality.NONE); dialogStage.initOwner(primaryStage); Scene scene = new Scene(page); dialogStage.setScene(scene); // Set the person into the controller. ActionsEnCoursController controller = loader.getController(); controller.setDialogStage(dialogStage); controller.setClasse(seanceSelect.getValue().getClasse()); // Show the dialog and wait until the user closes it dialogStage.showAndWait(); } catch (IOException e) { LOG.error(e); } }
From source file:investiagenofx2.view.InvestiaGenOFXController.java
private void linkAccountTransac(String linkAccountTransac) { try {//w w w. ja v a2 s. c om FXMLLoader loader = new FXMLLoader(); loader.setLocation(InvestiaGenOFX.class.getResource("view/linkaccountTransac.fxml")); AnchorPane page = (AnchorPane) loader.load(); Stage dialogStage = new Stage(); dialogStage.setTitle("Associer les comptes"); dialogStage.getIcons().add(new Image("/myIcons/Teddy-Bear-Sick-icon.png")); dialogStage.initModality(Modality.WINDOW_MODAL); Scene scene = new Scene(page); dialogStage.initOwner(InvestiaGenOFX.getPrimaryStage()); dialogStage.setScene(scene); InvestiaGenOFX.setOnCloseRequest(dialogStage); LinkaccountTransacController controller = loader.getController(); controller.setlinkAccountTransac(linkAccountTransac); dialogStage.showAndWait(); } catch (Exception ex) { Logger.getLogger(InvestiaGenOFXController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:mesclasses.view.JourneeController.java
private Cours openCoursDialog(Cours cours) { try {/*w ww. java 2s .co m*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource(Constants.COURS_EDIT_DIALOG)); AnchorPane page = (AnchorPane) loader.load(); // Create the dialog Stage. Stage dialogStage = new Stage(); dialogStage.setTitle("Cration d'un cours ponctuel"); dialogStage.initModality(Modality.WINDOW_MODAL); dialogStage.initOwner(primaryStage); Scene scene = new Scene(page); dialogStage.setScene(scene); // Set the person into the controller. CoursEditDialogController controller = loader.getController(); controller.setDialogStage(dialogStage); controller.setCours(cours, true); dialogStage.showAndWait(); int status = controller.getStatus(); if (status >= 0) { //update/cancel return controller.getCours(); } } catch (IOException e) { ModalUtil.alert("Erreur I/O", e.getMessage()); } return null; }
From source file:com.jf.javafx.Application.java
/** * Load a node and its controller./* ww w . j a va 2 s .c o m*/ * * @param path * @return the node */ public Pair<Node, ?> createNode(String path) { final Application app = this; File fxml = getTemplateFile(path + ".fxml"); Node node; Object controller = null; try { ResourceBundle bundle; try { bundle = getResourceBundle("controllers/" + path); } catch (Exception ex) { bundle = null; } FXMLLoader loader = new FXMLLoader(fxml.toURL(), bundle, new JavaFXBuilderFactory(), (Class<?> param) -> { try { Class cls = Controller.class; if (cls.isAssignableFrom(param)) { try { return param.getConstructor(Application.class).newInstance(app); } catch (Exception ex) { Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); return param.newInstance(); } } else { return param.newInstance(); } } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | SecurityException ex) { MsgBox.showException(ex); return null; } }); node = loader.load(); controller = loader.getController(); } catch (IOException ex) { MsgBox.showException(ex, "Error while navigate to path: " + path); // customize error screen AnchorPane p = new AnchorPane(); // StringWriter sw = new StringWriter(); // ex.printStackTrace(new PrintWriter(sw)); // p.getChildren().add(new Label(sw.toString())); node = p; } return new Pair(node, controller); }
From source file:com.github.drbookings.ui.controller.MainController.java
private void showAddBookingDialog(final LocalDate date, final String roomName) { try {/* w ww.j a va 2 s .c o m*/ final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/AddBookingView.fxml")); final Parent root = loader.load(); final Stage stage = new Stage(); stage.setWidth(300); stage.setHeight(600); final Scene scene = new Scene(root); stage.setTitle("Add BookingBean"); stage.setScene(scene); final AddBookingController c = loader.getController(); c.setManager(manager); c.datePickerCheckIn.setValue(date); c.comboBoxRoom.getSelectionModel().select(roomName); final Stage windowStage = (Stage) node.getScene().getWindow(); stage.initOwner(windowStage); stage.initModality(Modality.WINDOW_MODAL); stage.setX(windowStage.getX() + windowStage.getWidth() / 2 - stage.getWidth() / 2); stage.setY((windowStage.getY() + windowStage.getHeight()) / 2 - stage.getHeight() / 2); stage.show(); } catch (final IOException e) { logger.error(e.getLocalizedMessage(), e); } }
From source file:com.github.drbookings.ui.controller.MainController.java
private void showUpcomingEvents() { try {//from w ww . j av a2s . c o m final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/UpcomingView.fxml")); final Parent root = loader.load(); final Stage stage = new Stage(); final Scene scene = new Scene(root); stage.setTitle("What's next"); stage.setScene(scene); stage.setWidth(600); stage.setHeight(400); final Stage windowStage = (Stage) node.getScene().getWindow(); stage.setX(windowStage.getX() + windowStage.getWidth() / 2 - stage.getWidth() / 2); stage.setY((windowStage.getY() + windowStage.getHeight()) / 2 - stage.getHeight() / 2); final UpcomingController c = loader.getController(); c.setManager(getManager()); stage.show(); } catch (final IOException e) { logger.error(e.getLocalizedMessage(), e); } }
From source file:snpviewer.SnpViewer.java
public void showSavedRegionsTable() { if (savedRegions.size() > 0) { FXMLLoader tableLoader = new FXMLLoader(getClass().getResource("MultiRegionReporter.fxml")); try {//w w w . j a v a2s .com Pane tablePane = (Pane) tableLoader.load(); MultiRegionReporterController multiReg = (MultiRegionReporterController) tableLoader .getController(); Scene tableScene = new Scene(tablePane); Stage tableStage = new Stage(); tableStage.setScene(tableScene); tableScene.getStylesheets() .add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm()); tableStage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png"))); multiReg.displayData(savedRegions); tableStage.setTitle("Saved Regions"); tableStage.initModality(Modality.NONE); tableStage.show(); } catch (Exception ex) { Dialogs.showErrorDialog(null, "Error displaying" + " Saved Regions - see Details for stack trace.", "Saved Regions Display Error!", "SnpViewer", ex); } } else { Dialogs.showInformationDialog(null, "No regions " + "found.", "Saved Regions", "SnpViewer"); } }
From source file:snpviewer.SnpViewer.java
public void removeSamples(ActionEvent event) { FXMLLoader loader = new FXMLLoader(getClass().getResource("RemoveSamplesInterface.fxml")); try {// w ww .j av a 2 s . co m Pane pane = (Pane) loader.load(); RemoveSamplesInterfaceController removeController = (RemoveSamplesInterfaceController) loader .getController(); Scene scene = new Scene(pane); Stage stage = new Stage(); stage.setScene(scene); scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm()); stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png"))); stage.setTitle("Remove Samples"); removeController.setSamples(affObserve, unObserve); stage.initModality(Modality.APPLICATION_MODAL); stage.showAndWait(); List<Integer> indicesToRemove = removeController.getSamplesToRemove(); //System.out.println(indicesToRemove.toString()); if (indicesToRemove.isEmpty()) { return; } ArrayList<Integer> affsToRemove = new ArrayList<>(); ArrayList<Integer> unsToRemove = new ArrayList<>(); for (Integer r : indicesToRemove) { if (r < affObserve.size()) {//index corresponds to affFiles affsToRemove.add(r); } else {//index corresponds to unFiles r -= affObserve.size(); unsToRemove.add(r); } } ArrayList<File> dirsToDelete = new ArrayList<>(); if (!affsToRemove.isEmpty()) { Collections.sort(affsToRemove, Collections.reverseOrder()); for (int i : affsToRemove) { dirsToDelete.add(affObserve.get(i).getOutputDirectory()); affObserve.remove(i); } } if (!unsToRemove.isEmpty()) { Collections.sort(unsToRemove, Collections.reverseOrder()); for (int i : unsToRemove) { dirsToDelete.add(unObserve.get(i).getOutputDirectory()); unObserve.remove(i); } } if (affObserve.isEmpty() && unObserve.isEmpty()) { resetView(); } else { refreshView(null, false); } saveProject(); for (File dir : dirsToDelete) { FileUtils.deleteDirectory(dir); } } catch (Exception ex) { Dialogs.showErrorDialog(null, "Sample removal failed - please see " + "details for stack trace and report this error.", "Remove Samples Failed!", "SnpViewer", ex); } }
From source file:snpviewer.SnpViewer.java
public void autoFindRegions() { if (affObserve.isEmpty()) { Dialogs.showErrorDialog(null,/*from w w w . j a v a2s . c om*/ "Find Regions can only be run when there " + "is at least one Affected sample in the project. Use the " + "'Add Affected' button/menu item to add Affected samples.", "No Affected samples to analyze!", "SnpViewer"); return; } Stage stage = new Stage(); FXMLLoader loader = new FXMLLoader(getClass().getResource("FindRegionsInterface.fxml")); try { Pane page = (Pane) loader.load(); FindRegionsInterfaceController findReg = (FindRegionsInterfaceController) loader.getController(); Scene scene = new Scene(page); stage.setScene(scene); scene.getStylesheets().add(SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm()); setProgressMode(true); stage.initModality(Modality.APPLICATION_MODAL); stage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png"))); stage.showAndWait(); if (findReg.getCancelled()) { setProgressMode(false); return; } //int w, double r, boolean con, int refWind, double refCut, //int minReportSize, int minReportRun, double het, double dischord) int window = Integer.parseInt(findReg.getWindow()); double regionLength = Double.parseDouble(findReg.getRegionLength()); boolean checkConcordant = findReg.getCheckConcordance(); int refineWindow = Integer.parseInt(findReg.getRefineSize()); double refineTolerance = Double.parseDouble(findReg.getRefineTolerance()); int minReport = Integer.parseInt(findReg.getReportLength()); int minReportRun = Integer.parseInt(findReg.getReportMinSnps()); double hetTolerance = Double.parseDouble(findReg.getHetTolerance()); double dischordTolerance = Double.parseDouble(findReg.getDischordTolerance()); boolean autosomesOnly = findReg.getAutosomesOnly(); LinkedHashSet<String> c = new LinkedHashSet(); for (Object item : chromosomeSelector.getItems()) { if (item instanceof String) { String chrom = (String) item; if (autosomesOnly) { if (chrom.matches("\\d+")) {//only add autosomes c.add(chrom); } } else { c.add(chrom); } } } final RegionFinder regionFinder = new RegionFinder(c, affFiles, unFiles, window, regionLength, checkConcordant, refineWindow, refineTolerance, minReport, minReportRun, hetTolerance, dischordTolerance); regionFinder.setOnSucceeded(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { progressBar.progressProperty().unbind(); progressMessage.textProperty().unbind(); progressMessage.setText("Done"); progressTitle.textProperty().unbind(); setProgressMode(false); Object result = t.getSource().getValue(); ArrayList<RegionSummary> foundRegions = new ArrayList<>(); if (result instanceof ArrayList) { for (Object r : (ArrayList) result) { if (r instanceof RegionSummary) { RegionSummary reg = (RegionSummary) r; foundRegions.add(reg); } } if (foundRegions.size() > 0) { FXMLLoader tableLoader = new FXMLLoader( getClass().getResource("MultiRegionReporter.fxml")); try { Pane tablePane = (Pane) tableLoader.load(); MultiRegionReporterController multiReg = (MultiRegionReporterController) tableLoader .getController(); Scene tableScene = new Scene(tablePane); Stage tableStage = new Stage(); tableStage.setScene(tableScene); tableScene.getStylesheets().add( SnpViewer.class.getResource("SnpViewerStyleSheet.css").toExternalForm()); multiReg.displayData(foundRegions); tableStage.setTitle("Find Regions Results"); tableStage.getIcons() .add(new Image(this.getClass().getResourceAsStream("icon.png"))); tableStage.initModality(Modality.NONE); tableStage.show(); } catch (Exception ex) { Dialogs.showErrorDialog(null, "Error displaying" + " results from Find Regions Method.", "Find Regions Error!", "SnpViewer", ex); } } else { Dialogs.showInformationDialog(null, "No regions " + "found.", "Find Regions", "SnpViewer"); } savedRegions.addAll(foundRegions); RegionSummary sorter = new RegionSummary(); sorter.mergeRegionsByPosition(savedRegions); } saveProject(); int c = chromosomeSelector.getSelectionModel().getSelectedIndex(); if (c > -1) { selectionOverlayPane.getChildren().clear(); selectionOverlayPane.getChildren().add(dragSelectRectangle); drawSavedRegions((String) chromosomeBoxList[c]); } progressMessage.setText(""); progressTitle.setText(""); progressBar.progressProperty().set(0); } }); regionFinder.setOnFailed(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { progressBar.progressProperty().unbind(); progressMessage.textProperty().unbind(); progressMessage.setText("Failed!"); progressTitle.textProperty().unbind(); Dialogs.showErrorDialog(null, "Find Regions method failed.", "Error!", "SnpViewer", t.getSource().getException()); setProgressMode(false); progressMessage.setText(""); progressTitle.setText(""); progressBar.progressProperty().set(0); } }); regionFinder.setOnCancelled(new EventHandler<WorkerStateEvent>() { @Override public void handle(WorkerStateEvent t) { progressBar.progressProperty().unbind(); progressMessage.textProperty().unbind(); progressMessage.setText("Cancelled"); progressTitle.textProperty().unbind(); Dialogs.showErrorDialog(null, "Find Regions method Cancelled.", "Cancelled", "SnpViewer"); setProgressMode(false); progressMessage.setText(""); progressTitle.setText(""); progressBar.progressProperty().set(0); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { regionFinder.cancel(); } }); progressBar.progressProperty().unbind(); progressMessage.textProperty().unbind(); progressTitle.textProperty().unbind(); progressBar.progressProperty().bind(regionFinder.progressProperty()); progressMessage.textProperty().bind(regionFinder.messageProperty()); progressTitle.textProperty().bind(regionFinder.titleProperty()); regionFinder.start(); } catch (IOException ex) { Dialogs.showErrorDialog(null, "Error starting Find Regions method.", "Error!", "SnpViewer", ex); progressBar.progressProperty().unbind(); progressMessage.textProperty().unbind(); progressTitle.textProperty().unbind(); setProgressMode(false); } }