Put alignmentProperties in scrollpane
[jalview.git] / src / jalview / gui / AnnotationExporter.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\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
9  *\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
14  *\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
18  */\r
19 \r
20 package jalview.gui;\r
21 \r
22 import java.util.*;\r
23 \r
24 import java.awt.*;\r
25 import java.awt.event.*;\r
26 import javax.swing.*;\r
27 \r
28 import jalview.datamodel.*;\r
29 import jalview.io.*;\r
30 \r
31 public class AnnotationExporter\r
32     extends JPanel\r
33 {\r
34   JInternalFrame frame;\r
35   AlignmentPanel ap;\r
36   boolean features = true;\r
37   AlignmentAnnotation[] annotations;\r
38   Vector sequenceGroups;\r
39   Hashtable alignmentProperties;\r
40 \r
41   public AnnotationExporter()\r
42   {\r
43     try\r
44     {\r
45       jbInit();\r
46     }\r
47     catch (Exception ex)\r
48     {\r
49       ex.printStackTrace();\r
50     }\r
51 \r
52     frame = new JInternalFrame();\r
53     frame.setContentPane(this);\r
54     frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
55     Desktop.addInternalFrame(frame,\r
56                              "",\r
57                              260, 125);\r
58   }\r
59 \r
60   public void exportFeatures(AlignmentPanel ap)\r
61   {\r
62     this.ap = ap;\r
63     features = true;\r
64     frame.setTitle("Export Features");\r
65   }\r
66 \r
67   public void exportAnnotations(AlignmentPanel ap,\r
68                                 AlignmentAnnotation[] annotations,\r
69                                 Vector sequenceGroups,\r
70                                 Hashtable alProperties)\r
71   {\r
72     this.ap = ap;\r
73     features = false;\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
79   }\r
80 \r
81   public void toFile_actionPerformed(ActionEvent e)\r
82   {\r
83     JalviewFileChooser chooser = new JalviewFileChooser(\r
84         jalview.bin.Cache.getProperty("LAST_DIRECTORY"));\r
85 \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
90 \r
91     int value = chooser.showSaveDialog(this);\r
92 \r
93     if (value == JalviewFileChooser.APPROVE_OPTION)\r
94     {\r
95       String text = "No features found on alignment";\r
96       if (features)\r
97       {\r
98         if (GFFFormat.isSelected())\r
99         {\r
100           text = new FeaturesFile().printGFFFormat(\r
101               ap.av.alignment.getDataset().getSequencesArray(),\r
102               ap.av.featuresDisplayed);\r
103         }\r
104         else\r
105         {\r
106           text = new FeaturesFile().printJalviewFormat(\r
107               ap.av.alignment.getDataset().getSequencesArray(),\r
108               ap.av.featuresDisplayed);\r
109         }\r
110       }\r
111       else\r
112       {\r
113         text = new AnnotationFile().printAnnotations(\r
114             annotations,\r
115             sequenceGroups,\r
116             alignmentProperties);\r
117       }\r
118 \r
119       try\r
120       {\r
121         java.io.PrintWriter out = new java.io.PrintWriter(\r
122             new java.io.FileWriter(chooser.getSelectedFile()));\r
123 \r
124         out.print(text);\r
125         out.close();\r
126       }\r
127       catch (Exception ex)\r
128       {\r
129         ex.printStackTrace();\r
130       }\r
131     }\r
132 \r
133     close_actionPerformed(null);\r
134   }\r
135 \r
136   public void toTextbox_actionPerformed(ActionEvent e)\r
137   {\r
138     String text = "No features found on alignment";\r
139     if (features)\r
140     {\r
141       if (GFFFormat.isSelected())\r
142       {\r
143         text = new FeaturesFile().printGFFFormat(\r
144             ap.av.alignment.getDataset().getSequencesArray(),\r
145             ap.av.featuresDisplayed);\r
146       }\r
147       else\r
148       {\r
149         text = new FeaturesFile().printJalviewFormat(\r
150             ap.av.alignment.getDataset().getSequencesArray(),\r
151             ap.av.featuresDisplayed);\r
152       }\r
153     }\r
154     else if (!features)\r
155     {\r
156       text = new AnnotationFile().printAnnotations(\r
157           annotations,\r
158           sequenceGroups,\r
159           alignmentProperties);\r
160     }\r
161 \r
162     CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
163     cap.setText(text);\r
164     Desktop.addInternalFrame(cap,\r
165                              (features ? "Features for - " :\r
166                               "Annotations for - ")\r
167                              + ap.alignFrame.getTitle(),\r
168                              600,\r
169                              500);\r
170 \r
171     close_actionPerformed(null);\r
172   }\r
173 \r
174   public void close_actionPerformed(ActionEvent e)\r
175   {\r
176     try\r
177     {\r
178       frame.setClosed(true);\r
179     }\r
180     catch (java.beans.PropertyVetoException ex)\r
181     {}\r
182   }\r
183 \r
184   private void jbInit()\r
185       throws Exception\r
186   {\r
187     this.setLayout(flowLayout1);\r
188     toFile.setText("to File");\r
189     toFile.addActionListener(new ActionListener()\r
190     {\r
191       public void actionPerformed(ActionEvent e)\r
192       {\r
193         toFile_actionPerformed(e);\r
194       }\r
195     });\r
196     toTextbox.setText("to Textbox");\r
197     toTextbox.addActionListener(new ActionListener()\r
198     {\r
199       public void actionPerformed(ActionEvent e)\r
200       {\r
201         toTextbox_actionPerformed(e);\r
202       }\r
203     });\r
204     close.setText("Close");\r
205     close.addActionListener(new ActionListener()\r
206     {\r
207       public void actionPerformed(ActionEvent e)\r
208       {\r
209         close_actionPerformed(e);\r
210       }\r
211     });\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
233   }\r
234 \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
245 \r
246 }\r