2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
21 import java.awt.event.*;
23 import jalview.datamodel.*;
25 import jalview.schemes.TCoffeeColourScheme;
27 public class CutAndPasteTransfer extends Panel implements ActionListener,
30 boolean pdbImport = false;
32 boolean treeImport = false;
34 boolean annotationImport = false;
38 AlignFrame alignFrame;
40 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
50 this.alignFrame = alignFrame;
54 buttonPanel.setVisible(false);
58 public String getText()
60 return textarea.getText();
63 public void setText(String text)
65 textarea.setText(text);
68 public void setPDBImport(Sequence seq)
71 accept.setLabel("Accept");
72 addSequences.setVisible(false);
76 public void setTreeImport()
79 accept.setLabel("Accept");
80 addSequences.setVisible(false);
83 public void setAnnotationImport()
85 annotationImport = true;
86 accept.setLabel("Accept");
87 addSequences.setVisible(false);
90 public void actionPerformed(ActionEvent evt)
92 if (evt.getSource() == accept)
96 else if (evt.getSource() == addSequences)
100 else if (evt.getSource() == cancel)
106 protected void ok(boolean newWindow)
108 String text = getText();
109 int length = text.length();
110 textarea.append("\n");
111 if (textarea.getText().length() == length)
113 String warning = "\n\n#################################################\n"
114 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
115 + "\nCAN'T INPUT FULL ALIGNMENT"
116 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
117 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
118 + "\n#################################################\n";
119 textarea.setText(text.substring(0, text.length() - warning.length())
122 textarea.setCaretPosition(text.length());
127 PDBEntry pdb = new PDBEntry();
130 if (alignFrame.alignPanel.av.applet.jmolAvailable)
131 new jalview.appletgui.AppletJmol(pdb, new Sequence[]
132 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
135 new MCview.AppletPDBViewer(pdb, new Sequence[]
136 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
143 jalview.io.NewickFile fin = new jalview.io.NewickFile(
144 textarea.getText(), "Paste");
147 if (fin.getTree() != null)
149 alignFrame.loadTree(fin, "Pasted tree file");
152 } catch (Exception ex)
154 // TODO: JAL-1102 - should have a warning message in dialog, not simply
155 // overwrite the broken input data with the exception
156 textarea.setText("Could not parse Newick file!\n" + ex);
160 else if (annotationImport)
162 TCoffeeScoreFile tcf = null;
165 tcf = new TCoffeeScoreFile(textarea.getText(),
166 jalview.io.AppletFormatAdapter.PASTE);
169 if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(),
172 alignFrame.tcoffeeColour.setEnabled(true);
173 alignFrame.alignPanel.fontChanged();
174 alignFrame.changeColour(new TCoffeeColourScheme(
175 alignFrame.viewport.getAlignment()));
177 .setText("Successfully pasted T-Coffee scores to alignment.");
181 // file valid but didn't get added to alignment for some reason
182 alignFrame.statusBar.setText("Failed to add T-Coffee scores: "
183 + (tcf.getWarningMessage() != null ? tcf
184 .getWarningMessage() : ""));
191 } catch (Exception x)
197 if (new AnnotationFile().readAnnotationFile(
198 alignFrame.viewport.getAlignment(), textarea.getText(),
199 jalview.io.AppletFormatAdapter.PASTE))
201 alignFrame.alignPanel.fontChanged();
202 alignFrame.alignPanel.setScrollValues(0, 0);
204 .setText("Successfully pasted annotation to alignment.");
209 if (!alignFrame.parseFeaturesFile(textarea.getText(),
210 jalview.io.AppletFormatAdapter.PASTE))
213 .setText("Couldn't parse pasted text as a valid annotation, feature, GFF, or T-Coffee score file.");
218 else if (alignFrame != null)
222 String format = new IdentifyFile().Identify(text,
223 AppletFormatAdapter.PASTE);
226 al = new AppletFormatAdapter().readFile(text,
227 AppletFormatAdapter.PASTE, format);
228 } catch (java.io.IOException ex)
230 ex.printStackTrace();
237 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
238 "Cut & Paste input - " + format, false);
239 af.statusBar.setText("Successfully pasted alignment file");
243 alignFrame.addSequences(al.getSequencesArray());
245 .setText("Successfully pasted alignment file");
249 // TODO: dialog should indicate if data was parsed correctly or not - see
251 if (this.getParent() instanceof Frame)
253 ((Frame) this.getParent()).setVisible(false);
257 ((Dialog) this.getParent()).setVisible(false);
261 protected void cancel()
263 textarea.setText("");
264 if (this.getParent() instanceof Frame)
266 ((Frame) this.getParent()).setVisible(false);
270 ((Dialog) this.getParent()).setVisible(false);
274 protected TextArea textarea = new TextArea();
276 Button accept = new Button("New Window");
278 Button addSequences = new Button("Add to Current Alignment");
280 Button cancel = new Button("Close");
282 protected Panel buttonPanel = new Panel();
284 BorderLayout borderLayout1 = new BorderLayout();
286 private void jbInit() throws Exception
288 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
289 textarea.setText("Paste your alignment file here");
290 textarea.addMouseListener(this);
291 this.setLayout(borderLayout1);
292 accept.addActionListener(this);
293 addSequences.addActionListener(this);
294 cancel.addActionListener(this);
295 this.add(buttonPanel, BorderLayout.SOUTH);
296 buttonPanel.add(accept, null);
297 buttonPanel.add(addSequences);
298 buttonPanel.add(cancel, null);
299 this.add(textarea, java.awt.BorderLayout.CENTER);
302 public void mousePressed(MouseEvent evt)
304 if (textarea.getText().startsWith("Paste your"))
306 textarea.setText("");
310 public void mouseReleased(MouseEvent evt)
314 public void mouseClicked(MouseEvent evt)
318 public void mouseEntered(MouseEvent evt)
322 public void mouseExited(MouseEvent evt)