JAL-845 SplitFrame key bindings delegation to AlignFrame menu actions
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 3 Feb 2015 16:50:22 +0000 (16:50 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 3 Feb 2015 16:50:22 +0000 (16:50 +0000)
src/jalview/gui/SplitFrame.java
src/jalview/jbgui/GAlignFrame.java

index 2288d72..24babda 100644 (file)
@@ -6,8 +6,8 @@ import java.awt.Component;
 import java.awt.MouseInfo;
 import java.awt.Point;
 import java.awt.Rectangle;
-import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.KeyAdapter;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
@@ -15,7 +15,6 @@ import java.util.Map.Entry;
 
 import javax.swing.AbstractAction;
 import javax.swing.JComponent;
-import javax.swing.JMenuItem;
 import javax.swing.KeyStroke;
 import javax.swing.event.InternalFrameAdapter;
 import javax.swing.event.InternalFrameEvent;
@@ -134,35 +133,16 @@ public class SplitFrame extends GSplitFrame
   }
 
   /**
-   * Set key bindings (recommended for Swing over key accelerators).
+   * Set key bindings (recommended for Swing over key accelerators). For now,
+   * delegate to the corresponding key accelerator for the AlignFrame that the
+   * mouse is in. Hopefully can be simplified in future if AlignFrame is changed
+   * to use key bindings rather than accelerators.
    */
   private void addKeyBindings()
   {
-    /*
-     * Bind Cmd-Alt/I (invert column selection)
-     */
-    // If AlignFrame exposed a Map of Action objects by key,
-    // we could delegate all key bindings with a single lookup
-    this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
-            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.ALT_MASK, false),
-            "INV_SEQ_SEL");
-    this.getActionMap().put("INV_SEQ_SEL", new AbstractAction()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        Component c = getComponentAtMouse();
-        if (c instanceof AlignFrame)
-        {
-          ((AlignFrame) c).invertColSel_actionPerformed(null);
-        }
-      }
-    });
     if (getTopComponent() instanceof AlignFrame)
     {
-      for (Entry<KeyStroke, JMenuItem> acc : ((AlignFrame) getTopComponent())
+      for (Entry<KeyStroke, ActionListener> acc : ((AlignFrame) getTopComponent())
               .getAccelerators().entrySet())
       {
 
@@ -177,11 +157,17 @@ public class SplitFrame extends GSplitFrame
             if (c instanceof AlignFrame)
             {
               ((AlignFrame) c).getAccelerators().get(ks)
-                      .getActionListeners()[0].actionPerformed(null);
+                      .actionPerformed(null);
             }
           }
         });
       }
+      /*
+       * Disable unwanted here
+       */
+      // X expand views - wrecks the split pane view
+      this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(
+              KeyStroke.getKeyStroke(KeyEvent.VK_X, 0, false));
     }
   }
 }
index 44770a2..6f963a5 100755 (executable)
@@ -35,16 +35,15 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusAdapter;
 import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.swing.AbstractAction;
 import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JComponent;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
@@ -391,7 +390,7 @@ public class GAlignFrame extends JInternalFrame
 
   private boolean showAutoCalculatedAbove = false;
 
