JAL-2629 add HMMER version check
[jalview.git] / src / jalview / gui / Preferences.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.bin.Cache;
25 import jalview.gui.Help.HelpId;
26 import jalview.gui.StructureViewer.ViewerType;
27 import jalview.io.FileFormatI;
28 import jalview.io.JalviewFileChooser;
29 import jalview.io.JalviewFileView;
30 import jalview.jbgui.GPreferences;
31 import jalview.jbgui.GSequenceLink;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ColourSchemes;
34 import jalview.schemes.ResidueColourScheme;
35 import jalview.urls.UrlLinkTableModel;
36 import jalview.urls.api.UrlProviderFactoryI;
37 import jalview.urls.api.UrlProviderI;
38 import jalview.urls.desktop.DesktopUrlProviderFactory;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
41 import jalview.util.UrlConstants;
42 import jalview.ws.sifts.SiftsSettings;
43
44 import java.awt.BorderLayout;
45 import java.awt.Color;
46 import java.awt.Component;
47 import java.awt.Dimension;
48 import java.awt.Font;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
52 import java.io.File;
53 import java.io.IOException;
54 import java.util.ArrayList;
55 import java.util.List;
56 import java.util.Scanner;
57
58 import javax.help.HelpSetException;
59 import javax.swing.JColorChooser;
60 import javax.swing.JFileChooser;
61 import javax.swing.JInternalFrame;
62 import javax.swing.JPanel;
63 import javax.swing.ListSelectionModel;
64 import javax.swing.RowFilter;
65 import javax.swing.RowSorter;
66 import javax.swing.SortOrder;
67 import javax.swing.event.DocumentEvent;
68 import javax.swing.event.DocumentListener;
69 import javax.swing.event.ListSelectionEvent;
70 import javax.swing.event.ListSelectionListener;
71 import javax.swing.table.TableCellRenderer;
72 import javax.swing.table.TableColumn;
73 import javax.swing.table.TableModel;
74 import javax.swing.table.TableRowSorter;
75
76 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
77
78 /**
79  * DOCUMENT ME!
80  * 
81  * @author $author$
82  * @version $Revision$
83  */
84 public class Preferences extends GPreferences
85 {
86   public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
87
88   public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
89
90   public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
91
92   public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
93
94   public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
95
96   public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
97
98   public static final String ADD_SS_ANN = "ADD_SS_ANN";
99
100   public static final String USE_RNAVIEW = "USE_RNAVIEW";
101
102   public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
103
104   public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
105
106   public static final String CHIMERA_PATH = "CHIMERA_PATH";
107   
108   public static final String HMMER_PATH = "HMMER_PATH";
109
110   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
111
112   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
113
114   public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
115
116   private static final int MIN_FONT_SIZE = 1;
117
118   private static final int MAX_FONT_SIZE = 30;
119
120   /**
121    * Holds name and link separated with | character. Sequence ID must be
122    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
123    */
124   public static UrlProviderI sequenceUrlLinks;
125
126   public static UrlLinkTableModel dataModel;
127
128   /**
129    * Holds name and link separated with | character. Sequence IDS and Sequences
130    * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
131    * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
132    * for first and second token specified after a pipe character at end |,|.
133    * (TODO: proper escape for using | to separate ids or sequences
134    */
135
136   public static List<String> groupURLLinks;
137   static
138   {
139     // get links selected to be in the menu (SEQUENCE_LINKS)
140     // and links entered by the user but not selected (STORED_LINKS)
141     String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
142     String notInMenuString = Cache.getDefault("STORED_LINKS", "");
143     String defaultUrl = Cache.getDefault("DEFAULT_URL",
144             UrlConstants.DEFAULT_LABEL);
145
146     // if both links lists are empty, add the DEFAULT_URL link
147     // otherwise we assume the default link is in one of the lists
148     if (inMenuString.isEmpty() && notInMenuString.isEmpty())
149     {
150       inMenuString = UrlConstants.DEFAULT_STRING;
151     }
152     UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
153             inMenuString, notInMenuString);
154     sequenceUrlLinks = factory.createUrlProvider();
155     dataModel = new UrlLinkTableModel(sequenceUrlLinks);
156
157     /**
158      * TODO: reformulate groupURL encoding so two or more can be stored in the
159      * .properties file as '|' separated strings
160      */
161
162     groupURLLinks = new ArrayList<>();
163   }
164
165   JInternalFrame frame;
166
167   DasSourceBrowser dasSource;
168
169   private WsPreferences wsPrefs;
170
171   private OptionsParam promptEachTimeOpt = new OptionsParam(
172           MessageManager.getString("label.prompt_each_time"),
173           "Prompt each time");
174
175   private OptionsParam lineArtOpt = new OptionsParam(
176           MessageManager.getString("label.lineart"), "Lineart");
177
178   private OptionsParam textOpt = new OptionsParam(
179           MessageManager.getString("action.text"), "Text");
180
181   /**
182    * Creates a new Preferences object.
183    */
184   public Preferences()
185   {
186     super();
187     frame = new JInternalFrame();
188     frame.setContentPane(this);
189     dasSource = new DasSourceBrowser();
190     dasTab.add(dasSource, BorderLayout.CENTER);
191     wsPrefs = new WsPreferences();
192     wsTab.add(wsPrefs, BorderLayout.CENTER);
193     int width = 500, height = 450;
194     new jalview.util.Platform();
195     if (Platform.isAMac())
196     {
197       width = 570;
198       height = 480;
199     }
200
201     Desktop.addInternalFrame(frame,
202             MessageManager.getString("label.preferences"), width, height);
203     frame.setMinimumSize(new Dimension(width, height));
204
205     /*
206      * Set HMMER tab defaults
207      */
208     trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
209     isHMMERInstalled
210             .setSelected(Cache.getDefault("HMMER_INSTALLED", false));
211     if (Cache.getDefault("USE_UNIPROT", false))
212     {
213       uniprot.setSelected(true);
214     }
215     else
216     {
217       alignment.setSelected(true);
218     }
219     numberOfSequencesToKeepField
220             .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
221     installationLocation.setEnabled(isHMMERInstalled.isSelected());
222     hmmerPath.setEnabled(isHMMERInstalled.isSelected());
223     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
224     hmmerPath.addActionListener(new ActionListener()
225     {
226       @Override
227       public void actionPerformed(ActionEvent e)
228       {
229         validateHMMERPath();
230       }
231     });
232
233     /*
234      * Set Visual tab defaults
235      */
236     seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
237     rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
238     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
239     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
240
241     conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
242     quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
243     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
244     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
245     showUnconserved
246             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
247     showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
248     showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
249             false));
250     showGroupConservation.setSelected(Cache.getDefault(
251             "SHOW_GROUP_CONSERVATION", false));
252     showConsensHistogram.setSelected(Cache.getDefault(
253             "SHOW_CONSENSUS_HISTOGRAM", true));
254     showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
255             false));
256     showInformationHistogram.setSelected(
257             Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
258     showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
259     showNpTooltip.setSelected(Cache
260             .getDefault("SHOW_NPFEATS_TOOLTIP", true));
261     showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
262             true));
263
264     String[] fonts = java.awt.GraphicsEnvironment
265             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
266     for (int i = 0; i < fonts.length; i++)
267     {
268       fontNameCB.addItem(fonts[i]);
269     }
270
271     for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
272     {
273       fontSizeCB.addItem(i + "");
274     }
275
276     fontStyleCB.addItem("plain");
277     fontStyleCB.addItem("bold");
278     fontStyleCB.addItem("italic");
279
280     fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
281     fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
282     fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
283             + ""));
284
285     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
286     scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
287             false));
288
289     idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
290
291     wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
292
293     gapSymbolCB.addItem("-");
294     gapSymbolCB.addItem(".");
295
296     gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
297
298     sortby.addItem("No sort");
299     sortby.addItem("Id");
300     sortby.addItem("Pairwise Identity");
301     sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
302
303     sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
304     sortAnnBy
305             .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
306     sortAnnBy
307             .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
308     SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
309             .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
310                     SequenceAnnotationOrder.NONE.name()));
311     sortAnnBy.setSelectedItem(savedSort.toString());
312
313     sortAutocalc.addItem("Autocalculated first");
314     sortAutocalc.addItem("Autocalculated last");
315     final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
316     sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
317             : sortAutocalc.getItemAt(1));
318     startupCheckbox
319             .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
320     startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
321             Cache.getDefault("www.jalview.org", "http://www.jalview.org")
322                     + "/examples/exampleFile_2_3.jar"));
323
324     /*
325      * Set Colours tab defaults
326      */
327     protColour.addItem(ResidueColourScheme.NONE);
328     nucColour.addItem(ResidueColourScheme.NONE);
329     for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
330     {
331       String name = cs.getSchemeName();
332       protColour.addItem(name);
333       nucColour.addItem(name);
334     }
335     String oldProp = Cache.getDefault(DEFAULT_COLOUR,
336             ResidueColourScheme.NONE);
337     String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
338     protColour.setSelectedItem(newProp != null ? newProp : oldProp);
339     newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
340     nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
341     minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
342             Color.orange));
343     maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
344             Color.red));
345
346     /*
347      * Set Structure tab defaults.
348      */
349     final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
350     structFromPdb.setSelected(structSelected);
351     useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
352     useRnaView.setEnabled(structSelected);
353     addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
354     addSecondaryStructure.setEnabled(structSelected);
355     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
356     addTempFactor.setEnabled(structSelected);
357     structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
358             ViewerType.JMOL.name()));
359     chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
360     chimeraPath.addActionListener(new ActionListener()
361     {
362       @Override
363       public void actionPerformed(ActionEvent e)
364       {
365         validateChimeraPath();
366       }
367     });
368
369     if (Cache.getDefault("MAP_WITH_SIFTS", false))
370     {
371       siftsMapping.setSelected(true);
372     }
373     else
374     {
375       nwMapping.setSelected(true);
376     }
377
378     SiftsSettings
379             .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
380
381     /*
382      * Set Connections tab defaults
383      */
384
385     // set up sorting
386     linkUrlTable.setModel(dataModel);
387     final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
388             linkUrlTable.getModel());
389     linkUrlTable.setRowSorter(sorter);
390     List<RowSorter.SortKey> sortKeys = new ArrayList<>();
391
392     UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
393     sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
394             SortOrder.DESCENDING));
395     sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
396             SortOrder.DESCENDING));
397     sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
398             SortOrder.ASCENDING));
399
400     sorter.setSortKeys(sortKeys);
401     sorter.sort();
402     
403     // set up filtering
404     ActionListener onReset;
405     onReset = new ActionListener()
406     {
407       @Override
408       public void actionPerformed(ActionEvent e)
409       {
410         filterTB.setText("");
411         sorter.setRowFilter(RowFilter.regexFilter(""));
412       }
413
414     };
415     doReset.addActionListener(onReset);
416
417     // filter to display only custom urls
418     final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
419     {
420       @Override
421       public boolean include(
422               Entry<? extends TableModel, ? extends Object> entry)
423       {
424         return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
425       }
426     };
427
428     final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
429             linkUrlTable.getModel());
430     customSorter.setRowFilter(customUrlFilter);
431
432     ActionListener onCustomOnly;
433     onCustomOnly = new ActionListener()
434     {
435       @Override
436       public void actionPerformed(ActionEvent e)
437       {
438         filterTB.setText("");
439         sorter.setRowFilter(customUrlFilter);
440       }
441     };
442     userOnly.addActionListener(onCustomOnly);
443
444     filterTB.getDocument().addDocumentListener(new DocumentListener()
445     {
446       String caseInsensitiveFlag = "(?i)";
447
448       @Override
449       public void changedUpdate(DocumentEvent e)
450       {
451         sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
452                 + filterTB.getText()));
453       }
454
455       @Override
456       public void removeUpdate(DocumentEvent e)
457       {
458         sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
459                 + filterTB.getText()));
460       }
461
462       @Override
463       public void insertUpdate(DocumentEvent e)
464       {
465         sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
466                 + filterTB.getText()));
467       }
468     });
469
470     // set up list selection functionality
471     linkUrlTable.getSelectionModel().addListSelectionListener(
472             new UrlListSelectionHandler());
473
474     // set up radio buttons
475     int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
476             .getPrimaryColumn();
477     String onClickName = linkUrlTable.getColumnName(onClickCol);
478     linkUrlTable.getColumn(onClickName).setCellRenderer(
479                new RadioButtonRenderer());
480     linkUrlTable.getColumn(onClickName)
481             .setCellEditor(new RadioButtonEditor());
482
483     // get boolean columns and resize those to min possible
484     for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
485     {
486       if (linkUrlTable.getModel().getColumnClass(column)
487               .equals(Boolean.class))
488       {
489         TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
490                 column);
491         int preferredWidth = tableColumn.getMinWidth();
492
493         TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
494                 column);
495         Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
496         int cwidth = c.getPreferredSize().width
497                 + linkUrlTable.getIntercellSpacing().width;
498         preferredWidth = Math.max(preferredWidth, cwidth);
499
500         tableColumn.setPreferredWidth(preferredWidth);
501       }
502     }
503
504     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
505     useProxy_actionPerformed(); // make sure useProxy is correctly initialised
506     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
507     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
508
509     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
510
511     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
512     // note antisense here: default is true
513     questionnaire
514             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
515     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
516
517     /*
518      * Set Output tab defaults
519      */
520     epsRendering.addItem(promptEachTimeOpt);
521     epsRendering.addItem(lineArtOpt);
522     epsRendering.addItem(textOpt);
523     String defaultEPS = Cache.getDefault("EPS_RENDERING",
524             "Prompt each time");
525     if (defaultEPS.equalsIgnoreCase("Text"))
526     {
527       epsRendering.setSelectedItem(textOpt);
528     }
529     else if (defaultEPS.equalsIgnoreCase("Lineart"))
530     {
531       epsRendering.setSelectedItem(lineArtOpt);
532     }
533     else
534     {
535       epsRendering.setSelectedItem(promptEachTimeOpt);
536     }
537     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
538     userIdWidth.setEnabled(!autoIdWidth.isSelected());
539     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
540     Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
541     userIdWidth.setText(wi == null ? "" : wi.toString());
542     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
543     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
544     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
545     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
546     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
547     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
548     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
549     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
550     embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
551             true));
552
553     /*
554      * Set Editing tab defaults
555      */
556     autoCalculateConsCheck.setSelected(Cache.getDefault(
557             "AUTO_CALC_CONSENSUS", true));
558     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
559     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
560
561     annotations_actionPerformed(null); // update the display of the annotation
562                                        // settings
563   }
564
565   /**
566    * Save user selections on the Preferences tabs to the Cache and write out to
567    * file.
568    * 
569    * @param e
570    */
571   @Override
572   public void ok_actionPerformed(ActionEvent e)
573   {
574     if (!validateSettings())
575     {
576       return;
577     }
578
579     /*
580      * Save Visual settings
581      */
582     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
583             Boolean.toString(seqLimit.isSelected()));
584     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
585             Boolean.toString(rightAlign.isSelected()));
586     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
587             Boolean.toString(fullScreen.isSelected()));
588     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
589             Boolean.toString(openoverv.isSelected()));
590     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
591             Boolean.toString(annotations.isSelected()));
592     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
593             Boolean.toString(conservation.isSelected()));
594     Cache.applicationProperties.setProperty("SHOW_QUALITY",
595             Boolean.toString(quality.isSelected()));
596     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
597             Boolean.toString(identity.isSelected()));
598
599     Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
600             .getSelectedItem().toString());
601
602     Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
603             .getSelectedItem().toString());
604     Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
605             .getSelectedItem().toString());
606     Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
607             .getSelectedItem().toString());
608
609     Cache.applicationProperties.setProperty("ID_ITALICS",
610             Boolean.toString(idItalics.isSelected()));
611     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
612             Boolean.toString(showUnconserved.isSelected()));
613     Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
614             Boolean.toString(showOccupancy.isSelected()));
615     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
616             Boolean.toString(showGroupConsensus.isSelected()));
617     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
618             Boolean.toString(showGroupConservation.isSelected()));
619     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
620             Boolean.toString(showConsensHistogram.isSelected()));
621     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
622             Boolean.toString(showConsensLogo.isSelected()));
623     Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
624             Boolean.toString(showConsensHistogram.isSelected()));
625     Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
626             Boolean.toString(showHMMLogo.isSelected()));
627     Cache.applicationProperties.setProperty("ANTI_ALIAS",
628             Boolean.toString(smoothFont.isSelected()));
629     Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
630             Boolean.toString(scaleProteinToCdna.isSelected()));
631     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
632             Boolean.toString(showNpTooltip.isSelected()));
633     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
634             Boolean.toString(showDbRefTooltip.isSelected()));
635
636     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
637             Boolean.toString(wrap.isSelected()));
638
639     Cache.applicationProperties.setProperty("STARTUP_FILE",
640             startupFileTextfield.getText());
641     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
642             Boolean.toString(startupCheckbox.isSelected()));
643
644     Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
645             .getSelectedItem().toString());
646
647     // convert description of sort order to enum name for save
648     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
649             .forDescription(sortAnnBy.getSelectedItem().toString());
650     if (annSortOrder != null)
651     {
652       Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
653               annSortOrder.name());
654     }
655
656     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
657     Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
658             .valueOf(showAutocalcFirst).toString());
659
660     /*
661      * Save Colours settings
662      */
663     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
664             .getSelectedItem().toString());
665     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
666             .getSelectedItem().toString());
667     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
668             minColour.getBackground());
669     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
670             maxColour.getBackground());
671
672     /*
673      * Save HMMER settings
674      */
675     Cache.applicationProperties.setProperty("TRIM_TERMINI",
676             Boolean.toString(trimTermini.isSelected()));
677     Cache.applicationProperties.setProperty("USE_UNIPROT",
678             Boolean.toString(uniprot.isSelected()));
679     Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
680             numberOfSequencesToKeepField.getText());
681     Cache.applicationProperties.setProperty(HMMER_PATH,
682             hmmerPath.getText());
683     boolean hmmerInstalled = isHMMERInstalled.isSelected();
684     Cache.applicationProperties.setProperty("HMMER_INSTALLED",
685             Boolean.toString(hmmerInstalled));
686     boolean hmmerFunctioning = validateHMMERPath(false);
687     Cache.applicationProperties.setProperty("HMMER_FUNCTIONING",
688             Boolean.toString(hmmerFunctioning));
689     AlignFrame[] frames = Desktop.getAlignFrames();
690     boolean hmmerStatus = hmmerFunctioning && hmmerInstalled ? true : false;
691     for (AlignFrame frame : frames)
692     {
693       frame.updateHMMERStatus(hmmerStatus);
694     }
695     if (hmmerStatus)
696     {
697       String ver = getHMMERVersion();
698       Cache.setProperty("HMMER_VERSION", ver);
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 path = hmmerPath.getText().trim();
1197     if (path.length() > 0)
1198     {
1199       File f = new File(path);
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
1212       File hmmbuild = new File(path + "/binaries/hmmbuild.exe");
1213       {
1214         if (!hmmbuild.canExecute())
1215         {
1216           message += MessageManager.getString("label.hmmbuild_not_found")
1217                   + "\n";
1218           missing++;
1219         }
1220       }
1221
1222       File hmmalign = new File(path + "/binaries/hmmalign.exe");
1223       {
1224         if (!hmmalign.canExecute())
1225         {
1226           message += MessageManager.getString("label.hmmalign_not_found")
1227                   + "\n";
1228           missing++;
1229         }
1230       }
1231
1232       File hmmsearch = new File(path + "/binaries/hmmsearch.exe");
1233       {
1234         if (!hmmsearch.canExecute())
1235         {
1236           message += MessageManager.getString("label.hmmsearch_not_found")
1237                   + "\n";
1238           missing++;
1239         }
1240       }
1241
1242       if (missing > 0)
1243       {
1244         if (missing < 3)
1245         {
1246           if (showDialog)
1247           {
1248             JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1249                   MessageManager.getString("label.invalid_folder"),
1250                   JvOptionPane.ERROR_MESSAGE);
1251           }
1252           return false;
1253         }
1254         else
1255         {
1256           if (showDialog)
1257           {
1258             JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1259                   MessageManager.getString("label.no_binaries"),
1260                   MessageManager.getString("label.invalid_folder"),
1261                   JvOptionPane.ERROR_MESSAGE);
1262           }
1263
1264           return false;
1265         }
1266       }
1267
1268     }
1269     return true;
1270   }
1271
1272   private String getHMMERVersion()
1273   {
1274     File file = new File(hmmerPath.getText() + "/release-notes.txt");
1275     Scanner scanner = null;
1276     try
1277     {
1278       scanner = new Scanner(file);
1279     } catch (IOException e)
1280     {
1281       e.printStackTrace();
1282       return null;
1283     }
1284     scanner.next();
1285     String res = scanner.next();
1286     scanner.close();
1287     return res;
1288   }
1289
1290   private boolean validateHMMERPath()
1291   {
1292     return validateHMMERPath(true);
1293   }
1294
1295   /**
1296    * If Chimera is selected, check it can be found on default or user-specified
1297    * path, if not show a warning/help dialog.
1298    */
1299   @Override
1300   protected void structureViewer_actionPerformed(String selectedItem)
1301   {
1302     if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1303     {
1304       return;
1305     }
1306     boolean found = false;
1307
1308     /*
1309      * Try user-specified and standard paths for Chimera executable.
1310      */
1311     List<String> paths = StructureManager.getChimeraPaths();
1312     paths.add(0, chimeraPath.getText());
1313     for (String path : paths)
1314     {
1315       if (new File(path.trim()).canExecute())
1316       {
1317         found = true;
1318         break;
1319       }
1320     }
1321     if (!found)
1322     {
1323       String[] options = { "OK", "Help" };
1324       int showHelp = JvOptionPane.showInternalOptionDialog(
1325               Desktop.desktop,
1326               JvSwingUtils.wrapTooltip(true,
1327                       MessageManager.getString("label.chimera_missing")),
1328               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1329               null, options, options[0]);
1330       if (showHelp == JvOptionPane.NO_OPTION)
1331       {
1332         try
1333         {
1334           Help.showHelpWindow(HelpId.StructureViewer);
1335         } catch (HelpSetException e)
1336         {
1337           e.printStackTrace();
1338         }
1339       }
1340     }
1341   }
1342
1343   public class OptionsParam
1344   {
1345     private String name;
1346
1347     private String code;
1348
1349     public OptionsParam(String name, String code)
1350     {
1351       this.name = name;
1352       this.code = code;
1353     }
1354
1355     public String getName()
1356     {
1357       return name;
1358     }
1359
1360     public void setName(String name)
1361     {
1362       this.name = name;
1363     }
1364
1365     public String getCode()
1366     {
1367       return code;
1368     }
1369
1370     public void setCode(String code)
1371     {
1372       this.code = code;
1373     }
1374
1375     @Override
1376     public String toString()
1377     {
1378       return name;
1379     }
1380
1381     @Override
1382     public boolean equals(Object that)
1383     {
1384       if (!(that instanceof OptionsParam))
1385       {
1386         return false;
1387       }
1388       return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1389     }
1390
1391     @Override
1392     public int hashCode()
1393     {
1394       return name.hashCode() + code.hashCode();
1395     }
1396   }
1397   
1398   private class UrlListSelectionHandler implements ListSelectionListener
1399   {
1400
1401     @Override
1402     public void valueChanged(ListSelectionEvent e)
1403     {
1404       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1405
1406       int index = lsm.getMinSelectionIndex();
1407       if (index == -1)
1408       {
1409         // no selection, so disable delete/edit buttons
1410         editLink.setEnabled(false);
1411         deleteLink.setEnabled(false);
1412         return;
1413       }
1414       int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1415
1416       // enable/disable edit and delete link buttons
1417       if (((UrlLinkTableModel) linkUrlTable.getModel())
1418               .isRowDeletable(modelIndex))
1419       {
1420         deleteLink.setEnabled(true);
1421       }
1422       else
1423       {
1424         deleteLink.setEnabled(false);
1425       }
1426
1427       if (((UrlLinkTableModel) linkUrlTable.getModel())
1428               .isRowEditable(modelIndex))
1429       {
1430         editLink.setEnabled(true);
1431       }
1432       else
1433       {
1434         editLink.setEnabled(false);
1435       }
1436     }
1437 }
1438 }