diff --git a/client/src/main/java/ctbrec/ui/AutosizeAlert.java b/client/src/main/java/ctbrec/ui/AutosizeAlert.java index 1eabba96..2a9fa974 100644 --- a/client/src/main/java/ctbrec/ui/AutosizeAlert.java +++ b/client/src/main/java/ctbrec/ui/AutosizeAlert.java @@ -1,23 +1,43 @@ package ctbrec.ui; +import java.io.InputStream; + +import ctbrec.ui.controls.Dialogs; +import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.image.Image; import javafx.scene.layout.Region; +import javafx.stage.Stage; public class AutosizeAlert extends Alert { + private Scene parent; + public AutosizeAlert(AlertType type) { + super(type, null); + } + + public AutosizeAlert(AlertType type, Scene parent) { super(type); + this.parent = parent; init(); } - public AutosizeAlert(AlertType type, String text, ButtonType... buttons) { + public AutosizeAlert(AlertType type, String text, Scene parent, ButtonType... buttons) { super(type, text, buttons); + this.parent = parent; init(); } private void init() { setResizable(true); getDialogPane().setMinHeight(Region.USE_PREF_SIZE); + if(parent != null) { + Stage stage = (Stage) getDialogPane().getScene().getWindow(); + stage.getScene().getStylesheets().addAll(parent.getStylesheets()); + InputStream icon = Dialogs.class.getResourceAsStream("/icon.png"); + stage.getIcons().add(new Image(icon)); + } } } diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index 227b4ae1..36f6e466 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -181,9 +181,9 @@ public class CamrecApplication extends Application { primaryStage.show(); primaryStage.setOnCloseRequest((e) -> { e.consume(); - Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.INFORMATION); + Alert shutdownInfo = new AutosizeAlert(Alert.AlertType.INFORMATION, primaryStage.getScene()); shutdownInfo.setTitle("Shutdown"); - shutdownInfo.setContentText("Shutting down. Please wait a few seconds..."); + shutdownInfo.setContentText("Shutting down. Please wait while recordings are finished..."); shutdownInfo.show(); new Thread() { @@ -211,7 +211,7 @@ public class CamrecApplication extends Application { }); } catch (IOException e1) { Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, primaryStage.getScene()); alert.setTitle("Error saving settings"); alert.setContentText("Couldn't save settings: " + e1.getLocalizedMessage()); alert.showAndWait(); @@ -329,7 +329,7 @@ public class CamrecApplication extends Application { Config.init(sites); } catch (Exception e) { LOG.error("Couldn't load settings", e); - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, primaryStage.getScene()); alert.setTitle("Whoopsie"); alert.setContentText("Couldn't load settings. Falling back to defaults. A backup of your settings has been created."); alert.showAndWait(); diff --git a/client/src/main/java/ctbrec/ui/RecordedModelsTab.java b/client/src/main/java/ctbrec/ui/RecordedModelsTab.java index bf7db4cc..54df4fe4 100644 --- a/client/src/main/java/ctbrec/ui/RecordedModelsTab.java +++ b/client/src/main/java/ctbrec/ui/RecordedModelsTab.java @@ -34,6 +34,7 @@ import ctbrec.ui.action.ResumeAction; import ctbrec.ui.action.StopRecordingAction; import ctbrec.ui.controls.AutoFillTextField; import ctbrec.ui.controls.SearchBox; +import javafx.application.Platform; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringPropertyBase; import javafx.collections.FXCollections; @@ -282,7 +283,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { try { recorder.startRecording(model); } catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e1) { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't add model"); alert.setContentText("The model " + model.getName() + " could not be added: " + e1.getLocalizedMessage()); @@ -292,7 +293,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { } } - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Unknown URL format"); alert.setHeaderText("Couldn't add model"); alert.setContentText("The URL you entered has an unknown format or the function does not support this site, yet"); @@ -302,7 +303,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { private void addModelByName(String siteModelCombo) { String[] parts = model.getText().trim().split(":"); if (parts.length != 2) { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Wrong format"); alert.setHeaderText("Couldn't add model"); alert.setContentText("Use something like \"MyFreeCams:ModelName\""); @@ -318,7 +319,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { Model m = site.createModel(modelName); recorder.startRecording(m); } catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e1) { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't add model"); alert.setContentText("The model " + modelName + " could not be added: " + e1.getLocalizedMessage()); @@ -328,7 +329,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { } } - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Unknown site"); alert.setHeaderText("Couldn't add model"); alert.setContentText("The site you entered is unknown"); @@ -567,7 +568,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { private void switchStreamSource(JavaFxModel fxModel) { try { if (!fxModel.isOnline()) { - Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION); + Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION, getTabPane().getScene()); alert.setTitle("Switch resolution"); alert.setHeaderText("Couldn't switch stream resolution"); alert.setContentText("The resolution can only be changed, when the model is online"); @@ -575,7 +576,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { return; } } catch (IOException | ExecutionException | InterruptedException e1) { - Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION); + Alert alert = new AutosizeAlert(Alert.AlertType.INFORMATION, getTabPane().getScene()); alert.setTitle("Switch resolution"); alert.setHeaderText("Couldn't switch stream resolution"); alert.setContentText("An error occured while checking, if the model is online"); @@ -605,7 +606,7 @@ public class RecordedModelsTab extends Tab implements TabSelectionListener { } private void showErrorDialog(Throwable throwable, String header, String msg) { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Error"); alert.setHeaderText(header); alert.setContentText(msg + ": " + throwable.getLocalizedMessage()); diff --git a/client/src/main/java/ctbrec/ui/RecordingsTab.java b/client/src/main/java/ctbrec/ui/RecordingsTab.java index e2d33cbe..98cbddfd 100644 --- a/client/src/main/java/ctbrec/ui/RecordingsTab.java +++ b/client/src/main/java/ctbrec/ui/RecordingsTab.java @@ -255,7 +255,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { }); updateService.setOnFailed((event) -> { LOG.info("Couldn't get list of recordings from recorder", event.getSource().getException()); - AutosizeAlert autosizeAlert = new AutosizeAlert(AlertType.ERROR); + AutosizeAlert autosizeAlert = new AutosizeAlert(AlertType.ERROR, getTabPane().getScene()); autosizeAlert.setTitle("Whoopsie!"); autosizeAlert.setHeaderText("Recordings not available"); autosizeAlert.setContentText("An error occured while retrieving the list of recordings"); @@ -516,7 +516,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { Platform.runLater(new Runnable() { @Override public void run() { - AutosizeAlert autosizeAlert = new AutosizeAlert(AlertType.ERROR); + AutosizeAlert autosizeAlert = new AutosizeAlert(AlertType.ERROR, getTabPane().getScene()); autosizeAlert.setTitle(title); autosizeAlert.setHeaderText(msg); autosizeAlert.setContentText("An error occured: " + e.getLocalizedMessage()); @@ -563,7 +563,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener { Recording r = recordings.get(0); msg = "Delete " + r.getModelName() + "/" + r.getStartDate() + " for good?"; } - AutosizeAlert confirm = new AutosizeAlert(AlertType.CONFIRMATION, msg, YES, NO); + AutosizeAlert confirm = new AutosizeAlert(AlertType.CONFIRMATION, msg, getTabPane().getScene(), YES, NO); confirm.setTitle("Delete recording?"); confirm.setHeaderText(msg); confirm.setContentText(""); diff --git a/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java b/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java index 6b4d9b59..c4b07242 100644 --- a/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java +++ b/client/src/main/java/ctbrec/ui/StreamSourceSelectionDialog.java @@ -1,5 +1,6 @@ package ctbrec.ui; +import java.io.InputStream; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -8,9 +9,11 @@ import java.util.function.Function; import ctbrec.Model; import ctbrec.recorder.download.StreamSource; +import ctbrec.ui.controls.Dialogs; import javafx.concurrent.Task; import javafx.scene.Scene; import javafx.scene.control.ChoiceDialog; +import javafx.scene.image.Image; import javafx.stage.Stage; public class StreamSourceSelectionDialog { @@ -34,6 +37,8 @@ public class StreamSourceSelectionDialog { choiceDialog.setResizable(true); Stage stage = (Stage) choiceDialog.getDialogPane().getScene().getWindow(); stage.getScene().getStylesheets().addAll(parent.getStylesheets()); + InputStream icon = Dialogs.class.getResourceAsStream("/icon.png"); + stage.getIcons().add(new Image(icon)); Optional selectedSource = choiceDialog.showAndWait(); if(selectedSource.isPresent()) { int index = sources.indexOf(selectedSource.get()); diff --git a/client/src/main/java/ctbrec/ui/ThumbCell.java b/client/src/main/java/ctbrec/ui/ThumbCell.java index 1dcaa066..ad16ba1d 100644 --- a/client/src/main/java/ctbrec/ui/ThumbCell.java +++ b/client/src/main/java/ctbrec/ui/ThumbCell.java @@ -437,7 +437,7 @@ public class ThumbCell extends StackPane { return null; }; Function onFail = (throwable) -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't start/stop recording"); alert.setContentText("I/O error while starting/stopping the recording: " + throwable.getLocalizedMessage()); @@ -463,7 +463,7 @@ public class ThumbCell extends StackPane { } catch (Exception e1) { LOG.error("Couldn't pause/resume recording", e1); Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't pause/resume recording"); alert.setContentText("I/O error while pausing/resuming the recording: " + e1.getLocalizedMessage()); @@ -488,7 +488,7 @@ public class ThumbCell extends StackPane { } catch (Exception e1) { LOG.error("Couldn't start/stop recording", e1); Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't start/stop recording"); alert.setContentText("I/O error while starting/stopping the recording: " + e1.getLocalizedMessage()); @@ -511,7 +511,7 @@ public class ThumbCell extends StackPane { return true; } else { Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't follow model"); alert.setContentText(""); @@ -527,7 +527,7 @@ public class ThumbCell extends StackPane { return true; } else { Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't unfollow model"); alert.setContentText(""); @@ -539,7 +539,7 @@ public class ThumbCell extends StackPane { } catch (Exception e1) { LOG.error("Couldn't follow/unfollow model {}", model.getName(), e1); Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't follow/unfollow model"); alert.setContentText("I/O error while following/unfollowing model " + model.getName() + ": " + e1.getLocalizedMessage()); diff --git a/client/src/main/java/ctbrec/ui/ThumbOverviewTab.java b/client/src/main/java/ctbrec/ui/ThumbOverviewTab.java index f47f890c..02349f7b 100644 --- a/client/src/main/java/ctbrec/ui/ThumbOverviewTab.java +++ b/client/src/main/java/ctbrec/ui/ThumbOverviewTab.java @@ -478,7 +478,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { MenuItem sendTip = new MenuItem("Send Tip"); sendTip.setOnAction((e) -> { - TipDialog tipDialog = new TipDialog(sendTip.getParentPopup().getScene(), site, cell.getModel()); + TipDialog tipDialog = new TipDialog(getTabPane().getScene(), site, cell.getModel()); tipDialog.showAndWait(); String tipText = tipDialog.getResult(); if(tipText != null) { @@ -692,7 +692,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { if(updatesSuspended) { return; } - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle("Error"); alert.setHeaderText("Couldn't fetch model list"); if(event.getSource().getException() != null) { diff --git a/client/src/main/java/ctbrec/ui/TipDialog.java b/client/src/main/java/ctbrec/ui/TipDialog.java index f0358091..459d8d8a 100644 --- a/client/src/main/java/ctbrec/ui/TipDialog.java +++ b/client/src/main/java/ctbrec/ui/TipDialog.java @@ -21,8 +21,10 @@ public class TipDialog extends TextInputDialog { private static final transient Logger LOG = LoggerFactory.getLogger(TipDialog.class); private Site site; + private Scene parent; public TipDialog(Scene parent, Site site, Model model) { + this.parent = parent; this.site = site; setTitle("Send Tip"); loadTokenBalance(); @@ -56,7 +58,7 @@ public class TipDialog extends TextInputDialog { if (tokens <= 0) { String msg = "Do you want to buy tokens now?\n\nIf you agree, "+site.getName()+" will open in a browser. " + "The used address is an affiliate link, which supports me, but doesn't cost you anything more."; - Alert buyTokens = new AutosizeAlert(Alert.AlertType.CONFIRMATION, msg, ButtonType.NO, ButtonType.YES); + Alert buyTokens = new AutosizeAlert(Alert.AlertType.CONFIRMATION, msg, parent, ButtonType.NO, ButtonType.YES); buyTokens.setTitle("No tokens"); buyTokens.setHeaderText("You don't have any tokens"); buyTokens.showAndWait(); @@ -81,7 +83,7 @@ public class TipDialog extends TextInputDialog { private void showErrorDialog(Throwable throwable) { Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, parent); alert.setTitle("Error"); alert.setHeaderText("Couldn't retrieve token balance"); alert.setContentText("Error while loading your token balance: " + throwable.getLocalizedMessage()); diff --git a/client/src/main/java/ctbrec/ui/action/StopRecordingAction.java b/client/src/main/java/ctbrec/ui/action/StopRecordingAction.java index a4dcab38..cbe523e8 100644 --- a/client/src/main/java/ctbrec/ui/action/StopRecordingAction.java +++ b/client/src/main/java/ctbrec/ui/action/StopRecordingAction.java @@ -17,7 +17,7 @@ public class StopRecordingAction extends ModelMassEditAction { recorder.stopRecording(m); } catch(Exception e) { Platform.runLater(() -> - Dialogs.showError("Couldn't stop recording", "Stopping recording of " + m.getName() + " failed", e)); + Dialogs.showError(source.getScene(), "Couldn't stop recording", "Stopping recording of " + m.getName() + " failed", e)); } }; } diff --git a/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java b/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java index a5a4983c..b76e34d6 100644 --- a/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java +++ b/client/src/main/java/ctbrec/ui/controls/AbstractFileSelectionBox.java @@ -145,7 +145,7 @@ public abstract class AbstractFileSelectionBox extends HBox { fileInput.setText(program.getCanonicalPath()); } catch (IOException e1) { LOG.error("Couldn't determine path", e1); - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getScene()); alert.setTitle("Whoopsie"); alert.setContentText("Couldn't determine path"); alert.showAndWait(); diff --git a/client/src/main/java/ctbrec/ui/controls/Dialogs.java b/client/src/main/java/ctbrec/ui/controls/Dialogs.java index e0f6dabc..ba7ba737 100644 --- a/client/src/main/java/ctbrec/ui/controls/Dialogs.java +++ b/client/src/main/java/ctbrec/ui/controls/Dialogs.java @@ -24,7 +24,7 @@ public class Dialogs { public static void showError(Scene parent, String header, String text, Throwable t) { Runnable r = () -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, parent); alert.setTitle("Error"); alert.setHeaderText(header); String content = text; diff --git a/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java b/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java index 377797ee..e9bde4f1 100644 --- a/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java +++ b/client/src/main/java/ctbrec/ui/sites/camsoda/CamsodaShowsTab.java @@ -147,7 +147,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener { private void showErrorDialog(String title, String head, String msg) { Platform.runLater(() -> { - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR); + Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); alert.setTitle(title); alert.setHeaderText(head); alert.setContentText(msg);