2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.util.List;
24 import java.awt.event.*;
27 import jalview.datamodel.*;
29 import jalview.util.MessageManager;
33 * GUI dialog for exporting features or alignment annotations depending upon
34 * which method is called.
39 public class AnnotationExporter extends JPanel
45 boolean features = true;
47 AlignmentAnnotation[] annotations;
49 List<SequenceGroup> sequenceGroups;
51 Hashtable alignmentProperties;
53 public AnnotationExporter()
58 } catch (Exception ex)
63 frame = new JInternalFrame();
64 frame.setContentPane(this);
65 frame.setLayer(JLayeredPane.PALETTE_LAYER);
66 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
67 frame.getPreferredSize().height);
70 public void exportFeatures(AlignmentPanel ap)
74 CSVFormat.setVisible(false);
75 frame.setTitle("Export Features");
78 public void exportAnnotations(AlignmentPanel ap,
79 AlignmentAnnotation[] annotations, List<SequenceGroup> list,
80 Hashtable alProperties)
84 GFFFormat.setVisible(false);
85 CSVFormat.setVisible(true);
86 this.annotations = annotations;
87 this.sequenceGroups = list;
88 this.alignmentProperties = alProperties;
89 frame.setTitle("Export Annotations");
92 public void toFile_actionPerformed(ActionEvent e)
94 JalviewFileChooser chooser = new JalviewFileChooser(
95 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
97 chooser.setFileView(new JalviewFileView());
98 chooser.setDialogTitle(features ? "Save Features to File"
99 : "Save Annotation to File");
100 chooser.setToolTipText("Save");
102 int value = chooser.showSaveDialog(this);
104 if (value == JalviewFileChooser.APPROVE_OPTION)
106 String text = "No features found on alignment";
109 if (GFFFormat.isSelected())
111 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
112 .getDataset().getSequencesArray(),
113 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
117 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
118 .getDataset().getSequencesArray(),
119 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
124 if (CSVFormat.isSelected())
126 text = new AnnotationFile().printCSVAnnotations(annotations);
130 text = new AnnotationFile().printAnnotations(annotations,
131 sequenceGroups, alignmentProperties);
137 java.io.PrintWriter out = new java.io.PrintWriter(
138 new java.io.FileWriter(chooser.getSelectedFile()));
142 } catch (Exception ex)
144 ex.printStackTrace();
148 close_actionPerformed(null);
151 public void toTextbox_actionPerformed(ActionEvent e)
153 String text = "No features found on alignment";
156 if (GFFFormat.isSelected())
158 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
159 .getDataset().getSequencesArray(),
160 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
164 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
165 .getDataset().getSequencesArray(),
166 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
171 if (CSVFormat.isSelected())
173 text = new AnnotationFile().printCSVAnnotations(annotations);
177 text = new AnnotationFile().printAnnotations(annotations,
178 sequenceGroups, alignmentProperties);
182 CutAndPasteTransfer cap = new CutAndPasteTransfer();
186 Desktop.addInternalFrame(cap, (features ? "Features for - "
187 : "Annotations for - ") + ap.alignFrame.getTitle(), 600, 500);
188 } catch (OutOfMemoryError oom)
190 new OOMWarning("generating "
191 + (features ? "Features for - " : "Annotations for - ")
192 + ap.alignFrame.getTitle(), oom);
196 close_actionPerformed(null);
199 private Hashtable getDisplayedFeatureCols()
201 Hashtable fcols = new Hashtable();
202 if (ap.av.featuresDisplayed == null)
206 Enumeration en = ap.av.featuresDisplayed.keys();
207 FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider
211 while (en.hasMoreElements())
213 Object col = en.nextElement();
214 fcols.put(col, fr.featureColours.get(col));
219 public void close_actionPerformed(ActionEvent e)
223 frame.setClosed(true);
224 } catch (java.beans.PropertyVetoException ex)
229 private void jbInit() throws Exception
231 this.setLayout(new BorderLayout());
233 toFile.setText(MessageManager.getString("label.to_file"));
234 toFile.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 toFile_actionPerformed(e);
241 toTextbox.setText(MessageManager.getString("label.to_textbox"));
242 toTextbox.addActionListener(new ActionListener()
244 public void actionPerformed(ActionEvent e)
246 toTextbox_actionPerformed(e);
249 close.setText(MessageManager.getString("action.close"));
250 close.addActionListener(new ActionListener()
252 public void actionPerformed(ActionEvent e)
254 close_actionPerformed(e);
257 jalviewFormat.setOpaque(false);
258 jalviewFormat.setSelected(true);
259 jalviewFormat.setText("Jalview");
260 GFFFormat.setOpaque(false);
261 GFFFormat.setText("GFF");
262 CSVFormat.setOpaque(false);
263 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
264 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
265 jLabel1.setText(MessageManager.getString("action.format") + " ");
266 this.setBackground(Color.white);
267 jPanel3.setBorder(BorderFactory.createEtchedBorder());
268 jPanel3.setOpaque(false);
269 jPanel1.setOpaque(false);
271 jPanel1.add(toTextbox);
273 jPanel3.add(jLabel1);
274 jPanel3.add(jalviewFormat);
275 jPanel3.add(GFFFormat);
276 jPanel3.add(CSVFormat);
277 buttonGroup.add(jalviewFormat);
278 buttonGroup.add(GFFFormat);
279 buttonGroup.add(CSVFormat);
280 this.add(jPanel3, BorderLayout.CENTER);
281 this.add(jPanel1, BorderLayout.SOUTH);
284 JPanel jPanel1 = new JPanel();
286 JButton toFile = new JButton();
288 JButton toTextbox = new JButton();
290 JButton close = new JButton();
292 ButtonGroup buttonGroup = new ButtonGroup();
294 JRadioButton jalviewFormat = new JRadioButton();
296 JRadioButton GFFFormat = new JRadioButton();
298 JRadioButton CSVFormat = new JRadioButton();
300 JLabel jLabel1 = new JLabel();
302 JPanel jPanel3 = new JPanel();
304 FlowLayout flowLayout1 = new FlowLayout();