Changeset 5018 in josm for trunk


Ignore:
Timestamp:
2012-02-22T19:54:15+01:00 (13 years ago)
Author:
akks
Message:

fix "Shortcut redefinition" warnings after MapFrame reinitialization - see #7424 (core part)

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

Legend:

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

    r4999 r5018  
    6666    private SideButton downButton;
    6767
     68    private EnableFilterAction enableFilterAction;
     69    private HidingFilterAction hidingFilterAction;
    6870
    6971    public FilterDialog(){
     
    7274                KeyEvent.VK_F, Shortcut.ALT_SHIFT), 162);
    7375        build();
    74 
    75         MultikeyActionsHandler.getInstance().addAction(new EnableFilterAction());
    76         MultikeyActionsHandler.getInstance().addAction(new HidingFilterAction());
     76        enableFilterAction = new EnableFilterAction();
     77        hidingFilterAction = new HidingFilterAction();
     78        MultikeyActionsHandler.getInstance().addAction(enableFilterAction);
     79        MultikeyActionsHandler.getInstance().addAction(hidingFilterAction);
    7780    }
    7881
     
    195198    }
    196199
     200    @Override
     201    public void destroy() {
     202        MultikeyActionsHandler.getInstance().removeAction(enableFilterAction);
     203        MultikeyActionsHandler.getInstance().removeAction(hidingFilterAction);
     204        super.destroy();
     205    }
     206   
    197207    static class StringRenderer extends DefaultTableCellRenderer {
    198208        @Override
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r4999 r5018  
    9090        instance = new LayerListDialog(mapFrame);
    9191
    92         MultikeyActionsHandler.getInstance().addAction(instance.new ShowHideLayerAction(false));
    93         MultikeyActionsHandler.getInstance().addAction(instance.new ActivateLayerAction());
    94         JumpToMarkerActions.initialize();
    9592    }
    9693
     
    120117
    121118    ActivateLayerAction activateLayerAction;
    122 
     119    ShowHideLayerAction showHideLayerAction;
     120   
    123121    //TODO This duplicates ShowHide actions functionality
    124122    /** stores which layer index to toggle and executes the ShowHide action if the layer is present */
     
    240238        activateLayerAction = new ActivateLayerAction();
    241239        activateLayerAction.updateEnabledState();
     240        MultikeyActionsHandler.getInstance().addAction(activateLayerAction);
    242241        adaptTo(activateLayerAction, selectionModel);
     242   
     243        JumpToMarkerActions.initialize();
    243244
    244245        // -- show hide action
    245         ShowHideLayerAction showHideLayerAction = new ShowHideLayerAction();
     246        showHideLayerAction = new ShowHideLayerAction();
     247        MultikeyActionsHandler.getInstance().addAction(showHideLayerAction);
    246248        adaptTo(showHideLayerAction, selectionModel);
    247249
     
    345347            Main.unregisterActionShortcut(visibilityToggleActions[i], visibilityToggleShortcuts[i]);
    346348        }
     349        MultikeyActionsHandler.getInstance().removeAction(activateLayerAction);
     350        MultikeyActionsHandler.getInstance().removeAction(showHideLayerAction);
     351        JumpToMarkerActions.unregisterActions();
    347352        super.destroy();
    348353        instance = null;
  • trunk/src/org/openstreetmap/josm/gui/layer/JumpToMarkerActions.java

    r4999 r5018  
    2323    }
    2424
     25    private static JumpToNextMarker jumpToNextMarkerAction;
     26    private static JumpToPreviousMarker jumpToPreviousMarkerAction;
     27           
    2528    public static void initialize() {
    26         MultikeyActionsHandler.getInstance().addAction(new JumpToNextMarker(null));
    27         MultikeyActionsHandler.getInstance().addAction(new JumpToPreviousMarker(null));
     29        jumpToNextMarkerAction = new JumpToNextMarker(null);
     30        jumpToPreviousMarkerAction = new JumpToPreviousMarker(null);
     31        MultikeyActionsHandler.getInstance().addAction(jumpToNextMarkerAction);
     32        MultikeyActionsHandler.getInstance().addAction(jumpToPreviousMarkerAction);
     33    }
     34   
     35    public static void unregisterActions() {
     36        MultikeyActionsHandler.getInstance().removeAction(jumpToNextMarkerAction);
     37        MultikeyActionsHandler.getInstance().removeAction(jumpToPreviousMarkerAction);
    2838    }
    2939
  • trunk/src/org/openstreetmap/josm/tools/MultikeyActionsHandler.java

    r4999 r5018  
    99import java.awt.event.ActionListener;
    1010import java.awt.event.KeyEvent;
     11import java.util.HashMap;
     12import java.util.Map;
    1113import java.util.Timer;
    1214import java.util.TimerTask;
     
    3133    private static final String STATUS_BAR_ID = new String("multikeyShortcut");
    3234
     35    private Map<MultikeyShortcutAction, MyAction> myActions = new HashMap<MultikeyShortcutAction,MyAction>();
     36           
    3337    private class MyKeyEventDispatcher implements KeyEventDispatcher {
    3438        @Override
     
    203207        if(action.getMultikeyShortcut() != null) {
    204208            MyAction myAction = new MyAction(action);
     209            myActions.put(action, myAction);
    205210            Main.registerActionShortcut(myAction, myAction.shortcut);
    206211        }
    207212    }
     213   
     214    // unregister action and its shortcut completely
     215    public void removeAction(MultikeyShortcutAction action) {
     216        MyAction a = myActions.get(action);
     217        if (a!=null) {
     218            Main.unregisterActionShortcut(a, a.shortcut);
     219            myActions.remove(a);
     220        }
     221    }
    208222}
Note: See TracChangeset for help on using the changeset viewer.