-  private Map<KeyStroke, JMenuItem> accelerators = new HashMap<KeyStroke, JMenuItem>();
+  private Map<KeyStroke, ActionListener> accelerators = new HashMap<KeyStroke, ActionListener>();
 
   public GAlignFrame()
   {
@@ -406,7 +405,7 @@ public class GAlignFrame extends JInternalFrame
         JMenuItem item = new JMenuItem(
                 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
 
-        item.addActionListener(new java.awt.event.ActionListener()
+        item.addActionListener(new ActionListener()
         {
           @Override
           public void actionPerformed(ActionEvent e)
@@ -434,8 +433,6 @@ public class GAlignFrame extends JInternalFrame
       reload.setMnemonic('R');
     }
 
-    // setKeyBindings();
-
     if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
     {
       java.util.Enumeration userColours = jalview.gui.UserDefinedColours
@@ -517,30 +514,6 @@ public class GAlignFrame extends JInternalFrame
 
   }
 
-  /**
-   * Set key bindings (recommended for Swing over key accelerators).
-   */
-  private void setKeyBindings()
-  {
-    /*
-     * Experiment using Cmd-Alt/K (unmapped) as a synonym for Cmd-Alt/I (invert
-     * column selection)
-     */
-    this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
-            KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.ALT_MASK, false),
-            "INV_SEQ_SEL");
-    this.getActionMap().put("INV_SEQ_SEL", new AbstractAction()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        invertColSel_actionPerformed(null);
-      }
-    });
-  }
-
   public void setColourSelected(String defaultColour)
   {
 
@@ -641,85 +614,85 @@ public class GAlignFrame extends JInternalFrame
   private void jbInit() throws Exception
   {
     fileMenu.setText(MessageManager.getString("action.file"));
+
     saveAs.setText(MessageManager.getString("action.save_as") + "...");
-    KeyStroke keyStroke = javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_S, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.SHIFT_MASK, false);
-    saveAs.setAccelerator(keyStroke);
-    accelerators.put(keyStroke, saveAs);
-    saveAs.addActionListener(new ActionListener()
+    ActionListener al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         saveAs_actionPerformed(e);
       }
-    });
+    };
+    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask()
+            | KeyEvent.SHIFT_MASK, false);
+    addMenuActionAndAccelerator(keyStroke, saveAs, al);
+
     closeMenuItem.setText(MessageManager.getString("action.close"));
-    closeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_W, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    closeMenuItem.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         closeMenuItem_actionPerformed(false);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, closeMenuItem, al);
+
     editMenu.setText(MessageManager.getString("action.edit"));
     viewMenu.setText(MessageManager.getString("action.view"));
     annotationsMenu.setText(MessageManager.getString("action.annotations"));
     colourMenu.setText(MessageManager.getString("action.colour"));
     calculateMenu.setText(MessageManager.getString("action.calculate"));
     webService.setText(MessageManager.getString("action.web_service"));
+
     selectAllSequenceMenuItem.setText(MessageManager
             .getString("action.select_all"));
-    selectAllSequenceMenuItem.setAccelerator(javax.swing.KeyStroke
-            .getKeyStroke(java.awt.event.KeyEvent.VK_A, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask(), false));
-    selectAllSequenceMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                selectAllSequenceMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        selectAllSequenceMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, selectAllSequenceMenuItem, al);
+
     deselectAllSequenceMenuItem.setText(MessageManager
             .getString("action.deselect_all"));
-    deselectAllSequenceMenuItem.setAccelerator(javax.swing.KeyStroke
-            .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false));
-    deselectAllSequenceMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                deselectAllSequenceMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        deselectAllSequenceMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, deselectAllSequenceMenuItem, al);
+
     invertSequenceMenuItem.setText(MessageManager
             .getString("action.invert_sequence_selection"));
-    keyStroke = javax.swing.KeyStroke
-            .getKeyStroke(java.awt.event.KeyEvent.VK_I, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask(), false);
-    invertSequenceMenuItem.setAccelerator(keyStroke);
-    accelerators.put(keyStroke, invertSequenceMenuItem);
-    invertSequenceMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                invertSequenceMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_I, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        invertSequenceMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, invertSequenceMenuItem, al);
+
     grpsFromSelection.setText(MessageManager
             .getString("action.make_groups_selection"));
-    grpsFromSelection.addActionListener(new java.awt.event.ActionListener()
+    grpsFromSelection.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -731,7 +704,7 @@ public class GAlignFrame extends JInternalFrame
             .getString("action.view_flanking_regions"));
     expandAlignment.setToolTipText(MessageManager
             .getString("label.view_flanking_regions"));
-    expandAlignment.addActionListener(new java.awt.event.ActionListener()
+    expandAlignment.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -741,86 +714,84 @@ public class GAlignFrame extends JInternalFrame
     });
     remove2LeftMenuItem.setText(MessageManager
             .getString("action.remove_left"));
-    remove2LeftMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_L, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    remove2LeftMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                remove2LeftMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        remove2LeftMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, remove2LeftMenuItem, al);
+
     remove2RightMenuItem.setText(MessageManager
             .getString("action.remove_right"));
