2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 extends GCutAndPasteTransfer
39 AlignViewport viewport;
41 public CutAndPasteTransfer()
43 SwingUtilities.invokeLater(new Runnable()
47 textarea.requestFocus();
56 public void setForInput(AlignViewport viewport)
58 this.viewport = viewport;
64 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
70 * @return DOCUMENT ME!
72 public String getText()
74 return textarea.getText();
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(jalview.bin.Cache
96 .getProperty("LAST_DIRECTORY"));
98 chooser.setAcceptAllFileFilterUsed(false);
99 chooser.setFileView(new JalviewFileView());
100 chooser.setDialogTitle("Save Text to File");
101 chooser.setToolTipText("Save");
103 int value = chooser.showSaveDialog(this);
105 if (value == JalviewFileChooser.APPROVE_OPTION)
109 java.io.PrintWriter out = new java.io.PrintWriter(
110 new java.io.FileWriter(chooser.getSelectedFile()));
112 out.print(getText());
114 } catch (Exception ex)
116 ex.printStackTrace();
128 public void copyItem_actionPerformed(ActionEvent e)
130 textarea.getSelectedText();
131 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
132 c.setContents(new StringSelection(textarea.getSelectedText()), null);
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
154 .getTransferData(DataFlavor.stringFlavor));
155 } catch (Exception ex)
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);
176 } catch (java.io.IOException ex)
178 JOptionPane.showInternalMessageDialog(Desktop.desktop,
179 "Couldn't read the pasted text.\n" + ex.toString(),
180 "Error parsing text", JOptionPane.WARNING_MESSAGE);
186 if (viewport != null)
188 for (int i = 0; i < al.getHeight(); i++)
190 viewport.getAlignment().addSequence(al.getSequenceAt(i));
193 viewport.firePropertyChange("alignment", null, viewport
194 .getAlignment().getSequences());
198 AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
199 AlignFrame.DEFAULT_HEIGHT);
200 af.currentFileFormat = format;
201 Desktop.addInternalFrame(af, "Cut & Paste input - " + format,
202 AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
203 af.statusBar.setText("Successfully pasted alignment file");
207 af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
209 } catch (Exception ex)
222 public void cancel_actionPerformed(ActionEvent e)
226 this.setClosed(true);
227 } catch (Exception ex)
232 public void textarea_mousePressed(MouseEvent e)
234 if (SwingUtilities.isRightMouseButton(e))
236 JPopupMenu popup = new JPopupMenu("Edit");
237 JMenuItem item = new JMenuItem("Copy");
238 item.addActionListener(new ActionListener()
240 public void actionPerformed(ActionEvent e)
242 copyItem_actionPerformed(e);
246 item = new JMenuItem("Paste");
247 item.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 pasteMenu_actionPerformed(e);
255 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);