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
124 .getString("label.save_features_to_file") : MessageManager
125 .getString("label.save_annotation_to_file"));
126 chooser.setToolTipText(MessageManager.getString("action.save"));
128 int value = chooser.showSaveDialog(this);
130 if (value == JalviewFileChooser.APPROVE_OPTION)
132 String text = getFileContents();
136 java.io.PrintWriter out = new java.io.PrintWriter(
137 new java.io.FileWriter(chooser.getSelectedFile()));
141 } catch (Exception ex)
143 ex.printStackTrace();
147 close_actionPerformed(null);
150 private String getFileContents()
152 String text = MessageManager
153 .getString("label.no_features_on_alignment");
156 if (GFFFormat.isSelected())
158 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
159 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
160 .getDisplayedFeatureCols(), true, ap.av.isShowNPFeats());// ap.av.featuresDisplayed//);
164 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
165 .getDataset().getSequencesArray(), ap.getFeatureRenderer()
166 .getDisplayedFeatureCols(), true, ap.av.isShowNPFeats()); // ap.av.featuresDisplayed);
171 if (CSVFormat.isSelected())
173 text = new AnnotationFile().printCSVAnnotations(annotations);
179 text = new AnnotationFile().printAnnotationsForView(ap.av);
183 text = new AnnotationFile().printAnnotations(annotations, null,
191 public void toTextbox_actionPerformed(ActionEvent e)
193 CutAndPasteTransfer cap = new CutAndPasteTransfer();
197 String text = getFileContents();
199 Desktop.addInternalFrame(
201 (features ? MessageManager.formatMessage(
202 "label.features_for_params",
203 new String[] { ap.alignFrame.getTitle() })
204 : MessageManager.formatMessage(
205 "label.annotations_for_params",
206 new String[] { ap.alignFrame.getTitle() })),
208 } catch (OutOfMemoryError oom)
210 new OOMWarning((features ? MessageManager.formatMessage(
211 "label.generating_features_for_params",
212 new String[] { ap.alignFrame.getTitle() })
213 : MessageManager.formatMessage(
214 "label.generating_annotations_for_params",
215 new String[] { ap.alignFrame.getTitle() })), oom);
219 close_actionPerformed(null);
222 public void close_actionPerformed(ActionEvent e)
226 frame.setClosed(true);
227 } catch (java.beans.PropertyVetoException ex)
232 private void jbInit() throws Exception
234 this.setLayout(new BorderLayout());
236 toFile.setText(MessageManager.getString("label.to_file"));
237 toFile.addActionListener(new ActionListener()
239 public void actionPerformed(ActionEvent e)
241 toFile_actionPerformed(e);
244 toTextbox.setText(MessageManager.getString("label.to_textbox"));
245 toTextbox.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
249 toTextbox_actionPerformed(e);
252 close.setText(MessageManager.getString("action.close"));
253 close.addActionListener(new ActionListener()
255 public void actionPerformed(ActionEvent e)
257 close_actionPerformed(e);
260 jalviewFormat.setOpaque(false);
261 jalviewFormat.setSelected(true);
262 jalviewFormat.setText("Jalview");
263 GFFFormat.setOpaque(false);
264 GFFFormat.setText("GFF");
265 CSVFormat.setOpaque(false);
266 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
267 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
268 jLabel1.setText(MessageManager.getString("action.format") + " ");
269 this.setBackground(Color.white);
270 jPanel3.setBorder(BorderFactory.createEtchedBorder());
271 jPanel3.setOpaque(false);
272 jPanel1.setOpaque(false);
274 jPanel1.add(toTextbox);
276 jPanel3.add(jLabel1);
277 jPanel3.add(jalviewFormat);
278 jPanel3.add(GFFFormat);
279 jPanel3.add(CSVFormat);
280 buttonGroup.add(jalviewFormat);
281 buttonGroup.add(GFFFormat);
282 buttonGroup.add(CSVFormat);
283 this.add(jPanel3, BorderLayout.CENTER);
284 this.add(jPanel1, BorderLayout.SOUTH);
287 JPanel jPanel1 = new JPanel();
289 JButton toFile = new JButton();
291 JButton toTextbox = new JButton();
293 JButton close = new JButton();
295 ButtonGroup buttonGroup = new ButtonGroup();
297 JRadioButton jalviewFormat = new JRadioButton();
299 JRadioButton GFFFormat = new JRadioButton();
301 JRadioButton CSVFormat = new JRadioButton();
303 JLabel jLabel1 = new JLabel();
305 JPanel jPanel3 = new JPanel();
307 FlowLayout flowLayout1 = new FlowLayout();