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
22 import java.awt.datatransfer.*;
23 import java.awt.event.*;
26 import jalview.datamodel.*;
28 import jalview.jbgui.*;
36 public class CutAndPasteTransfer
37 extends GCutAndPasteTransfer
40 AlignViewport viewport;
42 public CutAndPasteTransfer()
44 SwingUtilities.invokeLater(new Runnable()
48 textarea.requestFocus();
57 public void setForInput(AlignViewport viewport)
59 this.viewport = viewport;
65 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
71 * @return DOCUMENT ME!
73 public String getText()
75 return textarea.getText();
81 * @param text DOCUMENT ME!
83 public void setText(String text)
85 textarea.setText(text);
88 public void appendText(String text)
90 textarea.append(text);
93 public void save_actionPerformed(ActionEvent e)
95 JalviewFileChooser chooser = new JalviewFileChooser(
96 jalview.bin.Cache.getProperty(
99 chooser.setAcceptAllFileFilterUsed(false);
100 chooser.setFileView(new JalviewFileView());
101 chooser.setDialogTitle("Save Text to File");
102 chooser.setToolTipText("Save");
104 int value = chooser.showSaveDialog(this);
106 if (value == JalviewFileChooser.APPROVE_OPTION)
110 java.io.PrintWriter out = new java.io.PrintWriter(
111 new java.io.FileWriter(chooser.getSelectedFile()));
113 out.print(getText());
118 ex.printStackTrace();
127 * @param e DOCUMENT ME!
129 public void copyItem_actionPerformed(ActionEvent e)
131 textarea.getSelectedText();
132 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
133 c.setContents(new StringSelection(textarea.getSelectedText()), null);
139 * @param e DOCUMENT ME!
141 public void pasteMenu_actionPerformed(ActionEvent e)
143 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
144 Transferable contents = c.getContents(this);
146 if (contents == null)
153 textarea.append( (String) contents.getTransferData(
154 DataFlavor.stringFlavor));
164 * @param e DOCUMENT ME!
166 public void ok_actionPerformed(ActionEvent e)
168 String format = new IdentifyFile().Identify(getText(), "Paste");
171 if (FormatAdapter.isValidFormat(format))
175 al = new FormatAdapter().readFile(getText(), "Paste", format);
177 catch (java.io.IOException ex)
179 JOptionPane.showInternalMessageDialog(Desktop.desktop,
180 "Couldn't read the pasted text.\n" +
182 "Error parsing text",
183 JOptionPane.WARNING_MESSAGE);
189 if (viewport != null)
191 for (int i = 0; i < al.getHeight(); i++)
193 viewport.getAlignment().addSequence(al.getSequenceAt(i));
196 viewport.firePropertyChange("alignment", null,
197 viewport.getAlignment().getSequences());
201 AlignFrame af = new AlignFrame(al,
202 AlignFrame.DEFAULT_WIDTH,
203 AlignFrame.DEFAULT_HEIGHT);
204 af.currentFileFormat = format;
205 Desktop.addInternalFrame(af, "Cut & Paste input - " + format,
206 AlignFrame.DEFAULT_WIDTH,
207 AlignFrame.DEFAULT_HEIGHT);
208 af.statusBar.setText("Successfully pasted alignment file");
212 af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
224 * @param e DOCUMENT ME!
226 public void cancel_actionPerformed(ActionEvent e)
230 this.setClosed(true);
237 public void textarea_mousePressed(MouseEvent e)
239 if (SwingUtilities.isRightMouseButton(e))
241 JPopupMenu popup = new JPopupMenu("Edit");
242 JMenuItem item = new JMenuItem("Copy");
243 item.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 copyItem_actionPerformed(e);
251 item = new JMenuItem("Paste");
252 item.addActionListener(new ActionListener()
254 public void actionPerformed(ActionEvent e)
256 pasteMenu_actionPerformed(e);
260 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);