forked from j62/ctbrec
1
0
Fork 0

Apply application stylesheets to custom dialogs

This commit is contained in:
0xboobface 2019-04-11 14:31:23 +02:00
parent 62c6f9a885
commit 9696edd002
8 changed files with 31 additions and 8 deletions

View File

@ -594,7 +594,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener {
showStreamSwitchErrorDialog(t); showStreamSwitchErrorDialog(t);
return null; return null;
}; };
StreamSourceSelectionDialog.show(fxModel.getDelegate(), onSuccess, onFail); StreamSourceSelectionDialog.show(getTabPane().getScene(), fxModel.getDelegate(), onSuccess, onFail);
} }
private void showStreamSwitchErrorDialog(Throwable throwable) { private void showStreamSwitchErrorDialog(Throwable throwable) {

View File

@ -9,10 +9,12 @@ import java.util.function.Function;
import ctbrec.Model; import ctbrec.Model;
import ctbrec.recorder.download.StreamSource; import ctbrec.recorder.download.StreamSource;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceDialog; import javafx.scene.control.ChoiceDialog;
import javafx.stage.Stage;
public class StreamSourceSelectionDialog { public class StreamSourceSelectionDialog {
public static void show(Model model, Function<Model,Void> onSuccess, Function<Throwable, Void> onFail) { public static void show(Scene parent, Model model, Function<Model,Void> onSuccess, Function<Throwable, Void> onFail) {
Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() { Task<List<StreamSource>> selectStreamSource = new Task<List<StreamSource>>() {
@Override @Override
protected List<StreamSource> call() throws Exception { protected List<StreamSource> call() throws Exception {
@ -30,6 +32,8 @@ public class StreamSourceSelectionDialog {
choiceDialog.setTitle("Stream Quality"); choiceDialog.setTitle("Stream Quality");
choiceDialog.setHeaderText("Select your preferred stream quality"); choiceDialog.setHeaderText("Select your preferred stream quality");
choiceDialog.setResizable(true); choiceDialog.setResizable(true);
Stage stage = (Stage) choiceDialog.getDialogPane().getScene().getWindow();
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
Optional<StreamSource> selectedSource = choiceDialog.showAndWait(); Optional<StreamSource> selectedSource = choiceDialog.showAndWait();
if(selectedSource.isPresent()) { if(selectedSource.isPresent()) {
int index = sources.indexOf(selectedSource.get()); int index = sources.indexOf(selectedSource.get());

View File

@ -444,7 +444,7 @@ public class ThumbCell extends StackPane {
alert.showAndWait(); alert.showAndWait();
return null; return null;
}; };
StreamSourceSelectionDialog.show(model, onSuccess, onFail); StreamSourceSelectionDialog.show(getScene(), model, onSuccess, onFail);
} else { } else {
_startStopAction(model, start); _startStopAction(model, start);
} }

View File

@ -478,7 +478,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
MenuItem sendTip = new MenuItem("Send Tip"); MenuItem sendTip = new MenuItem("Send Tip");
sendTip.setOnAction((e) -> { sendTip.setOnAction((e) -> {
TipDialog tipDialog = new TipDialog(site, cell.getModel()); TipDialog tipDialog = new TipDialog(sendTip.getParentPopup().getScene(), site, cell.getModel());
tipDialog.showAndWait(); tipDialog.showAndWait();
String tipText = tipDialog.getResult(); String tipText = tipDialog.getResult();
if(tipText != null) { if(tipText != null) {

View File

@ -11,16 +11,18 @@ import ctbrec.Model;
import ctbrec.sites.Site; import ctbrec.sites.Site;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.TextInputDialog; import javafx.scene.control.TextInputDialog;
import javafx.stage.Stage;
public class TipDialog extends TextInputDialog { public class TipDialog extends TextInputDialog {
private static final transient Logger LOG = LoggerFactory.getLogger(TipDialog.class); private static final transient Logger LOG = LoggerFactory.getLogger(TipDialog.class);
private Site site; private Site site;
public TipDialog(Site site, Model model) { public TipDialog(Scene parent, Site site, Model model) {
this.site = site; this.site = site;
setTitle("Send Tip"); setTitle("Send Tip");
loadTokenBalance(); loadTokenBalance();
@ -28,6 +30,10 @@ public class TipDialog extends TextInputDialog {
setContentText("Amount of tokens to tip:"); setContentText("Amount of tokens to tip:");
setResizable(true); setResizable(true);
getEditor().setDisable(true); getEditor().setDisable(true);
if(parent != null) {
Stage stage = (Stage) getDialogPane().getScene().getWindow();
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
}
} }
private void loadTokenBalance() { private void loadTokenBalance() {

View File

@ -33,7 +33,7 @@ public class EditNotesAction {
new Thread(() -> { new Thread(() -> {
Platform.runLater(() -> { Platform.runLater(() -> {
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), ""); String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
Optional<String> newNotes = Dialogs.showTextInput("Model Notes", "Notes for " + model.getName(), notes); Optional<String> newNotes = Dialogs.showTextInput(source.getScene(), "Model Notes", "Notes for " + model.getName(), notes);
newNotes.ifPresent(n -> { newNotes.ifPresent(n -> {
if(!n.trim().isEmpty()) { if(!n.trim().isEmpty()) {
Config.getInstance().getSettings().modelNotes.put(model.getUrl(), n); Config.getInstance().getSettings().modelNotes.put(model.getUrl(), n);

View File

@ -6,6 +6,7 @@ import java.util.Optional;
import ctbrec.ui.AutosizeAlert; import ctbrec.ui.AutosizeAlert;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog; import javafx.scene.control.Dialog;
@ -16,7 +17,12 @@ import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
public class Dialogs { public class Dialogs {
// TODO reduce calls to this method and use Dialogs.showError(Scene parent, String header, String text, Throwable t) instead
public static void showError(String header, String text, Throwable t) { public static void showError(String header, String text, Throwable t) {
showError(null, header, text, t);
}
public static void showError(Scene parent, String header, String text, Throwable t) {
Runnable r = () -> { Runnable r = () -> {
Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); Alert alert = new AutosizeAlert(Alert.AlertType.ERROR);
alert.setTitle("Error"); alert.setTitle("Error");
@ -26,6 +32,10 @@ public class Dialogs {
content += " " + t.getLocalizedMessage(); content += " " + t.getLocalizedMessage();
} }
alert.setContentText(content); alert.setContentText(content);
if(parent != null) {
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
}
alert.showAndWait(); alert.showAndWait();
}; };
@ -36,7 +46,7 @@ public class Dialogs {
} }
} }
public static Optional<String> showTextInput(String title, String header, String text) { public static Optional<String> showTextInput(Scene parent, String title, String header, String text) {
Dialog<String> dialog = new Dialog<>(); Dialog<String> dialog = new Dialog<>();
dialog.setTitle(title); dialog.setTitle(title);
dialog.setHeaderText(header); dialog.setHeaderText(header);
@ -46,6 +56,9 @@ public class Dialogs {
InputStream icon = Dialogs.class.getResourceAsStream("/icon.png"); InputStream icon = Dialogs.class.getResourceAsStream("/icon.png");
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow(); Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image(icon)); stage.getIcons().add(new Image(icon));
if(parent != null) {
stage.getScene().getStylesheets().addAll(parent.getStylesheets());
}
GridPane grid = new GridPane(); GridPane grid = new GridPane();
grid.setHgap(10); grid.setHgap(10);

View File

@ -55,7 +55,7 @@ public class Wizard extends BorderPane {
try { try {
validator.run(); validator.run();
} catch(IllegalStateException e) { } catch(IllegalStateException e) {
Dialogs.showError("Settings invalid", e.getMessage(), null); Dialogs.showError(Wizard.this.getScene(), "Settings invalid", e.getMessage(), null);
return; return;
} }
} }