2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
43 AlignViewport viewport;
\r
45 public CutAndPasteTransfer()
\r
47 SwingUtilities.invokeLater(new Runnable()
\r
51 textarea.requestFocus();
\r
60 public void setForInput(AlignViewport viewport)
\r
62 this.viewport = viewport;
\r
63 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
\r
69 * @return DOCUMENT ME!
\r
71 public String getText()
\r
73 return textarea.getText();
\r
79 * @param text DOCUMENT ME!
\r
81 public void setText(String text)
\r
83 textarea.setText(text);
\r
86 public void appendText(String text)
\r
88 textarea.append(text);
\r
92 public void save_actionPerformed(ActionEvent e)
\r
94 JalviewFileChooser chooser = new JalviewFileChooser(
\r
95 jalview.bin.Cache.getProperty(
\r
98 chooser.setAcceptAllFileFilterUsed(false);
\r
99 chooser.setFileView(new JalviewFileView());
\r
100 chooser.setDialogTitle("Save Text to File");
\r
101 chooser.setToolTipText("Save");
\r
103 int value = chooser.showSaveDialog(this);
\r
105 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
109 java.io.PrintWriter out = new java.io.PrintWriter(
\r
110 new java.io.FileWriter(chooser.getSelectedFile()));
\r
112 out.print(getText());
\r
115 catch (Exception ex)
\r
117 ex.printStackTrace();
\r
128 * @param e DOCUMENT ME!
\r
130 public void copyItem_actionPerformed(ActionEvent e)
\r
132 textarea.getSelectedText();
\r
133 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
\r
134 c.setContents(new StringSelection(textarea.getSelectedText()), null);
\r
140 * @param e DOCUMENT ME!
\r
142 public void pasteMenu_actionPerformed(ActionEvent e)
\r
144 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
\r
145 Transferable contents = c.getContents(this);
\r
147 if (contents == null)
\r
154 textarea.append((String) contents.getTransferData(
\r
155 DataFlavor.stringFlavor));
\r
157 catch (Exception ex)
\r
165 * @param e DOCUMENT ME!
\r
167 public void ok_actionPerformed(ActionEvent e)
\r
169 String format = new IdentifyFile().Identify(getText(), "Paste");
\r
170 SequenceI[] sequences = null;
\r
172 if (FormatAdapter.isValidFormat(format))
\r
175 sequences = new FormatAdapter().readFile(getText(), "Paste", format);
\r
176 }catch(java.io.IOException ex)
\r
178 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
179 "Couldn't read the pasted text.\n" +ex.toString(),
\r
180 "Error parsing text",
\r
181 JOptionPane.WARNING_MESSAGE);
\r
185 if (sequences != null)
\r
189 for(int i=0; i<sequences.length; i++)
\r
190 viewport.getAlignment().addSequence(sequences[i]);
\r
192 viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());
\r
196 AlignFrame af = new AlignFrame(new Alignment(sequences),
\r
197 AlignFrame.DEFAULT_WIDTH,
\r
198 AlignFrame.DEFAULT_HEIGHT);
\r
199 af.currentFileFormat = format;
\r
200 Desktop.addInternalFrame(af, "Cut & Paste input - " + format,
\r
201 AlignFrame.DEFAULT_WIDTH,
\r
202 AlignFrame.DEFAULT_HEIGHT);
\r
203 af.statusBar.setText("Successfully pasted alignment file");
\r
207 af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false));
\r
209 catch (Exception ex)
\r
219 * @param e DOCUMENT ME!
\r
221 public void cancel_actionPerformed(ActionEvent e)
\r
225 this.setClosed(true);
\r
227 catch (Exception ex)
\r
232 public void textarea_mousePressed(MouseEvent e)
\r
234 if(SwingUtilities.isRightMouseButton(e))
\r
236 JPopupMenu popup = new JPopupMenu("Edit");
\r
237 JMenuItem item = new JMenuItem("Copy");
\r
238 item.addActionListener(new ActionListener()
\r
239 {public void actionPerformed(ActionEvent e)
\r
241 copyItem_actionPerformed(e);
\r
245 item = new JMenuItem("Paste");
\r
246 item.addActionListener(new ActionListener()
\r
247 {public void actionPerformed(ActionEvent e)
\r
249 pasteMenu_actionPerformed(e);
\r
253 popup.show(this, e.getX()+10, e.getY()+textarea.getY()+40);
\r