Changeset 4333 in josm


Ignore:
Timestamp:
Aug 22, 2011 1:04:01 PM (21 months ago)
Author:
xeen
Message:

add shortcuts to toggle layer visibility (defaults are ALT+1 .. ALT+0 for layers 1 through 10). Fixes #30

File:
1 edited

Legend:

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

    r4265 r4333  
    165165 
    166166        return buttonPanel; 
     167    } 
     168 
     169    /** stores which layer index to toggle and executes the ShowHide action if the layer is present */ 
     170    private final class ToggleLayerIndexVisibility extends AbstractAction { 
     171        int layerIndex = -1; 
     172        public ToggleLayerIndexVisibility(int layerIndex) { 
     173            this.layerIndex = layerIndex; 
     174        } 
     175        @Override 
     176        public void actionPerformed(ActionEvent e) { 
     177            final Layer l = model.getLayer(model.getRowCount() - layerIndex); 
     178            if(l != null) { 
     179                new ShowHideLayerAction(l).actionPerformed(e); 
     180            } 
     181        } 
     182    } 
     183 
     184    /** 
     185     * registers (shortcut to toggle right hand side toggle dialogs)+(number keys) shortcuts 
     186     * to toggle the visibility of the first ten layers. 
     187     */ 
     188    private final void createVisibilityToggleShortcuts() { 
     189        final int[] k = { KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4, 
     190                KeyEvent.VK_5, KeyEvent.VK_6, KeyEvent.VK_7, KeyEvent.VK_8, 
     191                KeyEvent.VK_9, KeyEvent.VK_0 }; 
     192 
     193        for(int i=1; i <= 10; i++) { 
     194            Main.registerActionShortcut( 
     195                    new ToggleLayerIndexVisibility(i), 
     196                    Shortcut.registerShortcut("subwindow:layers:toggleLayer" + i, 
     197                            tr("Toggle visibility of layer: {0}", i), 
     198                            k[i-1], 
     199                            Shortcut.GROUP_LAYER)); 
     200        } 
    167201    } 
    168202 
     
    239273 
    240274        add(createButtonPanel(), BorderLayout.SOUTH); 
     275        createVisibilityToggleShortcuts(); 
    241276    } 
    242277 
Note: See TracChangeset for help on using the changeset viewer.