2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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;
30 import jalview.datamodel.*;
32 import jalview.jbgui.*;
35 * Cut'n'paste files into the desktop
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)
111 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
117 * @return DOCUMENT ME!
119 public String getText()
121 return textarea.getText();
124 * Set contents of HTML Display pane
126 * @param text HTML text
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" : "text/html");
166 textarea.setText(txt);
174 public void copyItem_actionPerformed(ActionEvent e)
176 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
177 StringWriter sw = new StringWriter();
179 textarea.getEditorKit().write(sw, textarea.getDocument(), textarea.getSelectionStart(), textarea.getSelectionEnd()-textarea.getSelectionStart());
180 } catch (Exception x){};
181 StringSelection ssel=new StringSelection(sw.getBuffer().toString());
182 c.setContents(ssel,ssel);
192 public void cancel_actionPerformed(ActionEvent e)
196 this.setClosed(true);
197 } catch (Exception ex)
202 public void textarea_mousePressed(MouseEvent e)
204 if (SwingUtilities.isRightMouseButton(e))
206 JPopupMenu popup = new JPopupMenu("Edit");
207 JMenuItem item = new JMenuItem("Copy");
208 item.addActionListener(new ActionListener()
210 public void actionPerformed(ActionEvent e)
212 copyItem_actionPerformed(e);
216 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);