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