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.*;
26 import java.io.StringWriter;
29 import javax.swing.event.HyperlinkEvent;
30 import javax.swing.event.HyperlinkListener;
31 import javax.swing.event.HyperlinkEvent.EventType;
34 import jalview.jbgui.*;
35 import jalview.util.MessageManager;
38 * Cut'n'paste files into the desktop See JAL-1105
43 public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
46 AlignViewport viewport;
48 public CutAndPasteHtmlTransfer()
51 displaySource.setSelected(false);
52 textarea.addKeyListener(new KeyListener()
56 public void keyTyped(KeyEvent arg0)
58 // if (arg0.isControlDown() && arg0.getKeyCode()==KeyEvent.VK_C)
60 // copyItem_actionPerformed(null);
66 public void keyReleased(KeyEvent arg0)
68 // TODO Auto-generated method stub
73 public void keyPressed(KeyEvent arg0)
75 // TODO Auto-generated method stub
79 textarea.setEditable(false);
80 textarea.addHyperlinkListener(new HyperlinkListener()
84 public void hyperlinkUpdate(HyperlinkEvent e)
86 if (e.getEventType().equals(EventType.ACTIVATED))
88 Desktop.showUrl(e.getURL().toExternalForm());
92 SwingUtilities.invokeLater(new Runnable()
96 textarea.requestFocus();
105 public void setForInput(AlignViewport viewport)
107 this.viewport = viewport;
108 if (viewport != null)
110 ok.setText(MessageManager.getString("action.add"));
113 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
119 * @return DOCUMENT ME!
121 public String getText()
123 return textarea.getText();
127 * Set contents of HTML Display pane
132 public void setText(String text)
134 textarea.setText(text);
137 public void save_actionPerformed(ActionEvent e)
139 JalviewFileChooser chooser = new JalviewFileChooser(
140 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
142 chooser.setAcceptAllFileFilterUsed(false);
143 chooser.setFileView(new JalviewFileView());
144 chooser.setDialogTitle(MessageManager.getString("label.save_text_to_file"));
145 chooser.setToolTipText(MessageManager.getString("action.save"));
147 int value = chooser.showSaveDialog(this);
149 if (value == JalviewFileChooser.APPROVE_OPTION)
153 java.io.PrintWriter out = new java.io.PrintWriter(
154 new java.io.FileWriter(chooser.getSelectedFile()));
156 out.print(getText());
158 } catch (Exception ex)
160 ex.printStackTrace();
166 public void toggleHtml_actionPerformed(ActionEvent e)
168 String txt = textarea.getText();
169 textarea.setContentType(displaySource.isSelected() ? "text/text"
171 textarea.setText(txt);
180 public void copyItem_actionPerformed(ActionEvent e)
182 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
183 StringWriter sw = new StringWriter();
186 textarea.getEditorKit().write(sw, textarea.getDocument(),
187 textarea.getSelectionStart(),
188 textarea.getSelectionEnd() - textarea.getSelectionStart());
189 } catch (Exception x)
193 StringSelection ssel = new StringSelection(sw.getBuffer().toString());
194 c.setContents(ssel, ssel);
203 public void cancel_actionPerformed(ActionEvent e)
207 this.setClosed(true);
208 } catch (Exception ex)
213 public void textarea_mousePressed(MouseEvent e)
215 if (SwingUtilities.isRightMouseButton(e))
217 JPopupMenu popup = new JPopupMenu(
218 MessageManager.getString("action.edit"));
219 JMenuItem item = new JMenuItem(
220 MessageManager.getString("action.copy"));
221 item.addActionListener(new ActionListener()
223 public void actionPerformed(ActionEvent e)
225 copyItem_actionPerformed(e);
229 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);