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