2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.datatransfer.*;
25 import java.awt.event.*;
28 import jalview.datamodel.*;
30 import jalview.jbgui.*;
31 import jalview.util.MessageManager;
34 * Cut'n'paste files into the desktop See JAL-1105
39 public class CutAndPasteTransfer extends GCutAndPasteTransfer
42 AlignViewport viewport;
44 public CutAndPasteTransfer()
46 SwingUtilities.invokeLater(new Runnable()
50 textarea.requestFocus();
59 public void setForInput(AlignViewport viewport)
61 this.viewport = viewport;
64 ok.setText(MessageManager.getString("action.add"));
67 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
73 * @return DOCUMENT ME!
75 public String getText()
77 return textarea.getText();
86 public void setText(String text)
88 textarea.setText(text);
91 public void appendText(String text)
93 textarea.append(text);
96 public void save_actionPerformed(ActionEvent e)
98 JalviewFileChooser chooser = new JalviewFileChooser(
99 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
101 chooser.setAcceptAllFileFilterUsed(false);
102 chooser.setFileView(new JalviewFileView());
103 chooser.setDialogTitle(MessageManager.getString("label.save_text_to_file"));
104 chooser.setToolTipText(MessageManager.getString("action.save"));
106 int value = chooser.showSaveDialog(this);
108 if (value == JalviewFileChooser.APPROVE_OPTION)
112 java.io.PrintWriter out = new java.io.PrintWriter(
113 new java.io.FileWriter(chooser.getSelectedFile()));
115 out.print(getText());
117 } catch (Exception ex)
119 ex.printStackTrace();
131 public void copyItem_actionPerformed(ActionEvent e)
133 textarea.getSelectedText();
134 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
135 c.setContents(new StringSelection(textarea.getSelectedText()), null);
144 public void pasteMenu_actionPerformed(ActionEvent e)
146 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
147 Transferable contents = c.getContents(this);
149 if (contents == null)
156 textarea.append((String) contents
157 .getTransferData(DataFlavor.stringFlavor));
158 } catch (Exception ex)
169 public void ok_actionPerformed(ActionEvent e)
171 String format = new IdentifyFile().Identify(getText(), "Paste");
172 // TODO: identify feature, annotation or tree file and parse appropriately.
175 if (FormatAdapter.isValidFormat(format))
179 al = new FormatAdapter().readFile(getText(), "Paste", format);
180 } catch (java.io.IOException ex)
182 JOptionPane.showInternalMessageDialog(Desktop.desktop,
183 MessageManager.formatMessage(
184 "label.couldnt_read_pasted_text", new String[]
185 { ex.toString() }), MessageManager
186 .getString("label.error_parsing_text"),
187 JOptionPane.WARNING_MESSAGE);
193 if (viewport != null)
195 for (int i = 0; i < al.getHeight(); i++)
197 viewport.getAlignment().addSequence(al.getSequenceAt(i));
200 viewport.firePropertyChange("alignment", null, viewport
201 .getAlignment().getSequences());
205 AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
206 AlignFrame.DEFAULT_HEIGHT);
207 af.currentFileFormat = format;
208 Desktop.addInternalFrame(af, MessageManager.formatMessage(
209 "label.input_cut_paste_params", new String[]
210 { format }), AlignFrame.DEFAULT_WIDTH,
211 AlignFrame.DEFAULT_HEIGHT);
212 af.statusBar.setText(MessageManager
213 .getString("label.successfully_pasted_alignment_file"));
217 af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN",
219 } catch (Exception ex)
232 public void cancel_actionPerformed(ActionEvent e)
236 this.setClosed(true);
237 } catch (Exception ex)
242 public void textarea_mousePressed(MouseEvent e)
244 if (SwingUtilities.isRightMouseButton(e))
246 JPopupMenu popup = new JPopupMenu(
247 MessageManager.getString("action.edit"));
248 JMenuItem item = new JMenuItem(
249 MessageManager.getString("action.copy"));
250 item.addActionListener(new ActionListener()
252 public void actionPerformed(ActionEvent e)
254 copyItem_actionPerformed(e);
258 item = new JMenuItem(MessageManager.getString("action.paste"));
259 item.addActionListener(new ActionListener()
261 public void actionPerformed(ActionEvent e)
263 pasteMenu_actionPerformed(e);
267 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);