Keylistener added to frame and seqcanvas
authoramwaterhouse <Andrew Waterhouse>
Fri, 9 Dec 2005 11:12:56 +0000 (11:12 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 9 Dec 2005 11:12:56 +0000 (11:12 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignmentPanel.java

index cf4c40d..0670a31 100755 (executable)
@@ -48,6 +48,7 @@ public class AlignFrame extends Frame
     {\r
       ex.printStackTrace();\r
     }\r
+\r
     this.applet = applet;\r
     viewport = new AlignViewport(al, applet);\r
     alignPanel = new AlignmentPanel(this, viewport);\r
@@ -56,30 +57,6 @@ public class AlignFrame extends Frame
 \r
     if(applet!=null)\r
     {\r
-      String treeFile = applet.getParameter("treeFile");\r
-      if (treeFile != null)\r
-      {\r
-        try\r
-        {\r
-          jalview.io.NewickFile fin = new jalview.io.NewickFile(applet.\r
-              getCodeBase() + treeFile, "URL");\r
-          fin.parse();\r
-\r
-          if (fin.getTree() != null)\r
-          {\r
-            TreePanel tp = null;\r
-            tp = new TreePanel(viewport, viewport.getAlignment().getSequences(),\r
-                               fin, "FromFile", applet.getCodeBase() + treeFile);\r
-            jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);\r
-            addTreeMenuItem(tp, treeFile);\r
-          }\r
-        }\r
-        catch (Exception ex)\r
-        {\r
-          ex.printStackTrace();\r
-        }\r
-      }\r
-\r
       String param = applet.getParameter("sortBy");\r
       if (param != null)\r
       {\r
@@ -119,6 +96,13 @@ public class AlignFrame extends Frame
 \r
     }\r
 \r
+   MyKeyAdapter keyAdapter = new MyKeyAdapter();\r
+   //Some JVMS send keyevents to Top frame or lowest panel,\r
+   //Havent worked out why yet. So add to both this frame and seqCanvas for now\r
+   this.addKeyListener(keyAdapter);\r
+   alignPanel.seqPanel.seqCanvas.addKeyListener(keyAdapter);\r
+   alignPanel.idPanel.idCanvas.addKeyListener(keyAdapter);\r
+\r
     this.addWindowListener(new WindowAdapter()\r
     {\r
       public void windowClosing(WindowEvent e)\r
@@ -141,8 +125,6 @@ public class AlignFrame extends Frame
    jalview.bin.JalviewLite.addFrame(this, title,\r
                                     NEW_WINDOW_WIDTH,\r
                                     NEW_WINDOW_HEIGHT);\r
-\r
-\r
   }\r
 \r
   public AlignViewport getAlignViewport()\r
@@ -238,6 +220,62 @@ public class AlignFrame extends Frame
   }\r
 \r
 \r
+  class MyKeyAdapter extends KeyAdapter\r
+  {\r
+\r
+    public void keyPressed(KeyEvent evt)\r
+    {\r
+      switch (evt.getKeyCode())\r
+      {\r
+        case 27: // escape key\r
+          deselectAllSequenceMenuItem_actionPerformed(null);\r
+          break;\r
+        case KeyEvent.VK_X:\r
+          if (evt.isControlDown() || evt.isMetaDown())\r
+          {\r
+            cut_actionPerformed(null);\r
+          }\r
+          break;\r
+        case KeyEvent.VK_C:\r
+          if (evt.isControlDown() || evt.isMetaDown())\r
+          {\r
+            copy_actionPerformed(null);\r
+          }\r
+          break;\r
+        case KeyEvent.VK_V:\r
+          if (evt.isControlDown() || evt.isMetaDown())\r
+          {\r
+            paste(true);\r
+          }\r
+          break;\r
+        case KeyEvent.VK_A:\r
+          if (evt.isControlDown() || evt.isMetaDown())\r
+          {\r
+            selectAllSequenceMenuItem_actionPerformed(null);\r
+          }\r
+          break;\r
+        case KeyEvent.VK_DOWN:\r
+          moveSelectedSequences(false);\r
+          break;\r
+        case KeyEvent.VK_UP:\r
+          moveSelectedSequences(true);\r
+          break;\r
+        case KeyEvent.VK_F:\r
+          if (evt.isControlDown())\r
+          {\r
+            findMenuItem_actionPerformed(null);\r
+          }\r
+          break;\r
+        case KeyEvent.VK_BACK_SPACE:\r
+        case KeyEvent.VK_DELETE:\r
+          cut_actionPerformed(null);\r
+          break;\r
+\r
+      }\r
+    }\r
+  }\r
+\r
+\r
   public void inputText_actionPerformed(ActionEvent e)\r
   {\r
     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, applet);\r
@@ -1350,7 +1388,7 @@ public class AlignFrame extends Frame
     jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);\r
   }\r
 \r
