2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
22 import javax.swing.*;
\r
23 import java.awt.event.ActionListener;
\r
24 import java.awt.event.ActionEvent;
\r
26 import jalview.io.*;
\r
27 import jalview.datamodel.AlignmentAnnotation;
\r
29 import java.awt.Color;
\r
30 import java.awt.FlowLayout;
\r
31 import javax.swing.BorderFactory;
\r
34 public class AnnotationExporter
\r
37 JInternalFrame frame;
\r
39 boolean features = true;
\r
40 AlignmentAnnotation [] annotations;
\r
42 public AnnotationExporter()
\r
48 catch (Exception ex)
\r
50 ex.printStackTrace();
\r
53 frame = new JInternalFrame();
\r
54 frame.setContentPane(this);
\r
55 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
56 Desktop.addInternalFrame(frame,
\r
61 public void exportFeatures(AlignmentPanel ap)
\r
65 frame.setTitle("Export Features");
\r
68 public void exportAnnotations(AlignmentPanel ap,
\r
69 AlignmentAnnotation [] annotations)
\r
73 GFFFormat.setVisible(false);
\r
74 this.annotations = annotations;
\r
75 frame.setTitle("Export Annotations");
\r
78 public void toFile_actionPerformed(ActionEvent e)
\r
80 JalviewFileChooser chooser = new JalviewFileChooser(
\r
81 jalview.bin.Cache.getProperty( "LAST_DIRECTORY"));
\r
83 chooser.setFileView(new JalviewFileView());
\r
84 chooser.setDialogTitle(
\r
85 features ? "Save Features to File" : "Save Annotation to File");
\r
86 chooser.setToolTipText("Save");
\r
88 int value = chooser.showSaveDialog(this);
\r
90 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
92 String text = "No features found on alignment";
\r
95 if (GFFFormat.isSelected())
\r
96 text = new FeaturesFile().printGFFFormat(
\r
97 ap.av.alignment.getDataset().getSequencesArray(),
\r
98 ap.av.featuresDisplayed);
\r
100 text = new FeaturesFile().printJalviewFormat(
\r
101 ap.av.alignment.getDataset().getSequencesArray(),
\r
102 ap.av.featuresDisplayed);
\r
106 text = new AnnotationFile().printAnnotations( annotations );
\r
111 java.io.PrintWriter out = new java.io.PrintWriter(
\r
112 new java.io.FileWriter(chooser.getSelectedFile()));
\r
117 catch (Exception ex)
\r
119 ex.printStackTrace();
\r
124 public void toTextbox_actionPerformed(ActionEvent e)
\r
126 String text = "No features found on alignment";
\r
129 if (GFFFormat.isSelected())
\r
130 text = new FeaturesFile().printGFFFormat(
\r
131 ap.av.alignment.getDataset().getSequencesArray(),
\r
132 ap.av.featuresDisplayed);
\r
134 text = new FeaturesFile().printJalviewFormat(
\r
135 ap.av.alignment.getDataset().getSequencesArray(),
\r
136 ap.av.featuresDisplayed);
\r
140 text = new AnnotationFile().printAnnotations( annotations );
\r
144 CutAndPasteTransfer cap = new CutAndPasteTransfer();
\r
146 Desktop.addInternalFrame(cap,
\r
147 (features ? "Features for - " : "Annotations for - ")
\r
148 + ap.alignFrame.getTitle(),
\r
155 public void close_actionPerformed(ActionEvent e)
\r
158 frame.setClosed(true);
\r
159 }catch(java.beans.PropertyVetoException ex)
\r
165 private void jbInit()
\r
168 this.setLayout(flowLayout1);
\r
169 toFile.setText("to File");
\r
170 toFile.addActionListener(new ActionListener()
\r
172 public void actionPerformed(ActionEvent e)
\r
174 toFile_actionPerformed(e);
\r
177 toTextbox.setText("to Textbox");
\r
178 toTextbox.addActionListener(new ActionListener()
\r
180 public void actionPerformed(ActionEvent e)
\r
182 toTextbox_actionPerformed(e);
\r
185 close.setText("Close");
\r
186 close.addActionListener(new ActionListener()
\r
188 public void actionPerformed(ActionEvent e)
\r
190 close_actionPerformed(e);
\r
193 jalviewFormat.setOpaque(false);
\r
194 jalviewFormat.setSelected(true);
\r
195 jalviewFormat.setText("Jalview");
\r
196 GFFFormat.setOpaque(false);
\r
197 GFFFormat.setText("GFF");
\r
198 jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);
\r
199 jLabel1.setText("Format: ");
\r
200 this.setBackground(Color.white);
\r
201 jPanel3.setBorder(BorderFactory.createEtchedBorder());
\r
202 jPanel3.setOpaque(false);
\r
203 jPanel1.setOpaque(false);
\r
204 jPanel1.add(toFile);
\r
205 jPanel1.add(toTextbox);
\r
206 jPanel1.add(close);
\r
207 jPanel3.add(jLabel1);
\r
208 jPanel3.add(jalviewFormat);
\r
209 jPanel3.add(GFFFormat);
\r
210 buttonGroup.add(jalviewFormat);
\r
211 buttonGroup.add(GFFFormat);
\r
212 this.add(jPanel3, null);
\r
213 this.add(jPanel1, null);
\r
216 JPanel jPanel1 = new JPanel();
\r
217 JButton toFile = new JButton();
\r
218 JButton toTextbox = new JButton();
\r
219 JButton close = new JButton();
\r
220 ButtonGroup buttonGroup = new ButtonGroup();
\r
221 JRadioButton jalviewFormat = new JRadioButton();
\r
222 JRadioButton GFFFormat = new JRadioButton();
\r
223 JLabel jLabel1 = new JLabel();
\r
224 JPanel jPanel3 = new JPanel();
\r
225 FlowLayout flowLayout1 = new FlowLayout();
\r