2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import java.awt.datatransfer.*;
23 import java.awt.event.*;
24 import java.io.StringWriter;
27 import javax.swing.event.HyperlinkEvent;
28 import javax.swing.event.HyperlinkListener;
29 import javax.swing.event.HyperlinkEvent.EventType;
32 import jalview.jbgui.*;
33 import jalview.util.MessageManager;
36 * Cut'n'paste files into the desktop See JAL-1105
41 public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
44 AlignViewport viewport;
46 public CutAndPasteHtmlTransfer()
49 displaySource.setSelected(false);
50 textarea.addKeyListener(new KeyListener()
54 public void keyTyped(KeyEvent arg0)
56 // if (arg0.isControlDown() && arg0.getKeyCode()==KeyEvent.VK_C)
58 // copyItem_actionPerformed(null);
64 public void keyReleased(KeyEvent arg0)
66 // TODO Auto-generated method stub
71 public void keyPressed(KeyEvent arg0)
73 // TODO Auto-generated method stub
77 textarea.setEditable(false);
78 textarea.addHyperlinkListener(new HyperlinkListener()
82 public void hyperlinkUpdate(HyperlinkEvent e)
84 if (e.getEventType().equals(EventType.ACTIVATED))
86 Desktop.showUrl(e.getURL().toExternalForm());
90 SwingUtilities.invokeLater(new Runnable()
94 textarea.requestFocus();
103 public void setForInput(AlignViewport viewport)
105 this.viewport = viewport;
106 if (viewport != null)
108 ok.setText(MessageManager.getString("action.add"));
111 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
117 * @return DOCUMENT ME!
119 public String getText()
121 return textarea.getText();
125 * Set contents of HTML Display pane
130 public void setText(String text)
132 textarea.setText(text);
135 public void save_actionPerformed(ActionEvent e)
137 JalviewFileChooser chooser = new JalviewFileChooser(
138 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
140 chooser.setAcceptAllFileFilterUsed(false);
141 chooser.setFileView(new JalviewFileView());
142 chooser.setDialogTitle("Save Text to File");
143 chooser.setToolTipText(MessageManager.getString("action.save"));
145 int value = chooser.showSaveDialog(this);
147 if (value == JalviewFileChooser.APPROVE_OPTION)
151 java.io.PrintWriter out = new java.io.PrintWriter(
152 new java.io.FileWriter(chooser.getSelectedFile()));
154 out.print(getText());
156 } catch (Exception ex)
158 ex.printStackTrace();
164 public void toggleHtml_actionPerformed(ActionEvent e)
166 String txt = textarea.getText();
167 textarea.setContentType(displaySource.isSelected() ? "text/text"
169 textarea.setText(txt);
178 public void copyItem_actionPerformed(ActionEvent e)
180 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
181 StringWriter sw = new StringWriter();
184 textarea.getEditorKit().write(sw, textarea.getDocument(),
185 textarea.getSelectionStart(),
186 textarea.getSelectionEnd() - textarea.getSelectionStart());
187 } catch (Exception x)
191 StringSelection ssel = new StringSelection(sw.getBuffer().toString());
192 c.setContents(ssel, ssel);
201 public void cancel_actionPerformed(ActionEvent e)
205 this.setClosed(true);
206 } catch (Exception ex)
211 public void textarea_mousePressed(MouseEvent e)
213 if (SwingUtilities.isRightMouseButton(e))
215 JPopupMenu popup = new JPopupMenu(MessageManager.getString("action.edit"));
216 JMenuItem item = new JMenuItem(MessageManager.getString("action.copy"));
217 item.addActionListener(new ActionListener()
219 public void actionPerformed(ActionEvent e)
221 copyItem_actionPerformed(e);
225 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);