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