2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
21 import java.awt.datatransfer.*;
22 import java.awt.event.*;
23 import java.io.StringWriter;
26 import javax.swing.event.HyperlinkEvent;
27 import javax.swing.event.HyperlinkListener;
28 import javax.swing.event.HyperlinkEvent.EventType;
31 import jalview.jbgui.*;
34 * Cut'n'paste files into the desktop See JAL-1105
39 public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
42 AlignViewport viewport;
44 public CutAndPasteHtmlTransfer()
47 displaySource.setSelected(false);
48 textarea.addKeyListener(new KeyListener()
52 public void keyTyped(KeyEvent arg0)
54 // if (arg0.isControlDown() && arg0.getKeyCode()==KeyEvent.VK_C)
56 // copyItem_actionPerformed(null);
62 public void keyReleased(KeyEvent arg0)
64 // TODO Auto-generated method stub
69 public void keyPressed(KeyEvent arg0)
71 // TODO Auto-generated method stub
75 textarea.setEditable(false);
76 textarea.addHyperlinkListener(new HyperlinkListener()
80 public void hyperlinkUpdate(HyperlinkEvent e)
82 if (e.getEventType().equals(EventType.ACTIVATED))
84 Desktop.showUrl(e.getURL().toExternalForm());
88 SwingUtilities.invokeLater(new Runnable()
92 textarea.requestFocus();
101 public void setForInput(AlignViewport viewport)
103 this.viewport = viewport;
104 if (viewport != null)
109 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
115 * @return DOCUMENT ME!
117 public String getText()
119 return textarea.getText();
123 * Set contents of HTML Display pane
128 public void setText(String text)
130 textarea.setText(text);
133 public void save_actionPerformed(ActionEvent e)
135 JalviewFileChooser chooser = new JalviewFileChooser(
136 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
138 chooser.setAcceptAllFileFilterUsed(false);
139 chooser.setFileView(new JalviewFileView());
140 chooser.setDialogTitle("Save Text to File");
141 chooser.setToolTipText("Save");
143 int value = chooser.showSaveDialog(this);
145 if (value == JalviewFileChooser.APPROVE_OPTION)
149 java.io.PrintWriter out = new java.io.PrintWriter(
150 new java.io.FileWriter(chooser.getSelectedFile()));
152 out.print(getText());
154 } catch (Exception ex)
156 ex.printStackTrace();
162 public void toggleHtml_actionPerformed(ActionEvent e)
164 String txt = textarea.getText();
165 textarea.setContentType(displaySource.isSelected() ? "text/text"
167 textarea.setText(txt);
176 public void copyItem_actionPerformed(ActionEvent e)
178 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
179 StringWriter sw = new StringWriter();
182 textarea.getEditorKit().write(sw, textarea.getDocument(),
183 textarea.getSelectionStart(),
184 textarea.getSelectionEnd() - textarea.getSelectionStart());
185 } catch (Exception x)
189 StringSelection ssel = new StringSelection(sw.getBuffer().toString());
190 c.setContents(ssel, ssel);
199 public void cancel_actionPerformed(ActionEvent e)
203 this.setClosed(true);
204 } catch (Exception ex)
209 public void textarea_mousePressed(MouseEvent e)
211 if (SwingUtilities.isRightMouseButton(e))
213 JPopupMenu popup = new JPopupMenu("Edit");
214 JMenuItem item = new JMenuItem("Copy");
215 item.addActionListener(new ActionListener()
217 public void actionPerformed(ActionEvent e)
219 copyItem_actionPerformed(e);
223 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);