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