-    remove2RightMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_R, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    remove2RightMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                remove2RightMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        remove2RightMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, remove2RightMenuItem, al);
+
     removeGappedColumnMenuItem.setText(MessageManager
             .getString("action.remove_empty_columns"));
-    removeGappedColumnMenuItem.setAccelerator(javax.swing.KeyStroke
-            .getKeyStroke(java.awt.event.KeyEvent.VK_E, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask(), false));
-    removeGappedColumnMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                removeGappedColumnMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        removeGappedColumnMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, removeGappedColumnMenuItem, al);
+
     removeAllGapsMenuItem.setText(MessageManager
             .getString("action.remove_all_gaps"));
-    removeAllGapsMenuItem.setAccelerator(javax.swing.KeyStroke
-            .getKeyStroke(java.awt.event.KeyEvent.VK_E, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.SHIFT_MASK, false));
-    removeAllGapsMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                removeAllGapsMenuItem_actionPerformed(e);
-              }
-            });
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask()
+            | KeyEvent.SHIFT_MASK, false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        removeAllGapsMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, removeAllGapsMenuItem, al);
+
     justifyLeftMenuItem.setText(MessageManager
             .getString("action.left_justify_alignment"));
-    justifyLeftMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                justifyLeftMenuItem_actionPerformed(e);
-              }
-            });
+    justifyLeftMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        justifyLeftMenuItem_actionPerformed(e);
+      }
+    });
     justifyRightMenuItem.setText(MessageManager
             .getString("action.right_justify_alignment"));
-    justifyRightMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                justifyRightMenuItem_actionPerformed(e);
-              }
-            });
+    justifyRightMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        justifyRightMenuItem_actionPerformed(e);
+      }
+    });
     viewBoxesMenuItem.setText(MessageManager.getString("action.boxes"));
     viewBoxesMenuItem.setState(true);
-    viewBoxesMenuItem.addActionListener(new java.awt.event.ActionListener()
+    viewBoxesMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -830,7 +801,7 @@ public class GAlignFrame extends JInternalFrame
     });
     viewTextMenuItem.setText(MessageManager.getString("action.text"));
     viewTextMenuItem.setState(true);
-    viewTextMenuItem.addActionListener(new java.awt.event.ActionListener()
+    viewTextMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -841,28 +812,26 @@ public class GAlignFrame extends JInternalFrame
     showNonconservedMenuItem.setText(MessageManager
             .getString("label.show_non_conversed"));
     showNonconservedMenuItem.setState(false);
-    showNonconservedMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                showUnconservedMenuItem_actionPerformed(e);
-              }
-            });
+    showNonconservedMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        showUnconservedMenuItem_actionPerformed(e);
+      }
+    });
     sortPairwiseMenuItem.setText(MessageManager
             .getString("action.by_pairwise_id"));
-    sortPairwiseMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                sortPairwiseMenuItem_actionPerformed(e);
-              }
-            });
+    sortPairwiseMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        sortPairwiseMenuItem_actionPerformed(e);
+      }
+    });
     sortIDMenuItem.setText(MessageManager.getString("action.by_id"));
-    sortIDMenuItem.addActionListener(new java.awt.event.ActionListener()
+    sortIDMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -872,17 +841,16 @@ public class GAlignFrame extends JInternalFrame
     });
     sortLengthMenuItem
             .setText(MessageManager.getString("action.by_length"));
-    sortLengthMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                sortLengthMenuItem_actionPerformed(e);
-              }
-            });
+    sortLengthMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        sortLengthMenuItem_actionPerformed(e);
+      }
+    });
     sortGroupMenuItem.setText(MessageManager.getString("action.by_group"));
-    sortGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
+    sortGroupMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -890,34 +858,34 @@ public class GAlignFrame extends JInternalFrame
         sortGroupMenuItem_actionPerformed(e);
       }
     });
-    removeRedundancyMenuItem.setText(MessageManager
-            .getString("action.remove_redundancy").concat("..."));
-    removeRedundancyMenuItem.setAccelerator(javax.swing.KeyStroke
-            .getKeyStroke(java.awt.event.KeyEvent.VK_D, Toolkit
-                    .getDefaultToolkit().getMenuShortcutKeyMask(), false));
-    removeRedundancyMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                removeRedundancyMenuItem_actionPerformed(e);
-              }
-            });
+
+    removeRedundancyMenuItem.setText(MessageManager.getString(
+            "action.remove_redundancy").concat("..."));
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        removeRedundancyMenuItem_actionPerformed(e);
+      }
+    };
+    addMenuActionAndAccelerator(keyStroke, removeRedundancyMenuItem, al);
+
     pairwiseAlignmentMenuItem.setText(MessageManager
             .getString("action.pairwise_alignment"));
