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 jalview.api.AlignViewportI; |
24 |
|
import jalview.api.AlignmentViewPanel; |
25 |
|
import jalview.api.ComplexAlignFile; |
26 |
|
import jalview.api.FeatureSettingsModelI; |
27 |
|
import jalview.api.FeaturesDisplayedI; |
28 |
|
import jalview.api.FeaturesSourceI; |
29 |
|
import jalview.bin.Jalview; |
30 |
|
import jalview.datamodel.AlignmentI; |
31 |
|
import jalview.datamodel.HiddenColumns; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.io.AlignmentFileReaderI; |
34 |
|
import jalview.io.AppletFormatAdapter; |
35 |
|
import jalview.io.DataSourceType; |
36 |
|
import jalview.io.FileFormatException; |
37 |
|
import jalview.io.FileFormatI; |
38 |
|
import jalview.io.FormatAdapter; |
39 |
|
import jalview.io.IdentifyFile; |
40 |
|
import jalview.io.JalviewFileChooser; |
41 |
|
import jalview.io.JalviewFileView; |
42 |
|
import jalview.jbgui.GCutAndPasteTransfer; |
43 |
|
import jalview.json.binding.biojson.v1.ColourSchemeMapper; |
44 |
|
import jalview.schemes.ColourSchemeI; |
45 |
|
import jalview.util.MessageManager; |
46 |
|
|
47 |
|
import java.awt.Toolkit; |
48 |
|
import java.awt.datatransfer.Clipboard; |
49 |
|
import java.awt.datatransfer.DataFlavor; |
50 |
|
import java.awt.datatransfer.StringSelection; |
51 |
|
import java.awt.datatransfer.Transferable; |
52 |
|
import java.awt.event.ActionEvent; |
53 |
|
import java.awt.event.ActionListener; |
54 |
|
import java.awt.event.MouseEvent; |
55 |
|
import java.io.FileWriter; |
56 |
|
import java.io.IOException; |
57 |
|
import java.io.PrintWriter; |
58 |
|
|
59 |
|
import javax.swing.JMenuItem; |
60 |
|
import javax.swing.JPopupMenu; |
61 |
|
import javax.swing.SwingUtilities; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@author |
67 |
|
@version |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 142 (142) |
Complexity: 38 |
Complexity Density: 0.4 |
|
69 |
|
public class CutAndPasteTransfer extends GCutAndPasteTransfer |
70 |
|
{ |
71 |
|
|
72 |
|
AlignmentViewPanel alignpanel; |
73 |
|
|
74 |
|
AlignViewportI viewport; |
75 |
|
|
76 |
|
AlignmentFileReaderI source = null; |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
public CutAndPasteTransfer()... |
79 |
|
{ |
80 |
0 |
SwingUtilities.invokeLater(new Runnable() |
81 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public void run() |
84 |
|
{ |
85 |
0 |
textarea.requestFocus(); |
86 |
|
} |
87 |
|
}); |
88 |
|
|
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
94 |
0 |
public void setForInput(AlignmentViewPanel viewpanel)... |
95 |
|
{ |
96 |
0 |
this.alignpanel = viewpanel; |
97 |
0 |
if (alignpanel != null) |
98 |
|
{ |
99 |
0 |
this.viewport = alignpanel.getAlignViewport(); |
100 |
|
} |
101 |
0 |
if (viewport != null) |
102 |
|
{ |
103 |
0 |
ok.setText(MessageManager.getString("action.add")); |
104 |
|
} |
105 |
|
|
106 |
0 |
getContentPane().add(inputButtonPanel, java.awt.BorderLayout.SOUTH); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@return |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
public String getText()... |
115 |
|
{ |
116 |
0 |
return textarea.getText(); |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
@param |
123 |
|
|
124 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
0 |
public void setText(String text)... |
126 |
|
{ |
127 |
0 |
textarea.setText(text); |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
public void appendText(String text)... |
131 |
|
{ |
132 |
0 |
textarea.append(text); |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
135 |
0 |
@Override... |
136 |
|
public void save_actionPerformed(ActionEvent e) |
137 |
|
{ |
138 |
|
|
139 |
|
|
140 |
0 |
JalviewFileChooser chooser = new JalviewFileChooser( |
141 |
|
jalview.bin.Cache.getProperty("LAST_DIRECTORY")); |
142 |
|
|
143 |
0 |
chooser.setAcceptAllFileFilterUsed(false); |
144 |
0 |
chooser.setFileView(new JalviewFileView()); |
145 |
0 |
chooser.setDialogTitle( |
146 |
|
MessageManager.getString("label.save_text_to_file")); |
147 |
0 |
chooser.setToolTipText(MessageManager.getString("action.save")); |
148 |
|
|
149 |
0 |
int value = chooser.showSaveDialog(this); |
150 |
|
|
151 |
0 |
if (value == JalviewFileChooser.APPROVE_OPTION) |
152 |
|
{ |
153 |
0 |
try |
154 |
|
{ |
155 |
0 |
PrintWriter out = new PrintWriter( |
156 |
|
new FileWriter(chooser.getSelectedFile())); |
157 |
|
|
158 |
0 |
out.print(getText()); |
159 |
0 |
out.close(); |
160 |
|
} catch (Exception ex) |
161 |
|
{ |
162 |
0 |
ex.printStackTrace(); |
163 |
|
} |
164 |
|
|
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
@param |
172 |
|
|
173 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
174 |
0 |
@Override... |
175 |
|
public void copyItem_actionPerformed(ActionEvent e) |
176 |
|
{ |
177 |
0 |
textarea.getSelectedText(); |
178 |
0 |
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); |
179 |
0 |
c.setContents(new StringSelection(textarea.getSelectedText()), null); |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
@param |
186 |
|
|
187 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
188 |
0 |
@Override... |
189 |
|
public void pasteMenu_actionPerformed(ActionEvent e) |
190 |
|
{ |
191 |
0 |
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); |
192 |
0 |
Transferable contents = c.getContents(this); |
193 |
|
|
194 |
0 |
if (contents == null) |
195 |
|
{ |
196 |
0 |
return; |
197 |
|
} |
198 |
|
|
199 |
0 |
try |
200 |
|
{ |
201 |
0 |
textarea.append( |
202 |
|
(String) contents.getTransferData(DataFlavor.stringFlavor)); |
203 |
|
} catch (Exception ex) |
204 |
|
{ |
205 |
|
} |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
@param |
212 |
|
|
213 |
|
|
|
|
| 0% |
Uncovered Elements: 73 (73) |
Complexity: 17 |
Complexity Density: 0.33 |
|
214 |
0 |
@Override... |
215 |
|
public void ok_actionPerformed(ActionEvent e) |
216 |
|
{ |
217 |
0 |
String text = getText(); |
218 |
0 |
if (text.trim().length() < 1) |
219 |
|
{ |
220 |
0 |
return; |
221 |
|
} |
222 |
|
|
223 |
0 |
FileFormatI format = null; |
224 |
0 |
try |
225 |
|
{ |
226 |
0 |
format = new IdentifyFile().identify(text, DataSourceType.PASTE); |
227 |
|
} catch (FileFormatException e1) |
228 |
|
{ |
229 |
|
|
230 |
|
} |
231 |
0 |
if (format == null) |
232 |
|
{ |
233 |
0 |
System.err |
234 |
|
.println(MessageManager.getString("label.couldnt_read_data")); |
235 |
0 |
if (!Jalview.isHeadlessMode()) |
236 |
|
{ |
237 |
0 |
JvOptionPane.showInternalMessageDialog(Desktop.desktop, |
238 |
|
AppletFormatAdapter.getSupportedFormats(), |
239 |
|
MessageManager.getString("label.couldnt_read_data"), |
240 |
|
JvOptionPane.WARNING_MESSAGE); |
241 |
|
} |
242 |
0 |
return; |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
0 |
AlignmentI al = null; |
247 |
|
|
248 |
0 |
try |
249 |
|
{ |
250 |
0 |
FormatAdapter fa = new FormatAdapter(alignpanel); |
251 |
0 |
al = fa.readFile(getText(), DataSourceType.PASTE, format); |
252 |
0 |
source = fa.getAlignFile(); |
253 |
|
|
254 |
|
} catch (IOException ex) |
255 |
|
{ |
256 |
0 |
JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager |
257 |
|
.formatMessage("label.couldnt_read_pasted_text", new String[] |
258 |
|
{ ex.toString() }), |
259 |
|
MessageManager.getString("label.error_parsing_text"), |
260 |
|
JvOptionPane.WARNING_MESSAGE); |
261 |
|
} |
262 |
|
|
263 |
0 |
if (al != null && al.hasValidSequence()) |
264 |
|
{ |
265 |
0 |
String title = MessageManager |
266 |
|
.formatMessage("label.input_cut_paste_params", new String[] |
267 |
|
{ format.getName() }); |
268 |
0 |
FeatureSettingsModelI proxyColourScheme = source |
269 |
|
.getFeatureColourScheme(); |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
0 |
if (viewport != null && viewport.getAlignment() != null) |
276 |
|
{ |
277 |
0 |
if (proxyColourScheme != null) |
278 |
|
{ |
279 |
0 |
viewport.applyFeaturesStyle(proxyColourScheme); |
280 |
|
} |
281 |
0 |
((AlignViewport) viewport).addAlignment(al, title); |
282 |
|
} |
283 |
|
else |
284 |
|
{ |
285 |
|
|
286 |
0 |
AlignFrame af; |
287 |
0 |
if (source instanceof ComplexAlignFile) |
288 |
|
{ |
289 |
0 |
HiddenColumns hidden = ((ComplexAlignFile) source) |
290 |
|
.getHiddenColumns(); |
291 |
0 |
SequenceI[] hiddenSeqs = ((ComplexAlignFile) source) |
292 |
|
.getHiddenSequences(); |
293 |
0 |
boolean showSeqFeatures = ((ComplexAlignFile) source) |
294 |
|
.isShowSeqFeatures(); |
295 |
0 |
String colourSchemeName = ((ComplexAlignFile) source) |
296 |
|
.getGlobalColourScheme(); |
297 |
0 |
FeaturesDisplayedI fd = ((ComplexAlignFile) source) |
298 |
|
.getDisplayedFeatures(); |
299 |
0 |
af = new AlignFrame(al, hiddenSeqs, hidden, |
300 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
301 |
0 |
af.getViewport().setShowSequenceFeatures(showSeqFeatures); |
302 |
0 |
af.getViewport().setFeaturesDisplayed(fd); |
303 |
0 |
af.setMenusForViewport(); |
304 |
0 |
ColourSchemeI cs = ColourSchemeMapper.getJalviewColourScheme( |
305 |
|
colourSchemeName, al); |
306 |
0 |
if (cs != null) |
307 |
|
{ |
308 |
0 |
af.changeColour(cs); |
309 |
|
} |
310 |
|
} |
311 |
|
else |
312 |
|
{ |
313 |
0 |
af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH, |
314 |
|
AlignFrame.DEFAULT_HEIGHT); |
315 |
0 |
if (source instanceof FeaturesSourceI) |
316 |
|
{ |
317 |
0 |
af.getViewport().setShowSequenceFeatures(true); |
318 |
|
} |
319 |
|
} |
320 |
0 |
if (proxyColourScheme != null) |
321 |
|
{ |
322 |
0 |
af.getViewport().applyFeaturesStyle(proxyColourScheme); |
323 |
|
} |
324 |
0 |
af.currentFileFormat = format; |
325 |
0 |
Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH, |
326 |
|
AlignFrame.DEFAULT_HEIGHT); |
327 |
0 |
af.setStatus(MessageManager |
328 |
|
.getString("label.successfully_pasted_alignment_file")); |
329 |
|
|
330 |
0 |
try |
331 |
|
{ |
332 |
0 |
af.setMaximum( |
333 |
|
jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); |
334 |
|
} catch (Exception ex) |
335 |
|
{ |
336 |
|
} |
337 |
|
} |
338 |
|
} |
339 |
|
else |
340 |
|
{ |
341 |
0 |
System.err |
342 |
|
.println(MessageManager.getString("label.couldnt_read_data")); |
343 |
0 |
if (!Jalview.isHeadlessMode()) |
344 |
|
{ |
345 |
0 |
JvOptionPane.showInternalMessageDialog(Desktop.desktop, |
346 |
|
AppletFormatAdapter.getSupportedFormats(), |
347 |
|
MessageManager.getString("label.couldnt_read_data"), |
348 |
|
JvOptionPane.WARNING_MESSAGE); |
349 |
|
} |
350 |
|
} |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
@param |
357 |
|
|
358 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
359 |
0 |
@Override... |
360 |
|
public void cancel_actionPerformed(ActionEvent e) |
361 |
|
{ |
362 |
0 |
try |
363 |
|
{ |
364 |
0 |
this.setClosed(true); |
365 |
|
} catch (Exception ex) |
366 |
|
{ |
367 |
|
} |
368 |
|
} |
369 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
370 |
0 |
@Override... |
371 |
|
public void textarea_mousePressed(MouseEvent e) |
372 |
|
{ |
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
0 |
if (e.isPopupTrigger()) |
378 |
|
{ |
379 |
0 |
JPopupMenu popup = new JPopupMenu( |
380 |
|
MessageManager.getString("action.edit")); |
381 |
0 |
JMenuItem item = new JMenuItem( |
382 |
|
MessageManager.getString("action.copy")); |
383 |
0 |
item.addActionListener(new ActionListener() |
384 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
385 |
0 |
@Override... |
386 |
|
public void actionPerformed(ActionEvent e) |
387 |
|
{ |
388 |
0 |
copyItem_actionPerformed(e); |
389 |
|
} |
390 |
|
}); |
391 |
0 |
popup.add(item); |
392 |
0 |
item = new JMenuItem(MessageManager.getString("action.paste")); |
393 |
0 |
item.addActionListener(new ActionListener() |
394 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
395 |
0 |
@Override... |
396 |
|
public void actionPerformed(ActionEvent e) |
397 |
|
{ |
398 |
0 |
pasteMenu_actionPerformed(e); |
399 |
|
} |
400 |
|
}); |
401 |
0 |
popup.add(item); |
402 |
0 |
popup.show(this, e.getX() + 10, e.getY() + textarea.getY() + 40); |
403 |
|
|
404 |
|
} |
405 |
|
} |
406 |
|
|
407 |
|
} |