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