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(MessageManager.getString("action.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 ? MessageManager.formatMessage("label.features_for_params", new String[]{ap.alignFrame.getTitle()})
187 : MessageManager.formatMessage("label.annotations_for_params", new String[]{ap.alignFrame.getTitle()})), 600, 500);
188 } catch (OutOfMemoryError oom)
190 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()}))
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(MessageManager.getString("label.to_file"));
233 toFile.addActionListener(new ActionListener()
235 public void actionPerformed(ActionEvent e)
237 toFile_actionPerformed(e);
240 toTextbox.setText(MessageManager.getString("label.to_textbox"));
241 toTextbox.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
245 toTextbox_actionPerformed(e);
248 close.setText(MessageManager.getString("action.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(MessageManager.getString("label.csv_spreadsheet"));
263 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
264 jLabel1.setText(MessageManager.getString("action.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();