1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
49 |
|
|
50 |
|
@author |
51 |
|
@version |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 75 (75) |
Complexity: 23 |
Complexity Density: 0.46 |
|
53 |
|
public class CutAndPasteHtmlTransfer extends GCutAndPasteHtmlTransfer |
54 |
|
{ |
55 |
|
|
56 |
|
AlignmentViewport viewport; |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
58 |
0 |
public CutAndPasteHtmlTransfer()... |
59 |
|
{ |
60 |
0 |
super(); |
61 |
0 |
this.setFrameIcon(null); |
62 |
0 |
displaySource.setSelected(false); |
63 |
0 |
textarea.addKeyListener(new KeyListener() |
64 |
|
{ |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
@Override... |
67 |
|
public void keyTyped(KeyEvent arg0) |
68 |
|
{ |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
0 |
arg0.consume(); |
74 |
|
} |
75 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
76 |
0 |
@Override... |
77 |
|
public void keyReleased(KeyEvent arg0) |
78 |
|
{ |
79 |
|
|
80 |
|
|
81 |
|
} |
82 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
83 |
0 |
@Override... |
84 |
|
public void keyPressed(KeyEvent arg0) |
85 |
|
{ |
86 |
|
|
87 |
|
|
88 |
|
} |
89 |
|
}); |
90 |
0 |
textarea.setEditable(false); |
91 |
0 |
textarea.addHyperlinkListener(new HyperlinkListener() |
92 |
|
{ |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
94 |
0 |
@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 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0 |
@Override... |
106 |
|
public void run() |
107 |
|
{ |
108 |
0 |
textarea.requestFocus(); |
109 |
|
} |
110 |
|
}); |
111 |
|
|
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
117 |
0 |
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 |
|
|
130 |
|
|
131 |
|
@return |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
133 |
0 |
public String getText()... |
134 |
|
{ |
135 |
0 |
return textarea.getText(); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
|
143 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
144 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
151 |
0 |
@Override... |
152 |
|
public void save_actionPerformed(ActionEvent e) |
153 |
|
{ |
154 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
184 |
0 |
@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 |
|
|
195 |
|
|
196 |
|
@param |
197 |
|
|
198 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
199 |
0 |
@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 |
|
|
219 |
|
|
220 |
|
@param |
221 |
|
|
222 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
223 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
234 |
0 |
@Override... |
235 |
|
public void textarea_mousePressed(MouseEvent e) |
236 |
|
{ |
237 |
|
|
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 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
246 |
0 |
@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 |
|
} |