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.api.FeatureColourI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.SequenceI;
26 import jalview.io.AnnotationFile;
27 import jalview.io.FeaturesFile;
28 import jalview.io.JalviewFileChooser;
29 import jalview.io.JalviewFileView;
30 import jalview.util.MessageManager;
32 import java.awt.BorderLayout;
33 import java.awt.Color;
34 import java.awt.FlowLayout;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
37 import java.util.List;
40 import javax.swing.BorderFactory;
41 import javax.swing.ButtonGroup;
42 import javax.swing.JButton;
43 import javax.swing.JInternalFrame;
44 import javax.swing.JLabel;
45 import javax.swing.JLayeredPane;
46 import javax.swing.JPanel;
47 import javax.swing.JRadioButton;
48 import javax.swing.SwingConstants;
52 * GUI dialog for exporting features or alignment annotations depending upon
53 * which method is called.
58 public class AnnotationExporter extends JPanel
64 boolean features = true;
66 private AlignmentAnnotation[] annotations;
68 private boolean wholeView;
70 public AnnotationExporter()
75 } catch (Exception ex)
80 frame = new JInternalFrame();
81 frame.setContentPane(this);
82 frame.setLayer(JLayeredPane.PALETTE_LAYER);
83 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
84 frame.getPreferredSize().height);
87 public void exportFeatures(AlignmentPanel ap)
91 CSVFormat.setVisible(false);
92 frame.setTitle(MessageManager.getString("label.export_features"));
95 public void exportAnnotations(AlignmentPanel ap)
98 annotations = ap.av.isShowAnnotation() ? null
99 : ap.av.getAlignment().getAlignmentAnnotation();
101 startExportAnnotation();
104 public void exportAnnotations(AlignmentPanel alp,
105 AlignmentAnnotation[] toExport)
108 annotations = toExport;
110 startExportAnnotation();
113 private void startExportAnnotation()
116 GFFFormat.setVisible(false);
117 CSVFormat.setVisible(true);
118 frame.setTitle(MessageManager.getString("label.export_annotations"));
121 public void toFile_actionPerformed(ActionEvent e)
123 JalviewFileChooser chooser = new JalviewFileChooser(
124 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
126 chooser.setFileView(new JalviewFileView());
127 chooser.setDialogTitle(features
128 ? MessageManager.getString("label.save_features_to_file")
129 : MessageManager.getString("label.save_annotation_to_file"));
130 chooser.setToolTipText(MessageManager.getString("action.save"));
132 int value = chooser.showSaveDialog(this);
134 if (value == JalviewFileChooser.APPROVE_OPTION)
136 String text = getFileContents();
140 java.io.PrintWriter out = new java.io.PrintWriter(
141 new java.io.FileWriter(chooser.getSelectedFile()));
145 } catch (Exception ex)
147 ex.printStackTrace();
151 close_actionPerformed(null);
154 private String getFileContents()
156 String text = MessageManager
157 .getString("label.no_features_on_alignment");
160 FeaturesFile formatter = new FeaturesFile();
161 SequenceI[] sequences = ap.av.getAlignment().getSequencesArray();
162 Map<String, FeatureColourI> featureColours = ap.getFeatureRenderer()
163 .getDisplayedFeatureCols();
164 List<String> featureGroups = ap.getFeatureRenderer()
165 .getDisplayedFeatureGroups();
166 boolean includeNonPositional = ap.av.isShowNPFeats();
167 if (GFFFormat.isSelected())
169 text = formatter.printGffFormat(sequences, featureColours,
170 featureGroups, includeNonPositional);
174 text = formatter.printJalviewFormat(sequences, featureColours,
175 featureGroups, includeNonPositional);
180 if (CSVFormat.isSelected())
182 text = new AnnotationFile().printCSVAnnotations(annotations);
188 text = new AnnotationFile().printAnnotationsForView(ap.av);
192 text = new AnnotationFile().printAnnotations(annotations, null,
200 public void toTextbox_actionPerformed(ActionEvent e)
202 CutAndPasteTransfer cap = new CutAndPasteTransfer();
206 String text = getFileContents();
208 Desktop.addInternalFrame(cap, (features ? MessageManager
209 .formatMessage("label.features_for_params", new String[]
210 { ap.alignFrame.getTitle() })
211 : MessageManager.formatMessage("label.annotations_for_params",
213 { ap.alignFrame.getTitle() })),
215 } catch (OutOfMemoryError oom)
217 new OOMWarning((features ? MessageManager.formatMessage(
218 "label.generating_features_for_params", new String[]
219 { ap.alignFrame.getTitle() })
220 : MessageManager.formatMessage(
221 "label.generating_annotations_for_params",
223 { ap.alignFrame.getTitle() })),
228 close_actionPerformed(null);
231 public void close_actionPerformed(ActionEvent e)
235 frame.setClosed(true);
236 } catch (java.beans.PropertyVetoException ex)
241 private void jbInit() throws Exception
243 this.setLayout(new BorderLayout());
245 toFile.setText(MessageManager.getString("label.to_file"));
246 toFile.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 toFile_actionPerformed(e);
254 toTextbox.setText(MessageManager.getString("label.to_textbox"));
255 toTextbox.addActionListener(new ActionListener()
258 public void actionPerformed(ActionEvent e)
260 toTextbox_actionPerformed(e);
263 close.setText(MessageManager.getString("action.close"));
264 close.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 close_actionPerformed(e);
272 jalviewFormat.setOpaque(false);
273 jalviewFormat.setSelected(true);
274 jalviewFormat.setText("Jalview");
275 GFFFormat.setOpaque(false);
276 GFFFormat.setText("GFF");
277 CSVFormat.setOpaque(false);
278 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
279 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
280 jLabel1.setText(MessageManager.getString("action.format") + " ");
281 this.setBackground(Color.white);
282 jPanel3.setBorder(BorderFactory.createEtchedBorder());
283 jPanel3.setOpaque(false);
284 jPanel1.setOpaque(false);
286 jPanel1.add(toTextbox);
288 jPanel3.add(jLabel1);
289 jPanel3.add(jalviewFormat);
290 jPanel3.add(GFFFormat);
291 jPanel3.add(CSVFormat);
292 buttonGroup.add(jalviewFormat);
293 buttonGroup.add(GFFFormat);
294 buttonGroup.add(CSVFormat);
295 this.add(jPanel3, BorderLayout.CENTER);
296 this.add(jPanel1, BorderLayout.SOUTH);
299 JPanel jPanel1 = new JPanel();
301 JButton toFile = new JButton();
303 JButton toTextbox = new JButton();
305 JButton close = new JButton();
307 ButtonGroup buttonGroup = new ButtonGroup();
309 JRadioButton jalviewFormat = new JRadioButton();
311 JRadioButton GFFFormat = new JRadioButton();
313 JRadioButton CSVFormat = new JRadioButton();
315 JLabel jLabel1 = new JLabel();
317 JPanel jPanel3 = new JPanel();
319 FlowLayout flowLayout1 = new FlowLayout();