List of usage examples for javafx.scene Parent addEventHandler
public final <T extends Event> void addEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)
From source file:jlotoprint.MainViewController.java
public static Stage loadTemplateChooser() { final Stage stage = new Stage(); try {// w w w .ja v a2s . c o m FXMLLoader dialog = new FXMLLoader(MainViewController.class.getResource("TemplateDialog.fxml")); Parent root = (Parent) dialog.load(); root.addEventHandler(TemplateDialogEvent.CANCELED, (actionEvent) -> { stage.close(); }); stage.setScene(new Scene(root)); stage.setTitle("Choose a template"); stage.getIcons().add(new Image("file:resources/icon.png")); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner(JLotoPrint.stage.getScene().getWindow()); stage.show(); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); return null; } return stage; }
From source file:jlotoprint.MainViewController.java
@FXML public void handleOpenTemplateDesigner(ActionEvent event) { try {/* ww w .j a v a 2s .c o 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); } }