From 2f8b445a1c306a3566454bf5fcf87db6b22da683 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 10 Feb 2005 17:52:35 +0000 Subject: [PATCH] Cut and paste implemented --- src/jalview/gui/AlignFrame.java | 131 +++++++++++++++++++++++++++++++++--- src/jalview/jbgui/GAlignFrame.java | 86 +++++++++++++++++++++++ 2 files changed, 206 insertions(+), 11 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f3d0d99..83f7ba0 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -23,7 +23,8 @@ import java.awt.print.*; import javax.swing.*; import javax.swing.event.*; import java.util.*; -import jalview.datamodel.SequenceI; +import java.awt.datatransfer.*; + public class AlignFrame extends GAlignFrame { @@ -38,7 +39,20 @@ public class AlignFrame extends GAlignFrame fontNameMenuItem.setText(viewport.getFont().getName()); fontSizeMenuItem.setText(viewport.getFont().getSize()+""); - AlignmentUtil.fetchSequenceFeatures(al, alignPanel); + addInternalFrameListener(new InternalFrameAdapter() + { + public void internalFrameActivated(InternalFrameEvent evt) + { + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { alignPanel.requestFocus(); } + }); + + } + }); + + AlignmentUtil.fetchSequenceFeatures(al, alignPanel); } protected void saveAs_actionPerformed(ActionEvent e) @@ -183,6 +197,110 @@ public class AlignFrame extends GAlignFrame alignPanel.RefreshPanels(); } + protected void copy_actionPerformed(ActionEvent e) + { + if(viewport.getRubberbandGroup()==null) + return; + + SequenceGroup sg = viewport.getRubberbandGroup(); + + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + StringBuffer buffer= new StringBuffer(); + + for(int i=0; i 500) + newHeight = 500; + Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight); + } + else + { + viewport.setEndSeq(viewport.alignment.getHeight()); + viewport.alignment.getWidth(); + alignPanel.RefreshPanels(); + } + + }catch(Exception ex){}// could be anything being pasted in here + + } + + + protected void cut_actionPerformed(ActionEvent e) + { + copy_actionPerformed(null); + delete_actionPerformed(null); + } + + protected void delete_actionPerformed(ActionEvent e) + { + if (viewport.getRubberbandGroup() == null) + return; + + SequenceGroup sg = viewport.getRubberbandGroup(); + for (int i=0;i < sg.sequences.size(); i++) + viewport.getAlignment().deleteSequence(sg.getSequenceAt(i)); + + viewport.alignment.deleteGroup(sg); + viewport.resetSeqLimits( alignPanel.seqPanel.seqCanvas.getHeight()); + if(viewport.getAlignment().getHeight()<1) + try + { + this.setClosed(true); + }catch(Exception ex){} + alignPanel.RefreshPanels(); + + } + + protected void redoMenuItem_actionPerformed(ActionEvent e) { @@ -904,13 +1022,4 @@ public class AlignFrame extends GAlignFrame g.drawString("Clustal Alignment Web Service running", 30,30); } } - - - public void doKeyPressed(KeyEvent evt) - { - if(evt.isControlDown() && evt.getKeyChar()=='f') - findMenuItem_actionPerformed(null); - } - - } diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index 764f5cf..5c6494e 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -83,6 +83,12 @@ public class GAlignFrame extends JInternalFrame protected JCheckBoxMenuItem sequenceFeatures = new JCheckBoxMenuItem(); protected JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem(); JMenuItem deleteGroups = new JMenuItem(); + JMenuItem delete = new JMenuItem(); + JMenuItem copy = new JMenuItem(); + JMenuItem cut = new JMenuItem(); + JMenu jMenu1 = new JMenu(); + JMenuItem pasteNew = new JMenuItem(); + JMenuItem pasteThis = new JMenuItem(); public GAlignFrame() { @@ -619,6 +625,52 @@ public class GAlignFrame extends JInternalFrame deleteGroups_actionPerformed(e); } }); + copy.setText("Copy"); + copy.setMnemonic(KeyEvent.VK_C); + + copy.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + copy_actionPerformed(e); + } + }); + // pasteNew.setText("Paste (as new alignment)"); + cut.setText("Cut"); + cut.setMnemonic(KeyEvent.VK_X); + cut.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cut_actionPerformed(e); + } + }); + delete.setText("Delete"); + delete.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + delete_actionPerformed(e); + } + }); + jMenu1.setMnemonic('V'); + jMenu1.setText("Paste"); + pasteNew.setText("as new alignment"); + pasteNew.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + pasteNew_actionPerformed(e); + } + }); + pasteThis.setText("add to this alignment"); + pasteThis.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + pasteThis_actionPerformed(e); + } + }); alignFrameMenuBar.add(fileMenu); alignFrameMenuBar.add(editMenu); alignFrameMenuBar.add(searchMenu); @@ -633,6 +685,11 @@ public class GAlignFrame extends JInternalFrame fileMenu.add(printMenuItem); fileMenu.addSeparator(); fileMenu.add(closeMenuItem); + editMenu.add(copy); + editMenu.add(jMenu1); + editMenu.add(cut); + editMenu.add(delete); + editMenu.addSeparator(); editMenu.add(undoMenuItem); editMenu.add(redoMenuItem); editMenu.addSeparator(); @@ -693,6 +750,8 @@ public class GAlignFrame extends JInternalFrame alignMenu.add(clustalAlignMenuItem); alignMenu.add(pdbTest); this.getContentPane().add(statusBar, BorderLayout.SOUTH); + jMenu1.add(pasteNew); + jMenu1.add(pasteThis); } protected void saveAs_actionPerformed(ActionEvent e) @@ -1007,5 +1066,32 @@ public class GAlignFrame extends JInternalFrame } + protected void copy_actionPerformed(ActionEvent e) + { + + } + + + protected void cut_actionPerformed(ActionEvent e) + { + + } + + protected void delete_actionPerformed(ActionEvent e) + { + + } + + protected void pasteNew_actionPerformed(ActionEvent e) + { + + } + + protected void pasteThis_actionPerformed(ActionEvent e) + { + + } + + } -- 1.7.10.2