2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.*;
26 public class CutAndPasteTransfer extends Panel implements ActionListener,
29 boolean pdbImport = false;
31 boolean treeImport = false;
33 boolean annotationImport = false;
37 AlignFrame alignFrame;
39 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
49 this.alignFrame = alignFrame;
53 buttonPanel.setVisible(false);
57 public String getText()
59 return textarea.getText();
62 public void setText(String text)
64 textarea.setText(text);
67 public void setPDBImport(Sequence seq)
70 accept.setLabel("Accept");
71 addSequences.setVisible(false);
75 public void setTreeImport()
78 accept.setLabel("Accept");
79 addSequences.setVisible(false);
82 public void setAnnotationImport()
84 annotationImport = true;
85 accept.setLabel("Accept");
86 addSequences.setVisible(false);
89 public void actionPerformed(ActionEvent evt)
91 if (evt.getSource() == accept)
95 else if (evt.getSource() == addSequences)
99 else if (evt.getSource() == cancel)
105 protected void ok(boolean newWindow)
107 String text = getText();
108 int length = text.length();
109 textarea.append("\n");
110 if (textarea.getText().length() == length)
112 String warning = "\n\n#################################################\n"
113 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
114 + "\nCAN'T INPUT FULL ALIGNMENT"
115 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
116 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
117 + "\n#################################################\n";
118 textarea.setText(text.substring(0, text.length() - warning.length())
121 textarea.setCaretPosition(text.length());
126 PDBEntry pdb = new PDBEntry();
129 if (alignFrame.alignPanel.av.applet.jmolAvailable)
130 new jalview.appletgui.AppletJmol(pdb, new Sequence[]
131 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
134 new MCview.AppletPDBViewer(pdb, new Sequence[]
135 { seq }, null, alignFrame.alignPanel, AppletFormatAdapter.PASTE);
142 jalview.io.NewickFile fin = new jalview.io.NewickFile(
143 textarea.getText(), "Paste");
146 if (fin.getTree() != null)
148 alignFrame.loadTree(fin, "Pasted tree file");
151 } catch (Exception ex)
153 textarea.setText("Could not parse Newick file!\n" + ex);
157 else if (annotationImport)
159 if (new AnnotationFile().readAnnotationFile(
160 alignFrame.viewport.getAlignment(), textarea.getText(),
161 jalview.io.AppletFormatAdapter.PASTE))
163 alignFrame.alignPanel.fontChanged();
164 alignFrame.alignPanel.setScrollValues(0, 0);
169 alignFrame.parseFeaturesFile(textarea.getText(),
170 jalview.io.AppletFormatAdapter.PASTE);
173 else if (alignFrame != null)
177 String format = new IdentifyFile().Identify(text,
178 AppletFormatAdapter.PASTE);
181 al = new AppletFormatAdapter().readFile(text,
182 AppletFormatAdapter.PASTE, format);
183 } catch (java.io.IOException ex)
185 ex.printStackTrace();
192 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
193 "Cut & Paste input - " + format, false);
194 af.statusBar.setText("Successfully pasted alignment file");
198 alignFrame.addSequences(al.getSequencesArray());
203 if (this.getParent() instanceof Frame)
205 ((Frame) this.getParent()).setVisible(false);
209 ((Dialog) this.getParent()).setVisible(false);
213 protected void cancel()
215 textarea.setText("");
216 if (this.getParent() instanceof Frame)
218 ((Frame) this.getParent()).setVisible(false);
222 ((Dialog) this.getParent()).setVisible(false);
226 protected TextArea textarea = new TextArea();
228 Button accept = new Button("New Window");
230 Button addSequences = new Button("Add to Current Alignment");
232 Button cancel = new Button("Close");
234 protected Panel buttonPanel = new Panel();
236 BorderLayout borderLayout1 = new BorderLayout();
238 private void jbInit() throws Exception
240 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
241 textarea.setText("Paste your alignment file here");
242 textarea.addMouseListener(this);
243 this.setLayout(borderLayout1);
244 accept.addActionListener(this);
245 addSequences.addActionListener(this);
246 cancel.addActionListener(this);
247 this.add(buttonPanel, BorderLayout.SOUTH);
248 buttonPanel.add(accept, null);
249 buttonPanel.add(addSequences);
250 buttonPanel.add(cancel, null);
251 this.add(textarea, java.awt.BorderLayout.CENTER);
254 public void mousePressed(MouseEvent evt)
256 if (textarea.getText().startsWith("Paste your"))
258 textarea.setText("");
262 public void mouseReleased(MouseEvent evt)
266 public void mouseClicked(MouseEvent evt)
270 public void mouseEntered(MouseEvent evt)
274 public void mouseExited(MouseEvent evt)