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