2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
28 import jalview.schemes.TCoffeeColourScheme;
29 import jalview.util.MessageManager;
31 public class CutAndPasteTransfer extends Panel implements ActionListener,
34 boolean pdbImport = false;
36 boolean treeImport = false;
38 boolean annotationImport = false;
42 AlignFrame alignFrame;
44 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
54 this.alignFrame = alignFrame;
58 buttonPanel.setVisible(false);
62 public String getText()
64 return textarea.getText();
67 public void setText(String text)
69 textarea.setText(text);
72 public void setPDBImport(Sequence seq)
75 accept.setLabel(MessageManager.getString("action.accept"));
76 addSequences.setVisible(false);
80 public void setTreeImport()
83 accept.setLabel(MessageManager.getString("action.accept"));
84 addSequences.setVisible(false);
87 public void setAnnotationImport()
89 annotationImport = true;
90 accept.setLabel(MessageManager.getString("action.accept"));
91 addSequences.setVisible(false);
94 public void actionPerformed(ActionEvent evt)
96 if (evt.getSource() == accept)
100 else if (evt.getSource() == addSequences)
104 else if (evt.getSource() == cancel)
110 protected void ok(boolean newWindow)
112 String text = getText();
113 int length = text.length();
114 textarea.append("\n");
115 if (textarea.getText().length() == length)
117 String warning = "\n\n#################################################\n"
118 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
119 + "\nCAN'T INPUT FULL ALIGNMENT"
120 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
121 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
122 + "\n#################################################\n";
123 textarea.setText(text.substring(0, text.length() - warning.length())
126 textarea.setCaretPosition(text.length());
131 PDBEntry pdb = new PDBEntry();
134 if (alignFrame.alignPanel.av.applet.jmolAvailable)
135 new jalview.appletgui.AppletJmol(pdb, new Sequence[]
136 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
139 new MCview.AppletPDBViewer(pdb, new Sequence[]
140 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
147 jalview.io.NewickFile fin = new jalview.io.NewickFile(
148 textarea.getText(), "Paste");
151 if (fin.getTree() != null)
153 alignFrame.loadTree(fin, "Pasted tree file");
156 } catch (Exception ex)
158 // TODO: JAL-1102 - should have a warning message in dialog, not simply
159 // overwrite the broken input data with the exception
160 textarea.setText(MessageManager.formatMessage(
161 "label.could_not_parse_newick_file", new String[]
162 { ex.getMessage() }));
166 else if (annotationImport)
168 TCoffeeScoreFile tcf = null;
171 tcf = new TCoffeeScoreFile(textarea.getText(),
172 jalview.io.AppletFormatAdapter.PASTE);
175 if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(),
178 alignFrame.tcoffeeColour.setEnabled(true);
179 alignFrame.alignPanel.fontChanged();
180 alignFrame.changeColour(new TCoffeeColourScheme(
181 alignFrame.viewport.getAlignment()));
183 .setText(MessageManager
184 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
188 // file valid but didn't get added to alignment for some reason
189 alignFrame.statusBar.setText(MessageManager.formatMessage(
190 "label.failed_add_tcoffee_scores",
192 { (tcf.getWarningMessage() != null ? tcf
193 .getWarningMessage() : "") }));
200 } catch (Exception x)
206 if (new AnnotationFile().readAnnotationFile(
207 alignFrame.viewport.getAlignment(), textarea.getText(),
208 jalview.io.AppletFormatAdapter.PASTE))
210 alignFrame.alignPanel.fontChanged();
211 alignFrame.alignPanel.setScrollValues(0, 0);
213 .setText(MessageManager
214 .getString("label.successfully_pasted_annotation_to_alignment"));
219 if (!alignFrame.parseFeaturesFile(textarea.getText(),
220 jalview.io.AppletFormatAdapter.PASTE))
223 .setText(MessageManager
224 .getString("label.couldnt_parse_pasted_text_as_valid_annotation_feature_GFF_tcoffee_file"));
229 else if (alignFrame != null)
233 String format = new IdentifyFile().Identify(text,
234 AppletFormatAdapter.PASTE);
237 al = new AppletFormatAdapter().readFile(text,
238 AppletFormatAdapter.PASTE, format);
239 } catch (java.io.IOException ex)
241 ex.printStackTrace();
248 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
249 "Cut & Paste input - " + format, false);
251 .setText(MessageManager
252 .getString("label.successfully_pasted_annotation_to_alignment"));
256 alignFrame.addSequences(al.getSequencesArray());
257 alignFrame.statusBar.setText(MessageManager
258 .getString("label.successfully_pasted_alignment_file"));
262 // TODO: dialog should indicate if data was parsed correctly or not - see
264 if (this.getParent() instanceof Frame)
266 ((Frame) this.getParent()).setVisible(false);
270 ((Dialog) this.getParent()).setVisible(false);
274 protected void cancel()
276 textarea.setText("");
277 if (this.getParent() instanceof Frame)
279 ((Frame) this.getParent()).setVisible(false);
283 ((Dialog) this.getParent()).setVisible(false);
287 protected TextArea textarea = new TextArea();
289 Button accept = new Button("New Window");
291 Button addSequences = new Button("Add to Current Alignment");
293 Button cancel = new Button("Close");
295 protected Panel buttonPanel = new Panel();
297 BorderLayout borderLayout1 = new BorderLayout();
299 private void jbInit() throws Exception
301 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
302 textarea.setText(MessageManager
303 .getString("label.paste_your_alignment_file"));
304 textarea.addMouseListener(this);
305 this.setLayout(borderLayout1);
306 accept.addActionListener(this);
307 addSequences.addActionListener(this);
308 cancel.addActionListener(this);
309 this.add(buttonPanel, BorderLayout.SOUTH);
310 buttonPanel.add(accept, null);
311 buttonPanel.add(addSequences);
312 buttonPanel.add(cancel, null);
313 this.add(textarea, java.awt.BorderLayout.CENTER);
316 public void mousePressed(MouseEvent evt)
318 if (textarea.getText().startsWith(
319 MessageManager.getString("label.paste_your")))
321 textarea.setText("");
325 public void mouseReleased(MouseEvent evt)
329 public void mouseClicked(MouseEvent evt)
333 public void mouseEntered(MouseEvent evt)
337 public void mouseExited(MouseEvent evt)