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.*;
32 * GUI dialog for exporting features or alignment annotations depending upon
33 * which method is called.
38 public class AnnotationExporter extends JPanel
44 boolean features = true;
46 AlignmentAnnotation[] annotations;
48 List<SequenceGroup> sequenceGroups;
50 Hashtable alignmentProperties;
52 public AnnotationExporter()
57 } catch (Exception ex)
62 frame = new JInternalFrame();
63 frame.setContentPane(this);
64 frame.setLayer(JLayeredPane.PALETTE_LAYER);
65 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
66 frame.getPreferredSize().height);
69 public void exportFeatures(AlignmentPanel ap)
73 CSVFormat.setVisible(false);
74 frame.setTitle("Export Features");
77 public void exportAnnotations(AlignmentPanel ap,
78 AlignmentAnnotation[] annotations, List<SequenceGroup> list,
79 Hashtable alProperties)
83 GFFFormat.setVisible(false);
84 CSVFormat.setVisible(true);
85 this.annotations = annotations;
86 this.sequenceGroups = list;
87 this.alignmentProperties = alProperties;
88 frame.setTitle("Export Annotations");
91 public void toFile_actionPerformed(ActionEvent e)
93 JalviewFileChooser chooser = new JalviewFileChooser(
94 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
96 chooser.setFileView(new JalviewFileView());
97 chooser.setDialogTitle(features ? "Save Features to File"
98 : "Save Annotation to File");
99 chooser.setToolTipText("Save");
101 int value = chooser.showSaveDialog(this);
103 if (value == JalviewFileChooser.APPROVE_OPTION)
105 String text = "No features found on alignment";
108 if (GFFFormat.isSelected())
110 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
111 .getDataset().getSequencesArray(),
112 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
116 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
117 .getDataset().getSequencesArray(),
118 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
123 if (CSVFormat.isSelected())
125 text = new AnnotationFile().printCSVAnnotations(annotations);
129 text = new AnnotationFile().printAnnotations(annotations,
130 sequenceGroups, alignmentProperties);
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 public void toTextbox_actionPerformed(ActionEvent e)
152 String text = "No features found on alignment";
155 if (GFFFormat.isSelected())
157 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
158 .getDataset().getSequencesArray(),
159 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
163 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
164 .getDataset().getSequencesArray(),
165 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
170 if (CSVFormat.isSelected())
172 text = new AnnotationFile().printCSVAnnotations(annotations);
176 text = new AnnotationFile().printAnnotations(annotations,
177 sequenceGroups, alignmentProperties);
181 CutAndPasteTransfer cap = new CutAndPasteTransfer();
185 Desktop.addInternalFrame(cap, (features ? "Features for - "
186 : "Annotations for - ") + ap.alignFrame.getTitle(), 600, 500);
187 } catch (OutOfMemoryError oom)
189 new OOMWarning("generating "
190 + (features ? "Features for - " : "Annotations for - ")
191 + ap.alignFrame.getTitle(), oom);
195 close_actionPerformed(null);
198 private Hashtable getDisplayedFeatureCols()
200 Hashtable fcols = new Hashtable();
201 if (ap.av.featuresDisplayed == null)
205 Enumeration en = ap.av.featuresDisplayed.keys();
206 FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider
210 while (en.hasMoreElements())
212 Object col = en.nextElement();
213 fcols.put(col, fr.featureColours.get(col));
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("to File");
233 toFile.addActionListener(new ActionListener()
235 public void actionPerformed(ActionEvent e)
237 toFile_actionPerformed(e);
240 toTextbox.setText("to Textbox");
241 toTextbox.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 toTextbox_actionPerformed(e);
248 close.setText("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("CSV(Spreadsheet)");
263 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
264 jLabel1.setText("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();