-    pairwiseAlignmentMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                pairwiseAlignmentMenuItem_actionPerformed(e);
-              }
-            });
+    pairwiseAlignmentMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        pairwiseAlignmentMenuItem_actionPerformed(e);
+      }
+    });
     PCAMenuItem.setText(MessageManager
             .getString("label.principal_component_analysis"));
-    PCAMenuItem.addActionListener(new java.awt.event.ActionListener()
+    PCAMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -927,26 +895,24 @@ public class GAlignFrame extends JInternalFrame
     });
     averageDistanceTreeMenuItem.setText(MessageManager
             .getString("label.average_distance_identity"));
-    averageDistanceTreeMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                averageDistanceTreeMenuItem_actionPerformed(e);
-              }
-            });
+    averageDistanceTreeMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        averageDistanceTreeMenuItem_actionPerformed(e);
+      }
+    });
     neighbourTreeMenuItem.setText(MessageManager
             .getString("label.neighbour_joining_identity"));
-    neighbourTreeMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                neighbourTreeMenuItem_actionPerformed(e);
-              }
-            });
+    neighbourTreeMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        neighbourTreeMenuItem_actionPerformed(e);
+      }
+    });
     this.getContentPane().setLayout(borderLayout1);
     alignFrameMenuBar.setFont(new java.awt.Font("Verdana", 0, 11));
     statusBar.setBackground(Color.white);
@@ -957,7 +923,7 @@ public class GAlignFrame extends JInternalFrame
             .getString("label.out_to_textbox"));
     clustalColour.setText(MessageManager.getString("label.clustalx"));
 
-    clustalColour.addActionListener(new java.awt.event.ActionListener()
+    clustalColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -966,7 +932,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     zappoColour.setText(MessageManager.getString("label.zappo"));
-    zappoColour.addActionListener(new java.awt.event.ActionListener()
+    zappoColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -975,7 +941,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     taylorColour.setText(MessageManager.getString("label.taylor"));
-    taylorColour.addActionListener(new java.awt.event.ActionListener()
+    taylorColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -985,17 +951,16 @@ public class GAlignFrame extends JInternalFrame
     });
     hydrophobicityColour.setText(MessageManager
             .getString("label.hydrophobicity"));
-    hydrophobicityColour
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                hydrophobicityColour_actionPerformed(e);
-              }
-            });
+    hydrophobicityColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hydrophobicityColour_actionPerformed(e);
+      }
+    });
     helixColour.setText(MessageManager.getString("label.helix_propensity"));
-    helixColour.addActionListener(new java.awt.event.ActionListener()
+    helixColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1005,7 +970,7 @@ public class GAlignFrame extends JInternalFrame
     });
     strandColour.setText(MessageManager
             .getString("label.strand_propensity"));
-    strandColour.addActionListener(new java.awt.event.ActionListener()
+    strandColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1014,7 +979,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     turnColour.setText(MessageManager.getString("label.turn_propensity"));
-    turnColour.addActionListener(new java.awt.event.ActionListener()
+    turnColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1023,7 +988,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     buriedColour.setText(MessageManager.getString("label.buried_index"));
-    buriedColour.addActionListener(new java.awt.event.ActionListener()
+    buriedColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1033,7 +998,7 @@ public class GAlignFrame extends JInternalFrame
     });
     userDefinedColour.setText(MessageManager
             .getString("action.user_defined"));
-    userDefinedColour.addActionListener(new java.awt.event.ActionListener()
+    userDefinedColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1043,7 +1008,7 @@ public class GAlignFrame extends JInternalFrame
     });
     PIDColour
             .setText(MessageManager.getString("label.percentage_identity"));
