From b6de80b862aafc6be1e9037a8fbf999c08eb034d Mon Sep 17 00:00:00 2001 From: "Christian F." Date: Mon, 26 Aug 2024 07:39:21 +0200 Subject: [PATCH] - store window information for DialogAddDownload in config --- CHANGELOG.md | 1 + .../gui/dialog/DialogAddDownload.java | 55 ++++++++++++++++++- .../tool/ApplicationConfiguration.java | 7 +++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d69d4dbaf9..c07ba4b4d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - **BUGFIX:** MV aktualisiert nun vor dem Download mittels `-dq` oder `--download-quit` Parameter die Filmliste. - **BUGFIX:** FlatLaf Regression gelöst, die manchmal zu einer inkorrekten Darstellung der Oberfläche führte. - **BUGFIX(Linux/macOS):** Im "Film Speichern"-Dialog wurde der Zielpfad im Dark Mode weiß dargestellt. +- **BUGFIX:** "Film speichern"-Dialog speichert nun explizit seine Größe,etc und stellt sie wieder her. - **BUGFIX:** Im "Neues Abo anlegen"-Dialog werden Textfelder im Dark Mode nicht mehr weiß hinterlegt. - **BUGFIX:** Diverse Textfelder werden im Dark Mode nicht mehr mit weißem Hintergrund dargestellt. - **BUGFIX:** MV deaktiviert im Fehlerfall die moderne Suche automatisch, so dass ein Neustart der App möglich wird. diff --git a/src/main/java/mediathek/gui/dialog/DialogAddDownload.java b/src/main/java/mediathek/gui/dialog/DialogAddDownload.java index d75d131981..63cc4c5334 100644 --- a/src/main/java/mediathek/gui/dialog/DialogAddDownload.java +++ b/src/main/java/mediathek/gui/dialog/DialogAddDownload.java @@ -18,6 +18,7 @@ import mediathek.mainwindow.MediathekGui; import mediathek.tool.*; import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.sync.LockMode; import org.apache.commons.lang3.SystemUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -32,12 +33,15 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; import java.io.File; import java.nio.file.FileStore; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; import java.util.concurrent.CancellationException; @@ -88,8 +92,10 @@ public DialogAddDownload(@NotNull Frame parent, @NotNull DatenFilm film, @Nullab if (SystemUtils.IS_OS_MAC_OSX) { pack(); } - + restoreWindowSizeFromConfig(); setLocationRelativeTo(parent); + + addComponentListener(new DialogPositionComponentListener()); } public static void setModelPfad(String pfad, JComboBox jcb) { @@ -144,6 +150,24 @@ public static void saveComboPfad(JComboBox jcb, String orgPath) { MVConfig.add(MVConfig.Configs.SYSTEM_DIALOG_DOWNLOAD__PFADE_ZUM_SPEICHERN, s); } + private void restoreWindowSizeFromConfig() { + var config = ApplicationConfiguration.getConfiguration(); + try { + config.lock(LockMode.READ); + final int width = config.getInt(ApplicationConfiguration.AddDownloadDialog.WIDTH); + final int height = config.getInt(ApplicationConfiguration.AddDownloadDialog.HEIGHT); + final int x = config.getInt(ApplicationConfiguration.AddDownloadDialog.X); + final int y = config.getInt(ApplicationConfiguration.AddDownloadDialog.Y); + + setBounds(x, y, width, height); + } catch (NoSuchElementException ignored) { + //do not restore anything + } finally { + config.unlock(LockMode.READ); + } + + } + private void setupFilmQualityRadioButtons() { var listener = new ActionListener() { @Override @@ -840,6 +864,35 @@ private void saveDownload() { dispose(); } + private static class DialogPositionComponentListener extends ComponentAdapter { + @Override + public void componentResized(ComponentEvent e) { + storeWindowPosition(e); + } + + @Override + public void componentMoved(ComponentEvent e) { + storeWindowPosition(e); + } + + private void storeWindowPosition(ComponentEvent e) { + var config = ApplicationConfiguration.getConfiguration(); + var component = e.getComponent(); + + var dims = component.getSize(); + var loc = component.getLocation(); + try { + config.lock(LockMode.WRITE); + config.setProperty(ApplicationConfiguration.AddDownloadDialog.WIDTH, dims.width); + config.setProperty(ApplicationConfiguration.AddDownloadDialog.HEIGHT, dims.height); + config.setProperty(ApplicationConfiguration.AddDownloadDialog.X, loc.x); + config.setProperty(ApplicationConfiguration.AddDownloadDialog.Y, loc.y); + } finally { + config.unlock(LockMode.WRITE); + } + } + } + // //GEN-BEGIN:initComponents private void initComponents() { diff --git a/src/main/java/mediathek/tool/ApplicationConfiguration.java b/src/main/java/mediathek/tool/ApplicationConfiguration.java index 4a7a8b08e2..36c0b1fe31 100644 --- a/src/main/java/mediathek/tool/ApplicationConfiguration.java +++ b/src/main/java/mediathek/tool/ApplicationConfiguration.java @@ -260,6 +260,13 @@ public static class FilterDialog { public static final String VISIBLE = "application.ui.filter_dialog.visible"; } + public static class AddDownloadDialog { + public static final String WIDTH = "application.ui.adddownload_dialog.width"; + public static final String HEIGHT = "application.ui.adddownload_dialog.height"; + public static final String X = "application.ui.adddownload_dialog.location.x"; + public static final String Y = "application.ui.adddownload_dialog.location.y"; + } + public static class FilmInfoDialog { public static final String VISIBLE = "film.information.visible"; public static final String X = "film.information.location.x";