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