2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
28 public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener
30 boolean pdbImport = false;
31 boolean treeImport = false;
33 AlignFrame alignFrame;
35 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
39 } catch (Exception e) {
43 this.alignFrame = alignFrame;
47 buttonPanel.setVisible(false);
51 public String getText()
53 return textarea.getText();
56 public void setText(String text)
58 textarea.setText(text);
61 public void setPDBImport(Sequence seq)
68 public void actionPerformed(ActionEvent evt)
70 if(evt.getSource()==ok)
72 else if(evt.getSource()==cancel)
73 cancel_actionPerformed();
76 protected void ok_actionPerformed()
78 String text = getText();
79 int length = text.length();
80 textarea.append("\n");
81 if(textarea.getText().length()==length)
83 String warning = "\n\n#################################################\n"
84 +"WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
85 +"\nCAN'T INPUT FULL ALIGNMENT"
86 +"\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
87 +"\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
88 +"\n#################################################\n";
89 textarea.setText(text.substring(0, text.length()-warning.length())
92 textarea.setCaretPosition(text.length());
97 new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE,
99 alignFrame.getSeqcanvas());
104 jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),
108 if(fin.getTree()!=null)
109 alignFrame.loadTree(fin, "Pasted tree file");
114 textarea.setText("Could not parse Newick file!\n" + ex);
118 else if(alignFrame!=null)
120 SequenceI[] sequences = null;
122 String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE);
124 sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format);
125 }catch(java.io.IOException ex)
127 ex.printStackTrace();
129 if (sequences != null)
131 AlignFrame af = new AlignFrame(new Alignment(sequences), alignFrame.viewport.applet,
132 "Cut & Paste input - " + format,
134 af.statusBar.setText("Successfully pasted alignment file");
138 if(this.getParent() instanceof Frame)
139 ((Frame)this.getParent()).setVisible(false);
141 ((Dialog)this.getParent()).setVisible(false);
144 protected void cancel_actionPerformed()
146 textarea.setText("");
147 if(this.getParent() instanceof Frame)
148 ((Frame)this.getParent()).setVisible(false);
150 ((Dialog)this.getParent()).setVisible(false);
153 protected TextArea textarea = new TextArea();
154 Button ok = new Button();
155 Button cancel = new Button();
156 protected Panel buttonPanel = new Panel();
157 BorderLayout borderLayout1 = new BorderLayout();
160 private void jbInit() throws Exception {
161 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
162 textarea.setText("Paste your alignment file here");
163 textarea.addMouseListener(this);
164 this.setLayout(borderLayout1);
166 ok.addActionListener(this);
167 cancel.setLabel("Cancel");
168 cancel.addActionListener(this);
169 this.add(buttonPanel, BorderLayout.SOUTH);
170 buttonPanel.add(ok, null);
171 buttonPanel.add(cancel, null);
172 this.add(textarea, java.awt.BorderLayout.CENTER);
175 public void mousePressed(MouseEvent evt) {
176 if (textarea.getText().startsWith("Paste your")) {
177 textarea.setText("");
180 public void mouseReleased(MouseEvent evt){}
181 public void mouseClicked(MouseEvent evt){}
182 public void mouseEntered(MouseEvent evt){}
183 public void mouseExited(MouseEvent evt){}