2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import java.util.List;
25 import java.awt.event.*;
28 import jalview.datamodel.*;
30 import jalview.util.MessageManager;
34 * GUI dialog for exporting features or alignment annotations depending upon
35 * which method is called.
40 public class AnnotationExporter extends JPanel
46 boolean features = true;
48 AlignmentAnnotation[] annotations;
50 List<SequenceGroup> sequenceGroups;
52 Hashtable alignmentProperties;
54 public AnnotationExporter()
59 } catch (Exception ex)
64 frame = new JInternalFrame();
65 frame.setContentPane(this);
66 frame.setLayer(JLayeredPane.PALETTE_LAYER);
67 Desktop.addInternalFrame(frame, "", frame.getPreferredSize().width,
68 frame.getPreferredSize().height);
71 public void exportFeatures(AlignmentPanel ap)
75 CSVFormat.setVisible(false);
76 frame.setTitle("Export Features");
79 public void exportAnnotations(AlignmentPanel ap,
80 AlignmentAnnotation[] annotations, List<SequenceGroup> list,
81 Hashtable alProperties)
85 GFFFormat.setVisible(false);
86 CSVFormat.setVisible(true);
87 this.annotations = annotations;
88 this.sequenceGroups = list;
89 this.alignmentProperties = alProperties;
90 frame.setTitle("Export Annotations");
93 public void toFile_actionPerformed(ActionEvent e)
95 JalviewFileChooser chooser = new JalviewFileChooser(
96 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
98 chooser.setFileView(new JalviewFileView());
99 chooser.setDialogTitle(features ? "Save Features to File"
100 : "Save Annotation to File");
101 chooser.setToolTipText("Save");
103 int value = chooser.showSaveDialog(this);
105 if (value == JalviewFileChooser.APPROVE_OPTION)
107 String text = "No features found on alignment";
110 if (GFFFormat.isSelected())
112 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
113 .getDataset().getSequencesArray(),
114 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());// ap.av.featuresDisplayed//);
118 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
119 .getDataset().getSequencesArray(),
120 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats()); // ap.av.featuresDisplayed);
125 if (CSVFormat.isSelected())
127 text = new AnnotationFile().printCSVAnnotations(annotations);
131 text = new AnnotationFile().printAnnotations(annotations,
132 sequenceGroups, alignmentProperties);
138 java.io.PrintWriter out = new java.io.PrintWriter(
139 new java.io.FileWriter(chooser.getSelectedFile()));
143 } catch (Exception ex)
145 ex.printStackTrace();
149 close_actionPerformed(null);
152 public void toTextbox_actionPerformed(ActionEvent e)
154 String text = "No features found on alignment";
157 if (GFFFormat.isSelected())
159 text = new FeaturesFile().printGFFFormat(ap.av.getAlignment()
160 .getDataset().getSequencesArray(),
161 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
165 text = new FeaturesFile().printJalviewFormat(ap.av.getAlignment()
166 .getDataset().getSequencesArray(),
167 getDisplayedFeatureCols(), true, ap.av.isShowNpFeats());
172 if (CSVFormat.isSelected())
174 text = new AnnotationFile().printCSVAnnotations(annotations);
178 text = new AnnotationFile().printAnnotations(annotations,
179 sequenceGroups, alignmentProperties);
183 CutAndPasteTransfer cap = new CutAndPasteTransfer();
187 Desktop.addInternalFrame(cap, (features ? "Features for - "
188 : "Annotations for - ") + ap.alignFrame.getTitle(), 600, 500);
189 } catch (OutOfMemoryError oom)
191 new OOMWarning("generating "
192 + (features ? "Features for - " : "Annotations for - ")
193 + ap.alignFrame.getTitle(), oom);
197 close_actionPerformed(null);
200 private Hashtable getDisplayedFeatureCols()
202 Hashtable fcols = new Hashtable();
203 if (ap.av.featuresDisplayed == null)
207 Enumeration en = ap.av.featuresDisplayed.keys();
208 FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider
212 while (en.hasMoreElements())
214 Object col = en.nextElement();
215 fcols.put(col, fr.featureColours.get(col));
220 public void close_actionPerformed(ActionEvent e)
224 frame.setClosed(true);
225 } catch (java.beans.PropertyVetoException ex)
230 private void jbInit() throws Exception
232 this.setLayout(new BorderLayout());
234 toFile.setText(MessageManager.getString("label.to_file"));
235 toFile.addActionListener(new ActionListener()
237 public void actionPerformed(ActionEvent e)
239 toFile_actionPerformed(e);
242 toTextbox.setText(MessageManager.getString("label.to_textbox"));
243 toTextbox.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 toTextbox_actionPerformed(e);
250 close.setText(MessageManager.getString("action.close"));
251 close.addActionListener(new ActionListener()
253 public void actionPerformed(ActionEvent e)
255 close_actionPerformed(e);
258 jalviewFormat.setOpaque(false);
259 jalviewFormat.setSelected(true);
260 jalviewFormat.setText("Jalview");
261 GFFFormat.setOpaque(false);
262 GFFFormat.setText("GFF");
263 CSVFormat.setOpaque(false);
264 CSVFormat.setText(MessageManager.getString("label.csv_spreadsheet"));
265 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
266 jLabel1.setText(MessageManager.getString("action.format") + " ");
267 this.setBackground(Color.white);
268 jPanel3.setBorder(BorderFactory.createEtchedBorder());
269 jPanel3.setOpaque(false);
270 jPanel1.setOpaque(false);
272 jPanel1.add(toTextbox);
274 jPanel3.add(jLabel1);
275 jPanel3.add(jalviewFormat);
276 jPanel3.add(GFFFormat);
277 jPanel3.add(CSVFormat);
278 buttonGroup.add(jalviewFormat);
279 buttonGroup.add(GFFFormat);
280 buttonGroup.add(CSVFormat);
281 this.add(jPanel3, BorderLayout.CENTER);
282 this.add(jPanel1, BorderLayout.SOUTH);
285 JPanel jPanel1 = new JPanel();
287 JButton toFile = new JButton();
289 JButton toTextbox = new JButton();
291 JButton close = new JButton();
293 ButtonGroup buttonGroup = new ButtonGroup();
295 JRadioButton jalviewFormat = new JRadioButton();
297 JRadioButton GFFFormat = new JRadioButton();
299 JRadioButton CSVFormat = new JRadioButton();
301 JLabel jLabel1 = new JLabel();
303 JPanel jPanel3 = new JPanel();
305 FlowLayout flowLayout1 = new FlowLayout();