2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
21 import jalview.datamodel.*;
25 import jalview.jbgui.*;
28 import java.awt.datatransfer.*;
29 import java.awt.event.*;
40 public class CutAndPasteTransfer extends GCutAndPasteTransfer
43 AlignViewport viewport;
45 public CutAndPasteTransfer()
47 SwingUtilities.invokeLater(new Runnable()
51 textarea.requestFocus();
60 public void setForInput(AlignViewport viewport)
62 this.viewport = viewport;
63 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
69 * @return DOCUMENT ME!
71 public String getText()
73 return textarea.getText();
79 * @param text DOCUMENT ME!
81 public void setText(String text)
83 textarea.setText(text);
86 public void appendText(String text)
88 textarea.append(text);
92 public void save_actionPerformed(ActionEvent e)
94 JalviewFileChooser chooser = new JalviewFileChooser(
95 jalview.bin.Cache.getProperty(
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());
117 ex.printStackTrace();
128 * @param e DOCUMENT ME!
130 public void copyItem_actionPerformed(ActionEvent e)
132 textarea.getSelectedText();
133 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
134 c.setContents(new StringSelection(textarea.getSelectedText()), null);
140 * @param e DOCUMENT ME!
142 public void pasteMenu_actionPerformed(ActionEvent e)
144 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
145 Transferable contents = c.getContents(this);
147 if (contents == null)
154 textarea.append((String) contents.getTransferData(
155 DataFlavor.stringFlavor));
165 * @param e DOCUMENT ME!
167 public void ok_actionPerformed(ActionEvent e)
169 String format = new IdentifyFile().Identify(getText(), "Paste");
170 SequenceI[] sequences = null;
172 if (FormatAdapter.isValidFormat(format))
175 sequences = 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",
181 JOptionPane.WARNING_MESSAGE);
185 if (sequences != null)
189 for(int i=0; i<sequences.length; i++)
190 viewport.getAlignment().addSequence(sequences[i]);
192 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
196 AlignFrame af = new AlignFrame(new Alignment(sequences));
197 af.currentFileFormat = format;
198 Desktop.addInternalFrame(af, "Cut & Paste input - " + format,
199 AlignFrame.NEW_WINDOW_WIDTH,
200 AlignFrame.NEW_WINDOW_HEIGHT);
201 af.statusBar.setText("Successfully pasted alignment file");
205 af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
217 * @param e DOCUMENT ME!
219 public void cancel_actionPerformed(ActionEvent e)
223 this.setClosed(true);
230 public void textarea_mousePressed(MouseEvent e)
232 if(SwingUtilities.isRightMouseButton(e))
234 JPopupMenu popup = new JPopupMenu("Edit");
235 JMenuItem item = new JMenuItem("Copy");
236 item.addActionListener(new ActionListener()
237 {public void actionPerformed(ActionEvent e)
239 copyItem_actionPerformed(e);
243 item = new JMenuItem("Paste");
244 item.addActionListener(new ActionListener()
245 {public void actionPerformed(ActionEvent e)
247 pasteMenu_actionPerformed(e);
251 popup.show(this, e.getX()+10, e.getY()+textarea.getY()+40);