327609a686e9f907529db9a9f82349760accb6eb
[jalview.git] / src / jalview / gui / CutAndPasteTransfer.java
1 /********************
2  * 2004 Jalview Reengineered
3  * Barton Group
4  * Dundee University
5  *
6  * AM Waterhouse
7  *******************/
8
9 package jalview.gui;
10
11 import jalview.jbgui.GCutAndPasteTransfer;
12 import java.awt.*;
13 import java.awt.event.ActionEvent;
14 import java.awt.datatransfer.*;
15 import jalview.datamodel.Alignment;
16 import jalview.io.FormatAdapter;
17 import jalview.datamodel.SequenceI;
18 import javax.swing.JOptionPane;
19 import jalview.io.IdentifyFile;
20
21 public class CutAndPasteTransfer extends GCutAndPasteTransfer
22 {
23   public void setForInput()
24   {
25     getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
26   }
27
28   public String getText()
29   {
30     return textarea.getText();
31   }
32
33   public void setText(String text)
34   {
35     textarea.setText(text);
36   }
37
38   public void copyItem_actionPerformed(ActionEvent e)
39   {
40     Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
41     c.setContents( new StringSelection( textarea.getText()) , null ) ;
42   }
43
44   public void pasteMenu_actionPerformed(ActionEvent e)
45   {
46     Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
47     Transferable contents = c.getContents(this);
48     if (contents == null)
49       return;
50     try{
51       textarea.setText( (String) contents.getTransferData(DataFlavor.
52           stringFlavor));
53     }catch(Exception ex){}
54   }
55
56   public void ok_actionPerformed(ActionEvent e)
57   {
58       String format = IdentifyFile.Identify(getText(), "Paste");
59       SequenceI [] sequences = null;
60
61       if (FormatAdapter.formats.contains( format ))
62         sequences = FormatAdapter.readFile(getText(), "Paste", format);
63
64
65         if(sequences!=null)
66         {
67           AlignFrame af = new AlignFrame(new Alignment(sequences));
68           af.currentFileFormat = format;
69           Desktop.addInternalFrame(af, "Cut & Paste input - "+format,
70                            AlignFrame.NEW_WINDOW_WIDTH,
71                            AlignFrame.NEW_WINDOW_HEIGHT);
72           af.statusBar.setText("Successfully pasted alignment file");
73         }
74         else
75           JOptionPane.showInternalMessageDialog(Desktop.desktop, "Couldn't read the pasted text.\n"
76                                         +"Formats currently supported are\n"
77                                         +"Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM",
78                                         "Error parsing text", JOptionPane.WARNING_MESSAGE);
79
80   }
81
82   public void cancel_actionPerformed(ActionEvent e)
83   {
84     try{
85       this.setClosed(true);
86     }catch(Exception ex){}
87   }
88
89
90 }