Changeset 208 in josm


Ignore:
Timestamp:
2007-04-04T11:31:50+02:00 (15 years ago)
Author:
imi
Message:
  • fixed a NPE when hitting a mapmode shortcut after all layers have been closed
Location:
src/org/openstreetmap/josm
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r207 r208  
    136136                        if (map.mapView.editLayer != null)
    137137                                map.mapView.editLayer.listenerCommands.add(redoUndoListener);
    138                 }
     138                } else
     139                        old.destroy();
    139140                redoUndoListener.commandChanged(0,0);
    140141
  • src/org/openstreetmap/josm/actions/JosmAction.java

    r178 r208  
    77
    88import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.tools.Destroyable;
    910import org.openstreetmap.josm.tools.ImageProvider;
    1011import org.openstreetmap.josm.tools.ShortCutLabel;
     
    1213/**
    1314 * Base class helper for all Actions in JOSM. Just to make the life easier.
     15 *
     16 * destroy() from interface Destroyable is called e.g. for MapModes, when the last layer has
     17 * been removed and so the mapframe will be destroyed. For other JosmActions, destroy() may never
     18 * be called (currently).
     19 *
    1420 * @author imi
    1521 */
    16 abstract public class JosmAction extends AbstractAction {
     22abstract public class JosmAction extends AbstractAction implements Destroyable {
     23
     24        private KeyStroke shortCut;
    1725
    1826        public JosmAction(String name, String iconName, String tooltip, int shortCut, int modifier, boolean register) {
     
    2028                setHelpId();
    2129                putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+ShortCutLabel.name(shortCut, modifier)+"</font>&nbsp;</html>");
    22         Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(shortCut, modifier), name);
     30                this.shortCut = KeyStroke.getKeyStroke(shortCut, modifier);
     31        Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(this.shortCut, name);
    2332        Main.contentPane.getActionMap().put(name, this);
    2433        putValue("toolbar", iconName);
     
    2736        }
    2837
     38        public void destroy() {
     39                Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(shortCut);
     40                Main.contentPane.getActionMap().remove(shortCut);
     41        }
     42       
    2943        public JosmAction() {
    3044                setHelpId();
  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r198 r208  
    5858         */
    5959        public void actionPerformed(ActionEvent e) {
    60                 Main.map.selectMapMode(this);
     60                if (Main.map != null)
     61                        Main.map.selectMapMode(this);
    6162        }
    6263
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r205 r208  
    3333import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
    3434import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
     35import org.openstreetmap.josm.tools.Destroyable;
    3536
    3637/**
     
    4041 * @author imi
    4142 */
    42 public class MapFrame extends JPanel {
     43public class MapFrame extends JPanel implements Destroyable {
    4344
    4445        /**
     
    135136        }
    136137
     138        /**
     139         * Called as some kind of destructor when the last layer has been removed.
     140         * Delegates the call to all Destroyables within this component (e.g. MapModes)
     141         */
     142        public void destroy() {
     143                for (int i = 0; i < toolBarActions.getComponentCount(); ++i)
     144                        if (toolBarActions.getComponent(i) instanceof Destroyable)
     145                                ((Destroyable)toolBarActions).destroy();
     146    }
     147
    137148        public Action getDefaultButtonAction() {
    138149                return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
  • src/org/openstreetmap/josm/gui/layer/Layer.java

    r198 r208  
    99import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    1010import org.openstreetmap.josm.gui.MapView;
     11import org.openstreetmap.josm.tools.Destroyable;
    1112
    1213/**
     
    2526 * @author imi
    2627 */
    27 abstract public class Layer {
     28abstract public class Layer implements Destroyable {
    2829
    2930        /**
  • src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r178 r208  
    252252        }
    253253
     254        /**
     255         * Parse the toolbar preference setting and construct the toolbar GUI control.
     256         *
     257         * Call this, if anything has changed in the toolbar settings and you want to refresh
     258         * the toolbar content (e.g. after registering actions in a plugin)
     259         */
    254260        public void refreshToolbarControl() {
    255261                control.removeAll();
Note: See TracChangeset for help on using the changeset viewer.