Remove start end for now??
[jalview.git] / src / jalview / gui / Preferences.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 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 package jalview.gui;\r
20 \r
21 import jalview.io.*;\r
22 \r
23 import jalview.jbgui.*;\r
24 \r
25 import jalview.schemes.*;\r
26 \r
27 import java.awt.*;\r
28 import java.awt.event.*;\r
29 \r
30 import javax.swing.*;\r
31 \r
32 import java.util.*;\r
33 \r
34 import jalview.bin.Cache;\r
35 \r
36 \r
37 /**\r
38  * DOCUMENT ME!\r
39  *\r
40  * @author $author$\r
41  * @version $Revision$\r
42  */\r
43 public class Preferences extends GPreferences\r
44 {\r
45     /** Holds name and link separated with | character. Sequence ID must be $SEQUENCE_ID$ */\r
46     public static Vector sequenceURLLinks;\r
47     static\r
48     {\r
49       String string = Cache.getDefault("SEQUENCE_LINKS",\r
50                                        "SRS|http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:$SEQUENCE_ID$]+-vn+2");\r
51       sequenceURLLinks = new Vector();\r
52 \r
53       try\r
54       {\r
55         StringTokenizer st = new StringTokenizer(string, "|");\r
56         while (st.hasMoreElements())\r
57         {\r
58           sequenceURLLinks.addElement(st.nextToken() + "|" + st.nextToken());\r
59         }\r
60       }\r
61       catch (Exception ex)\r
62       {\r
63         System.out.println(ex + "\nError parsing sequence links");\r
64       }\r
65     }\r
66     Vector nameLinks, urlLinks;\r
67 \r
68     JInternalFrame frame;\r
69 \r
70     DasSourceBrowser dasSource;\r
71 \r
72 \r
73     /**\r
74      * Creates a new Preferences object.\r
75      */\r
76     public Preferences()\r
77     {\r
78 \r
79         frame = new JInternalFrame();\r
80         frame.setContentPane(this);\r
81         dasSource = new DasSourceBrowser();\r
82         dasPanel.add(dasSource, BorderLayout.CENTER);\r
83 \r
84         int width = 500, height = 420;\r
85         if(System.getProperty("os.name").startsWith("Mac"))\r
86         {\r
87           width = 570;\r
88           height = 460;\r
89         }\r
90 \r
91         Desktop.addInternalFrame(frame, "Preferences", width, height);\r
92         frame.setMinimumSize(new Dimension(width, height));\r
93 \r
94         seqLimit.setSelected(    Cache.getDefault("SHOW_JVSUFFIX", true));\r
95         fullScreen.setSelected(  Cache.getDefault("SHOW_FULLSCREEN", false));\r
96         annotations.setSelected( Cache.getDefault("SHOW_ANNOTATIONS", true));\r
97 \r
98         conservation.setEnabled( Cache.getDefault("SHOW_ANNOTATIONS", true));\r
99         quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));\r
100         identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));\r
101 \r
102         conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));\r
103         quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));\r
104         identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));\r
105 \r
106         for (int i = 0; i < 13; i++)\r
107         {\r
108             colour.addItem(ColourSchemeProperty.getColourName(i));\r
109         }\r
110 \r
111         String string = Cache.getDefault("DEFAULT_COLOUR", "None");\r
112 \r
113         colour.setSelectedItem(string);\r
114 \r
115         String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()\r
116                                                      .getAvailableFontFamilyNames();\r
117 \r
118         for (int i = 0; i < fonts.length; i++)\r
119         {\r
120             fontNameCB.addItem(fonts[i]);\r
121         }\r
122 \r
123         for (int i = 1; i < 31; i++)\r
124         {\r
125             fontSizeCB.addItem(i + "");\r
126         }\r
127 \r
128         fontStyleCB.addItem("plain");\r
129         fontStyleCB.addItem("bold");\r
130         fontStyleCB.addItem("italic");\r
131 \r
132         fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));\r
133         fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));\r
134         fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN + "") );\r
135 \r
136         smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));\r
137 \r
138         wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));\r
139 \r
140         gapSymbolCB.addItem("-");\r
141         gapSymbolCB.addItem(".");\r
142 \r
143         gapSymbolCB.setSelectedItem( Cache.getDefault("GAP_SYMBOL", "-"));\r
144 \r
145         startupCheckbox.setSelected( Cache.getDefault("SHOW_STARTUP_FILE", true) );\r
146         startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",\r
147          "http://www.jalview.org/examples/exampleFile.jar"));\r
148 \r
149         sortby.addItem("No sort");\r
150         sortby.addItem("Id");\r
151         sortby.addItem("Pairwise Identity");\r
152         sortby.setSelectedItem( Cache.getDefault("SORT_ALIGNMENT", "No sort") );\r
153 \r
154         epsRendering.addItem("Prompt each time");\r
155         epsRendering.addItem("Lineart");\r
156         epsRendering.addItem("Text");\r
157         epsRendering.setSelectedItem( Cache.getDefault("EPS_RENDERING", "Prompt each time"));\r
158 \r
159         blcjv.setSelected( Cache.getDefault("BLC_JVSUFFIX", true) );\r
160         clustaljv.setSelected( Cache.getDefault("CLUSTAL_JVSUFFIX", true) );\r
161         fastajv.setSelected( Cache.getDefault("FASTA_JVSUFFIX", true) );\r
162         msfjv.setSelected( Cache.getDefault("MSF_JVSUFFIX", true) );\r
163         pfamjv.setSelected( Cache.getDefault("PFAM_JVSUFFIX", true) );\r
164         pileupjv.setSelected( Cache.getDefault("PILEUP_JVSUFFIX", true) );\r
165         pirjv.setSelected( Cache.getDefault("PIR_JVSUFFIX", true) );\r
166 \r
167         modellerOutput.setSelected( Cache.getDefault("PIR_MODELLER", false));\r
168 \r
169         autoCalculateConsCheck.setSelected( Cache.getDefault("AUTO_CALC_CONSENSUS", true));\r
170         padGaps.setSelected( Cache.getDefault("PAD_GAPS", false));\r
171 \r
172   /****************************************************\r
173    * Set up Connections\r
174    */\r
175         nameLinks = new Vector();\r
176         urlLinks = new Vector();\r
177         for(int i=0; i<sequenceURLLinks.size(); i++)\r
178         {\r
179           String link = sequenceURLLinks.elementAt(i).toString();\r
180           nameLinks.addElement(link.substring(0, link.indexOf("|")) );\r
181           urlLinks.addElement(link.substring(link.indexOf("|")+1));\r
182         }\r
183 \r
184         updateLinkData();\r
185 \r
186         useProxy.setSelected( Cache.getDefault("USE_PROXY", false));\r
187         proxyServerTB.setEnabled(useProxy.isSelected());\r
188         proxyPortTB.setEnabled(useProxy.isSelected());\r
189         proxyServerTB.setText( Cache.getDefault("PROXY_SERVER", ""));\r
190         proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));\r
191 \r
192         defaultBrowser.setText( Cache.getDefault("DEFAULT_BROWSER",""));\r
193     try\r
194     {\r
195       jbInit();\r
196     }\r
197     catch (Exception ex)\r
198     {\r
199       ex.printStackTrace();\r
200     }\r
201 \r
202   }\r
203 \r
204 \r
205     /**\r
206      * DOCUMENT ME!\r
207      *\r
208      * @param e DOCUMENT ME!\r
209      */\r
210     public void ok_actionPerformed(ActionEvent e)\r
211     {\r
212 \r
213       Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean.toString(seqLimit.isSelected()));\r
214       Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean.toString(fullScreen.isSelected()));\r
215 \r
216       Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean.toString(annotations.isSelected()));\r
217       Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean.toString(conservation.isSelected()));\r
218       Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean.toString(quality.isSelected()));\r
219       Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean.toString(identity.isSelected()));\r
220 \r
221       Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour.getSelectedItem().toString());\r
222       Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB.getSelectedItem().toString());\r
223 \r
224       Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB.getSelectedItem().toString());\r
225       Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB.getSelectedItem().toString());\r
226       Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB.getSelectedItem().toString());\r
227 \r
228       Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected()));\r
229 \r
230       Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean.toString(wrap.isSelected()));\r
231 \r
232       Cache.applicationProperties.setProperty("STARTUP_FILE", startupFileTextfield.getText());\r
233       Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",  Boolean.toString(startupCheckbox.isSelected()));\r
234 \r
235       Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby.getSelectedItem().toString() );\r
236 \r
237       if(epsRendering.getSelectedItem().equals("Prompt each time"))\r
238         Cache.applicationProperties.remove("EPS_RENDERING");\r
239       else\r
240         Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering.getSelectedItem().toString());\r
241 \r
242       if(defaultBrowser.getText().trim().length()<1)\r
243         Cache.applicationProperties.remove("DEFAULT_BROWSER");\r
244       else\r
245         Cache.applicationProperties.setProperty("DEFAULT_BROWSER",\r
246                                                 defaultBrowser.getText());\r
247 \r
248         jalview.util.BrowserLauncher.resetBrowser();\r
249 \r
250         if(nameLinks.size()>0)\r
251         {\r
252           StringBuffer links = new StringBuffer();\r
253           sequenceURLLinks = new Vector();\r
254           for (int i = 0; i < nameLinks.size(); i++)\r
255           {\r
256             sequenceURLLinks.addElement(nameLinks.elementAt(i)+"|"+urlLinks.elementAt(i));\r
257             links.append(sequenceURLLinks.elementAt(i).toString());\r
258             links.append("|");\r
259           }\r
260           // remove last "|"\r
261           links.setLength( links.length()-1 );\r
262           Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links.toString());\r
263         }\r
264         else\r
265           Cache.applicationProperties.remove("SEQUENCE_LINKS");\r
266 \r
267 \r
268         Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected()));\r
269 \r
270         if (proxyServerTB.getText().trim().length() < 1)\r
271           Cache.applicationProperties.remove("PROXY_SERVER");\r
272         else\r
273           Cache.applicationProperties.setProperty("PROXY_SERVER",\r
274                                                   proxyServerTB.getText());\r
275 \r
276         if (proxyPortTB.getText().trim().length() < 1)\r
277           Cache.applicationProperties.remove("PROXY_PORT");\r
278         else\r
279           Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB.getText());\r
280 \r
281         if(useProxy.isSelected())\r
282         {\r
283           System.setProperty("http.proxyHost", proxyServerTB.getText());\r
284           System.setProperty("http.proxyPort", proxyPortTB.getText());\r
285         }\r
286         else\r
287         {\r
288           System.setProperty("http.proxyHost","");\r
289           System.setProperty("http.proxyPort","");\r
290         }\r
291 \r
292 \r
293         Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean.toString(blcjv.isSelected()) );\r
294         Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean.toString(clustaljv.isSelected()) );\r
295         Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean.toString(fastajv.isSelected()) );\r
296         Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean.toString(msfjv.isSelected()) );\r
297         Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean.toString(pfamjv.isSelected()) );\r
298         Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean.toString(pileupjv.isSelected()) );\r
299         Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean.toString(pirjv.isSelected()) );\r
300         Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean.toString(modellerOutput.isSelected()) );\r
301         jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();\r
302 \r
303         Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",\r
304                                                 Boolean.toString(autoCalculateConsCheck.isSelected()));\r
305         Cache.applicationProperties.setProperty("PAD_GAPS",\r
306                                                 Boolean.toString(padGaps.isSelected()));\r
307 \r
308         dasSource.saveProperties(Cache.applicationProperties);\r
309 \r
310         Cache.saveProperties();\r
311         try\r
312         {\r
313             frame.setClosed(true);\r
314         }\r
315         catch (Exception ex)\r
316         {\r
317         }\r
318     }\r
319 \r
320     /**\r
321      * DOCUMENT ME!\r
322      */\r
323     public void startupFileTextfield_mouseClicked()\r
324     {\r
325         JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(\r
326                     "LAST_DIRECTORY"),\r
327                 new String[]\r
328                 {\r
329                     "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",\r
330                     "jar"\r
331                 },\r
332                 new String[]\r
333                 {\r
334                     "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"\r
335                 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));\r
336         chooser.setFileView(new JalviewFileView());\r
337         chooser.setDialogTitle("Select startup file");\r
338 \r
339         int value = chooser.showOpenDialog(this);\r
340 \r
341         if (value == JalviewFileChooser.APPROVE_OPTION)\r
342         {\r
343             jalview.bin.Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",\r
344                 chooser.getSelectedFormat());\r
345             startupFileTextfield.setText(chooser.getSelectedFile()\r
346                                                 .getAbsolutePath());\r
347         }\r
348     }\r
349 \r
350     /**\r
351      * DOCUMENT ME!\r
352      *\r
353      * @param e DOCUMENT ME!\r
354      */\r
355     public void cancel_actionPerformed(ActionEvent e)\r
356     {\r
357         try\r
358         {\r
359             frame.setClosed(true);\r
360         }\r
361         catch (Exception ex)\r
362         {\r
363         }\r
364     }\r
365 \r
366     /**\r
367      * DOCUMENT ME!\r
368      *\r
369      * @param e DOCUMENT ME!\r
370      */\r
371     public void annotations_actionPerformed(ActionEvent e)\r
372     {\r
373         conservation.setEnabled(annotations.isSelected());\r
374         quality.setEnabled(annotations.isSelected());\r
375         identity.setEnabled(annotations.isSelected());\r
376     }\r
377 \r
378 \r
379     public void newLink_actionPerformed(ActionEvent e) {\r
380 \r
381       GSequenceLink link = new GSequenceLink();\r
382       boolean valid = false;\r
383       while( !valid )\r
384       {\r
385         if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,\r
386                                                   "New sequence URL link",\r
387                                                   JOptionPane.OK_CANCEL_OPTION\r
388                                                   ,-1, null)\r
389             == JOptionPane.OK_OPTION)\r
390         {\r
391           if (link.checkValid())\r
392           {\r
393             nameLinks.addElement(link.getName());\r
394             urlLinks.addElement(link.getURL());\r
395             updateLinkData();\r
396             valid = true;\r
397           }\r
398         }\r
399         else\r
400           break;\r
401       }\r
402     }\r
403 \r
404     public void editLink_actionPerformed(ActionEvent e) {\r
405       GSequenceLink link = new GSequenceLink();\r
406 \r
407       int index = linkNameList.getSelectedIndex();\r
408       if(index==-1)\r
409       {\r
410         JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"\r
411             ,"No link selected", JOptionPane.WARNING_MESSAGE);\r
412         return;\r
413       }\r
414 \r
415       link.setName( nameLinks.elementAt(index).toString() );\r
416       link.setURL( urlLinks.elementAt(index).toString() );\r
417 \r
418       boolean valid = false;\r
419       while (!valid)\r
420       {\r
421 \r
422         if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,\r
423                                                   "New sequence URL link",\r
424                                                   JOptionPane.OK_CANCEL_OPTION\r
425                                                   ,-1, null)\r
426             == JOptionPane.OK_OPTION)\r
427         {\r
428           if (link.checkValid())\r
429           {\r
430             nameLinks.setElementAt(link.getName(), index);\r
431             urlLinks.setElementAt(link.getURL(), index);\r
432             updateLinkData();\r
433             valid = true;\r
434           }\r
435         }\r
436 \r
437         else\r
438           break;\r
439       }\r
440     }\r
441 \r
442     public void deleteLink_actionPerformed(ActionEvent e) {\r
443       int index = linkNameList.getSelectedIndex();\r
444       if(index==-1)\r
445       {\r
446         JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"\r
447             ,"No link selected", JOptionPane.WARNING_MESSAGE);\r
448         return;\r
449       }\r
450       nameLinks.removeElementAt(index);\r
451       urlLinks.removeElementAt(index);\r
452       updateLinkData();\r
453     }\r
454 \r
455     void updateLinkData()\r
456     {\r
457       linkNameList.setListData(nameLinks);\r
458       linkURLList.setListData(urlLinks);\r
459     }\r
460 \r
461     public void defaultBrowser_mouseClicked(MouseEvent e)\r
462     {\r
463       JFileChooser chooser = new JFileChooser(".");\r
464       chooser.setDialogTitle("Select default web browser");\r
465 \r
466       int value = chooser.showOpenDialog(this);\r
467 \r
468       if (value == JFileChooser.APPROVE_OPTION)\r
469       {\r
470         defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());\r
471       }\r
472 \r
473   }\r
474 \r
475   private void jbInit()\r
476       throws Exception\r
477   {\r
478   }\r
479 }\r