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