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.*;
35 * Cut'n'paste files into the desktop See JAL-1105
40 public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
43 AlignViewport viewport;
45 public CutAndPasteHtmlTransfer()
48 displaySource.setSelected(false);
49 textarea.addKeyListener(new KeyListener()
53 public void keyTyped(KeyEvent arg0)
55 // if (arg0.isControlDown() && arg0.getKeyCode()==KeyEvent.VK_C)
57 // copyItem_actionPerformed(null);
63 public void keyReleased(KeyEvent arg0)
65 // TODO Auto-generated method stub
70 public void keyPressed(KeyEvent arg0)
72 // TODO Auto-generated method stub
76 textarea.setEditable(false);
77 textarea.addHyperlinkListener(new HyperlinkListener()
81 public void hyperlinkUpdate(HyperlinkEvent e)
83 if (e.getEventType().equals(EventType.ACTIVATED))
85 Desktop.showUrl(e.getURL().toExternalForm());
89 SwingUtilities.invokeLater(new Runnable()
93 textarea.requestFocus();
102 public void setForInput(AlignViewport viewport)
104 this.viewport = viewport;
105 if (viewport != null)
110 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
116 * @return DOCUMENT ME!
118 public String getText()
120 return textarea.getText();
124 * Set contents of HTML Display pane
129 public void setText(String text)
131 textarea.setText(text);
134 public void save_actionPerformed(ActionEvent e)
136 JalviewFileChooser chooser = new JalviewFileChooser(
137 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
139 chooser.setAcceptAllFileFilterUsed(false);
140 chooser.setFileView(new JalviewFileView());
141 chooser.setDialogTitle("Save Text to File");
142 chooser.setToolTipText("Save");
144 int value = chooser.showSaveDialog(this);
146 if (value == JalviewFileChooser.APPROVE_OPTION)
150 java.io.PrintWriter out = new java.io.PrintWriter(
151 new java.io.FileWriter(chooser.getSelectedFile()));
153 out.print(getText());
155 } catch (Exception ex)
157 ex.printStackTrace();
163 public void toggleHtml_actionPerformed(ActionEvent e)
165 String txt = textarea.getText();
166 textarea.setContentType(displaySource.isSelected() ? "text/text"
168 textarea.setText(txt);
177 public void copyItem_actionPerformed(ActionEvent e)
179 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
180 StringWriter sw = new StringWriter();
183 textarea.getEditorKit().write(sw, textarea.getDocument(),
184 textarea.getSelectionStart(),
185 textarea.getSelectionEnd() - textarea.getSelectionStart());
186 } catch (Exception x)
190 StringSelection ssel = new StringSelection(sw.getBuffer().toString());
191 c.setContents(ssel, ssel);
200 public void cancel_actionPerformed(ActionEvent e)
204 this.setClosed(true);
205 } catch (Exception ex)
210 public void textarea_mousePressed(MouseEvent e)
212 if (SwingUtilities.isRightMouseButton(e))
214 JPopupMenu popup = new JPopupMenu("Edit");
215 JMenuItem item = new JMenuItem("Copy");
216 item.addActionListener(new ActionListener()
218 public void actionPerformed(ActionEvent e)
220 copyItem_actionPerformed(e);
224 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);