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.
24 import java.util.List;
27 import java.awt.event.*;
30 import jalview.datamodel.*;
32 import jalview.util.MessageManager;
36 * GUI dialog for exporting features or alignment annotations depending upon
37 * which method is called.
42 public class AnnotationExporter extends JPanel
48 boolean features = true;
50 AlignmentAnnotation[] annotations;
52 List<SequenceGroup> sequenceGroups;
54 Hashtable alignmentProperties;
56 public AnnotationExporter()
61 } catch (Exception ex)
66 frame = new JInternalFrame();
67 frame.setContentPane(this);
68 frame.setLayer(JLayeredPane.PALETTE_LAYER);
69 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
70 frame.getPreferredSize().height);
73 public void exportFeatures(AlignmentPanel ap)
77 CSVFormat.setVisible(false);
78 frame.setTitle(MessageManager.getString("label.export_features"));
81 public void exportAnnotations(AlignmentPanel ap,
82 AlignmentAnnotation[] annotations, List<SequenceGroup> list,
83 Hashtable alProperties)
87 GFFFormat.setVisible(false);
88 CSVFormat.setVisible(true);
89 this.annotations = annotations;
90 this.sequenceGroups = list;
91 this.alignmentProperties = alProperties;
92 frame.setTitle(MessageManager.getString("label.export_annotations"));
95 public void toFile_actionPerformed(ActionEvent e)
97 JalviewFileChooser chooser = new JalviewFileChooser(
98 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
100 chooser.setFileView(new JalviewFileView());
101 chooser.setDialogTitle(features ? MessageManager.getString("label.save_features_to_file")
102 : MessageManager.getString("label.save_annotation_to_file"));
103 chooser.setToolTipText(MessageManager.getString("action.save"));
105 int value = chooser.showSaveDialog(this);
107 if (value == JalviewFileChooser.APPROVE_OPTION)
109 String text = MessageManager.getString("label.no_features_on_alignment");
112 if (GFFFormat.isSelected())
114 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
115 .getDataset().getSequencesArray(),
116 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
120 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
121 .getDataset().getSequencesArray(),
122 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
127 if (CSVFormat.isSelected())
129 text = new AnnotationFile().printCSVAnnotations(annotations);
133 text = new AnnotationFile().printAnnotations(annotations,
134 sequenceGroups, alignmentProperties);
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 public void toTextbox_actionPerformed(ActionEvent e)
156 String text = MessageManager.getString("label.no_features_on_alignment");
159 if (GFFFormat.isSelected())
161 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
162 .getDataset().getSequencesArray(),
163 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
167 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
168 .getDataset().getSequencesArray(),
169 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
174 if (CSVFormat.isSelected())
176 text = new AnnotationFile().printCSVAnnotations(annotations);
180 text = new AnnotationFile().printAnnotations(annotations,
181 sequenceGroups, alignmentProperties);
185 CutAndPasteTransfer cap = new CutAndPasteTransfer();
189 Desktop.addInternalFrame(
191 (features ? MessageManager.formatMessage(
192 "label.features_for_params", new String[]
193 { ap.alignFrame.getTitle() }) : MessageManager
194 .formatMessage("label.annotations_for_params",
196 { ap.alignFrame.getTitle() })), 600, 500);
197 } catch (OutOfMemoryError oom)
199 new OOMWarning((features ? MessageManager.formatMessage(
200 "label.generating_features_for_params", new String[]
201 { ap.alignFrame.getTitle() }) : MessageManager.formatMessage(
202 "label.generating_annotations_for_params", new String[]
203 { ap.alignFrame.getTitle() })), oom);
207 close_actionPerformed(null);
210 private Hashtable getDisplayedFeatureCols()
212 Hashtable fcols = new Hashtable();
213 if (ap.av.featuresDisplayed == null)
217 Enumeration en = ap.av.featuresDisplayed.keys();
218 FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider
222 while (en.hasMoreElements())
224 Object col = en.nextElement();
225 fcols.put(col, fr.featureColours.get(col));
230 public void close_actionPerformed(ActionEvent e)
234 frame.setClosed(true);
235 } catch (java.beans.PropertyVetoException ex)
240 private void jbInit() throws Exception
242 this.setLayout(new BorderLayout());
244 toFile.setText(MessageManager.getString("label.to_file"));
245 toFile.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
249 toFile_actionPerformed(e);
252 toTextbox.setText(MessageManager.getString("label.to_textbox"));
253 toTextbox.addActionListener(new ActionListener()
255 public void actionPerformed(ActionEvent e)
257 toTextbox_actionPerformed(e);
260 close.setText(MessageManager.getString("action.close"));
261 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();