Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.gui

File CutAndPasteHtmlTransfer.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

10
50
15
1
258
168
23
0.46
3.33
15
1.53

Classes

Class Line # Actions
CutAndPasteHtmlTransfer 53 50 23
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.gui;
22   
23    import java.awt.Toolkit;
24    import java.awt.datatransfer.Clipboard;
25    import java.awt.datatransfer.StringSelection;
26    import java.awt.event.ActionEvent;
27    import java.awt.event.ActionListener;
28    import java.awt.event.KeyEvent;
29    import java.awt.event.KeyListener;
30    import java.awt.event.MouseEvent;
31    import java.io.StringWriter;
32   
33    import javax.swing.JMenuItem;
34    import javax.swing.JPopupMenu;
35    import javax.swing.SwingUtilities;
36    import javax.swing.event.HyperlinkEvent;
37    import javax.swing.event.HyperlinkEvent.EventType;
38    import javax.swing.event.HyperlinkListener;
39   
40    import jalview.bin.Cache;
41    import jalview.io.JalviewFileChooser;
42    import jalview.io.JalviewFileView;
43    import jalview.jbgui.GCutAndPasteHtmlTransfer;
44    import jalview.util.MessageManager;
45    import jalview.viewmodel.AlignmentViewport;
46   
47    /**
48    * Cut'n'paste files into the desktop See JAL-1105
49    *
50    * @author $author$
51    * @version $Revision$
52    */
 
53    public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer
54    {
55   
56    AlignmentViewport viewport;
57   
 
58  0 toggle public CutAndPasteHtmlTransfer()
59    {
60  0 super();
61  0 this.setFrameIcon(null);
62  0 displaySource.setSelected(false);
63  0 textarea.addKeyListener(new KeyListener()
64    {
65   
 
66  0 toggle @Override
67    public void keyTyped(KeyEvent arg0)
68    {
69    // if (arg0.isControlDown() && arg0.getKeyCode()==KeyEvent.VK_C)
70    // {
71    // copyItem_actionPerformed(null);
72    // }
73  0 arg0.consume();
74    }
75   
 
76  0 toggle @Override
77    public void keyReleased(KeyEvent arg0)
78    {
79    // TODO Auto-generated method stub
80   
81    }
82   
 
83  0 toggle @Override
84    public void keyPressed(KeyEvent arg0)
85    {
86    // TODO Auto-generated method stub
87   
88    }
89    });
90  0 textarea.setEditable(false);
91  0 textarea.addHyperlinkListener(new HyperlinkListener()
92    {
93   
 
94  0 toggle @Override
95    public void hyperlinkUpdate(HyperlinkEvent e)
96    {
97  0 if (e.getEventType().equals(EventType.ACTIVATED))
98    {
99  0 Desktop.showUrl(e.getURL().toExternalForm());
100    }
101    }
102    });
103  0 SwingUtilities.invokeLater(new Runnable()
104    {
 
105  0 toggle @Override
106    public void run()
107    {
108  0 textarea.requestFocus();
109    }
110    });
111   
112    }
113   
114    /**
115    * DOCUMENT ME!
116    */
 
117  0 toggle public void setForInput(AlignmentViewport viewport)
118    {
119  0 this.viewport = viewport;
120  0 if (viewport != null)
121    {
122  0 ok.setText(MessageManager.getString("action.add"));
123    }
124   
125  0 getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH);
126    }
127   
128    /**
129    * DOCUMENT ME!
130    *
131    * @return DOCUMENT ME!
132    */
 
133  0 toggle public String getText()
134    {
135  0 return textarea.getText();
136    }
137   
138    /**
139    * Set contents of HTML Display pane
140    *
141    * @param text
142    * HTML text
143    */
 
144  0 toggle public void setText(String text)
145    {
146  0 textarea.setDocument(textarea.getEditorKit().createDefaultDocument());
147  0 textarea.setText(text);
148  0 textarea.setCaretPosition(0);
149    }
150   
 
151  0 toggle @Override
152    public void save_actionPerformed(ActionEvent e)
153    {
154    // TODO: JAL-3048 JalviewFileChooser - Save option
155   
156  0 JalviewFileChooser chooser = new JalviewFileChooser(
157    Cache.getProperty("LAST_DIRECTORY"));
158   
159  0 chooser.setAcceptAllFileFilterUsed(false);
160  0 chooser.setFileView(new JalviewFileView());
161  0 chooser.setDialogTitle(
162    MessageManager.getString("label.save_text_to_file"));
163  0 chooser.setToolTipText(MessageManager.getString("action.save"));
164   
165  0 int value = chooser.showSaveDialog(this);
166   
167  0 if (value == JalviewFileChooser.APPROVE_OPTION)
168    {
169  0 try
170    {
171  0 java.io.PrintWriter out = new java.io.PrintWriter(
172    new java.io.FileWriter(chooser.getSelectedFile()));
173   
174  0 out.print(getText());
175  0 out.close();
176    } catch (Exception ex)
177    {
178  0 ex.printStackTrace();
179    }
180   
181    }
182    }
183   
 
184  0 toggle @Override
185    public void toggleHtml_actionPerformed(ActionEvent e)
186    {
187  0 String txt = textarea.getText();
188  0 textarea.setContentType(
189  0 displaySource.isSelected() ? "text/text" : "text/html");
190  0 textarea.setText(txt);
191    }
192   
193    /**
194    * DOCUMENT ME!
195    *
196    * @param e
197    * DOCUMENT ME!
198    */
 
199  0 toggle @Override
200    public void copyItem_actionPerformed(ActionEvent e)
201    {
202  0 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
203  0 StringWriter sw = new StringWriter();
204  0 try
205    {
206  0 textarea.getEditorKit().write(sw, textarea.getDocument(),
207    textarea.getSelectionStart(),
208    textarea.getSelectionEnd() - textarea.getSelectionStart());
209    } catch (Exception x)
210    {
211    }
212  0 ;
213  0 StringSelection ssel = new StringSelection(sw.getBuffer().toString());
214  0 c.setContents(ssel, ssel);
215    }
216   
217    /**
218    * DOCUMENT ME!
219    *
220    * @param e
221    * DOCUMENT ME!
222    */
 
223  0 toggle @Override
224    public void cancel_actionPerformed(ActionEvent e)
225    {
226  0 try
227    {
228  0 this.setClosed(true);
229    } catch (Exception ex)
230    {
231    }
232    }
233   
 
234  0 toggle @Override
235    public void textarea_mousePressed(MouseEvent e)
236    {
237    // isPopupTrigger is on mousePressed (Mac) or mouseReleased (Windows)
238  0 if (e.isPopupTrigger())
239    {
240  0 JPopupMenu popup = new JPopupMenu(
241    MessageManager.getString("action.edit"));
242  0 JMenuItem item = new JMenuItem(
243    MessageManager.getString("action.copy"));
244  0 item.addActionListener(new ActionListener()
245    {
 
246  0 toggle @Override
247    public void actionPerformed(ActionEvent e)
248    {
249  0 copyItem_actionPerformed(e);
250    }
251    });
252  0 popup.add(item);
253  0 popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40);
254   
255    }
256    }
257   
258    }