Changeset 5463 in josm for trunk


Ignore:
Timestamp:
2012-08-20T22:30:52+02:00 (12 years ago)
Author:
jttt
Message:

Fix some memory leaks (see #7980)

Location:
trunk/src/org/openstreetmap/josm
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ValidateAction.java

    r5452 r5463  
    4545    public ValidateAction() {
    4646        super(tr("Validation"), "dialogs/validator", tr("Performs the data validation"),
    47             Shortcut.registerShortcut("tools:validate", tr("Tool: {0}", tr("Validation")),
    48             KeyEvent.VK_V, Shortcut.SHIFT), true);
     47                Shortcut.registerShortcut("tools:validate", tr("Tool: {0}", tr("Validation")),
     48                        KeyEvent.VK_V, Shortcut.SHIFT), true);
    4949    }
    5050
     
    6464     */
    6565    public void doValidate(ActionEvent ev, boolean getSelectedItems) {
    66         if (Main.main.validator.validateAction == null || Main.map == null || !Main.map.isVisible())
     66        if (Main.map == null || !Main.map.isVisible())
    6767            return;
    6868
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r5415 r5463  
    2222
    2323import org.openstreetmap.josm.Main;
    24 import org.openstreetmap.josm.actions.ValidateAction;
    2524import org.openstreetmap.josm.data.projection.Epsg4326;
    2625import org.openstreetmap.josm.data.projection.Lambert;
     
    6867    public static ValidatorLayer errorLayer = null;
    6968
    70     /** The validate action */
    71     public ValidateAction validateAction = new ValidateAction();
    72 
    7369    /** Grid detail, multiplier of east,north values for valuable cell sizing */
    7470    public static double griddetail;
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r5459 r5463  
    2727
    2828public class ImageryMenu extends JMenu implements MapView.LayerChangeListener {
    29     Action offsetAction = new JosmAction(
     29    private Action offsetAction = new JosmAction(
    3030            tr("Imagery offset"), "mapmode/adjustimg", tr("Adjust imagery offset"), null, false, false) {
    3131        {
     
    6565        }
    6666    };
    67     JMenuItem singleOffset = new JMenuItem(offsetAction);
    68     JMenuItem offsetMenuItem = singleOffset;
    69     Map_Rectifier_WMSmenuAction rectaction = new Map_Rectifier_WMSmenuAction();
    70     int offsPos;
     67    private JMenuItem singleOffset = new JMenuItem(offsetAction);
     68    private JMenuItem offsetMenuItem = singleOffset;
     69    private Map_Rectifier_WMSmenuAction rectaction = new Map_Rectifier_WMSmenuAction();
     70    private int offsPos;
    7171
    7272    public ImageryMenu() {
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r5459 r5463  
    5252import org.openstreetmap.josm.data.Preferences;
    5353import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
     54import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    5455import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5556import org.openstreetmap.josm.gui.dialogs.ChangesetDialog;
     
    147148        setLayout(new BorderLayout());
    148149
    149        
     150
    150151        mapView = new MapView(contentPane);
    151152
    152153        new FileDrop(mapView);
    153        
    154         leftPanel = new JPanel(); 
     154
     155        leftPanel = new JPanel();
    155156        leftPanel.setLayout(new GridBagLayout());
    156        
    157         leftPanel.add(mapView, GBC.std().fill()); 
    158        
     157
     158        leftPanel.add(mapView, GBC.std().fill());
     159
    159160        // toolbar
    160161        toolBarActions.setFloatable(false);
     
    256257        MapView.removeLayerChangeListener(this);
    257258        dialogsPanel.destroy();
     259        Main.pref.removePreferenceChangeListener(sidetoolbarPreferencesChangedListener);
    258260        for (int i = 0; i < toolBarActions.getComponentCount(); ++i) {
    259261            if (toolBarActions.getComponent(i) instanceof Destroyable) {
     
    431433        }));
    432434
    433         Main.pref.addPreferenceChangeListener(new Preferences.PreferenceChangedListener() {
     435        sidetoolbarPreferencesChangedListener = new Preferences.PreferenceChangedListener() {
    434436
    435437            @Override
     
    439441                }
    440442            }
    441         });
     443        };
     444        Main.pref.addPreferenceChangeListener(sidetoolbarPreferencesChangedListener);
    442445
    443446        if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
     
    539542        Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth());
    540543    }
    541    
    542      /*
     544
     545    /*
    543546     * Remove panel from top of MapView by class
    544547     */
    545      public void removeTopPanel(Class<?> type) {
     548    public void removeTopPanel(Class<?> type) {
    546549        int n = leftPanel.getComponentCount();
    547550        for (int i=0; i<n; i++) {
     
    550553                leftPanel.remove(i);
    551554                leftPanel.doLayout();
    552 //                repaint();
     555                //                repaint();
    553556                return;
    554557            }
    555558        }
    556559    }
    557    
     560
    558561    /*
    559     * Find panel on top of MapView by class
    560     */
     562     * Find panel on top of MapView by class
     563     */
    561564    public <T> T getTopPanel(Class<T> type) {
    562565        int n = leftPanel.getComponentCount();
    563566        for (int i=0; i<n; i++) {
    564567            Component c = leftPanel.getComponent(i);
    565             if (type.isInstance(c)) {
     568            if (type.isInstance(c))
    566569                return type.cast(c);
    567             }
    568570        }
    569571        return null;
     
    590592     */
    591593    private static final CopyOnWriteArrayList<MapModeChangeListener> mapModeChangeListeners = new CopyOnWriteArrayList<MapModeChangeListener>();
     594
     595    private PreferenceChangedListener sidetoolbarPreferencesChangedListener;
    592596    /**
    593597     * Adds a mapMode change listener
  • trunk/src/org/openstreetmap/josm/gui/SideButton.java

    r5028 r5463  
    2121
    2222import org.openstreetmap.josm.Main;
     23import org.openstreetmap.josm.tools.Destroyable;
    2324import org.openstreetmap.josm.tools.ImageProvider;
    2425import org.openstreetmap.josm.tools.Shortcut;
    2526
    26 public class SideButton extends JButton {
     27public class SideButton extends JButton implements Destroyable {
    2728    private final static int iconHeight = 20;
    2829
     
    136137        arrowButton.addActionListener(listener);
    137138    }
     139
     140    @Override
     141    public void destroy() {
     142        Action action = getAction();
     143        if (action instanceof Destroyable) {
     144            ((Destroyable) action).destroy();
     145        }
     146        setAction(null);
     147    }
    138148}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r5457 r5463  
    6060
    6161import org.openstreetmap.josm.Main;
    62 import org.openstreetmap.josm.actions.SaveActionBase;
    6362import org.openstreetmap.josm.gui.ExtendedDialog;
    6463import org.openstreetmap.josm.gui.PleaseWaitRunnable;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r5331 r5463  
    77import java.awt.BorderLayout;
    88import java.awt.Component;
     9import java.awt.Container;
    910import java.awt.Dimension;
    1011import java.awt.FlowLayout;
     
    2425import java.awt.event.WindowAdapter;
    2526import java.awt.event.WindowEvent;
     27import java.beans.PropertyChangeEvent;
    2628import java.util.ArrayList;
    2729import java.util.Arrays;
     
    4850import org.openstreetmap.josm.Main;
    4951import org.openstreetmap.josm.actions.JosmAction;
    50 import org.openstreetmap.josm.data.Preferences;
    5152import org.openstreetmap.josm.data.preferences.ParametrizedEnumProperty;
    5253import org.openstreetmap.josm.gui.MainMenu;
     
    5657import org.openstreetmap.josm.gui.help.HelpUtil;
    5758import org.openstreetmap.josm.gui.help.Helpful;
     59import org.openstreetmap.josm.tools.Destroyable;
    5860import org.openstreetmap.josm.tools.GBC;
    5961import org.openstreetmap.josm.tools.ImageProvider;
     
    366368        hideNotify();
    367369        Main.main.menu.windowMenu.remove(windowMenuItem);
     370        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     371        destroyComponents(this);
     372    }
     373
     374    private void destroyComponents(Component component) {
     375        if (component instanceof Container) {
     376            for (Component c: ((Container)component).getComponents()) {
     377                destroyComponents(c);
     378            }
     379        }
     380        if (component instanceof Destroyable) {
     381            ((Destroyable) component).destroy();
     382        }
    368383    }
    369384
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r5415 r5463  
    3333import org.openstreetmap.josm.Main;
    3434import org.openstreetmap.josm.actions.AutoScaleAction;
     35import org.openstreetmap.josm.actions.ValidateAction;
    3536import org.openstreetmap.josm.command.Command;
    3637import org.openstreetmap.josm.data.SelectionChangedListener;
     
    110111        tree.addTreeSelectionListener(new SelectionWatch());
    111112        InputMapUtils.unassignCtrlShiftUpDown(tree, JComponent.WHEN_FOCUSED);
    112                
     113
    113114        List<SideButton> buttons = new LinkedList<SideButton>();
    114115
     
    125126        });
    126127        InputMapUtils.addEnterAction(tree, selectButton.getAction());
    127        
     128
    128129        selectButton.setEnabled(false);
    129130        buttons.add(selectButton);
    130131
    131         buttons.add(new SideButton(Main.main.validator.validateAction));
     132        buttons.add(new SideButton(new ValidateAction()));
    132133
    133134        fixButton = new SideButton(new AbstractAction() {
     
    416417                hasFixes = hasFixes || error.isFixable();
    417418                if (addSelected) {
    418 //                    sel.addAll(error.getPrimitives()); // was selecting already deleted primitives! see #6640
    419                       sel.addAll(error.getSelectablePrimitives());
     419                    //                    sel.addAll(error.getPrimitives()); // was selecting already deleted primitives! see #6640
     420                    sel.addAll(error.getSelectablePrimitives());
    420421                }
    421422            }
  • trunk/src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java

    r5004 r5463  
    3737    private final static String ellipsis = "…" + separator;
    3838
    39     private final static JLabel lblLayerName = new JLabel();
    40     private final static JLabel lblFilename = new JLabel("");
    41     private final static JTextField tfFilename = new JTextField();
     39    private final JLabel lblLayerName = new JLabel();
     40    private final JLabel lblFilename = new JLabel("");
     41    private final JTextField tfFilename = new JTextField();
    4242    private final JButton btnFileChooser = new JButton(new LaunchFileChooserAction());
    4343
     
    6666                    }
    6767                }
    68         );
     68                );
    6969        // hide border
    7070        tfFilename.setBorder(BorderFactory.createLineBorder(getBackground()));
     
    163163    /** makes the given path fit lblFilename, appends ellipsis on the left if it doesn’t fit.
    164164     * Idea: /home/user/josm → …/user/josm → …/josm; and take the first one that fits */
    165     static final private String makePathFit(String t) {
     165    private String makePathFit(String t) {
    166166        boolean hasEllipsis = false;
    167167        while(t != null && !t.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java

    r5283 r5463  
    2020    /** small renderer class that handles the "should be uploaded/saved" texts. */
    2121    private static class RecommendedActionsTableCell implements TableCellRenderer {
    22         private final static JPanel pnlEmpty = new JPanel();
    23         private final static JLabel needsUpload = new JLabel(tr("should be uploaded"));
    24         private final static JLabel needsSave = new JLabel(tr("should be saved"));
     22        private final JPanel pnlEmpty = new JPanel();
     23        private final JLabel needsUpload = new JLabel(tr("should be uploaded"));
     24        private final JLabel needsSave = new JLabel(tr("should be saved"));
    2525        private final static GBC defaultCellStyle = GBC.eol().fill(GBC.HORIZONTAL).insets(2, 0, 2, 0);
    2626
  • trunk/src/org/openstreetmap/josm/tools/MultikeyActionsHandler.java

    r5018 r5463  
    2626import org.openstreetmap.josm.Main;
    2727import org.openstreetmap.josm.tools.MultikeyShortcutAction.MultikeyInfo;
    28 import org.openstreetmap.josm.tools.Shortcut;
    2928
    3029public class MultikeyActionsHandler {
     
    3433
    3534    private Map<MultikeyShortcutAction, MyAction> myActions = new HashMap<MultikeyShortcutAction,MyAction>();
    36            
     35
    3736    private class MyKeyEventDispatcher implements KeyEventDispatcher {
    3837        @Override
     
    211210        }
    212211    }
    213    
     212
    214213    // unregister action and its shortcut completely
    215214    public void removeAction(MultikeyShortcutAction action) {
     
    217216        if (a!=null) {
    218217            Main.unregisterActionShortcut(a, a.shortcut);
    219             myActions.remove(a);
     218            myActions.remove(action);
    220219        }
    221220    }
Note: See TracChangeset for help on using the changeset viewer.