Skip to content

Commit

Permalink
- store window information for DialogAddDownload in config
Browse files Browse the repository at this point in the history
  • Loading branch information
derreisende77 committed Aug 26, 2024
1 parent 4f5744c commit b6de80b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
55 changes: 54 additions & 1 deletion src/main/java/mediathek/gui/dialog/DialogAddDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> jcb) {
Expand Down Expand Up @@ -144,6 +150,24 @@ public static void saveComboPfad(JComboBox<String> 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
Expand Down Expand Up @@ -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);
}
}
}

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mediathek/tool/ApplicationConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit b6de80b

Please sign in to comment.