Merge branch 'develop' into features/hmmer
[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
254             .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
255     showGroupConservation.setSelected(
256             Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
257     showConsensHistogram.setSelected(
258             Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
259     showConsensLogo
260             .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
261     showInformationHistogram.setSelected(
262             Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
263     showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
264     showNpTooltip
265             .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
266     showDbRefTooltip
267             .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", 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(
288             Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
289
290     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
291     scaleProteinToCdna
292             .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, 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(
347             Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
348     maxColour.setBackground(
349             Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", 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(
363             Cache.getDefault(STRUCTURE_DISPLAY, 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(
403             new RowSorter.SortKey(m.getNameColumn(), 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
457                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
458       }
459
460       @Override
461       public void removeUpdate(DocumentEvent e)
462       {
463         sorter.setRowFilter(RowFilter
464                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
465       }
466
467       @Override
468       public void insertUpdate(DocumentEvent e)
469       {
470         sorter.setRowFilter(RowFilter
471                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
472       }
473     });
474
475     // set up list selection functionality
476     linkUrlTable.getSelectionModel()
477             .addListSelectionListener(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)
484             .setCellRenderer(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()
495                 .getColumn(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
556             .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
557
558     /*
559      * Set Editing tab defaults
560      */
561     autoCalculateConsCheck
562             .setSelected(Cache.getDefault("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",
605             gapSymbolCB.getSelectedItem().toString());
606
607     Cache.applicationProperties.setProperty("FONT_NAME",
608             fontNameCB.getSelectedItem().toString());
609     Cache.applicationProperties.setProperty("FONT_STYLE",
610             fontStyleCB.getSelectedItem().toString());
611     Cache.applicationProperties.setProperty("FONT_SIZE",
612             fontSizeCB.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",
650             sortby.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,
663             Boolean.valueOf(showAutocalcFirst).toString());
664
665     /*
666      * Save Colours settings
667      */
668     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
669             protColour.getSelectedItem().toString());
670     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
671             nucColour.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,
727             structViewer.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
905             .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
906     chooser.setFileView(new JalviewFileView());
907     chooser.setDialogTitle(
908             MessageManager.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
921               .setText(chooser.getSelectedFile().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,
977               null) == JvOptionPane.OK_OPTION)
978       {
979         if (link.checkValid())
980         {
981           if (((UrlLinkTableModel) linkUrlTable.getModel())
982                   .isUniqueName(link.getName()))
983           {
984             ((UrlLinkTableModel) linkUrlTable.getModel())
985                     .insertRow(link.getName(), link.getURL());
986             valid = true;
987           }
988           else
989           {
990             link.notifyDuplicate();
991             continue;
992           }
993         }
994       }
995       else
996       {
997         break;
998       }
999     }
1000   }
1001
1002   @Override
1003   public void editLink_actionPerformed(ActionEvent e)
1004   {
1005     GSequenceLink link = new GSequenceLink();
1006
1007     int index = linkUrlTable.getSelectedRow();
1008     if (index == -1)
1009     {
1010       // button no longer enabled if row is not selected
1011       Cache.log.debug("Edit with no row selected in linkUrlTable");
1012       return;
1013     }
1014
1015     int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1016             .getNameColumn();
1017     int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1018             .getUrlColumn();
1019     String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1020     link.setName(oldName);
1021     link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1022
1023     boolean valid = false;
1024     while (!valid)
1025     {
1026       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1027               MessageManager.getString("label.edit_sequence_url_link"),
1028               JvOptionPane.OK_CANCEL_OPTION, -1,
1029               null) == JvOptionPane.OK_OPTION)
1030       {
1031         if (link.checkValid())
1032         {
1033           if ((oldName.equals(link.getName()))
1034                   || (((UrlLinkTableModel) linkUrlTable.getModel())
1035                           .isUniqueName(link.getName())))
1036           {
1037             linkUrlTable.setValueAt(link.getName(), index, nameCol);
1038             linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1039             valid = true;
1040           }
1041           else
1042           {
1043             link.notifyDuplicate();
1044             continue;
1045           }
1046         }
1047       }
1048       else
1049       {
1050         break;
1051       }
1052     }
1053   }
1054
1055   @Override
1056   public void deleteLink_actionPerformed(ActionEvent e)
1057   {
1058     int index = linkUrlTable.getSelectedRow();
1059     int modelIndex = -1;
1060     if (index == -1)
1061     {
1062       // button no longer enabled if row is not selected
1063       Cache.log.debug("Delete with no row selected in linkUrlTable");
1064       return;
1065     }
1066     else
1067     {
1068       modelIndex = linkUrlTable.convertRowIndexToModel(index);
1069     }
1070
1071     // make sure we use the model index to delete, and not the table index
1072     ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1073   }
1074
1075   @Override
1076   public void defaultBrowser_mouseClicked(MouseEvent e)
1077   {
1078     JFileChooser chooser = new JFileChooser(".");
1079     chooser.setDialogTitle(
1080             MessageManager.getString("label.select_default_browser"));
1081
1082     int value = chooser.showOpenDialog(this);
1083
1084     if (value == JFileChooser.APPROVE_OPTION)
1085     {
1086       defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1087     }
1088
1089   }
1090
1091   /*
1092    * (non-Javadoc)
1093    * 
1094    * @see
1095    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1096    * .ActionEvent)
1097    */
1098   @Override
1099   protected void showunconserved_actionPerformed(ActionEvent e)
1100   {
1101     // TODO Auto-generated method stub
1102     super.showunconserved_actionPerformed(e);
1103   }
1104
1105   public static List<String> getGroupURLLinks()
1106   {
1107     return groupURLLinks;
1108   }
1109
1110   @Override
1111   public void minColour_actionPerformed(JPanel panel)
1112   {
1113     Color col = JColorChooser.showDialog(this,
1114             MessageManager.getString("label.select_colour_minimum_value"),
1115             minColour.getBackground());
1116     if (col != null)
1117     {
1118       panel.setBackground(col);
1119     }
1120     panel.repaint();
1121   }
1122
1123   @Override
1124   public void maxColour_actionPerformed(JPanel panel)
1125   {
1126     Color col = JColorChooser.showDialog(this,
1127             MessageManager.getString("label.select_colour_maximum_value"),
1128             maxColour.getBackground());
1129     if (col != null)
1130     {
1131       panel.setBackground(col);
1132     }
1133     panel.repaint();
1134   }
1135
1136   @Override
1137   protected void userIdWidth_actionPerformed()
1138   {
1139     try
1140     {
1141       String val = userIdWidth.getText().trim();
1142       if (val.length() > 0)
1143       {
1144         Integer iw = Integer.parseInt(val);
1145         if (iw.intValue() < 12)
1146         {
1147           throw new NumberFormatException();
1148         }
1149         userIdWidth.setText(iw.toString());
1150       }
1151     } catch (NumberFormatException x)
1152     {
1153       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1154               MessageManager
1155                       .getString("warn.user_defined_width_requirements"),
1156               MessageManager.getString("label.invalid_id_column_width"),
1157               JvOptionPane.WARNING_MESSAGE);
1158       userIdWidth.setText("");
1159     }
1160   }
1161
1162   @Override
1163   protected void autoIdWidth_actionPerformed()
1164   {
1165     userIdWidth.setEnabled(!autoIdWidth.isSelected());
1166     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1167   }
1168
1169   /**
1170    * Returns true if chimera path is to a valid executable, else show an error
1171    * dialog.
1172    */
1173   private boolean validateChimeraPath()
1174   {
1175     if (chimeraPath.getText().trim().length() > 0)
1176     {
1177       File f = new File(chimeraPath.getText());
1178       if (!f.canExecute())
1179       {
1180         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1181                 MessageManager.getString("label.invalid_chimera_path"),
1182                 MessageManager.getString("label.invalid_name"),
1183                 JvOptionPane.ERROR_MESSAGE);
1184         return false;
1185       }
1186     }
1187     return true;
1188   }
1189   
1190   /**
1191    * Returns true if hmmer path contains the necessary valid executables, else
1192    * show an error dialog (if showing dialog).
1193    */
1194   private boolean validateHMMERPath(boolean showDialog)
1195   {
1196     int missing = 0;
1197     String message = "";
1198     String folder = hmmerPath.getText().trim();
1199     if (folder.length() > 0)
1200     {
1201       File f = new File(folder);
1202       if (!f.exists())
1203       {
1204         if (showDialog)
1205         {
1206           JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1207                 MessageManager.getString("label.folder_not_exists"),
1208                 MessageManager.getString("label.invalid_folder"),
1209                 JvOptionPane.ERROR_MESSAGE);
1210         }
1211         return false;
1212       }
1213       AlignmentI alignment = new Alignment(
1214               new SequenceI[]
1215       { new Sequence("test", "WLWL", 0, 3) });
1216       if (canExecute(folder + "/hmmbuild"))
1217         {
1218         validateHMMBuild(alignment);
1219         }
1220       else
1221       {
1222         message += MessageManager.getString("label.hmmbuild_not_found")
1223                 + "\n";
1224         missing++;
1225       }
1226
1227
1228       if (canExecute(folder + "/hmmalign"))
1229         {
1230
1231         }
1232       else
1233       {
1234         message += MessageManager.getString("label.hmmalign_not_found")
1235                 + "\n";
1236         missing++;
1237       }
1238
1239
1240       if (canExecute(folder + "/hmmsearch"))
1241         {
1242
1243         }
1244       else
1245       {
1246         message += MessageManager.getString("label.hmmsearch_not_found")
1247                 + "\n";
1248         missing++;
1249       }
1250       }
1251
1252       if (missing > 0)
1253       {
1254         if (missing < 3)
1255         {
1256           if (showDialog)
1257           {
1258             JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1259                   MessageManager.getString("label.invalid_folder"),
1260                   JvOptionPane.ERROR_MESSAGE);
1261           }
1262           return false;
1263         }
1264         else
1265         {
1266           if (showDialog)
1267           {
1268             JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1269                   MessageManager.getString("label.no_binaries"),
1270                   MessageManager.getString("label.invalid_folder"),
1271                   JvOptionPane.ERROR_MESSAGE);
1272           }
1273
1274           return false;
1275         }
1276       }
1277
1278     return true;
1279   }
1280
1281   /**
1282    * Checks if a file can be executed
1283    * 
1284    * @param path
1285    *          the path to the file
1286    * @return
1287    */
1288   public boolean canExecute(String path)
1289   {
1290     File file = new File(path);
1291     if (!file.canExecute())
1292     {
1293       file = new File(path + ".exe");
1294       {
1295         if (!file.canExecute())
1296         {
1297           return false;
1298         }
1299       }
1300     }
1301     return true;
1302   }
1303
1304   /**
1305    * Runs hmmbuild to check if it is working. While doing this it parses the
1306    * version of HMMER.
1307    * 
1308    * @param frame
1309    * @return
1310    */
1311   public boolean validateHMMBuild(AlignmentI alignment)
1312   {
1313     HMMBuildThread hmmbuild = new HMMBuildThread(alignment);
1314     hmmbuild.hmmbuildWaitTillComplete();
1315     SequenceI hmmSeq = alignment.getSequenceAt(1);
1316     HiddenMarkovModel hmm;
1317     if (hmmSeq.isHMMConsensusSequence() && hmmSeq.getHMM() != null)
1318     {
1319       hmm = hmmSeq.getHMM();
1320
1321       if (hmm.getNumberOfSymbols() < 1)
1322       {
1323         return false;
1324       }
1325     }
1326     else
1327     {
1328       return false;
1329     }
1330
1331     String header = hmm.getFileHeader();
1332     if (header == null)
1333     {
1334       return false;
1335     }
1336     else
1337     {
1338       Scanner scanner = new Scanner(header);
1339       scanner.next();
1340       String string = scanner.next();
1341       String version = string.substring(1);
1342       Cache.setProperty("HMMER_VERSION", version);
1343       scanner.close();
1344
1345     }
1346     return true;
1347   }
1348
1349
1350   private boolean validateHMMERPath()
1351   {
1352     return validateHMMERPath(true);
1353   }
1354
1355   /**
1356    * If Chimera is selected, check it can be found on default or user-specified
1357    * path, if not show a warning/help dialog.
1358    */
1359   @Override
1360   protected void structureViewer_actionPerformed(String selectedItem)
1361   {
1362     if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1363     {
1364       return;
1365     }
1366     boolean found = false;
1367
1368     /*
1369      * Try user-specified and standard paths for Chimera executable.
1370      */
1371     List<String> paths = StructureManager.getChimeraPaths();
1372     paths.add(0, chimeraPath.getText());
1373     for (String path : paths)
1374     {
1375       if (new File(path.trim()).canExecute())
1376       {
1377         found = true;
1378         break;
1379       }
1380     }
1381     if (!found)
1382     {
1383       String[] options = { "OK", "Help" };
1384       int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1385               JvSwingUtils.wrapTooltip(true,
1386                       MessageManager.getString("label.chimera_missing")),
1387               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1388               null, options, options[0]);
1389       if (showHelp == JvOptionPane.NO_OPTION)
1390       {
1391         try
1392         {
1393           Help.showHelpWindow(HelpId.StructureViewer);
1394         } catch (HelpSetException e)
1395         {
1396           e.printStackTrace();
1397         }
1398       }
1399     }
1400   }
1401
1402   public class OptionsParam
1403   {
1404     private String name;
1405
1406     private String code;
1407
1408     public OptionsParam(String name, String code)
1409     {
1410       this.name = name;
1411       this.code = code;
1412     }
1413
1414     public String getName()
1415     {
1416       return name;
1417     }
1418
1419     public void setName(String name)
1420     {
1421       this.name = name;
1422     }
1423
1424     public String getCode()
1425     {
1426       return code;
1427     }
1428
1429     public void setCode(String code)
1430     {
1431       this.code = code;
1432     }
1433
1434     @Override
1435     public String toString()
1436     {
1437       return name;
1438     }
1439
1440     @Override
1441     public boolean equals(Object that)
1442     {
1443       if (!(that instanceof OptionsParam))
1444       {
1445         return false;
1446       }
1447       return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1448     }
1449
1450     @Override
1451     public int hashCode()
1452     {
1453       return name.hashCode() + code.hashCode();
1454     }
1455   }
1456
1457   private class UrlListSelectionHandler implements ListSelectionListener
1458   {
1459
1460     @Override
1461     public void valueChanged(ListSelectionEvent e)
1462     {
1463       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1464
1465       int index = lsm.getMinSelectionIndex();
1466       if (index == -1)
1467       {
1468         // no selection, so disable delete/edit buttons
1469         editLink.setEnabled(false);
1470         deleteLink.setEnabled(false);
1471         return;
1472       }
1473       int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1474
1475       // enable/disable edit and delete link buttons
1476       if (((UrlLinkTableModel) linkUrlTable.getModel())
1477               .isRowDeletable(modelIndex))
1478       {
1479         deleteLink.setEnabled(true);
1480       }
1481       else
1482       {
1483         deleteLink.setEnabled(false);
1484       }
1485
1486       if (((UrlLinkTableModel) linkUrlTable.getModel())
1487               .isRowEditable(modelIndex))
1488       {
1489         editLink.setEnabled(true);
1490       }
1491       else
1492       {
1493         editLink.setEnabled(false);
1494       }
1495     }
1496   }
1497 }