-    PIDColour.addActionListener(new java.awt.event.ActionListener()
+    PIDColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1053,7 +1018,7 @@ public class GAlignFrame extends JInternalFrame
     });
     BLOSUM62Colour
             .setText(MessageManager.getString("label.blosum62_score"));
-    BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
+    BLOSUM62Colour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1062,7 +1027,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
-    nucleotideColour.addActionListener(new java.awt.event.ActionListener()
+    nucleotideColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1073,55 +1038,51 @@ public class GAlignFrame extends JInternalFrame
 
     purinePyrimidineColour.setText(MessageManager
             .getString("label.purine_pyrimidine"));
-    purinePyrimidineColour
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                purinePyrimidineColour_actionPerformed(e);
-              }
-            });
+    purinePyrimidineColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        purinePyrimidineColour_actionPerformed(e);
+      }
+    });
 
     RNAInteractionColour.setText("RNA Interaction type");
-    RNAInteractionColour
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                RNAInteractionColour_actionPerformed(e);
-              }
-            });
+    RNAInteractionColour.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        RNAInteractionColour_actionPerformed(e);
+      }
+    });
     /*
      * covariationColour.setText("Covariation");
-     * covariationColour.addActionListener(new java.awt.event.ActionListener() {
-     * public void actionPerformed(ActionEvent e) {
-     * covariationColour_actionPerformed(e); } });
+     * covariationColour.addActionListener(new ActionListener() { public void
+     * actionPerformed(ActionEvent e) { covariationColour_actionPerformed(e); }
+     * });
      */
 
     avDistanceTreeBlosumMenuItem.setText(MessageManager
             .getString("label.average_distance_bloslum62"));
-    avDistanceTreeBlosumMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                avTreeBlosumMenuItem_actionPerformed(e);
-              }
-            });
+    avDistanceTreeBlosumMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        avTreeBlosumMenuItem_actionPerformed(e);
+      }
+    });
     njTreeBlosumMenuItem.setText(MessageManager
             .getString("label.neighbour_blosum62"));
-    njTreeBlosumMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                njTreeBlosumMenuItem_actionPerformed(e);
-              }
-            });
+    njTreeBlosumMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        njTreeBlosumMenuItem_actionPerformed(e);
+      }
+    });
     annotationPanelMenuItem.setActionCommand("");
     annotationPanelMenuItem.setText(MessageManager
             .getString("label.show_annotations"));
@@ -1218,17 +1179,16 @@ public class GAlignFrame extends JInternalFrame
     });
     colourTextMenuItem.setText(MessageManager
             .getString("label.colour_text"));
-    colourTextMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                colourTextMenuItem_actionPerformed(e);
-              }
-            });
+    colourTextMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        colourTextMenuItem_actionPerformed(e);
+      }
+    });
     htmlMenuItem.setText(MessageManager.getString("label.html"));
-    htmlMenuItem.addActionListener(new java.awt.event.ActionListener()
+    htmlMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1238,7 +1198,7 @@ public class GAlignFrame extends JInternalFrame
     });
     overviewMenuItem.setText(MessageManager
             .getString("label.overview_window"));
-    overviewMenuItem.addActionListener(new java.awt.event.ActionListener()
+    overviewMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1246,45 +1206,47 @@ public class GAlignFrame extends JInternalFrame
         overviewMenuItem_actionPerformed(e);
       }
     });
+
     undoMenuItem.setEnabled(false);
     undoMenuItem.setText(MessageManager.getString("action.undo"));
-    undoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_Z, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    undoMenuItem.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         undoMenuItem_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, undoMenuItem, al);
+
     redoMenuItem.setEnabled(false);
     redoMenuItem.setText(MessageManager.getString("action.redo"));
-    redoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_Y, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    redoMenuItem.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         redoMenuItem_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, redoMenuItem, al);
+
     conservationMenuItem.setText(MessageManager
             .getString("action.by_conservation"));
-    conservationMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                conservationMenuItem_actionPerformed(e);
-              }
-            });
+    conservationMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        conservationMenuItem_actionPerformed(e);
+      }
+    });
     noColourmenuItem.setText(MessageManager.getString("label.none"));
