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