2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.gui;
\r
25 import java.awt.event.*;
\r
26 import javax.swing.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.io.*;
\r
31 public class AnnotationExporter
\r
34 JInternalFrame frame;
\r
36 boolean features = true;
\r
37 AlignmentAnnotation[] annotations;
\r
38 Vector sequenceGroups;
\r
39 Hashtable alignmentProperties;
\r
41 public AnnotationExporter()
\r
47 catch (Exception ex)
\r
49 ex.printStackTrace();
\r
52 frame = new JInternalFrame();
\r
53 frame.setContentPane(this);
\r
54 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
55 Desktop.addInternalFrame(frame,
\r
60 public void exportFeatures(AlignmentPanel ap)
\r
64 frame.setTitle("Export Features");
\r
67 public void exportAnnotations(AlignmentPanel ap,
\r
68 AlignmentAnnotation[] annotations,
\r
69 Vector sequenceGroups,
\r
70 Hashtable alProperties)
\r
74 GFFFormat.setVisible(false);
\r
75 this.annotations = annotations;
\r
76 this.sequenceGroups = sequenceGroups;
\r
77 this.alignmentProperties = alProperties;
\r
78 frame.setTitle("Export Annotations");
\r
81 public void toFile_actionPerformed(ActionEvent e)
\r
83 JalviewFileChooser chooser = new JalviewFileChooser(
\r
84 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
\r
86 chooser.setFileView(new JalviewFileView());
\r
87 chooser.setDialogTitle(
\r
88 features ? "Save Features to File" : "Save Annotation to File");
\r
89 chooser.setToolTipText("Save");
\r
91 int value = chooser.showSaveDialog(this);
\r
93 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
95 String text = "No features found on alignment";
\r
98 if (GFFFormat.isSelected())
\r
100 text = new FeaturesFile().printGFFFormat(
\r
101 ap.av.alignment.getDataset().getSequencesArray(),
\r
102 ap.av.featuresDisplayed);
\r
106 text = new FeaturesFile().printJalviewFormat(
\r
107 ap.av.alignment.getDataset().getSequencesArray(),
\r
108 ap.av.featuresDisplayed);
\r
113 text = new AnnotationFile().printAnnotations(
\r
116 alignmentProperties);
\r
121 java.io.PrintWriter out = new java.io.PrintWriter(
\r
122 new java.io.FileWriter(chooser.getSelectedFile()));
\r
127 catch (Exception ex)
\r
129 ex.printStackTrace();
\r
133 close_actionPerformed(null);
\r
136 public void toTextbox_actionPerformed(ActionEvent e)
\r
138 String text = "No features found on alignment";
\r
141 if (GFFFormat.isSelected())
\r
143 text = new FeaturesFile().printGFFFormat(
\r
144 ap.av.alignment.getDataset().getSequencesArray(),
\r
145 ap.av.featuresDisplayed);
\r
149 text = new FeaturesFile().printJalviewFormat(
\r
150 ap.av.alignment.getDataset().getSequencesArray(),
\r
151 ap.av.featuresDisplayed);
\r
154 else if (!features)
\r
156 text = new AnnotationFile().printAnnotations(
\r
159 alignmentProperties);
\r
162 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
164 Desktop.addInternalFrame(cap,
\r
165 (features ? "Features for - " :
\r
166 "Annotations for - ")
\r
167 + ap.alignFrame.getTitle(),
\r
171 close_actionPerformed(null);
\r
174 public void close_actionPerformed(ActionEvent e)
\r
178 frame.setClosed(true);
\r
180 catch (java.beans.PropertyVetoException ex)
\r
184 private void jbInit()
\r
187 this.setLayout(flowLayout1);
\r
188 toFile.setText("to File");
\r
189 toFile.addActionListener(new ActionListener()
\r
191 public void actionPerformed(ActionEvent e)
\r
193 toFile_actionPerformed(e);
\r
196 toTextbox.setText("to Textbox");
\r
197 toTextbox.addActionListener(new ActionListener()
\r
199 public void actionPerformed(ActionEvent e)
\r
201 toTextbox_actionPerformed(e);
\r
204 close.setText("Close");
\r
205 close.addActionListener(new ActionListener()
\r
207 public void actionPerformed(ActionEvent e)
\r
209 close_actionPerformed(e);
\r
212 jalviewFormat.setOpaque(false);
\r
213 jalviewFormat.setSelected(true);
\r
214 jalviewFormat.setText("Jalview");
\r
215 GFFFormat.setOpaque(false);
\r
216 GFFFormat.setText("GFF");
\r
217 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
\r
218 jLabel1.setText("Format: ");
\r
219 this.setBackground(Color.white);
\r
220 jPanel3.setBorder(BorderFactory.createEtchedBorder());
\r
221 jPanel3.setOpaque(false);
\r
222 jPanel1.setOpaque(false);
\r
223 jPanel1.add(toFile);
\r
224 jPanel1.add(toTextbox);
\r
225 jPanel1.add(close);
\r
226 jPanel3.add(jLabel1);
\r
227 jPanel3.add(jalviewFormat);
\r
228 jPanel3.add(GFFFormat);
\r
229 buttonGroup.add(jalviewFormat);
\r
230 buttonGroup.add(GFFFormat);
\r
231 this.add(jPanel3, null);
\r
232 this.add(jPanel1, null);
\r
235 JPanel jPanel1 = new JPanel();
\r
236 JButton toFile = new JButton();
\r
237 JButton toTextbox = new JButton();
\r
238 JButton close = new JButton();
\r
239 ButtonGroup buttonGroup = new ButtonGroup();
\r
240 JRadioButton jalviewFormat = new JRadioButton();
\r
241 JRadioButton GFFFormat = new JRadioButton();
\r
242 JLabel jLabel1 = new JLabel();
\r
243 JPanel jPanel3 = new JPanel();
\r
244 FlowLayout flowLayout1 = new FlowLayout();
\r