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