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