2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\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
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
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
20 package jalview.appletgui;
\r
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
26 import jalview.io.*;
\r
28 public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener
\r
30 boolean pdbImport = false;
\r
31 boolean treeImport = false;
\r
33 AlignFrame alignFrame;
\r
35 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
\r
39 } catch (Exception e) {
\r
40 e.printStackTrace();
\r
43 this.alignFrame = alignFrame;
\r
47 buttonPanel.setVisible(false);
\r
51 public String getText()
\r
53 return textarea.getText();
\r
56 public void setText(String text)
\r
58 textarea.setText(text);
\r
61 public void setPDBImport(Sequence seq)
\r
68 public void actionPerformed(ActionEvent evt)
\r
70 if(evt.getSource()==ok)
\r
71 ok_actionPerformed();
\r
72 else if(evt.getSource()==cancel)
\r
73 cancel_actionPerformed();
\r
76 protected void ok_actionPerformed()
\r
78 String text = getText();
\r
79 int length = text.length();
\r
80 textarea.append("\n");
\r
81 if(textarea.getText().length()==length)
\r
83 String warning = "\n\n#################################################\n"
\r
84 +"WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
\r
85 +"\nCAN'T INPUT FULL ALIGNMENT"
\r
86 +"\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
\r
87 +"\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
\r
88 +"\n#################################################\n";
\r
89 textarea.setText(text.substring(0, text.length()-warning.length())
\r
92 textarea.setCaretPosition(text.length());
\r
97 new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE,
\r
99 alignFrame.getSeqcanvas());
\r
101 else if(treeImport)
\r
104 jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),
\r
108 if(fin.getTree()!=null)
\r
109 alignFrame.loadTree(fin, "Pasted tree file");
\r
112 catch (Exception ex)
\r
114 textarea.setText("Could not parse Newick file!\n" + ex);
\r
118 else if(alignFrame!=null)
\r
120 SequenceI[] sequences = null;
\r
122 String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE);
\r
124 sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);
\r
125 }catch(java.io.IOException ex)
\r
127 ex.printStackTrace();
\r
129 if (sequences != null)
\r
131 AlignFrame af = new AlignFrame(new Alignment(sequences), alignFrame.viewport.applet,
\r
132 "Cut & Paste input - " + format,
\r
134 af.statusBar.setText("Successfully pasted alignment file");
\r
138 if(this.getParent() instanceof Frame)
\r
139 ((Frame)this.getParent()).setVisible(false);
\r
141 ((Dialog)this.getParent()).setVisible(false);
\r
144 protected void cancel_actionPerformed()
\r
146 textarea.setText("");
\r
147 if(this.getParent() instanceof Frame)
\r
148 ((Frame)this.getParent()).setVisible(false);
\r
150 ((Dialog)this.getParent()).setVisible(false);
\r
153 protected TextArea textarea = new TextArea();
\r
154 Button ok = new Button();
\r
155 Button cancel = new Button();
\r
156 protected Panel buttonPanel = new Panel();
\r
157 BorderLayout borderLayout1 = new BorderLayout();
\r
160 private void jbInit() throws Exception {
\r
161 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
\r
162 textarea.setText("Paste your alignment file here");
\r
163 textarea.addMouseListener(this);
\r
164 this.setLayout(borderLayout1);
\r
166 ok.addActionListener(this);
\r
167 cancel.setLabel("Cancel");
\r
168 cancel.addActionListener(this);
\r
169 this.add(buttonPanel, BorderLayout.SOUTH);
\r
170 buttonPanel.add(ok, null);
\r
171 buttonPanel.add(cancel, null);
\r
172 this.add(textarea, java.awt.BorderLayout.CENTER);
\r
175 public void mousePressed(MouseEvent evt) {
\r
176 if (textarea.getText().startsWith("Paste your")) {
\r
177 textarea.setText("");
\r
180 public void mouseReleased(MouseEvent evt){}
\r
181 public void mouseClicked(MouseEvent evt){}
\r
182 public void mouseEntered(MouseEvent evt){}
\r
183 public void mouseExited(MouseEvent evt){}
\r