2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
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(MessageManager.getString("action.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 ? MessageManager.formatMessage("label.features_for_params", new String[]{ap.alignFrame.getTitle()})
188 : MessageManager.formatMessage("label.annotations_for_params", new String[]{ap.alignFrame.getTitle()})), 600, 500);
189 } catch (OutOfMemoryError oom)
191 new OOMWarning((features ? MessageManager.formatMessage("label.generating_features_for_params", new String[]{ap.alignFrame.getTitle()}) : MessageManager.formatMessage("label.generating_annotations_for_params", new String[]{ap.alignFrame.getTitle()}))
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();