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