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