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