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.api.FeatureColourI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.SequenceI;
26 import jalview.io.AnnotationFile;
27 import jalview.io.FeaturesFile;
28 import jalview.io.JalviewFileChooser;
29 import jalview.io.JalviewFileView;
30 import jalview.util.MessageManager;
32 import java.awt.BorderLayout;
33 import java.awt.Color;
34 import java.awt.FlowLayout;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
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 private AlignmentAnnotation[] annotations;
67 private boolean wholeView;
69 public AnnotationExporter()
74 } catch (Exception ex)
79 frame = new JInternalFrame();
80 frame.setContentPane(this);
81 frame.setLayer(JLayeredPane.PALETTE_LAYER);
82 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
83 frame.getPreferredSize().height);
86 public void exportFeatures(AlignmentPanel ap)
90 CSVFormat.setVisible(false);
91 frame.setTitle(MessageManager.getString("label.export_features"));
94 public void exportAnnotations(AlignmentPanel ap)
97 annotations = ap.av.isShowAnnotation() ? null : ap.av.getAlignment()
98 .getAlignmentAnnotation();
100 startExportAnnotation();
103 public void exportAnnotations(AlignmentPanel alp,
104 AlignmentAnnotation[] toExport)
107 annotations = toExport;
109 startExportAnnotation();
112 private void startExportAnnotation()
115 GFFFormat.setVisible(false);
116 CSVFormat.setVisible(true);
117 frame.setTitle(MessageManager.getString("label.export_annotations"));
120 public void toFile_actionPerformed(ActionEvent e)
122 JalviewFileChooser chooser = new JalviewFileChooser(
123 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
125 chooser.setFileView(new JalviewFileView());
126 chooser.setDialogTitle(features ? MessageManager
127 .getString("label.save_features_to_file") : MessageManager
128 .getString("label.save_annotation_to_file"));
129 chooser.setToolTipText(MessageManager.getString("action.save"));
131 int value = chooser.showSaveDialog(this);
133 if (value == JalviewFileChooser.APPROVE_OPTION)
135 String text = getFileContents();
139 java.io.PrintWriter out = new java.io.PrintWriter(
140 new java.io.FileWriter(chooser.getSelectedFile()));
144 } catch (Exception ex)
146 ex.printStackTrace();
150 close_actionPerformed(null);
153 private String getFileContents()
155 String text = MessageManager
156 .getString("label.no_features_on_alignment");
159 Map<String, FeatureColourI> displayedFeatureColours = ap
160 .getFeatureRenderer().getDisplayedFeatureCols();
161 FeaturesFile formatter = new FeaturesFile();
162 SequenceI[] sequences = ap.av.getAlignment().getSequencesArray();
163 Map<String, FeatureColourI> featureColours = ap.getFeatureRenderer()
164 .getDisplayedFeatureCols();
165 boolean includeNonPositional = ap.av.isShowNPFeats();
166 if (GFFFormat.isSelected())
168 text = new FeaturesFile().printGffFormat(ap.av.getAlignment()
169 .getDataset().getSequencesArray(), displayedFeatureColours,
170 true, ap.av.isShowNPFeats());
171 text = formatter.printGffFormat(sequences, featureColours, true,
172 includeNonPositional);
176 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
177 .getDataset().getSequencesArray(), displayedFeatureColours,
178 true, ap.av.isShowNPFeats()); // ap.av.featuresDisplayed);
179 text = formatter.printJalviewFormat(sequences, featureColours,
180 true, includeNonPositional);
185 if (CSVFormat.isSelected())
187 text = new AnnotationFile().printCSVAnnotations(annotations);
193 text = new AnnotationFile().printAnnotationsForView(ap.av);
197 text = new AnnotationFile().printAnnotations(annotations, null,
205 public void toTextbox_actionPerformed(ActionEvent e)
207 CutAndPasteTransfer cap = new CutAndPasteTransfer();
211 String text = getFileContents();
213 Desktop.addInternalFrame(
215 (features ? MessageManager.formatMessage(
216 "label.features_for_params",
217 new String[] { ap.alignFrame.getTitle() })
218 : MessageManager.formatMessage(
219 "label.annotations_for_params",
220 new String[] { ap.alignFrame.getTitle() })),
222 } catch (OutOfMemoryError oom)
224 new OOMWarning((features ? MessageManager.formatMessage(
225 "label.generating_features_for_params",
226 new String[] { ap.alignFrame.getTitle() })
227 : MessageManager.formatMessage(
228 "label.generating_annotations_for_params",
229 new String[] { ap.alignFrame.getTitle() })), oom);
233 close_actionPerformed(null);
236 public void close_actionPerformed(ActionEvent e)
240 frame.setClosed(true);
241 } catch (java.beans.PropertyVetoException ex)
246 private void jbInit() throws Exception
248 this.setLayout(new BorderLayout());
250 toFile.setText(MessageManager.getString("label.to_file"));
251 toFile.addActionListener(new ActionListener()
254 public void actionPerformed(ActionEvent e)
256 toFile_actionPerformed(e);
259 toTextbox.setText(MessageManager.getString("label.to_textbox"));
260 toTextbox.addActionListener(new ActionListener()
263 public void actionPerformed(ActionEvent e)
265 toTextbox_actionPerformed(e);
268 close.setText(MessageManager.getString("action.close"));
269 close.addActionListener(new ActionListener()
272 public void actionPerformed(ActionEvent e)
274 close_actionPerformed(e);
277 jalviewFormat.setOpaque(false);
278 jalviewFormat.setSelected(true);
279 jalviewFormat.setText("Jalview");
280 GFFFormat.setOpaque(false);
281 GFFFormat.setText("GFF");
282 CSVFormat.setOpaque(false);
283 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
284 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
285 jLabel1.setText(MessageManager.getString("action.format") + " ");
286 this.setBackground(Color.white);
287 jPanel3.setBorder(BorderFactory.createEtchedBorder());
288 jPanel3.setOpaque(false);
289 jPanel1.setOpaque(false);
291 jPanel1.add(toTextbox);
293 jPanel3.add(jLabel1);
294 jPanel3.add(jalviewFormat);
295 jPanel3.add(GFFFormat);
296 jPanel3.add(CSVFormat);
297 buttonGroup.add(jalviewFormat);
298 buttonGroup.add(GFFFormat);
299 buttonGroup.add(CSVFormat);
300 this.add(jPanel3, BorderLayout.CENTER);
301 this.add(jPanel1, BorderLayout.SOUTH);
304 JPanel jPanel1 = new JPanel();
306 JButton toFile = new JButton();
308 JButton toTextbox = new JButton();
310 JButton close = new JButton();
312 ButtonGroup buttonGroup = new ButtonGroup();
314 JRadioButton jalviewFormat = new JRadioButton();
316 JRadioButton GFFFormat = new JRadioButton();
318 JRadioButton CSVFormat = new JRadioButton();
320 JLabel jLabel1 = new JLabel();
322 JPanel jPanel3 = new JPanel();
324 FlowLayout flowLayout1 = new FlowLayout();