-    noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
+    noColourmenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1293,7 +1255,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     wrapMenuItem.setText(MessageManager.getString("label.wrap"));
-    wrapMenuItem.addActionListener(new java.awt.event.ActionListener()
+    wrapMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1301,47 +1263,50 @@ public class GAlignFrame extends JInternalFrame
         wrapMenuItem_actionPerformed(e);
       }
     });
+
     printMenuItem.setText(MessageManager.getString("action.print") + "...");
-    printMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_P, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    printMenuItem.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         printMenuItem_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, printMenuItem, al);
+
     renderGapsMenuItem
             .setText(MessageManager.getString("action.show_gaps"));
     renderGapsMenuItem.setState(true);
-    renderGapsMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                renderGapsMenuItem_actionPerformed(e);
-              }
-            });
+    renderGapsMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        renderGapsMenuItem_actionPerformed(e);
+      }
+    });
+
     findMenuItem.setText(MessageManager.getString("action.find"));
-    findMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_F, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
     findMenuItem.setToolTipText(JvSwingUtils.wrapTooltip(true,
             MessageManager.getString("label.find_tip")));
-    findMenuItem.addActionListener(new java.awt.event.ActionListener()
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         findMenuItem_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, findMenuItem, al);
+
     abovePIDThreshold.setText(MessageManager
             .getString("label.above_identity_threshold"));
-    abovePIDThreshold.addActionListener(new java.awt.event.ActionListener()
+    abovePIDThreshold.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1468,8 +1433,7 @@ public class GAlignFrame extends JInternalFrame
     buttonGroup.add(showAutoLast);
     showAutoFirst.setText(MessageManager.getString("label.show_first"));
     showAutoFirst.setSelected(Cache.getDefault(
-            Preferences.SHOW_AUTOCALC_ABOVE,
-            false));
+            Preferences.SHOW_AUTOCALC_ABOVE, false));
     showAutoFirst.addActionListener(new ActionListener()
     {
       @Override
@@ -1492,7 +1456,7 @@ public class GAlignFrame extends JInternalFrame
     });
 
     nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
-    nucleotideColour.addActionListener(new java.awt.event.ActionListener()
+    nucleotideColour.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1515,69 +1479,74 @@ public class GAlignFrame extends JInternalFrame
 
     deleteGroups
             .setText(MessageManager.getString("action.undefine_groups"));
-    deleteGroups.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_U, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    deleteGroups.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         deleteGroups_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, deleteGroups, al);
+
     createGroup.setText(MessageManager.getString("action.create_groups"));
-    createGroup.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_G, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    createGroup.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         createGroup_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, createGroup, al);
+
     unGroup.setText(MessageManager.getString("action.remove_group"));
-    unGroup.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_G, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.SHIFT_MASK, false));
-    unGroup.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask()
+            | KeyEvent.SHIFT_MASK, false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         unGroup_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, unGroup, al);
+
     copy.setText(MessageManager.getString("action.copy"));
-    copy.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_C, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
 
-    copy.addActionListener(new java.awt.event.ActionListener()
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         copy_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, copy, al);
+
     cut.setText(MessageManager.getString("action.cut"));
-    cut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_X, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    cut.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         cut_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, cut, al);
+
     delete.setText(MessageManager.getString("action.delete"));
-    delete.addActionListener(new java.awt.event.ActionListener()
+    delete.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1585,35 +1554,38 @@ public class GAlignFrame extends JInternalFrame
         delete_actionPerformed(e);
       }
     });
+
     pasteMenu.setText(MessageManager.getString("action.paste"));
     pasteNew.setText(MessageManager.getString("label.to_new_alignment"));
-    pasteNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_V, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.SHIFT_MASK, false));
-    pasteNew.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask()
+            | KeyEvent.SHIFT_MASK, false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         pasteNew_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, pasteNew, al);
+
     pasteThis.setText(MessageManager.getString("label.to_this_alignment"));
-    pasteThis.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_V, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    pasteThis.addActionListener(new java.awt.event.ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         pasteThis_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, pasteThis, al);
+
     applyToAllGroups.setText(MessageManager
             .getString("label.apply_colour_to_all_groups"));
-    applyToAllGroups.addActionListener(new java.awt.event.ActionListener()
+    applyToAllGroups.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1621,7 +1593,7 @@ public class GAlignFrame extends JInternalFrame
         applyToAllGroups_actionPerformed(e);
       }
     });
