2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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;
36 import jalview.viewmodel.AlignmentViewport;
39 * Cut'n'paste files into the desktop See JAL-1105
44 public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
47 AlignmentViewport viewport;
49 public CutAndPasteHtmlTransfer()
52 displaySource.setSelected(false);
53 textarea.addKeyListener(new KeyListener()
57 public void keyTyped(KeyEvent arg0)
59 // if (arg0.isControlDown() && arg0.getKeyCode()==KeyEvent.VK_C)
61 // copyItem_actionPerformed(null);
67 public void keyReleased(KeyEvent arg0)
69 // TODO Auto-generated method stub
74 public void keyPressed(KeyEvent arg0)
76 // TODO Auto-generated method stub
80 textarea.setEditable(false);
81 textarea.addHyperlinkListener(new HyperlinkListener()
85 public void hyperlinkUpdate(HyperlinkEvent e)
87 if (e.getEventType().equals(EventType.ACTIVATED))
89 Desktop.showUrl(e.getURL().toExternalForm());
93 SwingUtilities.invokeLater(new Runnable()
97 textarea.requestFocus();
106 public void setForInput(AlignmentViewport viewport)
108 this.viewport = viewport;
109 if (viewport != null)
111 ok.setText(MessageManager.getString("action.add"));
114 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
120 * @return DOCUMENT ME!
122 public String getText()
124 return textarea.getText();
128 * Set contents of HTML Display pane
133 public void setText(String text)
135 textarea.setText(text);
138 public void save_actionPerformed(ActionEvent e)
140 JalviewFileChooser chooser = new JalviewFileChooser(
141 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
143 chooser.setAcceptAllFileFilterUsed(false);
144 chooser.setFileView(new JalviewFileView());
145 chooser.setDialogTitle(MessageManager.getString("label.save_text_to_file"));
146 chooser.setToolTipText(MessageManager.getString("action.save"));
148 int value = chooser.showSaveDialog(this);
150 if (value == JalviewFileChooser.APPROVE_OPTION)
154 java.io.PrintWriter out = new java.io.PrintWriter(
155 new java.io.FileWriter(chooser.getSelectedFile()));
157 out.print(getText());
159 } catch (Exception ex)
161 ex.printStackTrace();
167 public void toggleHtml_actionPerformed(ActionEvent e)
169 String txt = textarea.getText();
170 textarea.setContentType(displaySource.isSelected() ? "text/text"
172 textarea.setText(txt);
181 public void copyItem_actionPerformed(ActionEvent e)
183 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
184 StringWriter sw = new StringWriter();
187 textarea.getEditorKit().write(sw, textarea.getDocument(),
188 textarea.getSelectionStart(),
189 textarea.getSelectionEnd() - textarea.getSelectionStart());
190 } catch (Exception x)
194 StringSelection ssel = new StringSelection(sw.getBuffer().toString());
195 c.setContents(ssel, ssel);
204 public void cancel_actionPerformed(ActionEvent e)
208 this.setClosed(true);
209 } catch (Exception ex)
214 public void textarea_mousePressed(MouseEvent e)
216 if (SwingUtilities.isRightMouseButton(e))
218 JPopupMenu popup = new JPopupMenu(
219 MessageManager.getString("action.edit"));
220 JMenuItem item = new JMenuItem(
221 MessageManager.getString("action.copy"));
222 item.addActionListener(new ActionListener()
224 public void actionPerformed(ActionEvent e)
226 copyItem_actionPerformed(e);
230 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);