From: amwaterhouse Date: Fri, 27 May 2005 14:05:45 +0000 (+0000) Subject: Add cut and paste menus X-Git-Tag: Release_2_0~158 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6a46ce948a9fe8bb82cbc279fe8887b24b5cd59b;p=jalview.git Add cut and paste menus --- diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index 33c58fb..327609a 100755 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -10,9 +10,20 @@ package jalview.gui; import jalview.jbgui.GCutAndPasteTransfer; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.datatransfer.*; +import jalview.datamodel.Alignment; +import jalview.io.FormatAdapter; +import jalview.datamodel.SequenceI; +import javax.swing.JOptionPane; +import jalview.io.IdentifyFile; public class CutAndPasteTransfer extends GCutAndPasteTransfer { + public void setForInput() + { + getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH); + } public String getText() { @@ -23,4 +34,57 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { textarea.setText(text); } + + public void copyItem_actionPerformed(ActionEvent e) + { + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + c.setContents( new StringSelection( textarea.getText()) , null ) ; + } + + public void pasteMenu_actionPerformed(ActionEvent e) + { + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable contents = c.getContents(this); + if (contents == null) + return; + try{ + textarea.setText( (String) contents.getTransferData(DataFlavor. + stringFlavor)); + }catch(Exception ex){} + } + + public void ok_actionPerformed(ActionEvent e) + { + String format = IdentifyFile.Identify(getText(), "Paste"); + SequenceI [] sequences = null; + + if (FormatAdapter.formats.contains( format )) + sequences = FormatAdapter.readFile(getText(), "Paste", format); + + + if(sequences!=null) + { + AlignFrame af = new AlignFrame(new Alignment(sequences)); + af.currentFileFormat = format; + Desktop.addInternalFrame(af, "Cut & Paste input - "+format, + AlignFrame.NEW_WINDOW_WIDTH, + AlignFrame.NEW_WINDOW_HEIGHT); + af.statusBar.setText("Successfully pasted alignment file"); + } + else + JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n" + +"Formats currently supported are\n" + +"Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM", + "Error parsing text", JOptionPane.WARNING_MESSAGE); + + } + + public void cancel_actionPerformed(ActionEvent e) + { + try{ + this.setClosed(true); + }catch(Exception ex){} + } + + }