Create instance of FormatAdapter
[jalview.git] / src / jalview / appletgui / CutAndPasteTransfer.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 \r
20 package jalview.appletgui;\r
21 \r
22 import java.awt.*;\r
23 import java.awt.event.*;\r
24 \r
25 import jalview.datamodel.*;\r
26 import jalview.io.*;\r
27 import jalview.jbappletgui.*;\r
28 \r
29 public class CutAndPasteTransfer\r
30     extends GCutAndPasteTransfer\r
31 {\r
32   jalview.bin.JalviewLite applet;\r
33   public CutAndPasteTransfer(boolean forImport, jalview.bin.JalviewLite mainApplet)\r
34   {\r
35     super();\r
36     applet = mainApplet;\r
37 \r
38     if (!forImport)\r
39     {\r
40       buttonPanel.setVisible(false);\r
41     }\r
42   }\r
43 \r
44   public String getText()\r
45   {\r
46     return textarea.getText();\r
47   }\r
48 \r
49   public void setText(String text)\r
50   {\r
51     textarea.setText(text);\r
52   }\r
53 \r
54   protected void ok_actionPerformed(ActionEvent e)\r
55   {\r
56     String text = getText();\r
57     int length = text.length();\r
58     textarea.append("\n");\r
59     if(textarea.getText().length()==length)\r
60     {\r
61       String warning = "\n\n#################################################\n"\r
62           +"WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"\r
63           +"\nCAN'T INPUT FULL ALIGNMENT"\r
64           +"\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"\r
65           +"\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"\r
66           +"\n#################################################\n";\r
67       textarea.setText(text.substring(0, text.length()-warning.length())\r
68           +warning);\r
69 \r
70       textarea.setCaretPosition(text.length());\r
71       return;\r
72     }\r
73 \r
74     SequenceI[] sequences = null;\r
75 \r
76     String format = IdentifyFile.Identify(text, "Paste");\r
77     sequences = new FormatAdapter().readFile(text, "Paste", format);\r
78 \r
79     if (sequences != null)\r
80     {\r
81       AlignFrame af = new AlignFrame(new Alignment(sequences), applet);\r
82       jalview.bin.JalviewLite.addFrame(af, "Cut & Paste input - " + format,\r
83                                        AlignFrame.NEW_WINDOW_WIDTH,\r
84                                        AlignFrame.NEW_WINDOW_HEIGHT);\r
85       af.statusBar.setText("Successfully pasted alignment file");\r
86     }\r
87 \r
88     Frame frame = (Frame)this.getParent();\r
89     frame.setVisible(false);\r
90   }\r
91 \r
92   protected void cancel_actionPerformed(ActionEvent e)\r
93   {\r
94     Frame frame = (Frame)this.getParent();\r
95     frame.setVisible(false);\r
96   }\r
97 \r
98 }\r