JAL-3013 resolve symlink to hmmer binaries folder
[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.hmmer.HmmerCommand;
28 import jalview.io.FileFormatI;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.jbgui.GPreferences;
32 import jalview.jbgui.GSequenceLink;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ColourSchemes;
35 import jalview.schemes.ResidueColourScheme;
36 import jalview.urls.UrlLinkTableModel;
37 import jalview.urls.api.UrlProviderFactoryI;
38 import jalview.urls.api.UrlProviderI;
39 import jalview.urls.desktop.DesktopUrlProviderFactory;
40 import jalview.util.FileUtils;
41 import jalview.util.MessageManager;
42 import jalview.util.Platform;
43 import jalview.util.UrlConstants;
44 import jalview.ws.sifts.SiftsSettings;
45
46 import java.awt.BorderLayout;
47 import java.awt.Color;
48 import java.awt.Component;
49 import java.awt.Dimension;
50 import java.awt.Font;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ActionListener;
53 import java.awt.event.FocusAdapter;
54 import java.awt.event.FocusEvent;
55 import java.awt.event.MouseEvent;
56 import java.io.File;
57 import java.util.ArrayList;
58 import java.util.List;
59
60 import javax.help.HelpSetException;
61 import javax.swing.JColorChooser;
62 import javax.swing.JFileChooser;
63 import javax.swing.JInternalFrame;
64 import javax.swing.JPanel;
65 import javax.swing.JTextField;
66 import javax.swing.ListSelectionModel;
67 import javax.swing.RowFilter;
68 import javax.swing.RowSorter;
69 import javax.swing.SortOrder;
70 import javax.swing.event.DocumentEvent;
71 import javax.swing.event.DocumentListener;
72 import javax.swing.event.ListSelectionEvent;
73 import javax.swing.event.ListSelectionListener;
74 import javax.swing.table.TableCellRenderer;
75 import javax.swing.table.TableColumn;
76 import javax.swing.table.TableModel;
77 import javax.swing.table.TableRowSorter;
78
79 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
80
81 /**
82  * DOCUMENT ME!
83  * 
84  * @author $author$
85  * @version $Revision$
86  */
87 public class Preferences extends GPreferences
88 {
89   // suggested list delimiter character
90   public static final String COMMA = ",";
91
92   public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT";
93
94   public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND";
95
96   public static final String HMMALIGN_TRIM_TERMINI = "HMMALIGN_TRIM_TERMINI";
97
98   public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
99
100   public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
101
102   public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
103
104   public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
105
106   public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
107
108   public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
109
110   public static final String ADD_SS_ANN = "ADD_SS_ANN";
111
112   public static final String USE_RNAVIEW = "USE_RNAVIEW";
113
114   public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
115
116   public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
117
118   public static final String CHIMERA_PATH = "CHIMERA_PATH";
119   
120   public static final String HMMER_PATH = "HMMER_PATH";
121
122   public static final String CYGWIN_PATH = "CYGWIN_PATH";
123
124   public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
125
126   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
127
128   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
129
130   public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
131
132   public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
133
134   public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
135
136   public static final String GAP_COLOUR = "GAP_COLOUR";
137
138   public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
139
140   private static final int MIN_FONT_SIZE = 1;
141
142   private static final int MAX_FONT_SIZE = 30;
143
144   /**
145    * Holds name and link separated with | character. Sequence ID must be
146    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
147    */
148   public static UrlProviderI sequenceUrlLinks;
149
150   public static UrlLinkTableModel dataModel;
151
152   /**
153    * Holds name and link separated with | character. Sequence IDS and Sequences
154    * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
155    * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
156    * for first and second token specified after a pipe character at end |,|.
157    * (TODO: proper escape for using | to separate ids or sequences
158    */
159
160   public static List<String> groupURLLinks;
161   static
162   {
163     // get links selected to be in the menu (SEQUENCE_LINKS)
164     // and links entered by the user but not selected (STORED_LINKS)
165     String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
166     String notInMenuString = Cache.getDefault("STORED_LINKS", "");
167     String defaultUrl = Cache.getDefault("DEFAULT_URL",
168             UrlConstants.DEFAULT_LABEL);
169
170     // if both links lists are empty, add the DEFAULT_URL link
171     // otherwise we assume the default link is in one of the lists
172     if (inMenuString.isEmpty() && notInMenuString.isEmpty())
173     {
174       inMenuString = UrlConstants.DEFAULT_STRING;
175     }
176     UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
177             inMenuString, notInMenuString);
178     sequenceUrlLinks = factory.createUrlProvider();
179     dataModel = new UrlLinkTableModel(sequenceUrlLinks);
180
181     /**
182      * TODO: reformulate groupURL encoding so two or more can be stored in the
183      * .properties file as '|' separated strings
184      */
185
186     groupURLLinks = new ArrayList<>();
187   }
188
189   JInternalFrame frame;
190
191   DasSourceBrowser dasSource;
192
193   private WsPreferences wsPrefs;
194
195   private OptionsParam promptEachTimeOpt = new OptionsParam(
196           MessageManager.getString("label.prompt_each_time"),
197           "Prompt each time");
198
199   private OptionsParam lineArtOpt = new OptionsParam(
200           MessageManager.getString("label.lineart"), "Lineart");
201
202   private OptionsParam textOpt = new OptionsParam(
203           MessageManager.getString("action.text"), "Text");
204
205   /**
206    * Creates a new Preferences object.
207    */
208   public Preferences()
209   {
210     super();
211     frame = new JInternalFrame();
212     frame.setContentPane(this);
213     dasSource = new DasSourceBrowser();
214     dasTab.add(dasSource, BorderLayout.CENTER);
215     wsPrefs = new WsPreferences();
216     wsTab.add(wsPrefs, BorderLayout.CENTER);
217     int width = 500, height = 450;
218     new jalview.util.Platform();
219     if (Platform.isAMac())
220     {
221       width = 570;
222       height = 480;
223     }
224
225     Desktop.addInternalFrame(frame,
226             MessageManager.getString("label.preferences"), width, height);
227     frame.setMinimumSize(new Dimension(width, height));
228
229     /*
230      * Set HMMER tab defaults
231      */
232     hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
233     if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
234     {
235       hmmerBackgroundUniprot.setSelected(true);
236     }
237     else
238     {
239       hmmerBackgroundAlignment.setSelected(true);
240     }
241     hmmerSequenceCount
242             .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
243     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
244     hmmerPath.addActionListener(new ActionListener()
245     {
246       @Override
247       public void actionPerformed(ActionEvent e)
248       {
249         validateHmmerPath();
250       }
251     });
252     hmmerPath.addFocusListener(new FocusAdapter()
253     {
254       @Override
255       public void focusLost(FocusEvent e)
256       {
257         validateHmmerPath();
258       }
259     });
260     if (cygwinPath != null)
261     {
262       String path = Cache.getProperty(CYGWIN_PATH);
263       if (path == null)
264       {
265         path = FileUtils.getPathTo("bash");
266       }
267       cygwinPath.setText(path);
268       cygwinPath.addActionListener(new ActionListener()
269       {
270         @Override
271         public void actionPerformed(ActionEvent e)
272         {
273           validateCygwinPath();
274         }
275       });
276       cygwinPath.addFocusListener(new FocusAdapter()
277       {
278         @Override
279         public void focusLost(FocusEvent e)
280         {
281           validateCygwinPath();
282         }
283       });
284     }
285
286     /*
287      * Set Visual tab defaults
288      */
289     seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
290     rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
291     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
292     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
293
294     conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
295     quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
296     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
297     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
298     showUnconserved
299             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
300     showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
301     showGroupConsensus
302             .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
303     showGroupConservation.setSelected(
304             Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
305     showConsensHistogram.setSelected(
306             Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
307     showConsensLogo
308             .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
309     showInformationHistogram.setSelected(
310             Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
311     showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
312     showNpTooltip
313             .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
314     showDbRefTooltip
315             .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
316
317     String[] fonts = java.awt.GraphicsEnvironment
318             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
319     for (int i = 0; i < fonts.length; i++)
320     {
321       fontNameCB.addItem(fonts[i]);
322     }
323
324     for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
325     {
326       fontSizeCB.addItem(i + "");
327     }
328
329     fontStyleCB.addItem("plain");
330     fontStyleCB.addItem("bold");
331     fontStyleCB.addItem("italic");
332
333     fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
334     fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
335     fontStyleCB.setSelectedItem(
336             Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
337
338     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
339     scaleProteinToCdna
340             .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
341
342     idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
343
344     wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
345
346     gapSymbolCB.addItem("-");
347     gapSymbolCB.addItem(".");
348
349     gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
350
351     sortby.addItem("No sort");
352     sortby.addItem("Id");
353     sortby.addItem("Pairwise Identity");
354     sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
355
356     sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
357     sortAnnBy
358             .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
359     sortAnnBy
360             .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
361     SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
362             .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
363                     SequenceAnnotationOrder.NONE.name()));
364     sortAnnBy.setSelectedItem(savedSort.toString());
365
366     sortAutocalc.addItem("Autocalculated first");
367     sortAutocalc.addItem("Autocalculated last");
368     final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
369     sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
370             : sortAutocalc.getItemAt(1));
371     startupCheckbox
372             .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
373     startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
374             Cache.getDefault("www.jalview.org", "http://www.jalview.org")
375                     + "/examples/exampleFile_2_3.jar"));
376
377     /*
378      * Set Colours tab defaults
379      */
380     protColour.addItem(ResidueColourScheme.NONE);
381     nucColour.addItem(ResidueColourScheme.NONE);
382     for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
383     {
384       String name = cs.getSchemeName();
385       protColour.addItem(name);
386       nucColour.addItem(name);
387     }
388     String oldProp = Cache.getDefault(DEFAULT_COLOUR,
389             ResidueColourScheme.NONE);
390     String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
391     protColour.setSelectedItem(newProp != null ? newProp : oldProp);
392     newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
393     nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
394     minColour.setBackground(
395             Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
396     maxColour.setBackground(
397             Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
398
399     /*
400      * Set overview panel defaults
401      */
402     gapColour.setBackground(
403             Cache.getDefaultColour(GAP_COLOUR,
404                     jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
405     hiddenColour.setBackground(
406             Cache.getDefaultColour(HIDDEN_COLOUR,
407                     jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
408     useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
409     gapLabel.setEnabled(!useLegacyGap.isSelected());
410     gapColour.setEnabled(!useLegacyGap.isSelected());
411     showHiddenAtStart
412             .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
413
414     /*
415      * Set Structure tab defaults.
416      */
417     final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
418     structFromPdb.setSelected(structSelected);
419     useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
420     useRnaView.setEnabled(structSelected);
421     addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
422     addSecondaryStructure.setEnabled(structSelected);
423     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
424     addTempFactor.setEnabled(structSelected);
425     structViewer.setSelectedItem(
426             Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
427     chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
428     chimeraPath.addActionListener(new ActionListener()
429     {
430       @Override
431       public void actionPerformed(ActionEvent e)
432       {
433         validateChimeraPath();
434       }
435     });
436
437     if (Cache.getDefault("MAP_WITH_SIFTS", false))
438     {
439       siftsMapping.setSelected(true);
440     }
441     else
442     {
443       nwMapping.setSelected(true);
444     }
445
446     SiftsSettings
447             .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
448
449     /*
450      * Set Connections tab defaults
451      */
452
453     // set up sorting
454     linkUrlTable.setModel(dataModel);
455     final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
456             linkUrlTable.getModel());
457     linkUrlTable.setRowSorter(sorter);
458     List<RowSorter.SortKey> sortKeys = new ArrayList<>();
459
460     UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
461     sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
462             SortOrder.DESCENDING));
463     sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
464             SortOrder.DESCENDING));
465     sortKeys.add(
466             new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
467
468     sorter.setSortKeys(sortKeys);
469     sorter.sort();
470
471     // set up filtering
472     ActionListener onReset;
473     onReset = new ActionListener()
474     {
475       @Override
476       public void actionPerformed(ActionEvent e)
477       {
478         filterTB.setText("");
479         sorter.setRowFilter(RowFilter.regexFilter(""));
480       }
481
482     };
483     doReset.addActionListener(onReset);
484
485     // filter to display only custom urls
486     final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
487     {
488       @Override
489       public boolean include(
490               Entry<? extends TableModel, ? extends Object> entry)
491       {
492         return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
493       }
494     };
495
496     final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
497             linkUrlTable.getModel());
498     customSorter.setRowFilter(customUrlFilter);
499
500     ActionListener onCustomOnly;
501     onCustomOnly = new ActionListener()
502     {
503       @Override
504       public void actionPerformed(ActionEvent e)
505       {
506         filterTB.setText("");
507         sorter.setRowFilter(customUrlFilter);
508       }
509     };
510     userOnly.addActionListener(onCustomOnly);
511
512     filterTB.getDocument().addDocumentListener(new DocumentListener()
513     {
514       String caseInsensitiveFlag = "(?i)";
515
516       @Override
517       public void changedUpdate(DocumentEvent e)
518       {
519         sorter.setRowFilter(RowFilter
520                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
521       }
522
523       @Override
524       public void removeUpdate(DocumentEvent e)
525       {
526         sorter.setRowFilter(RowFilter
527                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
528       }
529
530       @Override
531       public void insertUpdate(DocumentEvent e)
532       {
533         sorter.setRowFilter(RowFilter
534                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
535       }
536     });
537
538     // set up list selection functionality
539     linkUrlTable.getSelectionModel()
540             .addListSelectionListener(new UrlListSelectionHandler());
541
542     // set up radio buttons
543     int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
544             .getPrimaryColumn();
545     String onClickName = linkUrlTable.getColumnName(onClickCol);
546     linkUrlTable.getColumn(onClickName)
547             .setCellRenderer(new RadioButtonRenderer());
548     linkUrlTable.getColumn(onClickName)
549             .setCellEditor(new RadioButtonEditor());
550
551     // get boolean columns and resize those to min possible
552     for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
553     {
554       if (linkUrlTable.getModel().getColumnClass(column)
555               .equals(Boolean.class))
556       {
557         TableColumn tableColumn = linkUrlTable.getColumnModel()
558                 .getColumn(column);
559         int preferredWidth = tableColumn.getMinWidth();
560
561         TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
562                 column);
563         Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
564         int cwidth = c.getPreferredSize().width
565                 + linkUrlTable.getIntercellSpacing().width;
566         preferredWidth = Math.max(preferredWidth, cwidth);
567
568         tableColumn.setPreferredWidth(preferredWidth);
569       }
570     }
571
572     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
573     useProxy_actionPerformed(); // make sure useProxy is correctly initialised
574     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
575     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
576
577     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
578
579     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
580     // note antisense here: default is true
581     questionnaire
582             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
583     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
584
585     /*
586      * Set Output tab defaults
587      */
588     epsRendering.addItem(promptEachTimeOpt);
589     epsRendering.addItem(lineArtOpt);
590     epsRendering.addItem(textOpt);
591     String defaultEPS = Cache.getDefault("EPS_RENDERING",
592             "Prompt each time");
593     if (defaultEPS.equalsIgnoreCase("Text"))
594     {
595       epsRendering.setSelectedItem(textOpt);
596     }
597     else if (defaultEPS.equalsIgnoreCase("Lineart"))
598     {
599       epsRendering.setSelectedItem(lineArtOpt);
600     }
601     else
602     {
603       epsRendering.setSelectedItem(promptEachTimeOpt);
604     }
605     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
606     userIdWidth.setEnabled(!autoIdWidth.isSelected());
607     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
608     Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
609     userIdWidth.setText(wi == null ? "" : wi.toString());
610     // TODO: refactor to use common enum via FormatAdapter and allow extension
611     // for new flat file formats
612     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
613     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
614     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
615     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
616     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
617     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
618     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
619     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
620     embbedBioJSON
621             .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
622
623     /*
624      * Set Editing tab defaults
625      */
626     autoCalculateConsCheck
627             .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
628     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
629     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
630
631     annotations_actionPerformed(null); // update the display of the annotation
632                                        // settings
633   }
634
635   /**
636    * Save user selections on the Preferences tabs to the Cache and write out to
637    * file.
638    * 
639    * @param e
640    */
641   @Override
642   public void ok_actionPerformed(ActionEvent e)
643   {
644     if (!validateSettings())
645     {
646       return;
647     }
648
649     /*
650      * Save Visual settings
651      */
652     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
653             Boolean.toString(seqLimit.isSelected()));
654     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
655             Boolean.toString(rightAlign.isSelected()));
656     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
657             Boolean.toString(fullScreen.isSelected()));
658     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
659             Boolean.toString(openoverv.isSelected()));
660     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
661             Boolean.toString(annotations.isSelected()));
662     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
663             Boolean.toString(conservation.isSelected()));
664     Cache.applicationProperties.setProperty("SHOW_QUALITY",
665             Boolean.toString(quality.isSelected()));
666     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
667             Boolean.toString(identity.isSelected()));
668
669     Cache.applicationProperties.setProperty("GAP_SYMBOL",
670             gapSymbolCB.getSelectedItem().toString());
671
672     Cache.applicationProperties.setProperty("FONT_NAME",
673             fontNameCB.getSelectedItem().toString());
674     Cache.applicationProperties.setProperty("FONT_STYLE",
675             fontStyleCB.getSelectedItem().toString());
676     Cache.applicationProperties.setProperty("FONT_SIZE",
677             fontSizeCB.getSelectedItem().toString());
678
679     Cache.applicationProperties.setProperty("ID_ITALICS",
680             Boolean.toString(idItalics.isSelected()));
681     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
682             Boolean.toString(showUnconserved.isSelected()));
683     Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
684             Boolean.toString(showOccupancy.isSelected()));
685     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
686             Boolean.toString(showGroupConsensus.isSelected()));
687     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
688             Boolean.toString(showGroupConservation.isSelected()));
689     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
690             Boolean.toString(showConsensHistogram.isSelected()));
691     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
692             Boolean.toString(showConsensLogo.isSelected()));
693     Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
694             Boolean.toString(showConsensHistogram.isSelected()));
695     Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
696             Boolean.toString(showHMMLogo.isSelected()));
697     Cache.applicationProperties.setProperty("ANTI_ALIAS",
698             Boolean.toString(smoothFont.isSelected()));
699     Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
700             Boolean.toString(scaleProteinToCdna.isSelected()));
701     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
702             Boolean.toString(showNpTooltip.isSelected()));
703     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
704             Boolean.toString(showDbRefTooltip.isSelected()));
705
706     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
707             Boolean.toString(wrap.isSelected()));
708
709     Cache.applicationProperties.setProperty("STARTUP_FILE",
710             startupFileTextfield.getText());
711     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
712             Boolean.toString(startupCheckbox.isSelected()));
713
714     Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
715             sortby.getSelectedItem().toString());
716
717     // convert description of sort order to enum name for save
718     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
719             .forDescription(sortAnnBy.getSelectedItem().toString());
720     if (annSortOrder != null)
721     {
722       Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
723               annSortOrder.name());
724     }
725
726     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
727     Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
728             Boolean.valueOf(showAutocalcFirst).toString());
729
730     /*
731      * Save Colours settings
732      */
733     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
734             protColour.getSelectedItem().toString());
735     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
736             nucColour.getSelectedItem().toString());
737     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
738             minColour.getBackground());
739     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
740             maxColour.getBackground());
741
742     /*
743      * Save HMMER settings
744      */
745     Cache.applicationProperties.setProperty(HMMALIGN_TRIM_TERMINI,
746             Boolean.toString(hmmrTrimTermini.isSelected()));
747     Cache.applicationProperties.setProperty(HMMINFO_GLOBAL_BACKGROUND,
748             Boolean.toString(hmmerBackgroundUniprot.isSelected()));
749     Cache.applicationProperties.setProperty(HMMSEARCH_SEQCOUNT,
750             hmmerSequenceCount.getText());
751     Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
752     if (cygwinPath != null)
753     {
754       Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
755     }
756     AlignFrame[] frames = Desktop.getAlignFrames();
757     if (frames != null && frames.length > 0)
758     {
759       for (AlignFrame f : frames)
760       {
761         f.updateHMMERStatus();
762       }
763     }
764     
765     hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
766     if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
767     {
768       hmmerBackgroundUniprot.setSelected(true);
769     }
770     else
771     {
772       hmmerBackgroundAlignment.setSelected(true);
773     }
774     hmmerSequenceCount
775             .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
776     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
777
778     /*
779      * Save Overview settings
780      */
781     Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
782     Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
783     Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
784             Boolean.toString(useLegacyGap.isSelected()));
785     Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
786             Boolean.toString(showHiddenAtStart.isSelected()));
787
788     /*
789      * Save Structure settings
790      */
791     Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
792             Boolean.toString(addTempFactor.isSelected()));
793     Cache.applicationProperties.setProperty(ADD_SS_ANN,
794             Boolean.toString(addSecondaryStructure.isSelected()));
795     Cache.applicationProperties.setProperty(USE_RNAVIEW,
796             Boolean.toString(useRnaView.isSelected()));
797     Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
798             Boolean.toString(structFromPdb.isSelected()));
799     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
800             structViewer.getSelectedItem().toString());
801     Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
802     Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
803             Boolean.toString(siftsMapping.isSelected()));
804     SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
805
806     /*
807      * Save Output settings
808      */
809     Cache.applicationProperties.setProperty("EPS_RENDERING",
810             ((OptionsParam) epsRendering.getSelectedItem()).getCode());
811
812     /*
813      * Save Connections settings
814      */
815     Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
816
817     jalview.util.BrowserLauncher.resetBrowser();
818
819     // save user-defined and selected links
820     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
821     if (menuLinks.isEmpty())
822     {
823       Cache.applicationProperties.remove("SEQUENCE_LINKS");
824     }
825     else
826     {
827       Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
828               menuLinks.toString());
829     }
830
831     String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
832     if (nonMenuLinks.isEmpty())
833     {
834       Cache.applicationProperties.remove("STORED_LINKS");
835     }
836     else
837     {
838       Cache.applicationProperties.setProperty("STORED_LINKS",
839               nonMenuLinks.toString());
840     }
841
842     Cache.applicationProperties.setProperty("DEFAULT_URL",
843             sequenceUrlLinks.getPrimaryUrlId());
844
845     Cache.applicationProperties.setProperty("USE_PROXY",
846             Boolean.toString(useProxy.isSelected()));
847
848     Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
849
850     Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
851
852     if (useProxy.isSelected())
853     {
854       System.setProperty("http.proxyHost", proxyServerTB.getText());
855       System.setProperty("http.proxyPort", proxyPortTB.getText());
856     }
857     else
858     {
859       System.setProperty("http.proxyHost", "");
860       System.setProperty("http.proxyPort", "");
861     }
862     Cache.setProperty("VERSION_CHECK",
863             Boolean.toString(versioncheck.isSelected()));
864     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
865     {
866       // default is false - we only set this if the user has actively agreed
867       Cache.setProperty("USAGESTATS",
868               Boolean.toString(usagestats.isSelected()));
869     }
870     if (!questionnaire.isSelected())
871     {
872       Cache.setProperty("NOQUESTIONNAIRES", "true");
873     }
874     else
875     {
876       // special - made easy to edit a property file to disable questionnaires
877       // by just adding the given line
878       Cache.removeProperty("NOQUESTIONNAIRES");
879     }
880
881     /*
882      * Save Output settings
883      */
884     Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
885             Boolean.toString(blcjv.isSelected()));
886     Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
887             Boolean.toString(clustaljv.isSelected()));
888     Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
889             Boolean.toString(fastajv.isSelected()));
890     Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
891             Boolean.toString(msfjv.isSelected()));
892     Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
893             Boolean.toString(pfamjv.isSelected()));
894     Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
895             Boolean.toString(pileupjv.isSelected()));
896     Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
897             Boolean.toString(pirjv.isSelected()));
898     Cache.applicationProperties.setProperty("PIR_MODELLER",
899             Boolean.toString(modellerOutput.isSelected()));
900     Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
901             Boolean.toString(embbedBioJSON.isSelected()));
902     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
903
904     Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
905             Boolean.toString(autoIdWidth.isSelected()));
906     userIdWidth_actionPerformed();
907     Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
908             userIdWidth.getText());
909
910     /*
911      * Save Editing settings
912      */
913     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
914             Boolean.toString(autoCalculateConsCheck.isSelected()));
915     Cache.applicationProperties.setProperty("SORT_BY_TREE",
916             Boolean.toString(sortByTree.isSelected()));
917     Cache.applicationProperties.setProperty("PAD_GAPS",
918             Boolean.toString(padGaps.isSelected()));
919
920     dasSource.saveProperties(Cache.applicationProperties);
921     wsPrefs.updateAndRefreshWsMenuConfig(false);
922     Cache.saveProperties();
923     Desktop.instance.doConfigureStructurePrefs();
924     try
925     {
926       frame.setClosed(true);
927     } catch (Exception ex)
928     {
929     }
930   }
931
932   /**
933    * Do any necessary validation before saving settings. Return focus to the
934    * first tab which fails validation.
935    * 
936    * @return
937    */
938   private boolean validateSettings()
939   {
940     if (!validateStructure())
941     {
942       structureTab.requestFocusInWindow();
943       return false;
944     }
945     return true;
946   }
947
948   @Override
949   protected boolean validateStructure()
950   {
951     return validateChimeraPath();
952
953   }
954
955   /**
956    * DOCUMENT ME!
957    */
958   @Override
959   public void startupFileTextfield_mouseClicked()
960   {
961     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
962     JalviewFileChooser chooser = JalviewFileChooser
963             .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
964     chooser.setFileView(new JalviewFileView());
965     chooser.setDialogTitle(
966             MessageManager.getString("label.select_startup_file"));
967
968     int value = chooser.showOpenDialog(this);
969
970     if (value == JalviewFileChooser.APPROVE_OPTION)
971     {
972       FileFormatI format = chooser.getSelectedFormat();
973       if (format != null)
974       {
975         Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
976                 format.getName());
977       }
978       startupFileTextfield
979               .setText(chooser.getSelectedFile().getAbsolutePath());
980     }
981   }
982
983   /**
984    * DOCUMENT ME!
985    * 
986    * @param e
987    *          DOCUMENT ME!
988    */
989   @Override
990   public void cancel_actionPerformed(ActionEvent e)
991   {
992     try
993     {
994       wsPrefs.updateWsMenuConfig(true);
995       wsPrefs.refreshWs_actionPerformed(e);
996       frame.setClosed(true);
997     } catch (Exception ex)
998     {
999     }
1000   }
1001
1002   /**
1003    * DOCUMENT ME!
1004    * 
1005    * @param e
1006    *          DOCUMENT ME!
1007    */
1008   @Override
1009   public void annotations_actionPerformed(ActionEvent e)
1010   {
1011     conservation.setEnabled(annotations.isSelected());
1012     quality.setEnabled(annotations.isSelected());
1013     identity.setEnabled(annotations.isSelected());
1014     showOccupancy.setEnabled(annotations.isSelected());
1015     showGroupConsensus.setEnabled(annotations.isSelected());
1016     showGroupConservation.setEnabled(annotations.isSelected());
1017     showConsensHistogram.setEnabled(annotations.isSelected()
1018             && (identity.isSelected() || showGroupConsensus.isSelected()));
1019     showConsensLogo.setEnabled(annotations.isSelected()
1020             && (identity.isSelected() || showGroupConsensus.isSelected()));
1021     showInformationHistogram.setEnabled(annotations.isSelected());
1022     showHMMLogo.setEnabled(annotations.isSelected());
1023   }
1024
1025   @Override
1026   public void newLink_actionPerformed(ActionEvent e)
1027   {
1028     GSequenceLink link = new GSequenceLink();
1029     boolean valid = false;
1030     while (!valid)
1031     {
1032       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1033               MessageManager.getString("label.new_sequence_url_link"),
1034               JvOptionPane.OK_CANCEL_OPTION, -1,
1035               null) == JvOptionPane.OK_OPTION)
1036       {
1037         if (link.checkValid())
1038         {
1039           if (((UrlLinkTableModel) linkUrlTable.getModel())
1040                   .isUniqueName(link.getName()))
1041           {
1042             ((UrlLinkTableModel) linkUrlTable.getModel())
1043                     .insertRow(link.getName(), link.getURL());
1044             valid = true;
1045           }
1046           else
1047           {
1048             link.notifyDuplicate();
1049             continue;
1050           }
1051         }
1052       }
1053       else
1054       {
1055         break;
1056       }
1057     }
1058   }
1059
1060   @Override
1061   public void editLink_actionPerformed(ActionEvent e)
1062   {
1063     GSequenceLink link = new GSequenceLink();
1064
1065     int index = linkUrlTable.getSelectedRow();
1066     if (index == -1)
1067     {
1068       // button no longer enabled if row is not selected
1069       Cache.log.debug("Edit with no row selected in linkUrlTable");
1070       return;
1071     }
1072
1073     int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1074             .getNameColumn();
1075     int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1076             .getUrlColumn();
1077     String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1078     link.setName(oldName);
1079     link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1080
1081     boolean valid = false;
1082     while (!valid)
1083     {
1084       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1085               MessageManager.getString("label.edit_sequence_url_link"),
1086               JvOptionPane.OK_CANCEL_OPTION, -1,
1087               null) == JvOptionPane.OK_OPTION)
1088       {
1089         if (link.checkValid())
1090         {
1091           if ((oldName.equals(link.getName()))
1092                   || (((UrlLinkTableModel) linkUrlTable.getModel())
1093                           .isUniqueName(link.getName())))
1094           {
1095             linkUrlTable.setValueAt(link.getName(), index, nameCol);
1096             linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1097             valid = true;
1098           }
1099           else
1100           {
1101             link.notifyDuplicate();
1102             continue;
1103           }
1104         }
1105       }
1106       else
1107       {
1108         break;
1109       }
1110     }
1111   }
1112
1113   @Override
1114   public void deleteLink_actionPerformed(ActionEvent e)
1115   {
1116     int index = linkUrlTable.getSelectedRow();
1117     int modelIndex = -1;
1118     if (index == -1)
1119     {
1120       // button no longer enabled if row is not selected
1121       Cache.log.debug("Delete with no row selected in linkUrlTable");
1122       return;
1123     }
1124     else
1125     {
1126       modelIndex = linkUrlTable.convertRowIndexToModel(index);
1127     }
1128
1129     // make sure we use the model index to delete, and not the table index
1130     ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1131   }
1132
1133   @Override
1134   public void defaultBrowser_mouseClicked(MouseEvent e)
1135   {
1136     JFileChooser chooser = new JFileChooser(".");
1137     chooser.setDialogTitle(
1138             MessageManager.getString("label.select_default_browser"));
1139
1140     int value = chooser.showOpenDialog(this);
1141
1142     if (value == JFileChooser.APPROVE_OPTION)
1143     {
1144       defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1145     }
1146
1147   }
1148
1149   /*
1150    * (non-Javadoc)
1151    * 
1152    * @see
1153    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1154    * .ActionEvent)
1155    */
1156   @Override
1157   protected void showunconserved_actionPerformed(ActionEvent e)
1158   {
1159     // TODO Auto-generated method stub
1160     super.showunconserved_actionPerformed(e);
1161   }
1162
1163   public static List<String> getGroupURLLinks()
1164   {
1165     return groupURLLinks;
1166   }
1167
1168   @Override
1169   public void minColour_actionPerformed(JPanel panel)
1170   {
1171     Color col = JColorChooser.showDialog(this,
1172             MessageManager.getString("label.select_colour_minimum_value"),
1173             minColour.getBackground());
1174     if (col != null)
1175     {
1176       panel.setBackground(col);
1177     }
1178     panel.repaint();
1179   }
1180
1181   @Override
1182   public void maxColour_actionPerformed(JPanel panel)
1183   {
1184     Color col = JColorChooser.showDialog(this,
1185             MessageManager.getString("label.select_colour_maximum_value"),
1186             maxColour.getBackground());
1187     if (col != null)
1188     {
1189       panel.setBackground(col);
1190     }
1191     panel.repaint();
1192   }
1193
1194   @Override
1195   public void gapColour_actionPerformed(JPanel gap)
1196   {
1197     if (!useLegacyGap.isSelected())
1198     {
1199       Color col = JColorChooser.showDialog(this,
1200               MessageManager.getString("label.select_gap_colour"),
1201               gapColour.getBackground());
1202       if (col != null)
1203       {
1204         gap.setBackground(col);
1205       }
1206       gap.repaint();
1207     }
1208   }
1209
1210   @Override
1211   public void hiddenColour_actionPerformed(JPanel hidden)
1212   {
1213     Color col = JColorChooser.showDialog(this,
1214             MessageManager.getString("label.select_hidden_colour"),
1215             hiddenColour.getBackground());
1216     if (col != null)
1217     {
1218       hidden.setBackground(col);
1219     }
1220     hidden.repaint();
1221   }
1222
1223   @Override
1224   protected void useLegacyGaps_actionPerformed(ActionEvent e)
1225   {
1226     boolean enabled = useLegacyGap.isSelected();
1227     if (enabled)
1228     {
1229       gapColour.setBackground(
1230               jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1231     }
1232     else
1233     {
1234       gapColour.setBackground(
1235               jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1236     }
1237     gapColour.setEnabled(!enabled);
1238     gapLabel.setEnabled(!enabled);
1239   }
1240
1241   @Override
1242   protected void resetOvDefaults_actionPerformed(ActionEvent e)
1243   {
1244     useLegacyGap.setSelected(false);
1245     useLegacyGaps_actionPerformed(null);
1246     showHiddenAtStart.setSelected(true);
1247     hiddenColour.setBackground(
1248             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1249   }
1250
1251   @Override
1252   protected void userIdWidth_actionPerformed()
1253   {
1254     try
1255     {
1256       String val = userIdWidth.getText().trim();
1257       if (val.length() > 0)
1258       {
1259         Integer iw = Integer.parseInt(val);
1260         if (iw.intValue() < 12)
1261         {
1262           throw new NumberFormatException();
1263         }
1264         userIdWidth.setText(iw.toString());
1265       }
1266     } catch (NumberFormatException x)
1267     {
1268       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1269               MessageManager
1270                       .getString("warn.user_defined_width_requirements"),
1271               MessageManager.getString("label.invalid_id_column_width"),
1272               JvOptionPane.WARNING_MESSAGE);
1273       userIdWidth.setText("");
1274     }
1275   }
1276
1277   @Override
1278   protected void autoIdWidth_actionPerformed()
1279   {
1280     userIdWidth.setEnabled(!autoIdWidth.isSelected());
1281     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1282   }
1283
1284   /**
1285    * Returns true if chimera path is to a valid executable, else show an error
1286    * dialog.
1287    */
1288   private boolean validateChimeraPath()
1289   {
1290     if (chimeraPath.getText().trim().length() > 0)
1291     {
1292       File f = new File(chimeraPath.getText());
1293       if (!f.canExecute())
1294       {
1295         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1296                 MessageManager.getString("label.invalid_chimera_path"),
1297                 MessageManager.getString("label.invalid_name"),
1298                 JvOptionPane.ERROR_MESSAGE);
1299         return false;
1300       }
1301     }
1302     return true;
1303   }
1304   
1305   /**
1306    * Returns true if the given text field contains a path to a folder that
1307    * contains an executable with the given name, else false (after showing a
1308    * warning dialog). The executable name will be tried with .exe appended if not
1309    * found.
1310    * 
1311    * @param textField
1312    * @param executable
1313    */
1314   protected boolean validateExecutablePath(JTextField textField, String executable)
1315   {
1316     String folder = textField.getText().trim();
1317
1318     if (FileUtils.getExecutable(executable, folder) != null)
1319     {
1320       return true;
1321     }
1322     if (folder.length() > 0)
1323     {
1324       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1325               MessageManager.formatMessage("label.executable_not_found",
1326                       executable),
1327               MessageManager.getString("label.invalid_folder"),
1328               JvOptionPane.ERROR_MESSAGE);
1329     }
1330     return false;
1331   }
1332
1333   /**
1334    * Checks if a file can be executed
1335    * 
1336    * @param path
1337    *          the path to the file
1338    * @return
1339    */
1340   public boolean canExecute(String path)
1341   {
1342     File file = new File(path);
1343     if (!file.canExecute())
1344     {
1345       file = new File(path + ".exe");
1346       {
1347         if (!file.canExecute())
1348         {
1349           return false;
1350         }
1351       }
1352     }
1353     return true;
1354   }
1355
1356   /**
1357    * If Chimera is selected, check it can be found on default or user-specified
1358    * path, if not show a warning/help dialog.
1359    */
1360   @Override
1361   protected void structureViewer_actionPerformed(String selectedItem)
1362   {
1363     if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1364     {
1365       return;
1366     }
1367     boolean found = false;
1368
1369     /*
1370      * Try user-specified and standard paths for Chimera executable.
1371      */
1372     List<String> paths = StructureManager.getChimeraPaths();
1373     paths.add(0, chimeraPath.getText());
1374     for (String path : paths)
1375     {
1376       if (new File(path.trim()).canExecute())
1377       {
1378         found = true;
1379         break;
1380       }
1381     }
1382     if (!found)
1383     {
1384       String[] options = { "OK", "Help" };
1385       int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1386               JvSwingUtils.wrapTooltip(true,
1387                       MessageManager.getString("label.chimera_missing")),
1388               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1389               null, options, options[0]);
1390       if (showHelp == JvOptionPane.NO_OPTION)
1391       {
1392         try
1393         {
1394           Help.showHelpWindow(HelpId.StructureViewer);
1395         } catch (HelpSetException e)
1396         {
1397           e.printStackTrace();
1398         }
1399       }
1400     }
1401   }
1402
1403   @Override
1404   protected void validateHmmerPath()
1405   {
1406     validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1407   }
1408
1409   @Override
1410   protected void validateCygwinPath()
1411   {
1412     validateExecutablePath(cygwinPath, "run");
1413   }
1414
1415   public class OptionsParam
1416   {
1417     private String name;
1418
1419     private String code;
1420
1421     public OptionsParam(String name, String code)
1422     {
1423       this.name = name;
1424       this.code = code;
1425     }
1426
1427     public String getName()
1428     {
1429       return name;
1430     }
1431
1432     public void setName(String name)
1433     {
1434       this.name = name;
1435     }
1436
1437     public String getCode()
1438     {
1439       return code;
1440     }
1441
1442     public void setCode(String code)
1443     {
1444       this.code = code;
1445     }
1446
1447     @Override
1448     public String toString()
1449     {
1450       return name;
1451     }
1452
1453     @Override
1454     public boolean equals(Object that)
1455     {
1456       if (!(that instanceof OptionsParam))
1457       {
1458         return false;
1459       }
1460       return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1461     }
1462
1463     @Override
1464     public int hashCode()
1465     {
1466       return name.hashCode() + code.hashCode();
1467     }
1468   }
1469
1470   private class UrlListSelectionHandler implements ListSelectionListener
1471   {
1472
1473     @Override
1474     public void valueChanged(ListSelectionEvent e)
1475     {
1476       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1477
1478       int index = lsm.getMinSelectionIndex();
1479       if (index == -1)
1480       {
1481         // no selection, so disable delete/edit buttons
1482         editLink.setEnabled(false);
1483         deleteLink.setEnabled(false);
1484         return;
1485       }
1486       int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1487
1488       // enable/disable edit and delete link buttons
1489       if (((UrlLinkTableModel) linkUrlTable.getModel())
1490               .isRowDeletable(modelIndex))
1491       {
1492         deleteLink.setEnabled(true);
1493       }
1494       else
1495       {
1496         deleteLink.setEnabled(false);
1497       }
1498
1499       if (((UrlLinkTableModel) linkUrlTable.getModel())
1500               .isRowEditable(modelIndex))
1501       {
1502         editLink.setEnabled(true);
1503       }
1504       else
1505       {
1506         editLink.setEnabled(false);
1507       }
1508     }
1509   }
1510 }