-  void addTreeMenuItem(final TreePanel treePanel, String title)\r
+  public void addTreeMenuItem(final TreePanel treePanel, String title)\r
   {\r
     final MenuItem item = new MenuItem(title);\r
     sortByTreeMenu.add(item);\r
index 81b999f..e0767d1 100755 (executable)
@@ -44,6 +44,14 @@ public class AlignmentPanel extends Panel implements AdjustmentListener
 \r
   public AlignmentPanel(AlignFrame af, final AlignViewport av)\r
   {\r
+    this.addKeyListener(new KeyAdapter()\r
+    {\r
+      public void keyPressed(KeyEvent ke)\r
+      {\r
+        System.out.println("Align Panel "+ke);\r
+      }\r
+    });\r
+\r
     try\r
     {\r
       jbInit();\r
@@ -78,9 +86,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener
     hscroll.addAdjustmentListener(this);\r
     vscroll.addAdjustmentListener(this);\r
 \r
-    seqPanel.seqCanvas.addKeyListener(new MyKeyAdapter());\r
-    idPanel.idCanvas.addKeyListener(new MyKeyAdapter());\r
-\r
     addComponentListener(new ComponentAdapter()\r
     {\r
       public void componentResized(ComponentEvent evt)\r
@@ -103,61 +108,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener
 \r
   }\r
 \r
-  class MyKeyAdapter\r
-      extends KeyAdapter\r
-  {\r
-    public void keyPressed(KeyEvent evt)\r
-    {\r
-      // System.out.println(evt.getKeyCode()); log.\r
-      switch (evt.getKeyCode())\r
-      {\r
-        case 27: // escape key\r
-          alignFrame.deselectAllSequenceMenuItem_actionPerformed(null);\r
-          break;\r
-        case KeyEvent.VK_X:\r
-          if (evt.isControlDown())\r
-          {\r
-            alignFrame.cut_actionPerformed(null);\r
-          }\r
-          break;\r
-        case KeyEvent.VK_C:\r
-          if (evt.isControlDown())\r
-          {\r
-            alignFrame.copy_actionPerformed(null);\r
-          }\r
-          break;\r
-        case KeyEvent.VK_V:\r
-          if (evt.isControlDown())\r
-          {\r
-            alignFrame.paste(true);\r
-          }\r
-          break;\r
-        case KeyEvent.VK_A:\r
-          if (evt.isControlDown())\r
-          {\r
-            alignFrame.selectAllSequenceMenuItem_actionPerformed(null);\r
-          }\r
-          break;\r
-        case KeyEvent.VK_DOWN:\r
-          alignFrame.moveSelectedSequences(false);\r
-          break;\r
-        case KeyEvent.VK_UP:\r
-          alignFrame.moveSelectedSequences(true);\r
-          break;\r
-        case KeyEvent.VK_F:\r
-          if (evt.isControlDown())\r
-          {\r
-            alignFrame.findMenuItem_actionPerformed(null);\r
-          }\r
-          break;\r
-        case KeyEvent.VK_BACK_SPACE:\r
-        case KeyEvent.VK_DELETE:\r
-          alignFrame.cut_actionPerformed(null);\r
-          break;\r
-\r
-      }\r
-    }\r
-  }\r
 \r
   public void fontChanged()\r
   {\r