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
28 extends Panel implements ActionListener, MouseListener
30 boolean pdbImport = false;
31 boolean treeImport = false;
32 boolean annotationImport = false;
34 AlignFrame alignFrame;
36 public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame)
47 this.alignFrame = alignFrame;
51 buttonPanel.setVisible(false);
55 public String getText()
57 return textarea.getText();
60 public void setText(String text)
62 textarea.setText(text);
65 public void setPDBImport(Sequence seq)
68 accept.setLabel("Accept");
69 addSequences.setVisible(false);
73 public void setTreeImport()
76 accept.setLabel("Accept");
77 addSequences.setVisible(false);
80 public void setAnnotationImport()
82 annotationImport = true;
83 accept.setLabel("Accept");
84 addSequences.setVisible(false);
87 public void actionPerformed(ActionEvent evt)
89 if (evt.getSource() == accept)
93 else if (evt.getSource() == addSequences)
97 else if (evt.getSource() == cancel)
103 protected void ok(boolean newWindow)
105 String text = getText();
106 int length = text.length();
107 textarea.append("\n");
108 if (textarea.getText().length() == length)
111 "\n\n#################################################\n"
112 + "WARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n"
113 + "\nCAN'T INPUT FULL ALIGNMENT"
114 + "\n\nYOU MUST DELETE THIS WARNING TO CONTINUE"
115 + "\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE"
116 + "\n#################################################\n";
117 textarea.setText(text.substring(0, text.length() - warning.length())
120 textarea.setCaretPosition(text.length());
125 PDBEntry pdb = new PDBEntry();
128 if ( alignFrame.alignPanel.av.applet.jmolAvailable )
129 new jalview.appletgui.AppletJmol(pdb,
132 alignFrame.alignPanel,
133 AppletFormatAdapter.PASTE);
136 new MCview.AppletPDBViewer(pdb,
139 alignFrame.alignPanel,
140 AppletFormatAdapter.PASTE);
147 jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(),
151 if (fin.getTree() != null)
153 alignFrame.loadTree(fin, "Pasted tree file");
159 textarea.setText("Could not parse Newick file!\n" + ex);
163 else if (annotationImport)
165 if (new AnnotationFile().readAnnotationFile(
166 alignFrame.viewport.alignment, textarea.getText(),
167 jalview.io.AppletFormatAdapter.PASTE))
169 alignFrame.alignPanel.fontChanged();
170 alignFrame.alignPanel.setScrollValues(0, 0);
175 alignFrame.parseFeaturesFile(textarea.getText(),
176 jalview.io.AppletFormatAdapter.PASTE);
179 else if (alignFrame != null)
183 String format = new IdentifyFile().Identify(text,
184 AppletFormatAdapter.PASTE);
187 al = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE,
190 catch (java.io.IOException ex)
192 ex.printStackTrace();
199 AlignFrame af = new AlignFrame(al, alignFrame.viewport.applet,
200 "Cut & Paste input - " + format,
202 af.statusBar.setText("Successfully pasted alignment file");
206 alignFrame.addSequences(al.getSequencesArray());
211 if (this.getParent() instanceof Frame)
213 ( (Frame)this.getParent()).setVisible(false);
217 ( (Dialog)this.getParent()).setVisible(false);
221 protected void cancel()
223 textarea.setText("");
224 if (this.getParent() instanceof Frame)
226 ( (Frame)this.getParent()).setVisible(false);
230 ( (Dialog)this.getParent()).setVisible(false);
234 protected TextArea textarea = new TextArea();
235 Button accept = new Button("New Window");
236 Button addSequences = new Button("Add to Current Alignment");
237 Button cancel = new Button("Close");
239 protected Panel buttonPanel = new Panel();
240 BorderLayout borderLayout1 = new BorderLayout();
242 private void jbInit()
245 textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10));
246 textarea.setText("Paste your alignment file here");
247 textarea.addMouseListener(this);
248 this.setLayout(borderLayout1);
249 accept.addActionListener(this);
250 addSequences.addActionListener(this);
251 cancel.addActionListener(this);
252 this.add(buttonPanel, BorderLayout.SOUTH);
253 buttonPanel.add(accept, null);
254 buttonPanel.add(addSequences);
255 buttonPanel.add(cancel, null);
256 this.add(textarea, java.awt.BorderLayout.CENTER);
259 public void mousePressed(MouseEvent evt)
261 if (textarea.getText().startsWith("Paste your"))
263 textarea.setText("");
267 public void mouseReleased(MouseEvent evt)
270 public void mouseClicked(MouseEvent evt)
273 public void mouseEntered(MouseEvent evt)
276 public void mouseExited(MouseEvent evt)