2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.io.*;
\r
25 import jalview.jbgui.*;
\r
28 import java.awt.datatransfer.*;
\r
29 import java.awt.event.*;
\r
31 import javax.swing.*;
\r
38 * @version $Revision$
\r
40 public class CutAndPasteTransfer extends GCutAndPasteTransfer
\r
45 public void setForInput()
\r
47 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
\r
48 SwingUtilities.invokeLater(new Runnable()
\r
52 textarea.requestFocus();
\r
60 * @return DOCUMENT ME!
\r
62 public String getText()
\r
64 return textarea.getText();
\r
70 * @param text DOCUMENT ME!
\r
72 public void setText(String text)
\r
74 textarea.setText(text);
\r
80 * @param e DOCUMENT ME!
\r
82 public void copyItem_actionPerformed(ActionEvent e)
\r
84 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
\r
85 c.setContents(new StringSelection(textarea.getText()), null);
\r
91 * @param e DOCUMENT ME!
\r
93 public void pasteMenu_actionPerformed(ActionEvent e)
\r
95 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
\r
96 Transferable contents = c.getContents(this);
\r
98 if (contents == null)
\r
105 textarea.append((String) contents.getTransferData(
\r
106 DataFlavor.stringFlavor));
\r
108 catch (Exception ex)
\r
116 * @param e DOCUMENT ME!
\r
118 public void ok_actionPerformed(ActionEvent e)
\r
120 String format = IdentifyFile.Identify(getText(), "Paste");
\r
121 SequenceI[] sequences = null;
\r
123 if (FormatAdapter.formats.contains(format))
\r
125 sequences = new FormatAdapter().readFile(getText(), "Paste", format);
\r
128 if (sequences != null)
\r
130 AlignFrame af = new AlignFrame(new Alignment(sequences));
\r
131 af.currentFileFormat = format;
\r
132 Desktop.addInternalFrame(af, "Cut & Paste input - " + format,
\r
133 AlignFrame.NEW_WINDOW_WIDTH, AlignFrame.NEW_WINDOW_HEIGHT);
\r
134 af.statusBar.setText("Successfully pasted alignment file");
\r
138 af.setMaximum( jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
\r
140 catch (Exception ex)
\r
146 this.setClosed(true);
\r
148 catch (Exception ex)
\r
154 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
155 "Couldn't read the pasted text.\n" +
\r
156 "Formats currently supported are\n" +
\r
157 "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM",
\r
158 "Error parsing text", JOptionPane.WARNING_MESSAGE);
\r
165 * @param e DOCUMENT ME!
\r
167 public void cancel_actionPerformed(ActionEvent e)
\r
171 this.setClosed(true);
\r
173 catch (Exception ex)
\r
178 public void textarea_mousePressed(MouseEvent e)
\r
180 if(SwingUtilities.isRightMouseButton(e))
\r
182 JPopupMenu popup = new JPopupMenu("Edit");
\r
183 JMenuItem item = new JMenuItem("Copy");
\r
184 item.addActionListener(new ActionListener()
\r
185 {public void actionPerformed(ActionEvent e)
\r
187 copyItem_actionPerformed(e);
\r
191 item = new JMenuItem("Paste");
\r
192 item.addActionListener(new ActionListener()
\r
193 {public void actionPerformed(ActionEvent e)
\r
195 pasteMenu_actionPerformed(e);
\r
199 popup.show(this, e.getX(), e.getY()+textarea.getY()+30);
\r