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