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.datamodel.AlignmentAnnotation;
24 import jalview.io.AnnotationFile;
25 import jalview.io.FeaturesFile;
26 import jalview.io.JalviewFileChooser;
27 import jalview.io.JalviewFileView;
28 import jalview.util.MessageManager;
30 import java.awt.BorderLayout;
31 import java.awt.Color;
32 import java.awt.FlowLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
36 import javax.swing.BorderFactory;
37 import javax.swing.ButtonGroup;
38 import javax.swing.JButton;
39 import javax.swing.JInternalFrame;
40 import javax.swing.JLabel;
41 import javax.swing.JLayeredPane;
42 import javax.swing.JPanel;
43 import javax.swing.JRadioButton;
44 import javax.swing.SwingConstants;
48 * GUI dialog for exporting features or alignment annotations depending upon
49 * which method is called.
54 public class AnnotationExporter extends JPanel
60 boolean features = true;
62 private AlignmentAnnotation[] annotations;
64 private boolean wholeView;
66 public AnnotationExporter()
71 } catch (Exception ex)
76 frame = new JInternalFrame();
77 frame.setContentPane(this);
78 frame.setLayer(JLayeredPane.PALETTE_LAYER);
79 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
80 frame.getPreferredSize().height);
83 public void exportFeatures(AlignmentPanel ap)
87 CSVFormat.setVisible(false);
88 frame.setTitle(MessageManager.getString("label.export_features"));
91 public void exportAnnotations(AlignmentPanel ap)
94 annotations = ap.av.isShowAnnotation() ? null : ap.av.getAlignment()
95 .getAlignmentAnnotation();
97 startExportAnnotation();
100 public void exportAnnotations(AlignmentPanel alp,
101 AlignmentAnnotation[] toExport)
104 annotations = toExport;
106 startExportAnnotation();
109 private void startExportAnnotation()
112 GFFFormat.setVisible(false);
113 CSVFormat.setVisible(true);
114 frame.setTitle(MessageManager.getString("label.export_annotations"));
117 public void toFile_actionPerformed(ActionEvent e)
119 JalviewFileChooser chooser = new JalviewFileChooser(
120 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
122 chooser.setFileView(new JalviewFileView());
123 chooser.setDialogTitle(features ? MessageManager.getString("label.save_features_to_file")
124 : MessageManager.getString("label.save_annotation_to_file"));
125 chooser.setToolTipText(MessageManager.getString("action.save"));
127 int value = chooser.showSaveDialog(this);
129 if (value == JalviewFileChooser.APPROVE_OPTION)
131 String text = getFileContents();
135 java.io.PrintWriter out = new java.io.PrintWriter(
136 new java.io.FileWriter(chooser.getSelectedFile()));
140 } catch (Exception ex)
142 ex.printStackTrace();
146 close_actionPerformed(null);
149 private String getFileContents()
151 String text = MessageManager
152 .getString("label.no_features_on_alignment");
155 if (GFFFormat.isSelected())
157 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
158 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
159 .getDisplayedFeatureCols(), true, ap.av.isShowNPFeats());// ap.av.featuresDisplayed//);
163 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
164 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
165 .getDisplayedFeatureCols(), true, ap.av.isShowNPFeats()); // ap.av.featuresDisplayed);
170 if (CSVFormat.isSelected())
172 text = new AnnotationFile().printCSVAnnotations(annotations);
178 text = new AnnotationFile().printAnnotationsForView(ap.av);
182 text = new AnnotationFile().printAnnotations(annotations, null,
189 public void toTextbox_actionPerformed(ActionEvent e)
191 CutAndPasteTransfer cap = new CutAndPasteTransfer();
195 String text = getFileContents();
197 Desktop.addInternalFrame(
199 (features ? MessageManager.formatMessage(
200 "label.features_for_params", new String[]
201 { ap.alignFrame.getTitle() }) : MessageManager
202 .formatMessage("label.annotations_for_params",
204 { ap.alignFrame.getTitle() })), 600, 500);
205 } catch (OutOfMemoryError oom)
207 new OOMWarning((features ? MessageManager.formatMessage(
208 "label.generating_features_for_params", new String[]
209 { ap.alignFrame.getTitle() }) : MessageManager.formatMessage(
210 "label.generating_annotations_for_params", new String[]
211 { ap.alignFrame.getTitle() })), oom);
215 close_actionPerformed(null);
217 public void close_actionPerformed(ActionEvent e)
221 frame.setClosed(true);
222 } catch (java.beans.PropertyVetoException ex)
227 private void jbInit() throws Exception
229 this.setLayout(new BorderLayout());
231 toFile.setText(MessageManager.getString("label.to_file"));
232 toFile.addActionListener(new ActionListener()
234 public void actionPerformed(ActionEvent e)
236 toFile_actionPerformed(e);
239 toTextbox.setText(MessageManager.getString("label.to_textbox"));
240 toTextbox.addActionListener(new ActionListener()
242 public void actionPerformed(ActionEvent e)
244 toTextbox_actionPerformed(e);
247 close.setText(MessageManager.getString("action.close"));
248 close.addActionListener(new ActionListener()
250 public void actionPerformed(ActionEvent e)
252 close_actionPerformed(e);
255 jalviewFormat.setOpaque(false);
256 jalviewFormat.setSelected(true);
257 jalviewFormat.setText("Jalview");
258 GFFFormat.setOpaque(false);
259 GFFFormat.setText("GFF");
260 CSVFormat.setOpaque(false);
261 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
262 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
263 jLabel1.setText(MessageManager.getString("action.format") + " ");
264 this.setBackground(Color.white);
265 jPanel3.setBorder(BorderFactory.createEtchedBorder());
266 jPanel3.setOpaque(false);
267 jPanel1.setOpaque(false);
269 jPanel1.add(toTextbox);
271 jPanel3.add(jLabel1);
272 jPanel3.add(jalviewFormat);
273 jPanel3.add(GFFFormat);
274 jPanel3.add(CSVFormat);
275 buttonGroup.add(jalviewFormat);
276 buttonGroup.add(GFFFormat);
277 buttonGroup.add(CSVFormat);
278 this.add(jPanel3, BorderLayout.CENTER);
279 this.add(jPanel1, BorderLayout.SOUTH);
282 JPanel jPanel1 = new JPanel();
284 JButton toFile = new JButton();
286 JButton toTextbox = new JButton();
288 JButton close = new JButton();
290 ButtonGroup buttonGroup = new ButtonGroup();
292 JRadioButton jalviewFormat = new JRadioButton();
294 JRadioButton GFFFormat = new JRadioButton();
296 JRadioButton CSVFormat = new JRadioButton();
298 JLabel jLabel1 = new JLabel();
300 JPanel jPanel3 = new JPanel();
302 FlowLayout flowLayout1 = new FlowLayout();