JAL-674 make temperature factor, local secondary structure and service based secondar...
[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         if (chimeraPath.getText().trim().length() > 0)
295         {
296           File f = new File(chimeraPath.getText());
297           if (!f.canExecute())
298           {
299             JOptionPane.showInternalMessageDialog(Desktop.desktop,
300                     MessageManager.getString("label.invalid_path"),
301                     MessageManager.getString("label.invalid_name"),
302                     JOptionPane.ERROR_MESSAGE);
303           }
304         }
305       }
306     });
307
308     /*
309      * Set Connections tab defaults
310      */
311     nameLinks = new Vector();
312     urlLinks = new Vector();
313     for (int i = 0; i < sequenceURLLinks.size(); i++)
314     {
315       String link = sequenceURLLinks.elementAt(i).toString();
316       nameLinks.addElement(link.substring(0, link.indexOf("|")));
317       urlLinks.addElement(link.substring(link.indexOf("|") + 1));
318     }
319
320     updateLinkData();
321
322     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
323     proxyServerTB.setEnabled(useProxy.isSelected());
324     proxyPortTB.setEnabled(useProxy.isSelected());
325     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
326     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
327
328     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
329
330     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
331     // note antisense here: default is true
332     questionnaire
333             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
334     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
335
336     /*
337      * Set Output tab defaults
338      */
339     epsRendering
340             .addItem(MessageManager.getString("label.prompt_each_time"));
341     epsRendering.addItem(MessageManager.getString("label.lineart"));
342     epsRendering.addItem(MessageManager.getString("action.text"));
343     epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
344             "Prompt each time"));
345     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
346     userIdWidth.setEnabled(autoIdWidth.isSelected());
347     userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
348     Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
349     userIdWidth.setText(wi == null ? "" : wi.toString());
350     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
351     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
352     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
353     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
354     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
355     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
356     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
357     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
358
359     /*
360      * Set Editing tab defaults
361      */
362     autoCalculateConsCheck.setSelected(Cache.getDefault(
363             "AUTO_CALC_CONSENSUS", true));
364     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
365     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
366
367     annotations_actionPerformed(null); // update the display of the annotation
368                                        // settings
369   }
370
371   /**
372    * Save user selections on the Preferences tabs to the Cache and write out to
373    * file.
374    * 
375    * @param e
376    */
377   public void ok_actionPerformed(ActionEvent e)
378   {
379     /*
380      * Save Visual settings
381      */
382     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
383             Boolean.toString(seqLimit.isSelected()));
384     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
385             Boolean.toString(rightAlign.isSelected()));
386     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
387             Boolean.toString(fullScreen.isSelected()));
388     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
389             Boolean.toString(openoverv.isSelected()));
390     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
391             Boolean.toString(annotations.isSelected()));
392     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
393             Boolean.toString(conservation.isSelected()));
394     Cache.applicationProperties.setProperty("SHOW_QUALITY",
395             Boolean.toString(quality.isSelected()));
396     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
397             Boolean.toString(identity.isSelected()));
398
399     Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
400             .getSelectedItem().toString());
401
402     Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
403             .getSelectedItem().toString());
404     Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
405             .getSelectedItem().toString());
406     Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
407             .getSelectedItem().toString());
408
409     Cache.applicationProperties.setProperty("ID_ITALICS",
410             Boolean.toString(idItalics.isSelected()));
411     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
412             Boolean.toString(showUnconserved.isSelected()));
413     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
414             Boolean.toString(showGroupConsensus.isSelected()));
415     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
416             Boolean.toString(showGroupConservation.isSelected()));
417     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
418             Boolean.toString(showConsensHistogram.isSelected()));
419     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
420             Boolean.toString(showConsensLogo.isSelected()));
421     Cache.applicationProperties.setProperty("ANTI_ALIAS",
422             Boolean.toString(smoothFont.isSelected()));
423     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
424             Boolean.toString(showNpTooltip.isSelected()));
425     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
426             Boolean.toString(showDbRefTooltip.isSelected()));
427
428     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
429             Boolean.toString(wrap.isSelected()));
430
431     Cache.applicationProperties.setProperty("STARTUP_FILE",
432             startupFileTextfield.getText());
433     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
434             Boolean.toString(startupCheckbox.isSelected()));
435
436     Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
437             .getSelectedItem().toString());
438
439     // convert description of sort order to enum name for save
440     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
441             .forDescription(sortAnnBy.getSelectedItem().toString());
442     if (annSortOrder != null)
443     {
444       Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
445               annSortOrder.name());
446     }
447
448     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
449     Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
450             Boolean.valueOf(showAutocalcFirst).toString());
451
452     /*
453      * Save Colours settings
454      */
455     Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
456             .getSelectedItem().toString());
457     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
458             minColour.getBackground());
459     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
460             maxColour.getBackground());
461
462     /*
463      * Save Structure settings
464      */
465     Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
466             Boolean.toString(addTempFactor.isSelected()));
467     Cache.applicationProperties.setProperty(ADD_SS_ANN,
468             Boolean.toString(addSecondaryStructure.isSelected()));
469     Cache.applicationProperties.setProperty(USE_RNAVIEW,
470             Boolean.toString(useRnaView.isSelected()));
471     Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
472             Boolean.toString(structFromPdb.isSelected()));
473     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
474             .getSelectedItem().toString());
475     Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
476
477     /*
478      * Save Output settings
479      */
480     if (epsRendering.getSelectedItem().equals("Prompt each time"))
481     {
482       Cache.applicationProperties.remove("EPS_RENDERING");
483     }
484     else
485     {
486       Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
487               .getSelectedItem().toString());
488     }
489
490     /*
491      * Save Connections settings
492      */
493     Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
494
495     jalview.util.BrowserLauncher.resetBrowser();
496
497     if (nameLinks.size() > 0)
498     {
499       StringBuffer links = new StringBuffer();
500       sequenceURLLinks = new Vector();
501       for (int i = 0; i < nameLinks.size(); i++)
502       {
503         sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
504                 + urlLinks.elementAt(i));
505         links.append(sequenceURLLinks.elementAt(i).toString());
506         links.append("|");
507       }
508       // remove last "|"
509       links.setLength(links.length() - 1);
510       Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
511               links.toString());
512     }
513     else
514     {
515       Cache.applicationProperties.remove("SEQUENCE_LINKS");
516     }
517
518     Cache.applicationProperties.setProperty("USE_PROXY",
519             Boolean.toString(useProxy.isSelected()));
520
521     Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
522
523     Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
524
525     if (useProxy.isSelected())
526     {
527       System.setProperty("http.proxyHost", proxyServerTB.getText());
528       System.setProperty("http.proxyPort", proxyPortTB.getText());
529     }
530     else
531     {
532       System.setProperty("http.proxyHost", "");
533       System.setProperty("http.proxyPort", "");
534     }
535     Cache.setProperty("VERSION_CHECK",
536             Boolean.toString(versioncheck.isSelected()));
537     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
538     {
539       // default is false - we only set this if the user has actively agreed
540       Cache.setProperty("USAGESTATS",
541               Boolean.toString(usagestats.isSelected()));
542     }
543     if (!questionnaire.isSelected())
544     {
545       Cache.setProperty("NOQUESTIONNAIRES", "true");
546     }
547     else
548     {
549       // special - made easy to edit a property file to disable questionnaires
550       // by just adding the given line
551       Cache.removeProperty("NOQUESTIONNAIRES");
552     }
553
554     /*
555      * Save Output settings
556      */
557     Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
558             Boolean.toString(blcjv.isSelected()));
559     Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
560             Boolean.toString(clustaljv.isSelected()));
561     Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
562             Boolean.toString(fastajv.isSelected()));
563     Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
564             Boolean.toString(msfjv.isSelected()));
565     Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
566             Boolean.toString(pfamjv.isSelected()));
567     Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
568             Boolean.toString(pileupjv.isSelected()));
569     Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
570             Boolean.toString(pirjv.isSelected()));
571     Cache.applicationProperties.setProperty("PIR_MODELLER",
572             Boolean.toString(modellerOutput.isSelected()));
573     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
574
575     Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
576             Boolean.toString(autoIdWidth.isSelected()));
577     userIdWidth_actionPerformed();
578     Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
579             userIdWidth.getText());
580
581     /*
582      * Save Editing settings
583      */
584     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
585             Boolean.toString(autoCalculateConsCheck.isSelected()));
586     Cache.applicationProperties.setProperty("SORT_BY_TREE",
587             Boolean.toString(sortByTree.isSelected()));
588     Cache.applicationProperties.setProperty("PAD_GAPS",
589             Boolean.toString(padGaps.isSelected()));
590
591     dasSource.saveProperties(Cache.applicationProperties);
592     wsPrefs.updateAndRefreshWsMenuConfig(false);
593     Cache.saveProperties();
594     Desktop.instance.doConfigureStructurePrefs();
595     try
596     {
597       frame.setClosed(true);
598     } catch (Exception ex)
599     {
600     }
601   }
602
603   /**
604    * DOCUMENT ME!
605    */
606   public void startupFileTextfield_mouseClicked()
607   {
608     JalviewFileChooser chooser = new JalviewFileChooser(
609             jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
610             new String[]
611             { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
612             new String[]
613             { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
614             jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
615     chooser.setFileView(new JalviewFileView());
616     chooser.setDialogTitle(MessageManager.getString("label.select_startup_file"));
617
618     int value = chooser.showOpenDialog(this);
619
620     if (value == JalviewFileChooser.APPROVE_OPTION)
621     {
622       jalview.bin.Cache.applicationProperties.setProperty(
623               "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
624       startupFileTextfield.setText(chooser.getSelectedFile()
625               .getAbsolutePath());
626     }
627   }
628
629   /**
630    * DOCUMENT ME!
631    * 
632    * @param e
633    *          DOCUMENT ME!
634    */
635   public void cancel_actionPerformed(ActionEvent e)
636   {
637     try
638     {
639       wsPrefs.updateWsMenuConfig(true);
640       wsPrefs.refreshWs_actionPerformed(e);
641       frame.setClosed(true);
642     } catch (Exception ex)
643     {
644     }
645   }
646
647   /**
648    * DOCUMENT ME!
649    * 
650    * @param e
651    *          DOCUMENT ME!
652    */
653   public void annotations_actionPerformed(ActionEvent e)
654   {
655     conservation.setEnabled(annotations.isSelected());
656     quality.setEnabled(annotations.isSelected());
657     identity.setEnabled(annotations.isSelected());
658     showGroupConsensus.setEnabled(annotations.isSelected());
659     showGroupConservation.setEnabled(annotations.isSelected());
660     showConsensHistogram.setEnabled(annotations.isSelected()
661             && (identity.isSelected() || showGroupConsensus.isSelected()));
662     showConsensLogo.setEnabled(annotations.isSelected()
663             && (identity.isSelected() || showGroupConsensus.isSelected()));
664   }
665
666   public void newLink_actionPerformed(ActionEvent e)
667   {
668
669     GSequenceLink link = new GSequenceLink();
670     boolean valid = false;
671     while (!valid)
672     {
673       if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
674               MessageManager.getString("label.new_sequence_url_link"),
675               JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
676       {
677         if (link.checkValid())
678         {
679           nameLinks.addElement(link.getName());
680           urlLinks.addElement(link.getURL());
681           updateLinkData();
682           valid = true;
683         }
684       }
685       else
686       {
687         break;
688       }
689     }
690   }
691
692   public void editLink_actionPerformed(ActionEvent e)
693   {
694     GSequenceLink link = new GSequenceLink();
695
696     int index = linkNameList.getSelectedIndex();
697     if (index == -1)
698     {
699       JOptionPane.showInternalMessageDialog(Desktop.desktop,
700               MessageManager.getString("label.no_link_selected"),
701               MessageManager.getString("label.no_link_selected"),
702               JOptionPane.WARNING_MESSAGE);
703       return;
704     }
705
706     link.setName(nameLinks.elementAt(index).toString());
707     link.setURL(urlLinks.elementAt(index).toString());
708
709     boolean valid = false;
710     while (!valid)
711     {
712
713       if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
714               MessageManager.getString("label.new_sequence_url_link"),
715               JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
716       {
717         if (link.checkValid())
718         {
719           nameLinks.setElementAt(link.getName(), index);
720           urlLinks.setElementAt(link.getURL(), index);
721           updateLinkData();
722           valid = true;
723         }
724       }
725
726       else
727       {
728         break;
729       }
730     }
731   }
732
733   public void deleteLink_actionPerformed(ActionEvent e)
734   {
735     int index = linkNameList.getSelectedIndex();
736     if (index == -1)
737     {
738       JOptionPane.showInternalMessageDialog(Desktop.desktop,
739               MessageManager.getString("label.no_link_selected"),
740               MessageManager.getString("label.no_link_selected"),
741               JOptionPane.WARNING_MESSAGE);
742       return;
743     }
744     nameLinks.removeElementAt(index);
745     urlLinks.removeElementAt(index);
746     updateLinkData();
747   }
748
749   void updateLinkData()
750   {
751     linkNameList.setListData(nameLinks);
752     linkURLList.setListData(urlLinks);
753   }
754
755   public void defaultBrowser_mouseClicked(MouseEvent e)
756   {
757     JFileChooser chooser = new JFileChooser(".");
758     chooser.setDialogTitle(MessageManager.getString("label.select_default_browser"));
759
760     int value = chooser.showOpenDialog(this);
761
762     if (value == JFileChooser.APPROVE_OPTION)
763     {
764       defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
765     }
766
767   }
768
769   /*
770    * (non-Javadoc)
771    * 
772    * @see
773    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
774    * .ActionEvent)
775    */
776   protected void showunconserved_actionPerformed(ActionEvent e)
777   {
778     // TODO Auto-generated method stub
779     super.showunconserved_actionPerformed(e);
780   }
781
782   public static Collection getGroupURLLinks()
783   {
784     return groupURLLinks;
785   }
786
787   @Override
788   public void minColour_actionPerformed(JPanel panel)
789   {
790     Color col = JColorChooser.showDialog(this,
791             MessageManager.getString("label.select_colour_minimum_value"), minColour.getBackground());
792     if (col != null)
793     {
794       panel.setBackground(col);
795     }
796     panel.repaint();
797   }
798
799   @Override
800   public void maxColour_actionPerformed(JPanel panel)
801   {
802     Color col = JColorChooser.showDialog(this,
803             MessageManager.getString("label.select_colour_maximum_value"), maxColour.getBackground());
804     if (col != null)
805     {
806       panel.setBackground(col);
807     }
808     panel.repaint();
809   }
810
811   @Override
812   protected void userIdWidth_actionPerformed()
813   {
814     try
815     {
816       String val = userIdWidth.getText().trim();
817       if (val.length() > 0)
818       {
819         Integer iw = Integer.parseInt(val);
820         if (iw.intValue() < 12)
821         {
822           throw new NumberFormatException();
823         }
824         userIdWidth.setText(iw.toString());
825       }
826     } catch (NumberFormatException x)
827     {
828       JOptionPane
829               .showInternalMessageDialog(
830                       Desktop.desktop,
831                       MessageManager.getString("warn.user_defined_width_requirements"),
832                       MessageManager.getString("label.invalid_id_column_width"),
833                       JOptionPane.WARNING_MESSAGE);
834       userIdWidth.setText("");
835     }
836   }
837
838   @Override
839   protected void autoIdWidth_actionPerformed()
840   {
841     userIdWidth.setEnabled(!autoIdWidth.isSelected());
842     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
843   }
844
845 }