2e8aa890d0b3cb19e451c27f1f646a80e600a93b
[jalview.git] / src / jalview / gui / Preferences.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.bin.Cache;
25 import jalview.gui.StructureViewer.Viewer;
26 import jalview.io.JalviewFileChooser;
27 import jalview.io.JalviewFileView;
28 import jalview.jbgui.GPreferences;
29 import jalview.jbgui.GSequenceLink;
30 import jalview.schemes.ColourSchemeProperty;
31 import jalview.util.MessageManager;
32
33 import java.awt.BorderLayout;
34 import java.awt.Color;
35 import java.awt.Dimension;
36 import java.awt.Font;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.MouseEvent;
39 import java.util.Collection;
40 import java.util.StringTokenizer;
41 import java.util.Vector;
42
43 import javax.swing.JColorChooser;
44 import javax.swing.JFileChooser;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JOptionPane;
47 import javax.swing.JPanel;
48
49 /**
50  * DOCUMENT ME!
51  * 
52  * @author $author$
53  * @version $Revision$
54  */
55 public class Preferences extends GPreferences
56 {
57
58   public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
59
60   public static final String ADD_SS_ANN = "ADD_SS_ANN";
61
62   public static final String USE_RNAVIEW = "USE_RNAVIEW";
63
64   public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
65
66   public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
67
68   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
69
70   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
71
72   private static final int MIN_FONT_SIZE = 1;
73
74   private static final int MAX_FONT_SIZE = 30;
75
76   /**
77    * Holds name and link separated with | character. Sequence ID must be
78    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
79    */
80   public static Vector sequenceURLLinks;
81
82   /**
83    * Holds name and link separated with | character. Sequence IDS and Sequences
84    * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
85    * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
86    * for first and second token specified after a pipe character at end |,|.
87    * (TODO: proper escape for using | to separate ids or sequences
88    */
89
90   public static Vector groupURLLinks;
91   static
92   {
93     String string = Cache
94             .getDefault(
95                     "SEQUENCE_LINKS",
96                     "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
97     sequenceURLLinks = new Vector();
98
99     try
100     {
101       StringTokenizer st = new StringTokenizer(string, "|");
102       while (st.hasMoreElements())
103       {
104         String name = st.nextToken();
105         String url = st.nextToken();
106         // check for '|' within a regex
107         int rxstart = url.indexOf("$SEQUENCE_ID$");
108         while (rxstart == -1 && url.indexOf("/=$") == -1)
109         {
110           url = url + "|" + st.nextToken();
111         }
112         sequenceURLLinks.addElement(name + "|" + url);
113       }
114     } catch (Exception ex)
115     {
116       System.out.println(ex + "\nError parsing sequence links");
117     }
118     {
119       // upgrade old SRS link
120       int srsPos = sequenceURLLinks
121               .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
122       if (srsPos > -1)
123       {
124         sequenceURLLinks
125                 .setElementAt(
126                         "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
127                         srsPos);
128       }
129     }
130
131     /**
132      * TODO: reformulate groupURL encoding so two or more can be stored in the
133      * .properties file as '|' separated strings
134      */
135
136     groupURLLinks = new Vector();
137   }
138
139   Vector nameLinks, urlLinks;
140
141   JInternalFrame frame;
142
143   DasSourceBrowser dasSource;
144
145   private WsPreferences wsPrefs;
146
147   /**
148    * Creates a new Preferences object.
149    */
150   public Preferences()
151   {
152     super();
153     frame = new JInternalFrame();
154     frame.setContentPane(this);
155     dasSource = new DasSourceBrowser();
156     dasTab.add(dasSource, BorderLayout.CENTER);
157     wsPrefs = new WsPreferences();
158     wsTab.add(wsPrefs, BorderLayout.CENTER);
159     int width = 500, height = 420;
160     if (new jalview.util.Platform().isAMac())
161     {
162       width = 570;
163       height = 460;
164     }
165
166     Desktop.addInternalFrame(frame,
167             MessageManager.getString("label.preferences"), width, height);
168     frame.setMinimumSize(new Dimension(width, height));
169
170     /*
171      * Set Visual tab defaults
172      */
173     seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
174     rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
175     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
176     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
177
178     conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
179     quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
180     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
181     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
182     showUnconserved
183             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
184     showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
185             false));
186     showGroupConservation.setSelected(Cache.getDefault(
187             "SHOW_GROUP_CONSERVATION", false));
188     showConsensHistogram.setSelected(Cache.getDefault(
189             "SHOW_CONSENSUS_HISTOGRAM", true));
190     showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
191             false));
192     showNpTooltip.setSelected(Cache
193             .getDefault("SHOW_NPFEATS_TOOLTIP", true));
194     showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
195             true));
196
197     String[] fonts = java.awt.GraphicsEnvironment
198             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
199     for (int i = 0; i < fonts.length; i++)
200     {
201       fontNameCB.addItem(fonts[i]);
202     }
203
204     for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
205     {
206       fontSizeCB.addItem(i + "");
207     }
208
209     fontStyleCB.addItem("plain");
210     fontStyleCB.addItem("bold");
211     fontStyleCB.addItem("italic");
212
213     fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
214     fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
215     fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
216             + ""));
217
218     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
219
220     idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
221
222     wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
223
224     gapSymbolCB.addItem("-");
225     gapSymbolCB.addItem(".");
226
227     gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
228
229     sortby.addItem("No sort");
230     sortby.addItem("Id");
231     sortby.addItem("Pairwise Identity");
232     sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
233
234     sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
235     sortAnnBy
236             .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
237     sortAnnBy
238             .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
239     SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
240             .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
241                     SequenceAnnotationOrder.NONE.name()));
242     sortAnnBy.setSelectedItem(savedSort.toString());
243
244     sortAutocalc.addItem("Autocalculated first");
245     sortAutocalc.addItem("Autocalculated last");
246     final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE,
247             true);
248     sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
249             : sortAutocalc.getItemAt(1));
250     startupCheckbox
251             .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
252     startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
253             Cache.getDefault("www.jalview.org", "http://www.jalview.org")
254                     + "/examples/exampleFile_2_3.jar"));
255
256     /*
257      * Set Colours tab defaults
258      */
259     for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
260     {
261       colour.addItem(ColourSchemeProperty.getColourName(i));
262     }
263     String string = Cache.getDefault("DEFAULT_COLOUR", "None");
264     colour.setSelectedItem(string);
265     minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
266             Color.orange));
267     maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
268             Color.red));
269
270     /*
271      * Set Structure tab defaults.
272      */
273     final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
274     structFromPdb.setSelected(structSelected);
275     useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
276     useRnaView.setEnabled(structSelected);
277     addSecondaryStructure
278             .setSelected(Cache.getDefault(ADD_SS_ANN, false));
279     addSecondaryStructure.setEnabled(structSelected);
280     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
281     addTempFactor.setEnabled(structSelected);
282     structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
283             Viewer.JMOL.name()));
284
285     /*
286      * Set Connections tab defaults
287      */
288     nameLinks = new Vector();
289     urlLinks = new Vector();
290     for (int i = 0; i < sequenceURLLinks.size(); i++)
291     {
292       String link = sequenceURLLinks.elementAt(i).toString();
293       nameLinks.addElement(link.substring(0, link.indexOf("|")));
294       urlLinks.addElement(link.substring(link.indexOf("|") + 1));
295     }
296
297     updateLinkData();
298
299     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
300     proxyServerTB.setEnabled(useProxy.isSelected());
301     proxyPortTB.setEnabled(useProxy.isSelected());
302     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
303     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
304
305     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
306
307     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
308     // note antisense here: default is true
309     questionnaire
310             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
311     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
312
313     /*
314      * Set Output tab defaults
315      */
316     epsRendering
317             .addItem(MessageManager.getString("label.prompt_each_time"));
318     epsRendering.addItem(MessageManager.getString("label.lineart"));
319     epsRendering.addItem(MessageManager.getString("action.text"));
320     epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
321             "Prompt each time"));
322     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
323     userIdWidth.setEnabled(autoIdWidth.isSelected());
324     userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
325     Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
326     userIdWidth.setText(wi == null ? "" : wi.toString());
327     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
328     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
329     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
330     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
331     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
332     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
333     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
334     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
335
336     /*
337      * Set Editing tab defaults
338      */
339     autoCalculateConsCheck.setSelected(Cache.getDefault(
340             "AUTO_CALC_CONSENSUS", true));
341     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
342     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
343
344     annotations_actionPerformed(null); // update the display of the annotation
345                                        // settings
346   }
347
348   /**
349    * Save user selections on the Preferences tabs to the Cache and write out to
350    * file.
351    * 
352    * @param e
353    */
354   public void ok_actionPerformed(ActionEvent e)
355   {
356     /*
357      * Save Visual settings
358      */
359     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
360             Boolean.toString(seqLimit.isSelected()));
361     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
362             Boolean.toString(rightAlign.isSelected()));
363     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
364             Boolean.toString(fullScreen.isSelected()));
365     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
366             Boolean.toString(openoverv.isSelected()));
367     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
368             Boolean.toString(annotations.isSelected()));
369     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
370             Boolean.toString(conservation.isSelected()));
371     Cache.applicationProperties.setProperty("SHOW_QUALITY",
372             Boolean.toString(quality.isSelected()));
373     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
374             Boolean.toString(identity.isSelected()));
375
376     Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
377             .getSelectedItem().toString());
378
379     Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
380             .getSelectedItem().toString());
381     Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
382             .getSelectedItem().toString());
383     Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
384             .getSelectedItem().toString());
385
386     Cache.applicationProperties.setProperty("ID_ITALICS",
387             Boolean.toString(idItalics.isSelected()));
388     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
389             Boolean.toString(showUnconserved.isSelected()));
390     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
391             Boolean.toString(showGroupConsensus.isSelected()));
392     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
393             Boolean.toString(showGroupConservation.isSelected()));
394     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
395             Boolean.toString(showConsensHistogram.isSelected()));
396     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
397             Boolean.toString(showConsensLogo.isSelected()));
398     Cache.applicationProperties.setProperty("ANTI_ALIAS",
399             Boolean.toString(smoothFont.isSelected()));
400     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
401             Boolean.toString(showNpTooltip.isSelected()));
402     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
403             Boolean.toString(showDbRefTooltip.isSelected()));
404
405     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
406             Boolean.toString(wrap.isSelected()));
407
408     Cache.applicationProperties.setProperty("STARTUP_FILE",
409             startupFileTextfield.getText());
410     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
411             Boolean.toString(startupCheckbox.isSelected()));
412
413     Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
414             .getSelectedItem().toString());
415
416     // convert description of sort order to enum name for save
417     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
418             .forDescription(sortAnnBy.getSelectedItem().toString());
419     if (annSortOrder != null)
420     {
421       Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
422               annSortOrder.name());
423     }
424
425     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
426     Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
427             Boolean.valueOf(showAutocalcFirst).toString());
428
429     /*
430      * Save Colours settings
431      */
432     Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
433             .getSelectedItem().toString());
434     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
435             minColour.getBackground());
436     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
437             maxColour.getBackground());
438
439     /*
440      * Save Structure settings
441      */
442     Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
443             Boolean.toString(addTempFactor.isSelected()));
444     Cache.applicationProperties.setProperty(ADD_SS_ANN,
445             Boolean.toString(addSecondaryStructure.isSelected()));
446     Cache.applicationProperties.setProperty(USE_RNAVIEW,
447             Boolean.toString(useRnaView.isSelected()));
448     Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
449             Boolean.toString(structFromPdb.isSelected()));
450     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
451             .getSelectedItem().toString());
452
453     /*
454      * Save Output settings
455      */
456     if (epsRendering.getSelectedItem().equals("Prompt each time"))
457     {
458       Cache.applicationProperties.remove("EPS_RENDERING");
459     }
460     else
461     {
462       Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
463               .getSelectedItem().toString());
464     }
465
466     /*
467      * Save Connections settings
468      */
469     if (defaultBrowser.getText().trim().length() < 1)
470     {
471       Cache.applicationProperties.remove("DEFAULT_BROWSER");
472     }
473     else
474     {
475       Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
476               defaultBrowser.getText());
477     }
478
479     jalview.util.BrowserLauncher.resetBrowser();
480
481     if (nameLinks.size() > 0)
482     {
483       StringBuffer links = new StringBuffer();
484       sequenceURLLinks = new Vector();
485       for (int i = 0; i < nameLinks.size(); i++)
486       {
487         sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
488                 + urlLinks.elementAt(i));
489         links.append(sequenceURLLinks.elementAt(i).toString());
490         links.append("|");
491       }
492       // remove last "|"
493       links.setLength(links.length() - 1);
494       Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
495               links.toString());
496     }
497     else
498     {
499       Cache.applicationProperties.remove("SEQUENCE_LINKS");
500     }
501
502     Cache.applicationProperties.setProperty("USE_PROXY",
503             Boolean.toString(useProxy.isSelected()));
504
505     if (proxyServerTB.getText().trim().length() < 1)
506     {
507       Cache.applicationProperties.remove("PROXY_SERVER");
508     }
509     else
510     {
511       Cache.applicationProperties.setProperty("PROXY_SERVER",
512               proxyServerTB.getText());
513     }
514
515     if (proxyPortTB.getText().trim().length() < 1)
516     {
517       Cache.applicationProperties.remove("PROXY_PORT");
518     }
519     else
520     {
521       Cache.applicationProperties.setProperty("PROXY_PORT",
522               proxyPortTB.getText());
523     }
524
525     if (useProxy.isSelected())
526     {
527       System.setProperty("http.proxyHost", proxyServerTB.getText());
528       System.setProperty("http.proxyPort", proxyPortTB.getText());
529     }
530     else
531     {
532       System.setProperty("http.proxyHost", "");
533       System.setProperty("http.proxyPort", "");
534     }
535     Cache.setProperty("VERSION_CHECK",
536             Boolean.toString(versioncheck.isSelected()));
537     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
538     {
539       // default is false - we only set this if the user has actively agreed
540       Cache.setProperty("USAGESTATS",
541               Boolean.toString(usagestats.isSelected()));
542     }
543     if (!questionnaire.isSelected())
544     {
545       Cache.setProperty("NOQUESTIONNAIRES", "true");
546     }
547     else
548     {
549       // special - made easy to edit a property file to disable questionnaires
550       // by just adding the given line
551       Cache.removeProperty("NOQUESTIONNAIRES");
552     }
553
554     /*
555      * Save Output settings
556      */
557     Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
558             Boolean.toString(blcjv.isSelected()));
559     Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
560             Boolean.toString(clustaljv.isSelected()));
561     Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
562             Boolean.toString(fastajv.isSelected()));
563     Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
564             Boolean.toString(msfjv.isSelected()));
565     Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
566             Boolean.toString(pfamjv.isSelected()));
567     Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
568             Boolean.toString(pileupjv.isSelected()));
569     Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
570             Boolean.toString(pirjv.isSelected()));
571     Cache.applicationProperties.setProperty("PIR_MODELLER",
572             Boolean.toString(modellerOutput.isSelected()));
573     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
574
575     Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
576             Boolean.toString(autoIdWidth.isSelected()));
577     userIdWidth_actionPerformed();
578     Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
579             userIdWidth.getText());
580
581     /*
582      * Save Editing settings
583      */
584     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
585             Boolean.toString(autoCalculateConsCheck.isSelected()));
586     Cache.applicationProperties.setProperty("SORT_BY_TREE",
587             Boolean.toString(sortByTree.isSelected()));
588     Cache.applicationProperties.setProperty("PAD_GAPS",
589             Boolean.toString(padGaps.isSelected()));
590
591     dasSource.saveProperties(Cache.applicationProperties);
592     wsPrefs.updateAndRefreshWsMenuConfig(false);
593
594     Cache.saveProperties();
595
596     try
597     {
598       frame.setClosed(true);
599     } catch (Exception ex)
600     {
601     }
602   }
603
604   /**
605    * DOCUMENT ME!
606    */
607   public void startupFileTextfield_mouseClicked()
608   {
609     JalviewFileChooser chooser = new JalviewFileChooser(
610             jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
611             new String[]
612             { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
613             new String[]
614             { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
615             jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
616     chooser.setFileView(new JalviewFileView());
617     chooser.setDialogTitle(MessageManager.getString("label.select_startup_file"));
618
619     int value = chooser.showOpenDialog(this);
620
621     if (value == JalviewFileChooser.APPROVE_OPTION)
622     {
623       jalview.bin.Cache.applicationProperties.setProperty(
624               "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
625       startupFileTextfield.setText(chooser.getSelectedFile()
626               .getAbsolutePath());
627     }
628   }
629
630   /**
631    * DOCUMENT ME!
632    * 
633    * @param e
634    *          DOCUMENT ME!
635    */
636   public void cancel_actionPerformed(ActionEvent e)
637   {
638     try
639     {
640       wsPrefs.updateWsMenuConfig(true);
641       wsPrefs.refreshWs_actionPerformed(e);
642       frame.setClosed(true);
643     } catch (Exception ex)
644     {
645     }
646   }
647
648   /**
649    * DOCUMENT ME!
650    * 
651    * @param e
652    *          DOCUMENT ME!
653    */
654   public void annotations_actionPerformed(ActionEvent e)
655   {
656     conservation.setEnabled(annotations.isSelected());
657     quality.setEnabled(annotations.isSelected());
658     identity.setEnabled(annotations.isSelected());
659     showGroupConsensus.setEnabled(annotations.isSelected());
660     showGroupConservation.setEnabled(annotations.isSelected());
661     showConsensHistogram.setEnabled(annotations.isSelected()
662             && (identity.isSelected() || showGroupConsensus.isSelected()));
663     showConsensLogo.setEnabled(annotations.isSelected()
664             && (identity.isSelected() || showGroupConsensus.isSelected()));
665   }
666
667   public void newLink_actionPerformed(ActionEvent e)
668   {
669
670     GSequenceLink link = new GSequenceLink();
671     boolean valid = false;
672     while (!valid)
673     {
674       if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
675               MessageManager.getString("label.new_sequence_url_link"),
676               JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
677       {
678         if (link.checkValid())
679         {
680           nameLinks.addElement(link.getName());
681           urlLinks.addElement(link.getURL());
682           updateLinkData();
683           valid = true;
684         }
685       }
686       else
687       {
688         break;
689       }
690     }
691   }
692
693   public void editLink_actionPerformed(ActionEvent e)
694   {
695     GSequenceLink link = new GSequenceLink();
696
697     int index = linkNameList.getSelectedIndex();
698     if (index == -1)
699     {
700       JOptionPane.showInternalMessageDialog(Desktop.desktop,
701               MessageManager.getString("label.no_link_selected"),
702               MessageManager.getString("label.no_link_selected"),
703               JOptionPane.WARNING_MESSAGE);
704       return;
705     }
706
707     link.setName(nameLinks.elementAt(index).toString());
708     link.setURL(urlLinks.elementAt(index).toString());
709
710     boolean valid = false;
711     while (!valid)
712     {
713
714       if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
715               MessageManager.getString("label.new_sequence_url_link"),
716               JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
717       {
718         if (link.checkValid())
719         {
720           nameLinks.setElementAt(link.getName(), index);
721           urlLinks.setElementAt(link.getURL(), index);
722           updateLinkData();
723           valid = true;
724         }
725       }
726
727       else
728       {
729         break;
730       }
731     }
732   }
733
734   public void deleteLink_actionPerformed(ActionEvent e)
735   {
736     int index = linkNameList.getSelectedIndex();
737     if (index == -1)
738     {
739       JOptionPane.showInternalMessageDialog(Desktop.desktop,
740               MessageManager.getString("label.no_link_selected"),
741               MessageManager.getString("label.no_link_selected"),
742               JOptionPane.WARNING_MESSAGE);
743       return;
744     }
745     nameLinks.removeElementAt(index);
746     urlLinks.removeElementAt(index);
747     updateLinkData();
748   }
749
750   void updateLinkData()
751   {
752     linkNameList.setListData(nameLinks);
753     linkURLList.setListData(urlLinks);
754   }
755
756   public void defaultBrowser_mouseClicked(MouseEvent e)
757   {
758     JFileChooser chooser = new JFileChooser(".");
759     chooser.setDialogTitle(MessageManager.getString("label.select_default_browser"));
760
761     int value = chooser.showOpenDialog(this);
762
763     if (value == JFileChooser.APPROVE_OPTION)
764     {
765       defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
766     }
767
768   }
769
770   /*
771    * (non-Javadoc)
772    * 
773    * @see
774    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
775    * .ActionEvent)
776    */
777   protected void showunconserved_actionPerformed(ActionEvent e)
778   {
779     // TODO Auto-generated method stub
780     super.showunconserved_actionPerformed(e);
781   }
782
783   public static Collection getGroupURLLinks()
784   {
785     return groupURLLinks;
786   }
787
788   @Override
789   public void minColour_actionPerformed(JPanel panel)
790   {
791     Color col = JColorChooser.showDialog(this,
792             MessageManager.getString("label.select_colour_minimum_value"), minColour.getBackground());
793     if (col != null)
794     {
795       panel.setBackground(col);
796     }
797     panel.repaint();
798   }
799
800   @Override
801   public void maxColour_actionPerformed(JPanel panel)
802   {
803     Color col = JColorChooser.showDialog(this,
804             MessageManager.getString("label.select_colour_maximum_value"), maxColour.getBackground());
805     if (col != null)
806     {
807       panel.setBackground(col);
808     }
809     panel.repaint();
810   }
811
812   @Override
813   protected void userIdWidth_actionPerformed()
814   {
815     try
816     {
817       String val = userIdWidth.getText().trim();
818       if (val.length() > 0)
819       {
820         Integer iw = Integer.parseInt(val);
821         if (iw.intValue() < 12)
822         {
823           throw new NumberFormatException();
824         }
825         userIdWidth.setText(iw.toString());
826       }
827     } catch (NumberFormatException x)
828     {
829       JOptionPane
830               .showInternalMessageDialog(
831                       Desktop.desktop,
832                       MessageManager.getString("warn.user_defined_width_requirements"),
833                       MessageManager.getString("label.invalid_id_column_width"),
834                       JOptionPane.WARNING_MESSAGE);
835       userIdWidth.setText("");
836     }
837   }
838
839   @Override
840   protected void autoIdWidth_actionPerformed()
841   {
842     userIdWidth.setEnabled(!autoIdWidth.isSelected());
843     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
844   }
845
846 }