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