2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
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.
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.
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.SequenceI;
25 import jalview.io.AnnotationFile;
26 import jalview.io.FeaturesFile;
27 import jalview.io.JalviewFileChooser;
28 import jalview.io.JalviewFileView;
29 import jalview.util.MessageManager;
31 import java.awt.BorderLayout;
32 import java.awt.Color;
33 import java.awt.FlowLayout;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
38 import javax.swing.BorderFactory;
39 import javax.swing.ButtonGroup;
40 import javax.swing.JButton;
41 import javax.swing.JInternalFrame;
42 import javax.swing.JLabel;
43 import javax.swing.JLayeredPane;
44 import javax.swing.JPanel;
45 import javax.swing.JRadioButton;
46 import javax.swing.SwingConstants;
50 * GUI dialog for exporting features or alignment annotations depending upon
51 * which method is called.
56 public class AnnotationExporter extends JPanel
62 boolean features = true;
64 private AlignmentAnnotation[] annotations;
66 private boolean wholeView;
68 public AnnotationExporter()
73 } catch (Exception ex)
78 frame = new JInternalFrame();
79 frame.setContentPane(this);
80 frame.setLayer(JLayeredPane.PALETTE_LAYER);
81 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
82 frame.getPreferredSize().height);
85 public void exportFeatures(AlignmentPanel ap)
89 CSVFormat.setVisible(false);
90 frame.setTitle(MessageManager.getString("label.export_features"));
93 public void exportAnnotations(AlignmentPanel ap)
96 annotations = ap.av.isShowAnnotation() ? null : ap.av.getAlignment()
97 .getAlignmentAnnotation();
99 startExportAnnotation();
102 public void exportAnnotations(AlignmentPanel alp,
103 AlignmentAnnotation[] toExport)
106 annotations = toExport;
108 startExportAnnotation();
111 private void startExportAnnotation()
114 GFFFormat.setVisible(false);
115 CSVFormat.setVisible(true);
116 frame.setTitle(MessageManager.getString("label.export_annotations"));
119 public void toFile_actionPerformed(ActionEvent e)
121 JalviewFileChooser chooser = new JalviewFileChooser(
122 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
124 chooser.setFileView(new JalviewFileView());
125 chooser.setDialogTitle(features ? MessageManager
126 .getString("label.save_features_to_file") : MessageManager
127 .getString("label.save_annotation_to_file"));
128 chooser.setToolTipText(MessageManager.getString("action.save"));
130 int value = chooser.showSaveDialog(this);
132 if (value == JalviewFileChooser.APPROVE_OPTION)
134 String text = getFileContents();
138 java.io.PrintWriter out = new java.io.PrintWriter(
139 new java.io.FileWriter(chooser.getSelectedFile()));
143 } catch (Exception ex)
145 ex.printStackTrace();
149 close_actionPerformed(null);
152 private String getFileContents()
154 String text = MessageManager
155 .getString("label.no_features_on_alignment");
158 FeaturesFile formatter = new FeaturesFile();
159 SequenceI[] sequences = ap.av.getAlignment().getSequencesArray();
160 Map<String, Object> featureColours = ap.getFeatureRenderer()
161 .getDisplayedFeatureCols();
162 boolean includeNonPositional = ap.av.isShowNPFeats();
163 if (GFFFormat.isSelected())
165 text = formatter.printGffFormat(sequences, featureColours, true,
166 includeNonPositional);
170 text = formatter.printJalviewFormat(sequences, featureColours,
171 true, includeNonPositional);
176 if (CSVFormat.isSelected())
178 text = new AnnotationFile().printCSVAnnotations(annotations);
184 text = new AnnotationFile().printAnnotationsForView(ap.av);
188 text = new AnnotationFile().printAnnotations(annotations, null,
196 public void toTextbox_actionPerformed(ActionEvent e)
198 CutAndPasteTransfer cap = new CutAndPasteTransfer();
202 String text = getFileContents();
204 Desktop.addInternalFrame(
206 (features ? MessageManager.formatMessage(
207 "label.features_for_params",
208 new String[] { ap.alignFrame.getTitle() })
209 : MessageManager.formatMessage(
210 "label.annotations_for_params",
211 new String[] { ap.alignFrame.getTitle() })),
213 } catch (OutOfMemoryError oom)
215 new OOMWarning((features ? MessageManager.formatMessage(
216 "label.generating_features_for_params",
217 new String[] { ap.alignFrame.getTitle() })
218 : MessageManager.formatMessage(
219 "label.generating_annotations_for_params",
220 new String[] { ap.alignFrame.getTitle() })), oom);
224 close_actionPerformed(null);
227 public void close_actionPerformed(ActionEvent e)
231 frame.setClosed(true);
232 } catch (java.beans.PropertyVetoException ex)
237 private void jbInit() throws Exception
239 this.setLayout(new BorderLayout());
241 toFile.setText(MessageManager.getString("label.to_file"));
242 toFile.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 toFile_actionPerformed(e);
250 toTextbox.setText(MessageManager.getString("label.to_textbox"));
251 toTextbox.addActionListener(new ActionListener()
254 public void actionPerformed(ActionEvent e)
256 toTextbox_actionPerformed(e);
259 close.setText(MessageManager.getString("action.close"));
260 close.addActionListener(new ActionListener()
263 public void actionPerformed(ActionEvent e)
265 close_actionPerformed(e);
268 jalviewFormat.setOpaque(false);
269 jalviewFormat.setSelected(true);
270 jalviewFormat.setText("Jalview");
271 GFFFormat.setOpaque(false);
272 GFFFormat.setText("GFF");
273 CSVFormat.setOpaque(false);
274 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
275 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
276 jLabel1.setText(MessageManager.getString("action.format") + " ");
277 this.setBackground(Color.white);
278 jPanel3.setBorder(BorderFactory.createEtchedBorder());
279 jPanel3.setOpaque(false);
280 jPanel1.setOpaque(false);
282 jPanel1.add(toTextbox);
284 jPanel3.add(jLabel1);
285 jPanel3.add(jalviewFormat);
286 jPanel3.add(GFFFormat);
287 jPanel3.add(CSVFormat);
288 buttonGroup.add(jalviewFormat);
289 buttonGroup.add(GFFFormat);
290 buttonGroup.add(CSVFormat);
291 this.add(jPanel3, BorderLayout.CENTER);
292 this.add(jPanel1, BorderLayout.SOUTH);
295 JPanel jPanel1 = new JPanel();
297 JButton toFile = new JButton();
299 JButton toTextbox = new JButton();
301 JButton close = new JButton();
303 ButtonGroup buttonGroup = new ButtonGroup();
305 JRadioButton jalviewFormat = new JRadioButton();
307 JRadioButton GFFFormat = new JRadioButton();
309 JRadioButton CSVFormat = new JRadioButton();
311 JLabel jLabel1 = new JLabel();
313 JPanel jPanel3 = new JPanel();
315 FlowLayout flowLayout1 = new FlowLayout();