Changeset 3443 in josm for trunk


Ignore:
Timestamp:
2010-08-15T22:04:43+02:00 (14 years ago)
Author:
jttt
Message:

Fix some of the references/forgotten listeners that keeps MapView alive after all layers are removed (see #5331)

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

Legend:

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

    r3083 r3443  
    2424public abstract class AbstractInfoAction extends JosmAction {
    2525
    26     public AbstractInfoAction() {
    27         super();
     26    public AbstractInfoAction(boolean installAdapters) {
     27        super(installAdapters);
    2828    }
    2929
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r3416 r3443  
    6666     */
    6767    public JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register) {
     68        this(name, iconName, tooltip, shortcut, register, true);
     69    }
     70
     71    /**
     72     * Even newer super for all actions. Use if you don't want to install layer changed and selection changed adapters
     73     * @param name
     74     * @param iconName
     75     * @param tooltip
     76     * @param shortcut
     77     * @param register
     78     * @param installAdapters
     79     */
     80    public JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, boolean installAdapters) {
    6881        super(name, iconName == null ? null : ImageProvider.get(iconName));
    6982        setHelpId();
     
    7790            Main.toolbar.register(this);
    7891        }
    79         installAdapters();
     92        if (installAdapters) {
     93            installAdapters();
     94        }
    8095    }
    8196
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java

    r2512 r3443  
    77import java.awt.event.KeyEvent;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.gui.MapFrame;
    1011import org.openstreetmap.josm.gui.MapView;
     
    3031
    3132    /**
    32      * Shortcut to the mapview.
    33      */
    34     private final MapView mv;
    35     /**
    3633     * Manager that manages the selection rectangle with the aspect ratio of the
    3734     * MapView.
     
    4744                Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),
    4845                mapFrame, ImageProvider.getCursor("normal", "zoom"));
    49         mv = mapFrame.mapView;
    50         selectionManager = new SelectionManager(this, true, mv);
     46        selectionManager = new SelectionManager(this, true, mapFrame.mapView);
    5147    }
    5248
     
    5551     */
    5652    public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) {
    57         if (r.width >= 3 && r.height >= 3) {
     53        if (r.width >= 3 && r.height >= 3 && Main.isDisplayingMapView()) {
     54            MapView mv = Main.map.mapView;
    5855            mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth());
    5956        }
     
    6259    @Override public void enterMode() {
    6360        super.enterMode();
    64         selectionManager.register(mv);
     61        selectionManager.register(Main.map.mapView);
    6562    }
    6663
    6764    @Override public void exitMode() {
    6865        super.exitMode();
    69         selectionManager.unregister(mv);
     66        selectionManager.unregister(Main.map.mapView);
    7067    }
    7168
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r3278 r3443  
    214214            }
    215215        }
     216        mapView.destroy();
    216217    }
    217218
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r3416 r3443  
    222222
    223223        // listend to selection changes to redraw the map
    224         DataSet.addSelectionListener(new SelectionChangedListener(){
    225             public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    226                 repaint();
    227             }
    228         });
     224        DataSet.addSelectionListener(repaintSelectionChangedListener);
    229225
    230226        //store the last mouse action
     
    805801    }
    806802
     803    private SelectionChangedListener repaintSelectionChangedListener = new SelectionChangedListener(){
     804        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     805            repaint();
     806        }
     807    };
     808
     809    public void destroy() {
     810        Main.pref.removePreferenceChangeListener(this);
     811        DataSet.removeSelectionListener(repaintSelectionChangedListener);
     812    }
     813
    807814}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r3275 r3443  
    1212import java.awt.event.KeyEvent;
    1313import java.awt.event.MouseEvent;
    14 
    1514import java.util.ArrayList;
    1615import java.util.LinkedHashSet;
     
    7473        super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."),
    7574                Shortcut.registerShortcut("subwindow:commandstack", tr("Toggle: {0}", tr("Command Stack")), KeyEvent.VK_O, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 100, true);
    76         Main.main.undoRedo.listenerCommands.add(this);
    77 
    7875        undoTree.addMouseListener(new PopupMenuHandler());
    7976        undoTree.setRootVisible(false);
     
    212209            listener.updateEnabledState();
    213210        }
     211        Main.main.undoRedo.listenerCommands.add(this);
    214212    }
    215213
     
    227225        undoTreeModel.setRoot(new DefaultMutableTreeNode());
    228226        redoTreeModel.setRoot(new DefaultMutableTreeNode());
     227        Main.main.undoRedo.listenerCommands.remove(this);
    229228    }
    230229
     
    263262        // if one tree is empty, move selection to the other
    264263        switch (lastOperation) {
    265             case UNDO:
    266                 if (undoCommands.isEmpty()) {
    267                     lastOperation = UndoRedoType.REDO;
    268                 }
    269                 break;
    270             case REDO:
    271                 if (redoCommands.isEmpty()) {
    272                     lastOperation = UndoRedoType.UNDO;
    273                 }
    274                 break;
     264        case UNDO:
     265            if (undoCommands.isEmpty()) {
     266                lastOperation = UndoRedoType.REDO;
     267            }
     268            break;
     269        case REDO:
     270            if (redoCommands.isEmpty()) {
     271                lastOperation = UndoRedoType.UNDO;
     272            }
     273            break;
    275274        }
    276275
    277276        // select the next command to undo/redo
    278277        switch (lastOperation) {
    279             case UNDO:
    280                 undoTree.setSelectionRow(undoTree.getRowCount()-1);
    281                 break;
    282             case REDO:
    283                 redoTree.setSelectionRow(0);
    284                 break;
     278        case UNDO:
     279            undoTree.setSelectionRow(undoTree.getRowCount()-1);
     280            break;
     281        case REDO:
     282            redoTree.setSelectionRow(0);
     283            break;
    285284        }
    286285    }
     
    370369            this.type = type;
    371370            switch (type) {
    372                 case UNDO:
    373                     tree = undoTree;
    374                     putValue(NAME,tr("Undo"));
    375                     putValue(SHORT_DESCRIPTION, tr("Undo the selected and all later commands"));
    376                     putValue(SMALL_ICON, ImageProvider.get("undo"));
    377                     break;
    378                 case REDO:
    379                     tree = redoTree;
    380                     putValue(NAME,tr("Redo"));
    381                     putValue(SHORT_DESCRIPTION, tr("Redo the selected and all earlier commands"));
    382                     putValue(SMALL_ICON, ImageProvider.get("redo"));
    383                     break;
     371            case UNDO:
     372                tree = undoTree;
     373                putValue(NAME,tr("Undo"));
     374                putValue(SHORT_DESCRIPTION, tr("Undo the selected and all later commands"));
     375                putValue(SMALL_ICON, ImageProvider.get("undo"));
     376                break;
     377            case REDO:
     378                tree = redoTree;
     379                putValue(NAME,tr("Redo"));
     380                putValue(SHORT_DESCRIPTION, tr("Redo the selected and all earlier commands"));
     381                putValue(SMALL_ICON, ImageProvider.get("redo"));
     382                break;
    384383            }
    385384        }
     
    397396            // calculate the number of commands to undo/redo; then do it
    398397            switch (type) {
    399                 case UNDO:
    400                     int numUndo = ((DefaultMutableTreeNode) undoTreeModel.getRoot()).getChildCount() - idx;
    401                     Main.main.undoRedo.undo(numUndo);
    402                     break;
    403                 case REDO:
    404                     int numRedo = idx+1;
    405                     Main.main.undoRedo.redo(numRedo);
    406                     break;
     398            case UNDO:
     399                int numUndo = ((DefaultMutableTreeNode) undoTreeModel.getRoot()).getChildCount() - idx;
     400                Main.main.undoRedo.undo(numUndo);
     401                break;
     402            case REDO:
     403                int numRedo = idx+1;
     404                Main.main.undoRedo.redo(numRedo);
     405                break;
    407406            }
    408407            Main.map.repaint();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r3416 r3443  
    188188
    189189        public ShowUserInfoAction() {
     190            super(false);
    190191            putValue(NAME, tr("Show info"));
    191192            putValue(SHORT_DESCRIPTION, tr("Launches a browser with information about the user"));
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java

    r3083 r3443  
    117117
    118118        public ChangesetInfoAction() {
     119            super(true);
    119120            putValue(NAME, tr("Changeset info"));
    120121            putValue(SHORT_DESCRIPTION, tr("Launch browser with information about the changeset"));
Note: See TracChangeset for help on using the changeset viewer.