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(), ap
116 .getFeatureRenderer().getDisplayedFeatureCols(), true,
117 ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
121 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
122 .getDataset().getSequencesArray(), ap
123 .getFeatureRenderer().getDisplayedFeatureCols(), true,
124 ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
129 if (CSVFormat.isSelected())
131 text = new AnnotationFile().printCSVAnnotations(annotations);
135 text = new AnnotationFile().printAnnotations(annotations,
136 sequenceGroups, alignmentProperties);
142 java.io.PrintWriter out = new java.io.PrintWriter(
143 new java.io.FileWriter(chooser.getSelectedFile()));
147 } catch (Exception ex)
149 ex.printStackTrace();
153 close_actionPerformed(null);
156 public void toTextbox_actionPerformed(ActionEvent e)
158 String text = MessageManager.getString("label.no_features_on_alignment");
161 if (GFFFormat.isSelected())
163 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
164 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
165 .getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
169 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
170 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
171 .getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
176 if (CSVFormat.isSelected())
178 text = new AnnotationFile().printCSVAnnotations(annotations);
182 text = new AnnotationFile().printAnnotations(annotations,
183 sequenceGroups, alignmentProperties);
187 CutAndPasteTransfer cap = new CutAndPasteTransfer();
191 Desktop.addInternalFrame(
193 (features ? MessageManager.formatMessage(
194 "label.features_for_params", new String[]
195 { ap.alignFrame.getTitle() }) : MessageManager
196 .formatMessage("label.annotations_for_params",
198 { ap.alignFrame.getTitle() })), 600, 500);
199 } catch (OutOfMemoryError oom)
201 new OOMWarning((features ? MessageManager.formatMessage(
202 "label.generating_features_for_params", new String[]
203 { ap.alignFrame.getTitle() }) : MessageManager.formatMessage(
204 "label.generating_annotations_for_params", new String[]
205 { ap.alignFrame.getTitle() })), oom);
209 close_actionPerformed(null);
212 public void close_actionPerformed(ActionEvent e)
216 frame.setClosed(true);
217 } catch (java.beans.PropertyVetoException ex)
222 private void jbInit() throws Exception
224 this.setLayout(new BorderLayout());
226 toFile.setText(MessageManager.getString("label.to_file"));
227 toFile.addActionListener(new ActionListener()
229 public void actionPerformed(ActionEvent e)
231 toFile_actionPerformed(e);
234 toTextbox.setText(MessageManager.getString("label.to_textbox"));
235 toTextbox.addActionListener(new ActionListener()
237 public void actionPerformed(ActionEvent e)
239 toTextbox_actionPerformed(e);
242 close.setText(MessageManager.getString("action.close"));
243 close.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 close_actionPerformed(e);
250 jalviewFormat.setOpaque(false);
251 jalviewFormat.setSelected(true);
252 jalviewFormat.setText("Jalview");
253 GFFFormat.setOpaque(false);
254 GFFFormat.setText("GFF");
255 CSVFormat.setOpaque(false);
256 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
257 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
258 jLabel1.setText(MessageManager.getString("action.format") + " ");
259 this.setBackground(Color.white);
260 jPanel3.setBorder(BorderFactory.createEtchedBorder());
261 jPanel3.setOpaque(false);
262 jPanel1.setOpaque(false);
264 jPanel1.add(toTextbox);
266 jPanel3.add(jLabel1);
267 jPanel3.add(jalviewFormat);
268 jPanel3.add(GFFFormat);
269 jPanel3.add(CSVFormat);
270 buttonGroup.add(jalviewFormat);
271 buttonGroup.add(GFFFormat);
272 buttonGroup.add(CSVFormat);
273 this.add(jPanel3, BorderLayout.CENTER);
274 this.add(jPanel1, BorderLayout.SOUTH);
277 JPanel jPanel1 = new JPanel();
279 JButton toFile = new JButton();
281 JButton toTextbox = new JButton();
283 JButton close = new JButton();
285 ButtonGroup buttonGroup = new ButtonGroup();
287 JRadioButton jalviewFormat = new JRadioButton();
289 JRadioButton GFFFormat = new JRadioButton();
291 JRadioButton CSVFormat = new JRadioButton();
293 JLabel jLabel1 = new JLabel();
295 JPanel jPanel3 = new JPanel();
297 FlowLayout flowLayout1 = new FlowLayout();