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;
26 import jalview.util.MessageManager;
28 public class CutAndPasteTransfer extends Panel implements ActionListener,
31 boolean pdbImport = false;
33 boolean treeImport = false;
35 boolean annotationImport = false;
39 AlignFrame alignFrame;
41 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
51 this.alignFrame = alignFrame;
55 buttonPanel.setVisible(false);
59 public String getText()
61 return textarea.getText();
64 public void setText(String text)
66 textarea.setText(text);
69 public void setPDBImport(Sequence seq)
72 accept.setLabel(MessageManager.getString("action.accept"));
73 addSequences.setVisible(false);
77 public void setTreeImport()
80 accept.setLabel(MessageManager.getString("action.accept"));
81 addSequences.setVisible(false);
84 public void setAnnotationImport()
86 annotationImport = true;
87 accept.setLabel(MessageManager.getString("action.accept"));
88 addSequences.setVisible(false);
91 public void actionPerformed(ActionEvent evt)
93 if (evt.getSource() == accept)
97 else if (evt.getSource() == addSequences)
101 else if (evt.getSource() == cancel)
107 protected void ok(boolean newWindow)
109 String text = getText();
110 int length = text.length();
111 textarea.append("\n");
112 if (textarea.getText().length() == length)
114 String warning = "\n\n#################################################\n"
115 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
116 + "\nCAN'T INPUT FULL ALIGNMENT"
117 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
118 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
119 + "\n#################################################\n";
120 textarea.setText(text.substring(0, text.length() - warning.length())
123 textarea.setCaretPosition(text.length());
128 PDBEntry pdb = new PDBEntry();
131 if (alignFrame.alignPanel.av.applet.jmolAvailable)
132 new jalview.appletgui.AppletJmol(pdb, new Sequence[]
133 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
136 new MCview.AppletPDBViewer(pdb, new Sequence[]
137 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
144 jalview.io.NewickFile fin = new jalview.io.NewickFile(
145 textarea.getText(), "Paste");
148 if (fin.getTree() != null)
150 alignFrame.loadTree(fin, "Pasted tree file");
153 } catch (Exception ex)
155 // TODO: JAL-1102 - should have a warning message in dialog, not simply
156 // overwrite the broken input data with the exception
157 textarea.setText(MessageManager.formatMessage("label.could_not_parse_newick_file", new String[]{ex.getMessage()}));
161 else if (annotationImport)
163 TCoffeeScoreFile tcf = null;
166 tcf = new TCoffeeScoreFile(textarea.getText(),
167 jalview.io.AppletFormatAdapter.PASTE);
170 if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(),
173 alignFrame.tcoffeeColour.setEnabled(true);
174 alignFrame.alignPanel.fontChanged();
175 alignFrame.changeColour(new TCoffeeColourScheme(
176 alignFrame.viewport.getAlignment()));
178 .setText(MessageManager.getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
182 // file valid but didn't get added to alignment for some reason
183 alignFrame.statusBar.setText(MessageManager.formatMessage("label.failed_add_tcoffee_scores", new String[]{(tcf.getWarningMessage() != null ? tcf.getWarningMessage() : "")}));
190 } catch (Exception x)
196 if (new AnnotationFile().readAnnotationFile(
197 alignFrame.viewport.getAlignment(), textarea.getText(),
198 jalview.io.AppletFormatAdapter.PASTE))
200 alignFrame.alignPanel.fontChanged();
201 alignFrame.alignPanel.setScrollValues(0, 0);
203 .setText("Successfully pasted annotation to alignment.");
208 if (!alignFrame.parseFeaturesFile(textarea.getText(),
209 jalview.io.AppletFormatAdapter.PASTE))
212 .setText("Couldn't parse pasted text as a valid annotation, feature, GFF, or T-Coffee score file.");
217 else if (alignFrame != null)
221 String format = new IdentifyFile().Identify(text,
222 AppletFormatAdapter.PASTE);
225 al = new AppletFormatAdapter().readFile(text,
226 AppletFormatAdapter.PASTE, format);
227 } catch (java.io.IOException ex)
229 ex.printStackTrace();
236 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
237 "Cut & Paste input - " + format, false);
238 af.statusBar.setText(MessageManager.getString("label.successfully_pasted_annotation_to_alignment"));
242 alignFrame.addSequences(al.getSequencesArray());
244 .setText(MessageManager.getString("label.successfully_pasted_alignment_file"));
248 // TODO: dialog should indicate if data was parsed correctly or not - see
250 if (this.getParent() instanceof Frame)
252 ((Frame) this.getParent()).setVisible(false);
256 ((Dialog) this.getParent()).setVisible(false);
260 protected void cancel()
262 textarea.setText("");
263 if (this.getParent() instanceof Frame)
265 ((Frame) this.getParent()).setVisible(false);
269 ((Dialog) this.getParent()).setVisible(false);
273 protected TextArea textarea = new TextArea();
275 Button accept = new Button("New Window");
277 Button addSequences = new Button("Add to Current Alignment");
279 Button cancel = new Button("Close");
281 protected Panel buttonPanel = new Panel();
283 BorderLayout borderLayout1 = new BorderLayout();
285 private void jbInit() throws Exception
287 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
288 textarea.setText(MessageManager.getString("label.paste_your_alignment_file"));
289 textarea.addMouseListener(this);
290 this.setLayout(borderLayout1);
291 accept.addActionListener(this);
292 addSequences.addActionListener(this);
293 cancel.addActionListener(this);
294 this.add(buttonPanel, BorderLayout.SOUTH);
295 buttonPanel.add(accept, null);
296 buttonPanel.add(addSequences);
297 buttonPanel.add(cancel, null);
298 this.add(textarea, java.awt.BorderLayout.CENTER);
301 public void mousePressed(MouseEvent evt)
303 if (textarea.getText().startsWith(MessageManager.getString("label.paste_your")))
305 textarea.setText("");
309 public void mouseReleased(MouseEvent evt)
313 public void mouseClicked(MouseEvent evt)
317 public void mouseEntered(MouseEvent evt)
321 public void mouseExited(MouseEvent evt)