2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.SequenceGroup;
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;
36 import java.util.Enumeration;
37 import java.util.Hashtable;
38 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 AlignmentAnnotation[] annotations;
68 List<SequenceGroup> sequenceGroups;
70 Hashtable alignmentProperties;
72 public AnnotationExporter()
77 } catch (Exception ex)
82 frame = new JInternalFrame();
83 frame.setContentPane(this);
84 frame.setLayer(JLayeredPane.PALETTE_LAYER);
85 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
86 frame.getPreferredSize().height);
89 public void exportFeatures(AlignmentPanel ap)
93 CSVFormat.setVisible(false);
94 frame.setTitle(MessageManager.getString("label.export_features"));
97 public void exportAnnotations(AlignmentPanel ap,
98 AlignmentAnnotation[] annotations, List<SequenceGroup> list,
99 Hashtable alProperties)
103 GFFFormat.setVisible(false);
104 CSVFormat.setVisible(true);
105 this.annotations = annotations;
106 this.sequenceGroups = list;
107 this.alignmentProperties = alProperties;
108 frame.setTitle(MessageManager.getString("label.export_annotations"));
111 public void toFile_actionPerformed(ActionEvent e)
113 JalviewFileChooser chooser = new JalviewFileChooser(
114 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
116 chooser.setFileView(new JalviewFileView());
117 chooser.setDialogTitle(features ? MessageManager.getString("label.save_features_to_file")
118 : MessageManager.getString("label.save_annotation_to_file"));
119 chooser.setToolTipText(MessageManager.getString("action.save"));
121 int value = chooser.showSaveDialog(this);
123 if (value == JalviewFileChooser.APPROVE_OPTION)
125 String text = MessageManager.getString("label.no_features_on_alignment");
128 if (GFFFormat.isSelected())
130 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
131 .getDataset().getSequencesArray(),
132 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
136 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
137 .getDataset().getSequencesArray(),
138 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
143 if (CSVFormat.isSelected())
145 text = new AnnotationFile().printCSVAnnotations(annotations);
149 text = new AnnotationFile().printAnnotations(annotations,
150 sequenceGroups, alignmentProperties);
156 java.io.PrintWriter out = new java.io.PrintWriter(
157 new java.io.FileWriter(chooser.getSelectedFile()));
161 } catch (Exception ex)
163 ex.printStackTrace();
167 close_actionPerformed(null);
170 public void toTextbox_actionPerformed(ActionEvent e)
172 String text = MessageManager.getString("label.no_features_on_alignment");
175 if (GFFFormat.isSelected())
177 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
178 .getDataset().getSequencesArray(),
179 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
183 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
184 .getDataset().getSequencesArray(),
185 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
190 if (CSVFormat.isSelected())
192 text = new AnnotationFile().printCSVAnnotations(annotations);
196 text = new AnnotationFile().printAnnotations(annotations,
197 sequenceGroups, alignmentProperties);
201 CutAndPasteTransfer cap = new CutAndPasteTransfer();
205 Desktop.addInternalFrame(
207 (features ? MessageManager.formatMessage(
208 "label.features_for_params", new String[]
209 { ap.alignFrame.getTitle() }) : MessageManager
210 .formatMessage("label.annotations_for_params",
212 { ap.alignFrame.getTitle() })), 600, 500);
213 } catch (OutOfMemoryError oom)
215 new OOMWarning((features ? MessageManager.formatMessage(
216 "label.generating_features_for_params", new String[]
217 { ap.alignFrame.getTitle() }) : MessageManager.formatMessage(
218 "label.generating_annotations_for_params", new String[]
219 { ap.alignFrame.getTitle() })), oom);
223 close_actionPerformed(null);
226 private Hashtable getDisplayedFeatureCols()
228 Hashtable fcols = new Hashtable();
229 if (ap.av.getFeaturesDisplayed() == null)
234 Enumeration en = ap.av.getFeaturesDisplayed().keys();
235 FeatureRenderer fr = ap.getSeqPanel().seqCanvas.getFeatureRenderer(); // consider
239 while (en.hasMoreElements())
241 Object col = en.nextElement();
242 fcols.put(col, fr.featureColours.get(col));
247 public void close_actionPerformed(ActionEvent e)
251 frame.setClosed(true);
252 } catch (java.beans.PropertyVetoException ex)
257 private void jbInit() throws Exception
259 this.setLayout(new BorderLayout());
261 toFile.setText(MessageManager.getString("label.to_file"));
262 toFile.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent e)
266 toFile_actionPerformed(e);
269 toTextbox.setText(MessageManager.getString("label.to_textbox"));
270 toTextbox.addActionListener(new ActionListener()
272 public void actionPerformed(ActionEvent e)
274 toTextbox_actionPerformed(e);
277 close.setText(MessageManager.getString("action.close"));
278 close.addActionListener(new ActionListener()
280 public void actionPerformed(ActionEvent e)
282 close_actionPerformed(e);
285 jalviewFormat.setOpaque(false);
286 jalviewFormat.setSelected(true);
287 jalviewFormat.setText("Jalview");
288 GFFFormat.setOpaque(false);
289 GFFFormat.setText("GFF");
290 CSVFormat.setOpaque(false);
291 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
292 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
293 jLabel1.setText(MessageManager.getString("action.format") + " ");
294 this.setBackground(Color.white);
295 jPanel3.setBorder(BorderFactory.createEtchedBorder());
296 jPanel3.setOpaque(false);
297 jPanel1.setOpaque(false);
299 jPanel1.add(toTextbox);
301 jPanel3.add(jLabel1);
302 jPanel3.add(jalviewFormat);
303 jPanel3.add(GFFFormat);
304 jPanel3.add(CSVFormat);
305 buttonGroup.add(jalviewFormat);
306 buttonGroup.add(GFFFormat);
307 buttonGroup.add(CSVFormat);
308 this.add(jPanel3, BorderLayout.CENTER);
309 this.add(jPanel1, BorderLayout.SOUTH);
312 JPanel jPanel1 = new JPanel();
314 JButton toFile = new JButton();
316 JButton toTextbox = new JButton();
318 JButton close = new JButton();
320 ButtonGroup buttonGroup = new ButtonGroup();
322 JRadioButton jalviewFormat = new JRadioButton();
324 JRadioButton GFFFormat = new JRadioButton();
326 JRadioButton CSVFormat = new JRadioButton();
328 JLabel jLabel1 = new JLabel();
330 JPanel jPanel3 = new JPanel();
332 FlowLayout flowLayout1 = new FlowLayout();