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.Hashtable;
37 import java.util.List;
39 import javax.swing.BorderFactory;
40 import javax.swing.ButtonGroup;
41 import javax.swing.JButton;
42 import javax.swing.JInternalFrame;
43 import javax.swing.JLabel;
44 import javax.swing.JLayeredPane;
45 import javax.swing.JPanel;
46 import javax.swing.JRadioButton;
47 import javax.swing.SwingConstants;
51 * GUI dialog for exporting features or alignment annotations depending upon
52 * which method is called.
57 public class AnnotationExporter extends JPanel
63 boolean features = true;
65 AlignmentAnnotation[] annotations;
67 List<SequenceGroup> sequenceGroups;
69 Hashtable alignmentProperties;
71 public AnnotationExporter()
76 } catch (Exception ex)
81 frame = new JInternalFrame();
82 frame.setContentPane(this);
83 frame.setLayer(JLayeredPane.PALETTE_LAYER);
84 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
85 frame.getPreferredSize().height);
88 public void exportFeatures(AlignmentPanel ap)
92 CSVFormat.setVisible(false);
93 frame.setTitle(MessageManager.getString("label.export_features"));
96 public void exportAnnotations(AlignmentPanel ap,
97 AlignmentAnnotation[] annotations, List<SequenceGroup> list,
98 Hashtable alProperties)
102 GFFFormat.setVisible(false);
103 CSVFormat.setVisible(true);
104 this.annotations = annotations;
105 this.sequenceGroups = list;
106 this.alignmentProperties = alProperties;
107 frame.setTitle(MessageManager.getString("label.export_annotations"));
110 public void toFile_actionPerformed(ActionEvent e)
112 JalviewFileChooser chooser = new JalviewFileChooser(
113 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
115 chooser.setFileView(new JalviewFileView());
116 chooser.setDialogTitle(features ? MessageManager.getString("label.save_features_to_file")
117 : MessageManager.getString("label.save_annotation_to_file"));
118 chooser.setToolTipText(MessageManager.getString("action.save"));
120 int value = chooser.showSaveDialog(this);
122 if (value == JalviewFileChooser.APPROVE_OPTION)
124 String text = MessageManager.getString("label.no_features_on_alignment");
127 if (GFFFormat.isSelected())
129 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
130 .getDataset().getSequencesArray(), ap
131 .getFeatureRenderer().getDisplayedFeatureCols(), true,
132 ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
136 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
137 .getDataset().getSequencesArray(), ap
138 .getFeatureRenderer().getDisplayedFeatureCols(), true,
139 ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
144 if (CSVFormat.isSelected())
146 text = new AnnotationFile().printCSVAnnotations(annotations);
150 text = new AnnotationFile().printAnnotations(annotations,
151 sequenceGroups, alignmentProperties);
157 java.io.PrintWriter out = new java.io.PrintWriter(
158 new java.io.FileWriter(chooser.getSelectedFile()));
162 } catch (Exception ex)
164 ex.printStackTrace();
168 close_actionPerformed(null);
171 public void toTextbox_actionPerformed(ActionEvent e)
173 String text = MessageManager.getString("label.no_features_on_alignment");
176 if (GFFFormat.isSelected())
178 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
179 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
180 .getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
184 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
185 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
186 .getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
191 if (CSVFormat.isSelected())
193 text = new AnnotationFile().printCSVAnnotations(annotations);
197 text = new AnnotationFile().printAnnotations(annotations,
198 sequenceGroups, alignmentProperties);
202 CutAndPasteTransfer cap = new CutAndPasteTransfer();
206 Desktop.addInternalFrame(
208 (features ? MessageManager.formatMessage(
209 "label.features_for_params", new String[]
210 { ap.alignFrame.getTitle() }) : MessageManager
211 .formatMessage("label.annotations_for_params",
213 { ap.alignFrame.getTitle() })), 600, 500);
214 } catch (OutOfMemoryError oom)
216 new OOMWarning((features ? MessageManager.formatMessage(
217 "label.generating_features_for_params", new String[]
218 { ap.alignFrame.getTitle() }) : MessageManager.formatMessage(
219 "label.generating_annotations_for_params", new String[]
220 { ap.alignFrame.getTitle() })), oom);
224 close_actionPerformed(null);
226 public void close_actionPerformed(ActionEvent e)
230 frame.setClosed(true);
231 } catch (java.beans.PropertyVetoException ex)
236 private void jbInit() throws Exception
238 this.setLayout(new BorderLayout());
240 toFile.setText(MessageManager.getString("label.to_file"));
241 toFile.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 toFile_actionPerformed(e);
248 toTextbox.setText(MessageManager.getString("label.to_textbox"));
249 toTextbox.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 toTextbox_actionPerformed(e);
256 close.setText(MessageManager.getString("action.close"));
257 close.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 close_actionPerformed(e);
264 jalviewFormat.setOpaque(false);
265 jalviewFormat.setSelected(true);
266 jalviewFormat.setText("Jalview");
267 GFFFormat.setOpaque(false);
268 GFFFormat.setText("GFF");
269 CSVFormat.setOpaque(false);
270 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
271 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
272 jLabel1.setText(MessageManager.getString("action.format") + " ");
273 this.setBackground(Color.white);
274 jPanel3.setBorder(BorderFactory.createEtchedBorder());
275 jPanel3.setOpaque(false);
276 jPanel1.setOpaque(false);
278 jPanel1.add(toTextbox);
280 jPanel3.add(jLabel1);
281 jPanel3.add(jalviewFormat);
282 jPanel3.add(GFFFormat);
283 jPanel3.add(CSVFormat);
284 buttonGroup.add(jalviewFormat);
285 buttonGroup.add(GFFFormat);
286 buttonGroup.add(CSVFormat);
287 this.add(jPanel3, BorderLayout.CENTER);
288 this.add(jPanel1, BorderLayout.SOUTH);
291 JPanel jPanel1 = new JPanel();
293 JButton toFile = new JButton();
295 JButton toTextbox = new JButton();
297 JButton close = new JButton();
299 ButtonGroup buttonGroup = new ButtonGroup();
301 JRadioButton jalviewFormat = new JRadioButton();
303 JRadioButton GFFFormat = new JRadioButton();
305 JRadioButton CSVFormat = new JRadioButton();
307 JLabel jLabel1 = new JLabel();
309 JPanel jPanel3 = new JPanel();
311 FlowLayout flowLayout1 = new FlowLayout();