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.FeatureRenderer; |
24 |
|
import jalview.bin.Cache; |
25 |
|
import jalview.datamodel.AlignmentAnnotation; |
26 |
|
import jalview.datamodel.SequenceI; |
27 |
|
import jalview.io.AnnotationFile; |
28 |
|
import jalview.io.FeaturesFile; |
29 |
|
import jalview.io.JalviewFileChooser; |
30 |
|
import jalview.io.JalviewFileView; |
31 |
|
import jalview.util.MessageManager; |
32 |
|
|
33 |
|
import java.awt.Color; |
34 |
|
import java.awt.Dimension; |
35 |
|
import java.awt.event.ActionEvent; |
36 |
|
import java.awt.event.ActionListener; |
37 |
|
import java.io.FileWriter; |
38 |
|
import java.io.PrintWriter; |
39 |
|
|
40 |
|
import javax.swing.BoxLayout; |
41 |
|
import javax.swing.ButtonGroup; |
42 |
|
import javax.swing.JButton; |
43 |
|
import javax.swing.JCheckBox; |
44 |
|
import javax.swing.JInternalFrame; |
45 |
|
import javax.swing.JLabel; |
46 |
|
import javax.swing.JLayeredPane; |
47 |
|
import javax.swing.JPanel; |
48 |
|
import javax.swing.JRadioButton; |
49 |
|
import javax.swing.SwingConstants; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@author |
57 |
|
|
58 |
|
|
|
|
| 0% |
Uncovered Elements: 161 (161) |
Complexity: 33 |
Complexity Density: 0.27 |
|
59 |
|
public class AnnotationExporter extends JPanel |
60 |
|
{ |
61 |
|
private JInternalFrame frame; |
62 |
|
|
63 |
|
private AlignmentPanel ap; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private boolean exportFeatures = true; |
69 |
|
|
70 |
|
private AlignmentAnnotation[] annotations; |
71 |
|
|
72 |
|
private boolean wholeView; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
private JCheckBox includeLinkedFeatures; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
JRadioButton GFFFormat = new JRadioButton(); |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
JRadioButton CSVFormat = new JRadioButton(); |
89 |
|
|
90 |
|
private JPanel linkedFeaturesPanel; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
@param |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
97 |
0 |
public AnnotationExporter(AlignmentPanel panel)... |
98 |
|
{ |
99 |
0 |
this.ap = panel; |
100 |
0 |
try |
101 |
|
{ |
102 |
0 |
jbInit(); |
103 |
|
} catch (Exception ex) |
104 |
|
{ |
105 |
0 |
ex.printStackTrace(); |
106 |
|
} |
107 |
|
|
108 |
0 |
frame = new JInternalFrame(); |
109 |
0 |
frame.setContentPane(this); |
110 |
0 |
frame.setLayer(JLayeredPane.PALETTE_LAYER); |
111 |
0 |
Dimension preferredSize = frame.getPreferredSize(); |
112 |
0 |
Desktop.addInternalFrame(frame, "", true, preferredSize.width, |
113 |
|
preferredSize.height, true, true); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
121 |
0 |
public void exportFeatures()... |
122 |
|
{ |
123 |
0 |
exportFeatures = true; |
124 |
0 |
CSVFormat.setVisible(false); |
125 |
0 |
if (ap.av.isShowComplementFeatures()) |
126 |
|
{ |
127 |
0 |
linkedFeaturesPanel.setVisible(true); |
128 |
0 |
frame.pack(); |
129 |
|
} |
130 |
0 |
frame.setTitle(MessageManager.getString("label.export_features")); |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
136 |
0 |
public void exportAnnotations()... |
137 |
|
{ |
138 |
0 |
boolean showAnnotation = ap.av.isShowAnnotation(); |
139 |
0 |
exportAnnotation(showAnnotation ? null |
140 |
|
: ap.av.getAlignment().getAlignmentAnnotation(), true); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
0 |
public void exportAnnotation(AlignmentAnnotation toExport)... |
149 |
|
{ |
150 |
0 |
exportAnnotation(new AlignmentAnnotation[] { toExport }, false); |
151 |
|
} |
152 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
153 |
0 |
private void exportAnnotation(AlignmentAnnotation[] toExport,... |
154 |
|
boolean forWholeView) |
155 |
|
{ |
156 |
0 |
wholeView = forWholeView; |
157 |
0 |
annotations = toExport; |
158 |
0 |
exportFeatures = false; |
159 |
0 |
GFFFormat.setVisible(false); |
160 |
0 |
CSVFormat.setVisible(true); |
161 |
0 |
frame.setTitle(MessageManager.getString("label.export_annotations")); |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.31 |
|
164 |
0 |
private void toFile_actionPerformed()... |
165 |
|
{ |
166 |
|
|
167 |
0 |
JalviewFileChooser chooser = new JalviewFileChooser( |
168 |
|
Cache.getProperty("LAST_DIRECTORY")); |
169 |
|
|
170 |
0 |
chooser.setFileView(new JalviewFileView()); |
171 |
0 |
chooser.setDialogTitle(exportFeatures |
172 |
|
? MessageManager.getString("label.save_features_to_file") |
173 |
|
: MessageManager.getString("label.save_annotation_to_file")); |
174 |
0 |
chooser.setToolTipText(MessageManager.getString("action.save")); |
175 |
|
|
176 |
0 |
int value = chooser.showSaveDialog(this); |
177 |
|
|
178 |
0 |
if (value == JalviewFileChooser.APPROVE_OPTION) |
179 |
|
{ |
180 |
0 |
String text = getText(); |
181 |
|
|
182 |
0 |
try |
183 |
|
{ |
184 |
0 |
PrintWriter out = new PrintWriter( |
185 |
|
new FileWriter(chooser.getSelectedFile())); |
186 |
0 |
out.print(text); |
187 |
0 |
out.close(); |
188 |
|
} catch (Exception ex) |
189 |
|
{ |
190 |
0 |
ex.printStackTrace(); |
191 |
|
} |
192 |
|
} |
193 |
|
|
194 |
0 |
close_actionPerformed(); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
@return |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
203 |
0 |
private String getText()... |
204 |
|
{ |
205 |
0 |
return exportFeatures ? getFeaturesText() : getAnnotationsText(); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@return |
213 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
214 |
0 |
private String getAnnotationsText()... |
215 |
|
{ |
216 |
0 |
String text; |
217 |
0 |
if (CSVFormat.isSelected()) |
218 |
|
{ |
219 |
0 |
text = new AnnotationFile().printCSVAnnotations(annotations); |
220 |
|
} |
221 |
|
else |
222 |
|
{ |
223 |
0 |
if (wholeView) |
224 |
|
{ |
225 |
0 |
text = new AnnotationFile().printAnnotationsForView(ap.av); |
226 |
|
} |
227 |
|
else |
228 |
|
{ |
229 |
0 |
text = new AnnotationFile().printAnnotations(annotations, null, |
230 |
|
null); |
231 |
|
} |
232 |
|
} |
233 |
0 |
return text; |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
@return |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
242 |
0 |
private String getFeaturesText()... |
243 |
|
{ |
244 |
0 |
String text; |
245 |
0 |
SequenceI[] sequences = ap.av.getAlignment().getSequencesArray(); |
246 |
0 |
boolean includeNonPositional = ap.av.isShowNPFeats(); |
247 |
|
|
248 |
0 |
FeaturesFile formatter = new FeaturesFile(); |
249 |
0 |
final FeatureRenderer fr = ap.getFeatureRenderer(); |
250 |
0 |
boolean includeComplement = includeLinkedFeatures.isSelected(); |
251 |
|
|
252 |
0 |
if (GFFFormat.isSelected()) |
253 |
|
{ |
254 |
0 |
text = formatter.printGffFormat(sequences, fr, includeNonPositional, |
255 |
|
includeComplement); |
256 |
|
} |
257 |
|
else |
258 |
|
{ |
259 |
0 |
text = formatter.printJalviewFormat(sequences, fr, |
260 |
|
includeNonPositional, includeComplement); |
261 |
|
} |
262 |
0 |
return text; |
263 |
|
} |
264 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
265 |
0 |
private void toTextbox_actionPerformed()... |
266 |
|
{ |
267 |
0 |
CutAndPasteTransfer cap = new CutAndPasteTransfer(); |
268 |
|
|
269 |
0 |
try |
270 |
|
{ |
271 |
0 |
String text = getText(); |
272 |
0 |
cap.setText(text); |
273 |
0 |
Desktop.addInternalFrame(cap, (exportFeatures ? MessageManager |
274 |
|
.formatMessage("label.features_for_params", new String[] |
275 |
|
{ ap.alignFrame.getTitle() }) |
276 |
|
: MessageManager.formatMessage("label.annotations_for_params", |
277 |
|
new String[] |
278 |
|
{ ap.alignFrame.getTitle() })), |
279 |
|
600, 500); |
280 |
|
} catch (OutOfMemoryError oom) |
281 |
|
{ |
282 |
0 |
new OOMWarning((exportFeatures ? MessageManager.formatMessage( |
283 |
|
"label.generating_features_for_params", new String[] |
284 |
|
{ ap.alignFrame.getTitle() }) |
285 |
|
: MessageManager.formatMessage( |
286 |
|
"label.generating_annotations_for_params", |
287 |
|
new String[] |
288 |
|
{ ap.alignFrame.getTitle() })), |
289 |
|
oom); |
290 |
0 |
cap.dispose(); |
291 |
|
} |
292 |
|
|
293 |
0 |
close_actionPerformed(); |
294 |
|
} |
295 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
296 |
0 |
private void close_actionPerformed()... |
297 |
|
{ |
298 |
0 |
try |
299 |
|
{ |
300 |
0 |
frame.setClosed(true); |
301 |
|
} catch (java.beans.PropertyVetoException ex) |
302 |
|
{ |
303 |
|
} |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
@throws |
310 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
311 |
0 |
private void jbInit() throws Exception... |
312 |
|
{ |
313 |
0 |
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
314 |
0 |
this.setBackground(Color.white); |
315 |
|
|
316 |
0 |
JPanel formatPanel = buildFormatOptionsPanel(); |
317 |
0 |
JPanel linkedFeatures = buildLinkedFeaturesPanel(); |
318 |
0 |
JPanel actionsPanel = buildActionsPanel(); |
319 |
|
|
320 |
0 |
this.add(formatPanel); |
321 |
0 |
this.add(linkedFeatures); |
322 |
0 |
this.add(actionsPanel); |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
@return |
332 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
333 |
0 |
private JPanel buildLinkedFeaturesPanel()... |
334 |
|
{ |
335 |
0 |
linkedFeaturesPanel = new JPanel(); |
336 |
0 |
linkedFeaturesPanel.setOpaque(false); |
337 |
|
|
338 |
0 |
boolean nucleotide = ap.av.isNucleotide(); |
339 |
0 |
String complement = nucleotide |
340 |
|
? MessageManager.getString("label.protein").toLowerCase() |
341 |
|
: "CDS"; |
342 |
0 |
JLabel label = new JLabel( |
343 |
|
MessageManager.formatMessage("label.include_linked_features", |
344 |
|
complement)); |
345 |
0 |
label.setHorizontalAlignment(SwingConstants.TRAILING); |
346 |
0 |
String tooltip = MessageManager |
347 |
|
.formatMessage("label.include_linked_tooltip", complement); |
348 |
0 |
label.setToolTipText( |
349 |
|
JvSwingUtils.wrapTooltip(true, tooltip)); |
350 |
|
|
351 |
0 |
includeLinkedFeatures = new JCheckBox(); |
352 |
0 |
linkedFeaturesPanel.add(label); |
353 |
0 |
linkedFeaturesPanel.add(includeLinkedFeatures); |
354 |
0 |
linkedFeaturesPanel.setVisible(false); |
355 |
|
|
356 |
0 |
return linkedFeaturesPanel; |
357 |
|
} |
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
@return |
363 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
364 |
0 |
JPanel buildActionsPanel()... |
365 |
|
{ |
366 |
0 |
JPanel actionsPanel = new JPanel(); |
367 |
0 |
actionsPanel.setOpaque(false); |
368 |
|
|
369 |
0 |
JButton toFile = new JButton(MessageManager.getString("label.to_file")); |
370 |
0 |
toFile.addActionListener(new ActionListener() |
371 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
372 |
0 |
@Override... |
373 |
|
public void actionPerformed(ActionEvent e) |
374 |
|
{ |
375 |
0 |
toFile_actionPerformed(); |
376 |
|
} |
377 |
|
}); |
378 |
0 |
JButton toTextbox = new JButton( |
379 |
|
MessageManager.getString("label.to_textbox")); |
380 |
0 |
toTextbox.addActionListener(new ActionListener() |
381 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
382 |
0 |
@Override... |
383 |
|
public void actionPerformed(ActionEvent e) |
384 |
|
{ |
385 |
0 |
toTextbox_actionPerformed(); |
386 |
|
} |
387 |
|
}); |
388 |
0 |
JButton close = new JButton(MessageManager.getString("action.close")); |
389 |
0 |
close.addActionListener(new ActionListener() |
390 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
391 |
0 |
@Override... |
392 |
|
public void actionPerformed(ActionEvent e) |
393 |
|
{ |
394 |
0 |
close_actionPerformed(); |
395 |
|
} |
396 |
|
}); |
397 |
|
|
398 |
0 |
actionsPanel.add(toFile); |
399 |
0 |
actionsPanel.add(toTextbox); |
400 |
0 |
actionsPanel.add(close); |
401 |
|
|
402 |
0 |
return actionsPanel; |
403 |
|
} |
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
@return |
411 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
|
412 |
0 |
JPanel buildFormatOptionsPanel()... |
413 |
|
{ |
414 |
0 |
JPanel formatPanel = new JPanel(); |
415 |
|
|
416 |
0 |
formatPanel.setOpaque(false); |
417 |
|
|
418 |
0 |
JRadioButton jalviewFormat = new JRadioButton("Jalview"); |
419 |
0 |
jalviewFormat.setOpaque(false); |
420 |
0 |
jalviewFormat.setSelected(true); |
421 |
0 |
GFFFormat.setOpaque(false); |
422 |
0 |
GFFFormat.setText("GFF"); |
423 |
0 |
CSVFormat.setOpaque(false); |
424 |
0 |
CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet")); |
425 |
|
|
426 |
0 |
ButtonGroup buttonGroup = new ButtonGroup(); |
427 |
0 |
buttonGroup.add(jalviewFormat); |
428 |
0 |
buttonGroup.add(GFFFormat); |
429 |
0 |
buttonGroup.add(CSVFormat); |
430 |
|
|
431 |
0 |
JLabel format = new JLabel( |
432 |
|
MessageManager.getString("action.format") + " "); |
433 |
0 |
format.setHorizontalAlignment(SwingConstants.TRAILING); |
434 |
|
|
435 |
0 |
formatPanel.add(format); |
436 |
0 |
formatPanel.add(jalviewFormat); |
437 |
0 |
formatPanel.add(GFFFormat); |
438 |
0 |
formatPanel.add(CSVFormat); |
439 |
|
|
440 |
0 |
return formatPanel; |
441 |
|
} |
442 |
|
} |