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