-    createPNG.addActionListener(new java.awt.event.ActionListener()
+    createPNG.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1634,7 +1606,7 @@ public class GAlignFrame extends JInternalFrame
     createPNG.setText("PNG");
 
     font.setText(MessageManager.getString("action.font"));
-    font.addActionListener(new java.awt.event.ActionListener()
+    font.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1646,7 +1618,7 @@ public class GAlignFrame extends JInternalFrame
     seqLimits.setText(MessageManager
             .getString("label.show_sequence_limits"));
     seqLimits.setState(jalview.bin.Cache.getDefault("SHOW_JVSUFFIX", true));
-    seqLimits.addActionListener(new java.awt.event.ActionListener()
+    seqLimits.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1655,7 +1627,7 @@ public class GAlignFrame extends JInternalFrame
       }
     });
     epsFile.setText("EPS");
-    epsFile.addActionListener(new java.awt.event.ActionListener()
+    epsFile.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1665,7 +1637,7 @@ public class GAlignFrame extends JInternalFrame
     });
 
     createSVG.setText("SVG");
-    createSVG.addActionListener(new java.awt.event.ActionListener()
+    createSVG.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1678,7 +1650,7 @@ public class GAlignFrame extends JInternalFrame
             .getString("label.load_tree_for_sequence_set"));
     LoadtreeMenuItem.setText(MessageManager
             .getString("label.load_associated_tree"));
-    LoadtreeMenuItem.addActionListener(new java.awt.event.ActionListener()
+    LoadtreeMenuItem.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1689,7 +1661,7 @@ public class GAlignFrame extends JInternalFrame
 
     scaleAbove.setVisible(false);
     scaleAbove.setText(MessageManager.getString("action.scale_above"));
-    scaleAbove.addActionListener(new java.awt.event.ActionListener()
+    scaleAbove.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1700,7 +1672,7 @@ public class GAlignFrame extends JInternalFrame
     scaleLeft.setVisible(false);
     scaleLeft.setSelected(true);
     scaleLeft.setText(MessageManager.getString("action.scale_left"));
-    scaleLeft.addActionListener(new java.awt.event.ActionListener()
+    scaleLeft.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1711,7 +1683,7 @@ public class GAlignFrame extends JInternalFrame
     scaleRight.setVisible(false);
     scaleRight.setSelected(true);
     scaleRight.setText(MessageManager.getString("action.scale_right"));
-    scaleRight.addActionListener(new java.awt.event.ActionListener()
+    scaleRight.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1723,15 +1695,14 @@ public class GAlignFrame extends JInternalFrame
     centreColumnLabelsMenuItem.setState(false);
     centreColumnLabelsMenuItem.setText(MessageManager
             .getString("label.centre_column_labels"));
-    centreColumnLabelsMenuItem
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                centreColumnLabels_actionPerformed(e);
-              }
-            });
+    centreColumnLabelsMenuItem.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        centreColumnLabels_actionPerformed(e);
+      }
+    });
     followHighlightMenuItem.setVisible(true);
     followHighlightMenuItem.setState(true);
     followHighlightMenuItem.setText(MessageManager
@@ -1749,7 +1720,7 @@ public class GAlignFrame extends JInternalFrame
 
     modifyPID.setText(MessageManager
             .getString("label.modify_identity_thereshold"));
-    modifyPID.addActionListener(new java.awt.event.ActionListener()
+    modifyPID.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
@@ -1759,15 +1730,14 @@ public class GAlignFrame extends JInternalFrame
     });
     modifyConservation.setText(MessageManager
             .getString("label.modify_conservation_thereshold"));
-    modifyConservation
-            .addActionListener(new java.awt.event.ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                modifyConservation_actionPerformed(e);
-              }
-            });
+    modifyConservation.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        modifyConservation_actionPerformed(e);
+      }
+    });
     sortByTreeMenu
             .setText(MessageManager.getString("action.by_tree_order"));
     sort.setText(MessageManager.getString("action.sort"));
@@ -1887,7 +1857,8 @@ public class GAlignFrame extends JInternalFrame
             MessageManager.getString("label.view_as_cdna"));
     viewAsCdna.setToolTipText(JvSwingUtils.wrapTooltip(true,
             MessageManager.getString("label.view_as_cdna_tip")));
