public TemplateBox(String name) { setTitle(name); initModality(Modality.NONE); String style = LocalFont.getDefaultFontCSS(); getDialogPane().setStyle( style ); Stage stage = (Stage) getDialogPane().getScene().getWindow(); stage.setAlwaysOnTop(checkForceOnTop()); stage.getIcons().add(new Image(App.ICON_URL.toString())); getDialogPane().getButtonTypes().add(new ButtonType(Main.getString("close"), ButtonBar.ButtonData.CANCEL_CLOSE)); openedDialogs.add(this); final TemplateBox thisBox = this; setOnCloseRequest(new EventHandler<DialogEvent>() { @Override public void handle(DialogEvent event) { openedDialogs.remove(thisBox); for(EventHandler<DialogEvent> handler : handlers){ handler.handle(event); } } }); applyStyle(); }
/** * Initialize a dialog by setting its title, header and content * and set window style to "utility dialog". * * @param dialog The dialog to initialize * @param keyTitle Key for dialog title in the translation file * @param keyHeader Key for dialog header in the translation file * @param keyContent Key for dialog content in the translation file * @param windowData The position and size of the parent window */ protected static void prepareDialog(final Dialog dialog, final String keyTitle, final String keyHeader, final String keyContent, final ParentWindowData windowData) { dialog.setTitle(TRANSLATIONS.getString(keyTitle)); dialog.setHeaderText(TRANSLATIONS.getString(keyHeader)); dialog.setContentText(TRANSLATIONS.getString(keyContent)); ((Stage) dialog.getDialogPane().getScene().getWindow()).initStyle(StageStyle.UTILITY); dialog.setResizable(false); /* Handler to place the dialog in the middle of the main window instead of the middle * of the screen; the width oh the dialog is fixed. */ dialog.setOnShown(new EventHandler<DialogEvent>() { public void handle(final DialogEvent event) { dialog.setWidth(DIALOG_WIDTH); dialog.getDialogPane().setMaxWidth(DIALOG_WIDTH); dialog.getDialogPane().setMinWidth(DIALOG_WIDTH); dialog.setX(windowData.getX() + (windowData.getWidth() / 2) - (dialog.getWidth() / 2)); dialog.setY(windowData.getY() + 30); } }); }
/** * Method to be called on song end * @param lastReport last GameReport */ private void end(GameReport lastReport) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Clone Hero"); alert.setHeaderText("You've completed this song!"); alert.setContentText("Your score: " + lastReport.getScore()); alert.setOnCloseRequest(new EventHandler<DialogEvent>() { @Override public void handle(DialogEvent event) { stage.hide(); } }); alert.show(); }
public void addOnCloseRequest(EventHandler<DialogEvent> handler){ handlers.add(handler); }
private void resetFromModel(@SuppressWarnings("UnusedParameters") final DialogEvent dialogEvent) { pendingSelectedZoneIds.setValue(observableSet(applicationModel.selectedZoneIds.toArray(new ZoneId[applicationModel.selectedZoneIds.size()]))); zoneIdCheckboxes.stream().forEach(zoneIdCheckBox -> zoneIdCheckBox.setSelected(pendingSelectedZoneIds .contains(ZoneId.of(zoneIdCheckBox.getText())))); }
public JFXAlert(Stage stage) { // set the stage to transparent initStyle(StageStyle.TRANSPARENT); initOwner(stage); // create custom dialog pane setDialogPane(new DialogPane() { { getButtonTypes().add(ButtonType.CLOSE); Node closeButton = this.lookupButton(ButtonType.CLOSE); closeButton.managedProperty().bind(closeButton.visibleProperty()); closeButton.setVisible(false); } @Override protected Node createButtonBar() { return null; } }); // init style for the content container contentContainer = new StackPane(); contentContainer.getStyleClass().add("jfx-alert-content-container"); // set dialog pane content final Node materialNode = JFXDepthManager.createMaterialNode(contentContainer, 2); materialNode.setPickOnBounds(false); materialNode.addEventHandler(MouseEvent.MOUSE_CLICKED, event->event.consume()); // init style for overlay overlay = new StackPane(materialNode){ public String getUserAgentStylesheet() { return getClass().getResource("/css/controls/jfx-alert.css").toExternalForm(); } }; overlay.getStyleClass().add("jfx-alert-overlay"); // customize dialogPane final DialogPane dialogPane = getDialogPane(); dialogPane.getScene().setFill(Color.TRANSPARENT); dialogPane.setStyle("-fx-background-color: transparent;"); dialogPane.prefWidthProperty().bind(stage.getScene().widthProperty()); dialogPane.prefHeightProperty().bind(stage.getScene().heightProperty()); dialogPane.setContent(overlay); updateX(stage, dialogPane); updateY(stage, dialogPane); // bind dialog position to stage position stage.getScene().widthProperty().addListener(observable -> updateSize(dialogPane)); stage.getScene().heightProperty().addListener(observable -> updateSize(dialogPane)); stage.xProperty().addListener((observable, oldValue, newValue) -> updateX(stage, dialogPane)); stage.yProperty().addListener((observable, oldValue, newValue) -> updateY(stage, dialogPane)); // handle animation eventHandlerManager.addEventHandler(DialogEvent.DIALOG_SHOWING, event -> { if (getAnimation() != null) { getAnimation().initAnimation(contentContainer.getParent(), overlay); } }); eventHandlerManager.addEventHandler(DialogEvent.DIALOG_SHOWN, event -> { if (getAnimation() != null) { Animation animation = getAnimation().createShowingAnimation(contentContainer.getParent(), overlay); if (animation != null) { animation.play(); } } }); overlay.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { if (this.isOverlayClose()) { new Thread(() -> hideWithAnimation()).start(); } }); }
/** * {@link Alert#setOnCloseRequest(EventHandler)}. * @param handler the {@link EventHandler}. */ public void friendly_setOnCloseRequest( EventHandler< DialogEvent > handler ) { setOnCloseRequest( handler ); }
public final void setOnShowing(EventHandler<DialogEvent> handler) { dialog.setOnShowing(handler);}
public final EventHandler<DialogEvent> getOnShowing() { return dialog.getOnShowing(); }
public final void setOnShown(EventHandler<DialogEvent> handler) { dialog.setOnShown(handler);}
public final EventHandler<DialogEvent> getOnShown() { return dialog.getOnShown(); }
public final void setOnCloseRequest(EventHandler<DialogEvent> handler) {dialog.setOnCloseRequest(handler);}
public final EventHandler<DialogEvent> getOnCloseRequest() { return dialog.getOnCloseRequest(); }
public final void setOnHiding(EventHandler<DialogEvent> handler) { dialog.setOnHiding(handler);}
public final EventHandler<DialogEvent> getOnHiding() { return dialog.getOnHiding(); }
public final void setOnHidden(EventHandler<DialogEvent> handler) { dialog.setOnHidden(handler);}
public final EventHandler<DialogEvent> getOnHidden() { return dialog.getOnHidden(); }