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