Changeset 5471 in josm


Ignore:
Timestamp:
2012-08-22T01:48:59+02:00 (7 years ago)
Author:
Don-vip
Message:

see #7980 - fix another memory leak

File:
1 edited

Legend:

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

    r5463 r5471  
    2727public class SideButton extends JButton implements Destroyable {
    2828    private final static int iconHeight = 20;
     29   
     30    private PropertyChangeListener propertyChangeListener;
    2931
    3032    public SideButton(Action action)
     
    5254    }
    5355
    54     void fixIcon(Action action) {
     56    private void fixIcon(Action action) {
    5557        // need to listen for changes, so that putValue() that are called after the
    5658        // SideButton is constructed get the proper icon size
    57         if(action != null) {
    58             action.addPropertyChangeListener(new PropertyChangeListener() {
     59        if (action != null) {
     60            action.addPropertyChangeListener(propertyChangeListener = new PropertyChangeListener() {
    5961                @Override
    6062                public void propertyChange(PropertyChangeEvent evt) {
    61                     if(evt.getPropertyName() == javax.swing.Action.SMALL_ICON) {
     63                    if (evt.getPropertyName() == javax.swing.Action.SMALL_ICON) {
    6264                        fixIcon(null);
    6365                    }
     
    6668        }
    6769        Icon i = getIcon();
    68         if(i != null && i instanceof ImageIcon && i.getIconHeight() != iconHeight) {
     70        if (i != null && i instanceof ImageIcon && i.getIconHeight() != iconHeight) {
    6971            setIcon(getScaledImage(((ImageIcon) i).getImage()));
    7072        }
     
    144146            ((Destroyable) action).destroy();
    145147        }
    146         setAction(null);
     148        if (action != null) {
     149            if (propertyChangeListener != null) {
     150                action.removePropertyChangeListener(propertyChangeListener);
     151            }
     152            setAction(null);
     153        }
    147154    }
    148155}
Note: See TracChangeset for help on using the changeset viewer.