Ignore:
Timestamp:
2012-08-23T02:25:01+02:00 (12 years ago)
Author:
Don-vip
Message:

see #7980 - fix another two memory leaks

File:
1 edited

Legend:

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

    r4982 r5472  
    1515
    1616import javax.swing.AbstractAction;
     17import javax.swing.ActionMap;
     18import javax.swing.InputMap;
    1719import javax.swing.JComponent;
    1820import javax.swing.JPanel;
     21import javax.swing.KeyStroke;
    1922
    2023import org.openstreetmap.josm.Main;
    2124import org.openstreetmap.josm.data.coor.EastNorth;
     25import org.openstreetmap.josm.tools.Destroyable;
    2226import org.openstreetmap.josm.tools.PlatformHookOsx;
    2327import org.openstreetmap.josm.tools.Shortcut;
     
    2933 * @author imi
    3034 */
    31 public class MapMover extends MouseAdapter implements MouseMotionListener, MouseWheelListener {
     35public class MapMover extends MouseAdapter implements MouseMotionListener, MouseWheelListener, Destroyable {
    3236
    3337    private final class ZoomerAction extends AbstractAction {
     
    6771     */
    6872    private final NavigatableComponent nc;
     73    private final JPanel contentPane;
    6974
    7075    private boolean movementInPlace = false;
     
    7580    public MapMover(NavigatableComponent navComp, JPanel contentPane) {
    7681        this.nc = navComp;
     82        this.contentPane = contentPane;
    7783        nc.addMouseListener(this);
    7884        nc.addMouseMotionListener(this);
     
    217223    }
    218224
     225    @Override
     226    public void destroy() {
     227        if (this.contentPane != null) {
     228            InputMap inputMap = contentPane.getInputMap();
     229            KeyStroke[] inputKeys = inputMap.keys();
     230            if (inputKeys != null) {
     231                for (KeyStroke key : inputKeys) {
     232                    Object binding = inputMap.get(key);
     233                    if (binding instanceof String && ((String)binding).startsWith("MapMover.")) {
     234                        inputMap.remove(key);
     235                    }
     236                }
     237            }
     238            ActionMap actionMap = contentPane.getActionMap();
     239            Object[] actionsKeys = actionMap.keys();
     240            if (actionsKeys != null) {
     241                for (Object key : actionsKeys) {
     242                    if (key instanceof String && ((String)key).startsWith("MapMover.")) {
     243                        actionMap.remove(key);
     244                    }
     245                }
     246            }
     247        }
     248    }
    219249}
Note: See TracChangeset for help on using the changeset viewer.