Changeset 18686 in josm for trunk/src/org


Ignore:
Timestamp:
2023-03-08T20:00:36+01:00 (21 months ago)
Author:
taylor.smock
Message:

See #22767, fix failing unit tests

The fix for #22767 included a new unit test, which caused a cascading failure.
The first step of the fix included removing the destroyed dialog from the
MapFrame. Unfortunately, MapFrame#removeToggleDialog did not properly
remove the ToggleDialog -- it called DialogsPanel#remove(Component) with
the ToggleDialog as an argument. Since the DialogsPanel never adds the
ToggleDialog as a direct subcomponent, this was effectively a no-op.

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java

    r17374 r18686  
    105105        } else {
    106106            dlg.hideDialog();
     107        }
     108    }
     109
     110    /**
     111     * Remove a {@link ToggleDialog} from the list of known dialogs and trigger reconstruct.
     112     * @param toggleDialog The dialog to remove
     113     * @since 18686
     114     */
     115    public void remove(ToggleDialog toggleDialog) {
     116        remove(toggleDialog, true);
     117    }
     118
     119    /**
     120     * Remove a {@link ToggleDialog} from the list of known dialogs.
     121     * @param toggleDialog The dialog to remove
     122     * @param doReconstruct <code>true</code> if reconstruction should be triggered.
     123     * @since 18686
     124     */
     125    public void remove(ToggleDialog toggleDialog, boolean doReconstruct) {
     126        toggleDialog.setDialogsPanel(null);
     127        final JPanel oldPanel = panels.get(allDialogs.indexOf(toggleDialog));
     128        allDialogs.remove(toggleDialog);
     129        panels.remove(oldPanel);
     130        mSpltPane.remove(oldPanel);
     131        if (doReconstruct && !allDialogs.isEmpty()) {
     132            reconstruct(Action.ELEMENT_SHRINKS, toggleDialog);
    107133        }
    108134    }
     
    326352    @Override
    327353    public void destroy() {
    328         for (ToggleDialog t : allDialogs) {
     354        for (ToggleDialog t : new ArrayList<>(allDialogs)) {
    329355            try {
    330356                t.destroy();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r18216 r18686  
    478478    @Override
    479479    public void destroy() {
    480         dialogsPanel = null;
     480        if (dialogsPanel != null) {
     481            dialogsPanel.remove(this);
     482            dialogsPanel = null;
     483        }
    481484        rememberHeight();
    482485        closeDetachedDialog();
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r18685 r18686  
    145145     */
    146146    private static void destroyInstance() {
     147        MapFrame map = MainApplication.getMap();
     148        synchronized (ImageViewerDialog.class) {
     149            if (dialog != null && map != null && map.getToggleDialog(ImageViewerDialog.class) != null) {
     150                map.removeToggleDialog(dialog);
     151            }
     152        }
    147153        dialog = null;
    148154    }
Note: See TracChangeset for help on using the changeset viewer.