From 61872535898b3a4aa94a9b6027ee06db778124e1 Mon Sep 17 00:00:00 2001 From: Dennis Sheirer Date: Fri, 10 Nov 2023 05:31:05 -0500 Subject: [PATCH] #1619 Resolves issue where JavaFX window size and placement might show minimized after application is started and an initial JavaFX window is opened and then closed, where it impacted subsequent JavaFX window openings. Corrects issue where JavaFX stage monitors were not being registered correctly, so that they could be deregistered prior to application shutdown. --- .../dsheirer/gui/JavaFxWindowManager.java | 22 +-------------- .../preference/javafx/JavaFxPreferences.java | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/github/dsheirer/gui/JavaFxWindowManager.java b/src/main/java/io/github/dsheirer/gui/JavaFxWindowManager.java index c5eea1032..bf4df0765 100644 --- a/src/main/java/io/github/dsheirer/gui/JavaFxWindowManager.java +++ b/src/main/java/io/github/dsheirer/gui/JavaFxWindowManager.java @@ -164,27 +164,7 @@ private void createJFXPanel() public void shutdown() { MyEventBus.getGlobalEventBus().unregister(this); - - if(mChannelMapStage != null) - { - mUserPreferences.getJavaFxPreferences().unmonitor(mChannelMapStage); - } - - if(mIconManagerStage != null) - { - mUserPreferences.getJavaFxPreferences().unmonitor(mIconManagerStage); - } - - if(mPlaylistStage != null) - { - mUserPreferences.getJavaFxPreferences().unmonitor(mPlaylistStage); - } - - if(mUserPreferencesStage != null) - { - mUserPreferences.getJavaFxPreferences().unmonitor(mUserPreferencesStage); - } - + mUserPreferences.getJavaFxPreferences().clearStageMonitors(); Platform.exit(); } diff --git a/src/main/java/io/github/dsheirer/preference/javafx/JavaFxPreferences.java b/src/main/java/io/github/dsheirer/preference/javafx/JavaFxPreferences.java index 48a01b838..17f702e1f 100644 --- a/src/main/java/io/github/dsheirer/preference/javafx/JavaFxPreferences.java +++ b/src/main/java/io/github/dsheirer/preference/javafx/JavaFxPreferences.java @@ -1,6 +1,6 @@ /* * ***************************************************************************** - * Copyright (C) 2014-2020 Dennis Sheirer + * Copyright (C) 2014-2023 Dennis Sheirer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,10 @@ package io.github.dsheirer.preference.javafx; import io.github.dsheirer.preference.decoder.JmbeLibraryPreference; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.prefs.Preferences; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.ObservableList; @@ -28,11 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.prefs.Preferences; - /** * Manages user preferences for JavaFX elements (e.g. stages). */ @@ -59,7 +58,7 @@ public JavaFxPreferences() */ public void monitor(Stage stage, String key) { - mStageMonitors.remove(new StageMonitor(stage, key)); + mStageMonitors.add(new StageMonitor(stage, key)); } /** @@ -81,6 +80,21 @@ public void unmonitor(Stage stage) } } + /** + * Removes all stage monitors and prepares for shutdown. + */ + public void clearStageMonitors() + { + Iterator it = mStageMonitors.iterator(); + + while(it.hasNext()) + { + StageMonitor next = it.next(); + it.remove(); + next.dispose(); + } + } + /** * Monitors a stage's coordinates and stores location. On construction, applies stored coordinates to the stage. */