Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 5 additions & 53 deletions chunky/src/java/se/llbit/fxutil/Dialogs.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package se.llbit.fxutil;

import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Window;

Expand All @@ -30,33 +23,20 @@ public static Alert createAlert(AlertType type) {
return alert;
}

public static Dialog<ButtonType> createSpecialApprovalConfirmation(
String title,
String header,
String content,
String confirmLabel
) {
return new SpecialApprovalConfirmationDialog(
title,
header,
content,
confirmLabel
);
}

/**
* Init design of the dialog to the design of the main window.
* This sets the icon and color scheme.
*/
public static void setupDialogDesign(Dialog<?> dialog, Scene mainScene) {
Window mainWindow = mainScene.getWindow();
if(mainWindow instanceof Stage) {
if (mainWindow instanceof Stage) {
Stage mainWindowStage = (Stage) mainWindow;
Stage dialogStage = (Stage) dialog.getDialogPane().getScene().getWindow();

dialogStage.getIcons().addAll(mainWindowStage.getIcons());
}
dialog.initOwner(mainWindow);
dialog.initModality(Modality.WINDOW_MODAL);
}

/**
Expand All @@ -71,6 +51,7 @@ public static void setDefaultButton(Alert alert, ButtonType targetButtonType) {

/**
* Makes the given dialog always stay on top of its parent window.
*
* @param dialog A dialog
*/
public static void stayOnTop(Alert dialog) {
Expand All @@ -80,33 +61,4 @@ public static void stayOnTop(Alert dialog) {
((Stage) window).toFront();
}
}

/**
* makes extra sure that user wants to confirm things
*/
static class SpecialApprovalConfirmationDialog extends Dialog<ButtonType> {
final CheckBox checkBox;

SpecialApprovalConfirmationDialog(
String title,
String header,
String content,
String checkBoxLabel
) {
setResultConverter(param -> param);
checkBox = new CheckBox(checkBoxLabel);

final DialogPane dialogPane = getDialogPane();
dialogPane.getStyleClass().add("alert");
dialogPane.getStyleClass().add("warning");

setTitle(title);
dialogPane.setHeaderText(header);
dialogPane.setContent(new VBox(16, new Text(content), checkBox));
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

dialogPane.lookupButton(ButtonType.OK)
.disableProperty().bind(checkBox.selectedProperty().not());
}
}
}
Loading