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;
23 import jalview.datamodel.Alignment;
24 import jalview.datamodel.PDBEntry;
25 import jalview.datamodel.Sequence;
26 import jalview.io.AnnotationFile;
27 import jalview.io.AppletFormatAdapter;
28 import jalview.io.IdentifyFile;
29 import jalview.io.TCoffeeScoreFile;
30 import jalview.schemes.TCoffeeColourScheme;
31 import jalview.util.MessageManager;
33 import java.awt.BorderLayout;
34 import java.awt.Button;
35 import java.awt.Dialog;
37 import java.awt.Frame;
38 import java.awt.Panel;
39 import java.awt.TextArea;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.MouseEvent;
43 import java.awt.event.MouseListener;
45 public class CutAndPasteTransfer extends Panel implements ActionListener,
48 boolean pdbImport = false;
50 boolean treeImport = false;
52 boolean annotationImport = false;
56 AlignFrame alignFrame;
58 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
68 this.alignFrame = alignFrame;
72 buttonPanel.setVisible(false);
76 public String getText()
78 return textarea.getText();
81 public void setText(String text)
83 textarea.setText(text);
86 public void setPDBImport(Sequence seq)
89 accept.setLabel(MessageManager.getString("action.accept"));
90 addSequences.setVisible(false);
94 public void setTreeImport()
97 accept.setLabel(MessageManager.getString("action.accept"));
98 addSequences.setVisible(false);
101 public void setAnnotationImport()
103 annotationImport = true;
104 accept.setLabel(MessageManager.getString("action.accept"));
105 addSequences.setVisible(false);
108 public void actionPerformed(ActionEvent evt)
110 if (evt.getSource() == accept)
114 else if (evt.getSource() == addSequences)
118 else if (evt.getSource() == cancel)
124 protected void ok(boolean newWindow)
126 String text = getText();
127 int length = text.length();
128 textarea.append("\n");
129 if (textarea.getText().length() == length)
131 String warning = "\n\n#################################################\n"
132 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
133 + "\nCAN'T INPUT FULL ALIGNMENT"
134 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
135 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
136 + "\n#################################################\n";
137 textarea.setText(text.substring(0, text.length() - warning.length())
140 textarea.setCaretPosition(text.length());
145 PDBEntry pdb = new PDBEntry();
148 if (alignFrame.alignPanel.av.applet.jmolAvailable)
150 new jalview.appletgui.AppletJmol(pdb, new Sequence[]
151 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
155 new MCview.AppletPDBViewer(pdb, new Sequence[]
156 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
164 jalview.io.NewickFile fin = new jalview.io.NewickFile(
165 textarea.getText(), "Paste");
168 if (fin.getTree() != null)
170 alignFrame.loadTree(fin, "Pasted tree file");
173 } catch (Exception ex)
175 // TODO: JAL-1102 - should have a warning message in dialog, not simply
176 // overwrite the broken input data with the exception
177 textarea.setText(MessageManager.formatMessage(
178 "label.could_not_parse_newick_file", new String[]
179 { ex.getMessage() }));
183 else if (annotationImport)
185 TCoffeeScoreFile tcf = null;
188 tcf = new TCoffeeScoreFile(textarea.getText(),
189 jalview.io.AppletFormatAdapter.PASTE);
192 if (tcf.annotateAlignment(alignFrame.viewport.getAlignment(),
195 alignFrame.tcoffeeColour.setEnabled(true);
196 alignFrame.alignPanel.fontChanged();
197 alignFrame.changeColour(new TCoffeeColourScheme(
198 alignFrame.viewport.getAlignment()));
200 .setText(MessageManager
201 .getString("label.successfully_pasted_tcoffee_scores_to_alignment"));
205 // file valid but didn't get added to alignment for some reason
206 alignFrame.statusBar.setText(MessageManager.formatMessage(
207 "label.failed_add_tcoffee_scores",
209 { (tcf.getWarningMessage() != null ? tcf
210 .getWarningMessage() : "") }));
217 } catch (Exception x)
223 if (new AnnotationFile().annotateAlignmentView(alignFrame.viewport,
225 jalview.io.AppletFormatAdapter.PASTE))
227 alignFrame.alignPanel.fontChanged();
228 alignFrame.alignPanel.setScrollValues(0, 0);
230 .setText(MessageManager
231 .getString("label.successfully_pasted_annotation_to_alignment"));
236 if (!alignFrame.parseFeaturesFile(textarea.getText(),
237 jalview.io.AppletFormatAdapter.PASTE))
240 .setText(MessageManager
241 .getString("label.couldnt_parse_pasted_text_as_valid_annotation_feature_GFF_tcoffee_file"));
246 else if (alignFrame != null)
250 String format = new IdentifyFile().Identify(text,
251 AppletFormatAdapter.PASTE);
254 al = new AppletFormatAdapter().readFile(text,
255 AppletFormatAdapter.PASTE, format);
256 } catch (java.io.IOException ex)
258 ex.printStackTrace();
265 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
266 "Cut & Paste input - " + format, false);
268 .setText(MessageManager
269 .getString("label.successfully_pasted_annotation_to_alignment"));
273 alignFrame.addSequences(al.getSequencesArray());
274 alignFrame.statusBar.setText(MessageManager
275 .getString("label.successfully_pasted_alignment_file"));
279 // TODO: dialog should indicate if data was parsed correctly or not - see
281 if (this.getParent() instanceof Frame)
283 ((Frame) this.getParent()).setVisible(false);
287 ((Dialog) this.getParent()).setVisible(false);
291 protected void cancel()
293 textarea.setText("");
294 if (this.getParent() instanceof Frame)
296 ((Frame) this.getParent()).setVisible(false);
300 ((Dialog) this.getParent()).setVisible(false);
304 protected TextArea textarea = new TextArea();
306 Button accept = new Button("New Window");
308 Button addSequences = new Button("Add to Current Alignment");
310 Button cancel = new Button("Close");
312 protected Panel buttonPanel = new Panel();
314 BorderLayout borderLayout1 = new BorderLayout();
316 private void jbInit() throws Exception
318 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
319 textarea.setText(MessageManager
320 .getString("label.paste_your_alignment_file"));
321 textarea.addMouseListener(this);
322 this.setLayout(borderLayout1);
323 accept.addActionListener(this);
324 addSequences.addActionListener(this);
325 cancel.addActionListener(this);
326 this.add(buttonPanel, BorderLayout.SOUTH);
327 buttonPanel.add(accept, null);
328 buttonPanel.add(addSequences);
329 buttonPanel.add(cancel, null);
330 this.add(textarea, java.awt.BorderLayout.CENTER);
333 public void mousePressed(MouseEvent evt)
335 if (textarea.getText().startsWith(
336 MessageManager.getString("label.paste_your")))
338 textarea.setText("");
342 public void mouseReleased(MouseEvent evt)
346 public void mouseClicked(MouseEvent evt)
350 public void mouseEntered(MouseEvent evt)
354 public void mouseExited(MouseEvent evt)