dialogPane.getStyleClass().add("jfx-alert-overlay"); dialogPane.setContent(materialNode); setDialogPane(dialogPane); dialogPane.getScene().setFill(Color.TRANSPARENT); initStyle(StageStyle.TRANSPARENT); initOwner(window); if (this.isOverlayClose()) { hide(); widthListener = observable -> updateWidth(); heightListener = observable -> updateHeight(); xListener = observable -> updateX(); yListener = observable -> updateY(); addLayoutListeners(); JFXAlertAnimation currentAnimation = getCurrentAnimation(); currentAnimation.initAnimation(contentContainer.getParent(), dialogPane); }); eventHandlerManager.addEventHandler(DialogEvent.DIALOG_SHOWN, event -> { if (getOwner() != null) { updateLayout(); JFXAlertAnimation currentAnimation = getCurrentAnimation(); Animation animation = currentAnimation.createShowingAnimation(dialogPane.getContent(), dialogPane); if (animation != null) { if (animateClosing) {
private JFXAlertAnimation getCurrentAnimation() { JFXAlertAnimation usedAnimation = getAnimation(); usedAnimation = usedAnimation == null ? JFXAlertAnimation.NO_ANIMATION : usedAnimation; return usedAnimation; }
JFXAlert alert = new JFXAlert((Stage) alertButton.getScene().getWindow()); alert.initModality(Modality.APPLICATION_MODAL); alert.setOverlayClose(false); JFXDialogLayout layout = new JFXDialogLayout(); layout.setHeading(new Label("Modal Dialog using JFXAlert")); JFXButton closeButton = new JFXButton("ACCEPT"); closeButton.getStyleClass().add("dialog-accept"); closeButton.setOnAction(event -> alert.hideWithAnimation()); layout.setActions(closeButton); alert.setContent(layout); alert.show(); });
/** * play the hide animation for the dialog, as the java hide method is set to final * so it can not be overridden */ public void hideWithAnimation() { if (transition == null || transition.getStatus().equals(Animation.Status.STOPPED)) { JFXAlertAnimation currentAnimation = getCurrentAnimation(); Animation animation = currentAnimation.createHidingAnimation(getDialogPane().getContent(), getDialogPane()); if (animation != null) { transition = animation; animation.setOnFinished(finish -> { animateClosing = false; hide(); transition = null; }); animation.play(); } else { animateClosing = false; transition = null; Platform.runLater(this::hide); } } }
@Override protected double computePrefHeight(double width) { Window owner = getOwner(); if (owner != null) { return owner.getHeight(); } else { return super.computePrefHeight(width); } }
/** * play the hide animation for the dialog, as the java hide method is set to final * so it can not be overridden */ public void hideWithAnimation() { if (transition == null || transition.getStatus().equals(Animation.Status.STOPPED)) { JFXAlertAnimation currentAnimation = getCurrentAnimation(); Animation animation = currentAnimation.createHidingAnimation(getDialogPane().getContent(), getDialogPane()); if (animation != null) { transition = animation; animation.setOnFinished(finish -> { animateClosing = false; hide(); transition = null; }); animation.play(); } else { animateClosing = false; transition = null; Platform.runLater(this::hide); } } }
@Override protected double computePrefWidth(double height) { Window owner = getOwner(); if (owner != null) { return owner.getWidth(); } else { return super.computePrefWidth(height); } }
dialogPane.getStyleClass().add("jfx-alert-overlay"); dialogPane.setContent(materialNode); setDialogPane(dialogPane); dialogPane.getScene().setFill(Color.TRANSPARENT); initStyle(StageStyle.TRANSPARENT); initOwner(stage); if (this.isOverlayClose()) { hide(); widthListener = observable -> updateWidth(); heightListener = observable -> updateHeight(); xListener = observable -> updateX(); yListener = observable -> updateY(); addLayoutListeners(); JFXAlertAnimation currentAnimation = getCurrentAnimation(); currentAnimation.initAnimation(contentContainer.getParent(), dialogPane); }); eventHandlerManager.addEventHandler(DialogEvent.DIALOG_SHOWN, event -> { if (getOwner() != null) { updateLayout(); JFXAlertAnimation currentAnimation = getCurrentAnimation(); Animation animation = currentAnimation.createShowingAnimation(dialogPane.getContent(), dialogPane); if (animation != null) { if (animateClosing) {
private void addLayoutListeners() { Window stage = getOwner(); if (stage != null) { if (widthListener == null) { throw new RuntimeException("Owner can only be set using the constructor"); } stage.getScene().widthProperty().addListener(widthListener); stage.getScene().heightProperty().addListener(heightListener); stage.xProperty().addListener(xListener); stage.yProperty().addListener(yListener); } }
private JFXAlertAnimation getCurrentAnimation() { JFXAlertAnimation usedAnimation = getAnimation(); usedAnimation = usedAnimation == null ? JFXAlertAnimation.NO_ANIMATION : usedAnimation; return usedAnimation; }
private void removeLayoutListeners() { Window stage = getOwner(); if (stage != null) { stage.getScene().widthProperty().removeListener(widthListener); stage.getScene().heightProperty().removeListener(heightListener); stage.xProperty().removeListener(xListener); stage.yProperty().removeListener(yListener); } }
@Override protected double computePrefHeight(double width) { Window owner = getOwner(); if (owner != null) { return owner.getHeight(); } else { return super.computePrefHeight(width); } }