2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
26 import jalview.io.*;
\r
28 public class CutAndPasteTransfer
\r
29 extends Panel implements ActionListener, MouseListener
\r
31 boolean pdbImport = false;
\r
32 boolean treeImport = false;
\r
33 boolean annotationImport = false;
\r
35 AlignFrame alignFrame;
\r
37 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
\r
45 e.printStackTrace();
\r
48 this.alignFrame = alignFrame;
\r
52 buttonPanel.setVisible(false);
\r
56 public String getText()
\r
58 return textarea.getText();
\r
61 public void setText(String text)
\r
63 textarea.setText(text);
\r
66 public void setPDBImport(Sequence seq)
\r
69 accept.setLabel("Accept");
\r
70 addSequences.setVisible(false);
\r
74 public void setTreeImport()
\r
77 accept.setLabel("Accept");
\r
78 addSequences.setVisible(false);
\r
81 public void setAnnotationImport()
\r
83 annotationImport = true;
\r
84 accept.setLabel("Accept");
\r
85 addSequences.setVisible(false);
\r
88 public void actionPerformed(ActionEvent evt)
\r
90 if (evt.getSource() == accept)
\r
94 else if (evt.getSource() == addSequences)
\r
98 else if (evt.getSource() == cancel)
\r
104 protected void ok(boolean newWindow)
\r
106 String text = getText();
\r
107 int length = text.length();
\r
108 textarea.append("\n");
\r
109 if (textarea.getText().length() == length)
\r
112 "\n\n#################################################\n"
\r
113 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
\r
114 + "\nCAN'T INPUT FULL ALIGNMENT"
\r
115 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
\r
116 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
\r
117 + "\n#################################################\n";
\r
118 textarea.setText(text.substring(0, text.length() - warning.length())
\r
121 textarea.setCaretPosition(text.length());
\r
126 PDBEntry pdb = new PDBEntry();
\r
129 if ( alignFrame.alignPanel.av.applet.jmolAvailable )
\r
130 new jalview.appletgui.AppletJmol(pdb,
\r
133 alignFrame.alignPanel,
\r
134 AppletFormatAdapter.PASTE);
\r
137 new MCview.AppletPDBViewer(pdb,
\r
140 alignFrame.alignPanel,
\r
141 AppletFormatAdapter.PASTE);
\r
144 else if (treeImport)
\r
148 jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),
\r
152 if (fin.getTree() != null)
\r
154 alignFrame.loadTree(fin, "Pasted tree file");
\r
158 catch (Exception ex)
\r
160 textarea.setText("Could not parse Newick file!\n" + ex);
\r
164 else if (annotationImport)
\r
166 if (new AnnotationFile().readAnnotationFile(
\r
167 alignFrame.viewport.alignment, textarea.getText(),
\r
168 jalview.io.AppletFormatAdapter.PASTE))
\r
170 alignFrame.alignPanel.fontChanged();
\r
171 alignFrame.alignPanel.setScrollValues(0, 0);
\r
176 alignFrame.parseFeaturesFile(textarea.getText(),
\r
177 jalview.io.AppletFormatAdapter.PASTE);
\r
180 else if (alignFrame != null)
\r
182 Alignment al = null;
\r
184 String format = new IdentifyFile().Identify(text,
\r
185 AppletFormatAdapter.PASTE);
\r
188 al = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE,
\r
191 catch (java.io.IOException ex)
\r
193 ex.printStackTrace();
\r
200 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
\r
201 "Cut & Paste input - " + format,
\r
203 af.statusBar.setText("Successfully pasted alignment file");
\r
207 alignFrame.addSequences(al.getSequencesArray());
\r
212 if (this.getParent() instanceof Frame)
\r
214 ( (Frame)this.getParent()).setVisible(false);
\r
218 ( (Dialog)this.getParent()).setVisible(false);
\r
222 protected void cancel()
\r
224 textarea.setText("");
\r
225 if (this.getParent() instanceof Frame)
\r
227 ( (Frame)this.getParent()).setVisible(false);
\r
231 ( (Dialog)this.getParent()).setVisible(false);
\r
235 protected TextArea textarea = new TextArea();
\r
236 Button accept = new Button("New Window");
\r
237 Button addSequences = new Button("Add to Current Alignment");
\r
238 Button cancel = new Button("Close");
\r
240 protected Panel buttonPanel = new Panel();
\r
241 BorderLayout borderLayout1 = new BorderLayout();
\r
243 private void jbInit()
\r
246 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
\r
247 textarea.setText("Paste your alignment file here");
\r
248 textarea.addMouseListener(this);
\r
249 this.setLayout(borderLayout1);
\r
250 accept.addActionListener(this);
\r
251 addSequences.addActionListener(this);
\r
252 cancel.addActionListener(this);
\r
253 this.add(buttonPanel, BorderLayout.SOUTH);
\r
254 buttonPanel.add(accept, null);
\r
255 buttonPanel.add(addSequences);
\r
256 buttonPanel.add(cancel, null);
\r
257 this.add(textarea, java.awt.BorderLayout.CENTER);
\r
260 public void mousePressed(MouseEvent evt)
\r
262 if (textarea.getText().startsWith("Paste your"))
\r
264 textarea.setText("");
\r
268 public void mouseReleased(MouseEvent evt)
\r
271 public void mouseClicked(MouseEvent evt)
\r
274 public void mouseEntered(MouseEvent evt)
\r
277 public void mouseExited(MouseEvent evt)
\r