2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
22 import java.awt.event.*;
24 import jalview.datamodel.*;
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(textarea
144 .getText(), "Paste");
147 if (fin.getTree() != null)
149 alignFrame.loadTree(fin, "Pasted tree file");
152 } catch (Exception ex)
154 textarea.setText("Could not parse Newick file!\n" + ex);
158 else if (annotationImport)
160 if (new AnnotationFile().readAnnotationFile(
161 alignFrame.viewport.alignment, textarea.getText(),
162 jalview.io.AppletFormatAdapter.PASTE))
164 alignFrame.alignPanel.fontChanged();
165 alignFrame.alignPanel.setScrollValues(0, 0);
170 alignFrame.parseFeaturesFile(textarea.getText(),
171 jalview.io.AppletFormatAdapter.PASTE);
174 else if (alignFrame != null)
178 String format = new IdentifyFile().Identify(text,
179 AppletFormatAdapter.PASTE);
182 al = new AppletFormatAdapter().readFile(text,
183 AppletFormatAdapter.PASTE, format);
184 } catch (java.io.IOException ex)
186 ex.printStackTrace();
193 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
194 "Cut & Paste input - " + format, false);
195 af.statusBar.setText("Successfully pasted alignment file");
199 alignFrame.addSequences(al.getSequencesArray());
204 if (this.getParent() instanceof Frame)
206 ((Frame) this.getParent()).setVisible(false);
210 ((Dialog) this.getParent()).setVisible(false);
214 protected void cancel()
216 textarea.setText("");
217 if (this.getParent() instanceof Frame)
219 ((Frame) this.getParent()).setVisible(false);
223 ((Dialog) this.getParent()).setVisible(false);
227 protected TextArea textarea = new TextArea();
229 Button accept = new Button("New Window");
231 Button addSequences = new Button("Add to Current Alignment");
233 Button cancel = new Button("Close");
235 protected Panel buttonPanel = new Panel();
237 BorderLayout borderLayout1 = new BorderLayout();
239 private void jbInit() throws Exception
241 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
242 textarea.setText("Paste your alignment file here");
243 textarea.addMouseListener(this);
244 this.setLayout(borderLayout1);
245 accept.addActionListener(this);
246 addSequences.addActionListener(this);
247 cancel.addActionListener(this);
248 this.add(buttonPanel, BorderLayout.SOUTH);
249 buttonPanel.add(accept, null);
250 buttonPanel.add(addSequences);
251 buttonPanel.add(cancel, null);
252 this.add(textarea, java.awt.BorderLayout.CENTER);
255 public void mousePressed(MouseEvent evt)
257 if (textarea.getText().startsWith("Paste your"))
259 textarea.setText("");
263 public void mouseReleased(MouseEvent evt)
267 public void mouseClicked(MouseEvent evt)
271 public void mouseEntered(MouseEvent evt)
275 public void mouseExited(MouseEvent evt)