-    viewAsCdna.addActionListener(new ActionListener() {
+    viewAsCdna.addActionListener(new ActionListener()
+    {
       @Override
       public void actionPerformed(ActionEvent e)
       {
@@ -2150,20 +2121,22 @@ public class GAlignFrame extends JInternalFrame
         hiddenMarkers_actionPerformed(e);
       }
     });
+
     invertColSel.setText(MessageManager
             .getString("action.invert_column_selection"));
-    invertColSel.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_I, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask()
-                    | java.awt.event.KeyEvent.ALT_MASK, false));
-    invertColSel.addActionListener(new ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_I,
+            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
+            | KeyEvent.ALT_MASK, false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         invertColSel_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, invertColSel, al);
+
     tabbedPane.addChangeListener(new javax.swing.event.ChangeListener()
     {
       @Override
@@ -2190,18 +2163,20 @@ public class GAlignFrame extends JInternalFrame
         tabbedPane_focusGained(e);
       }
     });
+
     save.setText(MessageManager.getString("action.save"));
-    save.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_S, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    save.addActionListener(new ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         save_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, save, al);
+
     reload.setEnabled(false);
     reload.setText(MessageManager.getString("action.reload"));
     reload.addActionListener(new ActionListener()
@@ -2212,18 +2187,20 @@ public class GAlignFrame extends JInternalFrame
         reload_actionPerformed(e);
       }
     });
+
     newView.setText(MessageManager.getString("action.new_view"));
-    newView.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_T, Toolkit.getDefaultToolkit()
-                    .getMenuShortcutKeyMask(), false));
-    newView.addActionListener(new ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit
+            .getDefaultToolkit().getMenuShortcutKeyMask(), false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         newView_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, newView, al);
+
     tabbedPane.setToolTipText("<html><i>"
             + MessageManager.getString("label.rename_tab_eXpand_reGroup")
             + "</i></html>");
@@ -2249,30 +2226,33 @@ public class GAlignFrame extends JInternalFrame
         idRightAlign_actionPerformed(e);
       }
     });
+
     gatherViews.setEnabled(false);
     gatherViews.setText(MessageManager.getString("action.gather_views"));
-    gatherViews.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_G, 0, false));
-    gatherViews.addActionListener(new ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_G, 0, false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         gatherViews_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, gatherViews, al);
+
     expandViews.setEnabled(false);
     expandViews.setText(MessageManager.getString("action.expand_views"));
-    expandViews.setAccelerator(javax.swing.KeyStroke.getKeyStroke(
-            java.awt.event.KeyEvent.VK_X, 0, false));
-    expandViews.addActionListener(new ActionListener()
+    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_X, 0, false);
+    al = new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
         expandViews_actionPerformed(e);
       }
-    });
+    };
+    addMenuActionAndAccelerator(keyStroke, expandViews, al);
+
     pageSetup
             .setText(MessageManager.getString("action.page_setup") + "...");
     pageSetup.addActionListener(new ActionListener()
@@ -2484,6 +2464,22 @@ public class GAlignFrame extends JInternalFrame
     // selectMenu.add(listenToViewSelections);
   }
 
+  /**
+   * Adds the given action listener and key accelerator to the given menu item.
+   * Also saves in a lookup table to support lookup of action by key stroke.
+   * 
+   * @param keyStroke
+   * @param menuItem
+   * @param actionListener
+   */
+  protected void addMenuActionAndAccelerator(KeyStroke keyStroke,
+          JMenuItem menuItem, ActionListener actionListener)
+  {
+    menuItem.setAccelerator(keyStroke);
+    accelerators.put(keyStroke, actionListener);
+    menuItem.addActionListener(actionListener);
+  }
+
   protected void viewAsCdna_actionPerformed()
   {
   }
@@ -3214,7 +3210,7 @@ public class GAlignFrame extends JInternalFrame
     this.annotationSortOrder = annotationSortOrder;
   }
 
-  public Map<KeyStroke, JMenuItem> getAccelerators()
+  public Map<KeyStroke, ActionListener> getAccelerators()
   {
     return this.accelerators;
   }