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.bin.Cache;
24 import jalview.datamodel.AlignmentAnnotation;
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;
37 import javax.swing.BorderFactory;
38 import javax.swing.ButtonGroup;
39 import javax.swing.JButton;
40 import javax.swing.JInternalFrame;
41 import javax.swing.JLabel;
42 import javax.swing.JLayeredPane;
43 import javax.swing.JPanel;
44 import javax.swing.JRadioButton;
45 import javax.swing.SwingConstants;
49 * GUI dialog for exporting features or alignment annotations depending upon
50 * which method is called.
55 public class AnnotationExporter extends JPanel
61 boolean features = true;
63 private AlignmentAnnotation[] annotations;
65 private boolean wholeView;
67 public AnnotationExporter()
72 } catch (Exception ex)
77 frame = new JInternalFrame();
78 frame.setContentPane(this);
79 frame.setLayer(JLayeredPane.PALETTE_LAYER);
80 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
81 frame.getPreferredSize().height);
84 public void exportFeatures(AlignmentPanel ap)
88 CSVFormat.setVisible(false);
89 frame.setTitle(MessageManager.getString("label.export_features"));
92 public void exportAnnotations(AlignmentPanel ap)
95 annotations = ap.av.isShowAnnotation() ? null : ap.av.getAlignment()
96 .getAlignmentAnnotation();
98 startExportAnnotation();
101 public void exportAnnotations(AlignmentPanel alp,
102 AlignmentAnnotation[] toExport)
105 annotations = toExport;
107 startExportAnnotation();
110 private void startExportAnnotation()
113 GFFFormat.setVisible(false);
114 CSVFormat.setVisible(true);
115 frame.setTitle(MessageManager.getString("label.export_annotations"));
118 public void toFile_actionPerformed(ActionEvent e)
120 JalviewFileChooser chooser = new JalviewFileChooser(
121 Cache.getProperty("LAST_DIRECTORY"));
123 chooser.setFileView(new JalviewFileView());
124 chooser.setDialogTitle(features ? MessageManager.getString("label.save_features_to_file")
125 : MessageManager.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,
190 public void toTextbox_actionPerformed(ActionEvent e)
192 CutAndPasteTransfer cap = new CutAndPasteTransfer();
196 String text = getFileContents();
198 Desktop.addInternalFrame(
200 (features ? MessageManager.formatMessage(
201 "label.features_for_params", new String[]
202 { ap.alignFrame.getTitle() }) : MessageManager
203 .formatMessage("label.annotations_for_params",
205 { ap.alignFrame.getTitle() })), 600, 500);
206 } catch (OutOfMemoryError oom)
208 new OOMWarning((features ? MessageManager.formatMessage(
209 "label.generating_features_for_params", new String[]
210 { ap.alignFrame.getTitle() }) : MessageManager.formatMessage(
211 "label.generating_annotations_for_params", new String[]
212 { ap.alignFrame.getTitle() })), oom);
216 close_actionPerformed(null);
218 public void close_actionPerformed(ActionEvent e)
222 frame.setClosed(true);
223 } catch (java.beans.PropertyVetoException ex)
228 private void jbInit() throws Exception
230 this.setLayout(new BorderLayout());
232 toFile.setText(MessageManager.getString("label.to_file"));
233 toFile.addActionListener(new ActionListener()
235 public void actionPerformed(ActionEvent e)
237 toFile_actionPerformed(e);
240 toTextbox.setText(MessageManager.getString("label.to_textbox"));
241 toTextbox.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 toTextbox_actionPerformed(e);
248 close.setText(MessageManager.getString("action.close"));
249 close.addActionListener(new ActionListener()
251 public void actionPerformed(ActionEvent e)
253 close_actionPerformed(e);
256 jalviewFormat.setOpaque(false);
257 jalviewFormat.setSelected(true);
258 jalviewFormat.setText("Jalview");
259 GFFFormat.setOpaque(false);
260 GFFFormat.setText("GFF");
261 CSVFormat.setOpaque(false);
262 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
263 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
264 jLabel1.setText(MessageManager.getString("action.format") + " ");
265 this.setBackground(Color.white);
266 jPanel3.setBorder(BorderFactory.createEtchedBorder());
267 jPanel3.setOpaque(false);
268 jPanel1.setOpaque(false);
270 jPanel1.add(toTextbox);
272 jPanel3.add(jLabel1);
273 jPanel3.add(jalviewFormat);
274 jPanel3.add(GFFFormat);
275 jPanel3.add(CSVFormat);
276 buttonGroup.add(jalviewFormat);
277 buttonGroup.add(GFFFormat);
278 buttonGroup.add(CSVFormat);
279 this.add(jPanel3, BorderLayout.CENTER);
280 this.add(jPanel1, BorderLayout.SOUTH);
283 JPanel jPanel1 = new JPanel();
285 JButton toFile = new JButton();
287 JButton toTextbox = new JButton();
289 JButton close = new JButton();
291 ButtonGroup buttonGroup = new ButtonGroup();
293 JRadioButton jalviewFormat = new JRadioButton();
295 JRadioButton GFFFormat = new JRadioButton();
297 JRadioButton CSVFormat = new JRadioButton();
299 JLabel jLabel1 = new JLabel();
301 JPanel jPanel3 = new JPanel();
303 FlowLayout flowLayout1 = new FlowLayout();