Merge branch 'alpha/origin_2022_JAL-3066_Jalview_212_slivka-integration' into spike...
[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
24 import java.awt.BorderLayout;
25 import java.awt.Color;
26 import java.awt.Component;
27 import java.awt.Dimension;
28 import java.awt.Font;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.FocusAdapter;
32 import java.awt.event.FocusEvent;
33 import java.awt.event.MouseEvent;
34 import java.io.File;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.concurrent.CompletableFuture;
38
39 import javax.help.HelpSetException;
40 import javax.swing.JComboBox;
41 import javax.swing.JFileChooser;
42 import javax.swing.JInternalFrame;
43 import javax.swing.JPanel;
44 import javax.swing.JTextField;
45 import javax.swing.ListSelectionModel;
46 import javax.swing.RowFilter;
47 import javax.swing.RowSorter;
48 import javax.swing.SortOrder;
49 import javax.swing.event.DocumentEvent;
50 import javax.swing.event.DocumentListener;
51 import javax.swing.event.ListSelectionEvent;
52 import javax.swing.event.ListSelectionListener;
53 import javax.swing.table.TableCellRenderer;
54 import javax.swing.table.TableColumn;
55 import javax.swing.table.TableModel;
56 import javax.swing.table.TableRowSorter;
57
58 import jalview.hmmer.HmmerCommand;
59 import jalview.util.FileUtils;
60 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
61 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
62 import jalview.bin.Cache;
63 import jalview.ext.pymol.PymolManager;
64 import jalview.gui.Help.HelpId;
65 import jalview.gui.StructureViewer.ViewerType;
66 import jalview.io.BackupFiles;
67 import jalview.io.BackupFilesPresetEntry;
68 import jalview.io.FileFormatI;
69 import jalview.io.JalviewFileChooser;
70 import jalview.io.JalviewFileView;
71 import jalview.jbgui.GPreferences;
72 import jalview.jbgui.GSequenceLink;
73 import jalview.schemes.ColourSchemeI;
74 import jalview.schemes.ColourSchemes;
75 import jalview.schemes.ResidueColourScheme;
76 import jalview.urls.UrlLinkTableModel;
77 import jalview.urls.api.UrlProviderFactoryI;
78 import jalview.urls.api.UrlProviderI;
79 import jalview.urls.desktop.DesktopUrlProviderFactory;
80 import jalview.util.MessageManager;
81 import jalview.util.Platform;
82 import jalview.util.UrlConstants;
83 import jalview.ws.sifts.SiftsSettings;
84
85 /**
86  * DOCUMENT ME!
87  * 
88  * @author $author$
89  * @version $Revision$
90  */
91
92 public class Preferences extends GPreferences implements ApplicationSingletonI
93 {
94   // suggested list delimiter character
95   public static final String COMMA = ",";
96
97   public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT";
98
99   public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND";
100
101   public static final String HMMALIGN_TRIM_TERMINI = "HMMALIGN_TRIM_TERMINI";
102   
103   public static final String ADD_SS_ANN = "ADD_SS_ANN";
104
105   public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
106
107   public static final String ALLOW_UNPUBLISHED_PDB_QUERYING = "ALLOW_UNPUBLISHED_PDB_QUERYING";
108
109   public static final String ANNOTATIONCOLOUR_MAX = "ANNOTATIONCOLOUR_MAX";
110
111   public static final String ANNOTATIONCOLOUR_MIN = "ANNOTATIONCOLOUR_MIN";
112
113   public static final String ANTI_ALIAS = "ANTI_ALIAS";
114
115   public static final String AUTO_CALC_CONSENSUS = "AUTO_CALC_CONSENSUS";
116
117   public static final String AUTOASSOCIATE_PDBANDSEQS = "AUTOASSOCIATE_PDBANDSEQS";
118
119   public static final String BLOSUM62_PCA_FOR_NUCLEOTIDE = "BLOSUM62_PCA_FOR_NUCLEOTIDE";
120
121   public static final String CENTRE_COLUMN_LABELS = "CENTRE_COLUMN_LABELS";
122
123   public static final String CHIMERA_PATH = "CHIMERA_PATH";
124
125   public static final String CHIMERAX_PATH = "CHIMERAX_PATH";
126
127   public static final String DBREFFETCH_USEPICR = "DBREFFETCH_USEPICR";
128
129   public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
130
131   public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
132   public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
133
134   public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
135
136   public static final String FIGURE_AUTOIDWIDTH = "FIGURE_AUTOIDWIDTH";
137
138   public static final String FIGURE_FIXEDIDWIDTH = "FIGURE_FIXEDIDWIDTH";
139
140   public static final String FOLLOW_SELECTIONS = "FOLLOW_SELECTIONS";
141
142   public static final String FONT_NAME = "FONT_NAME";
143
144   public static final String FONT_SIZE = "FONT_SIZE";
145
146   public static final String FONT_STYLE = "FONT_STYLE";
147   
148   public static final String HMMER_PATH = "HMMER_PATH";
149
150   public static final String CYGWIN_PATH = "CYGWIN_PATH";
151
152   public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
153
154   public static final String GAP_COLOUR = "GAP_COLOUR";
155
156   public static final String GAP_SYMBOL = "GAP_SYMBOL";
157
158   public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
159
160   public static final String HIDE_INTRONS = "HIDE_INTRONS";
161
162   public static final String ID_ITALICS = "ID_ITALICS";
163
164   public static final String ID_ORG_HOSTURL = "ID_ORG_HOSTURL";
165
166   public static final String MAP_WITH_SIFTS = "MAP_WITH_SIFTS";
167
168   public static final String NOQUESTIONNAIRES = "NOQUESTIONNAIRES";
169
170   public static final String NORMALISE_CONSENSUS_LOGO = "NORMALISE_CONSENSUS_LOGO";
171
172   public static final String NORMALISE_LOGO = "NORMALISE_LOGO";
173
174   public static final String PAD_GAPS = "PAD_GAPS";
175
176   public static final String PDB_DOWNLOAD_FORMAT = "PDB_DOWNLOAD_FORMAT";
177
178   public static final String PYMOL_PATH = "PYMOL_PATH";
179
180   public static final String QUESTIONNAIRE = "QUESTIONNAIRE";
181
182   public static final String RELAXEDSEQIDMATCHING = "RELAXEDSEQIDMATCHING";
183
184   public static final String RIGHT_ALIGN_IDS = "RIGHT_ALIGN_IDS";
185
186   public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
187
188   public static final String SHOW_ANNOTATIONS = "SHOW_ANNOTATIONS";
189
190   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
191
192   public static final String SHOW_CONSENSUS = "SHOW_CONSENSUS";
193
194   public static final String SHOW_CONSENSUS_HISTOGRAM = "SHOW_CONSENSUS_HISTOGRAM";
195
196   public static final String SHOW_CONSENSUS_LOGO = "SHOW_CONSENSUS_LOGO";
197
198   public static final String SHOW_CONSERVATION = "SHOW_CONSERVATION";
199
200   public static final String SHOW_DBREFS_TOOLTIP = "SHOW_DBREFS_TOOLTIP";
201
202   public static final String SHOW_GROUP_CONSENSUS = "SHOW_GROUP_CONSENSUS";
203
204   public static final String SHOW_GROUP_CONSERVATION = "SHOW_GROUP_CONSERVATION";
205
206   public static final String SHOW_JVSUFFIX = "SHOW_JVSUFFIX";
207
208   public static final String SHOW_NPFEATS_TOOLTIP = "SHOW_NPFEATS_TOOLTIP";
209   public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
210
211   public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
212
213   public static final String SHOW_OVERVIEW = "SHOW_OVERVIEW";
214
215   public static final String SHOW_QUALITY = "SHOW_QUALITY";
216
217   public static final String SHOW_UNCONSERVED = "SHOW_UNCONSERVED";
218
219   public static final String SORT_ALIGNMENT = "SORT_ALIGNMENT";
220
221   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
222
223   public static final String SORT_BY_TREE = "SORT_BY_TREE";
224
225   public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
226
227   public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
228
229   public static final String STRUCTURE_DIMENSIONS = "STRUCTURE_DIMENSIONS";
230
231   public static final String UNIPROT_DOMAIN = "UNIPROT_DOMAIN";
232
233   public static final String USE_FULL_SO = "USE_FULL_SO";
234   public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
235
236   public static final String USE_RNAVIEW = "USE_RNAVIEW";
237
238   public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS";
239
240   public static final String WRAP_ALIGNMENT = "WRAP_ALIGNMENT";
241
242   private static final int MIN_FONT_SIZE = 1;
243
244   private static final int MAX_FONT_SIZE = 30;
245
246   private String previousProxyType;
247
248   private static Preferences INSTANCE = null; // add "final"
249   /**
250    * Holds name and link separated with | character. Sequence ID must be
251    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
252    */
253   public static UrlProviderI sequenceUrlLinks;
254
255   public static UrlLinkTableModel dataModel;
256
257   /**
258    * Holds name and link separated with | character. Sequence IDS and Sequences
259    * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and $SEQUENCES$
260    * or $SEQUENCES=/.possible | chars ./=$ and separation character for first and
261    * second token specified after a pipe character at end |,|. (TODO: proper
262    * escape for using | to separate ids or sequences
263    */
264
265   public static List<String> groupURLLinks;
266   static
267   {
268     // get links selected to be in the menu (SEQUENCE_LINKS)
269     // and links entered by the user but not selected (STORED_LINKS)
270     String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
271     String notInMenuString = Cache.getDefault("STORED_LINKS", "");
272     String defaultUrl = Cache.getDefault("DEFAULT_URL",
273             UrlConstants.DEFAULT_LABEL);
274
275     // if both links lists are empty, add the DEFAULT_URL link
276     // otherwise we assume the default link is in one of the lists
277     if (inMenuString.isEmpty() && notInMenuString.isEmpty())
278     {
279       inMenuString = UrlConstants.DEFAULT_STRING;
280     }
281     UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
282             inMenuString, notInMenuString);
283     sequenceUrlLinks = factory.createUrlProvider();
284     dataModel = new UrlLinkTableModel(sequenceUrlLinks);
285
286     /**
287      * TODO: reformulate groupURL encoding so two or more can be stored in the
288      * .properties file as '|' separated strings
289      */
290
291     groupURLLinks = new ArrayList<>();
292   }
293
294   JInternalFrame frame;
295
296   private WsPreferences wsPrefs;
297
298   private SlivkaPreferences slivkaPrefs;
299   private OptionsParam promptEachTimeOpt = new OptionsParam(
300           MessageManager.getString("label.prompt_each_time"),
301           "Prompt each time");
302
303   private OptionsParam lineArtOpt = new OptionsParam(
304           MessageManager.getString("label.lineart"), "Lineart");
305
306   private OptionsParam textOpt = new OptionsParam(
307           MessageManager.getString("action.text"), "Text");
308
309   // get singleton Preferences instance
310   public static Preferences getInstance()
311   {
312     if (INSTANCE == null || INSTANCE.frame == null
313             || INSTANCE.frame.isClosed())
314     {
315       INSTANCE = new Preferences();
316     }
317     return INSTANCE;
318
319     /*
320      * Replace code with the following for Jalvew-JS
321     Preferences INSTANCE = ApplicationSingletonProvider.getInstance(Preferences.class);
322     if (INSTANCE == null || INSTANCE.frame == null
323             || INSTANCE.frame.isClosed())
324     {
325       ApplicationSingletonProvider.remove(Preferences.class);
326       INSTANCE = ApplicationSingletonProvider.getInstance(Preferences.class);
327     }
328     return INSTANCE;
329     */
330   }
331
332   public static void openPreferences()
333   {
334     openPreferences(null, null);
335   }
336
337   public static void openPreferences(TabRef selectTab, String message)
338   {
339     Preferences p = getInstance();
340     if (selectTab != null)
341       p.selectTab(selectTab, message);
342     p.frame.show();
343     p.frame.moveToFront();
344     p.frame.grabFocus();
345   }
346
347   public void selectTab(TabRef selectTab, String message)
348   {
349     this.selectTab(selectTab);
350     if (message != null)
351       this.setMessage(message);
352     this.frame.show();
353   }
354   /**
355    * Creates a new Preferences object.
356    */
357   private Preferences()
358   {
359     super();
360     frame = new JInternalFrame();
361     frame.setContentPane(this);
362     if (!Platform.isJS())
363     /**
364      * Java only
365      * 
366      * @j2sIgnore
367      */
368     {
369       wsPrefs = new WsPreferences();
370       wsTab.add(wsPrefs, BorderLayout.CENTER);
371     }
372
373     slivkaPrefs = new SlivkaPreferences();
374     slivkaTab.add(slivkaPrefs, BorderLayout.CENTER);
375    
376     int width = 500, height = 450;
377     if (Platform.isAMacAndNotJS())
378     {
379       width = 570;
380       height = 480;
381     }
382
383     Desktop.addInternalFrame(frame,
384             MessageManager.getString("label.preferences"), width, height);
385     frame.setMinimumSize(new Dimension(width, height));
386
387     /*
388      * Set HMMER tab defaults
389      */
390     hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
391     if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
392     {
393       hmmerBackgroundUniprot.setSelected(true);
394     }
395     else
396     {
397       hmmerBackgroundAlignment.setSelected(true);
398     }
399     hmmerSequenceCount
400             .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
401     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
402     hmmerPath.addActionListener(new ActionListener()
403     {
404       @Override
405       public void actionPerformed(ActionEvent e)
406       {
407         validateHmmerPath();
408       }
409     });
410     hmmerPath.addFocusListener(new FocusAdapter()
411     {
412       @Override
413       public void focusLost(FocusEvent e)
414       {
415         validateHmmerPath();
416       }
417     });
418     if (cygwinPath != null)
419     {
420       String path = Cache.getProperty(CYGWIN_PATH);
421       if (path == null)
422       {
423         path = FileUtils.getPathTo("bash");
424       }
425       cygwinPath.setText(path);
426       cygwinPath.addActionListener(new ActionListener()
427       {
428         @Override
429         public void actionPerformed(ActionEvent e)
430         {
431           validateCygwinPath();
432         }
433       });
434       cygwinPath.addFocusListener(new FocusAdapter()
435       {
436         @Override
437         public void focusLost(FocusEvent e)
438         {
439           validateCygwinPath();
440         }
441       });
442     }
443
444     /*
445      * Set Visual tab defaults
446      */
447     seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
448     rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
449     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
450     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
451
452     conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
453     quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
454     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
455     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
456     showUnconserved
457             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
458     showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
459     showGroupConsensus
460             .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
461     showGroupConservation.setSelected(
462             Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
463     showConsensHistogram.setSelected(
464             Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
465     showConsensLogo
466             .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
467     showInformationHistogram.setSelected(
468             Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
469     showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
470     showNpTooltip
471             .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
472     showDbRefTooltip
473             .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
474
475     String[] fonts = java.awt.GraphicsEnvironment
476             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
477     for (int i = 0; i < fonts.length; i++)
478     {
479       fontNameCB.addItem(fonts[i]);
480     }
481
482     for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
483     {
484       fontSizeCB.addItem(i + "");
485     }
486
487     fontStyleCB.addItem("plain");
488     fontStyleCB.addItem("bold");
489     fontStyleCB.addItem("italic");
490
491     fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
492     fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
493     fontStyleCB.setSelectedItem(
494             Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
495
496     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", true));
497     scaleProteinToCdna
498             .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
499
500     idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
501
502     wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
503
504     gapSymbolCB.addItem("-");
505     gapSymbolCB.addItem(".");
506
507     gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
508
509     sortby.addItem("No sort");
510     sortby.addItem("Id");
511     sortby.addItem("Pairwise Identity");
512     sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
513
514     sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
515     sortAnnBy
516             .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
517     sortAnnBy
518             .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
519     SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
520             .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
521                     SequenceAnnotationOrder.NONE.name()));
522     sortAnnBy.setSelectedItem(savedSort.toString());
523
524     sortAutocalc.addItem("Autocalculated first");
525     sortAutocalc.addItem("Autocalculated last");
526     final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
527     sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
528             : sortAutocalc.getItemAt(1));
529     startupCheckbox
530             .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
531     startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
532             Cache.getDefault("www.jalview.org", "https://www.jalview.org")
533                     + "/examples/exampleFile_2_7.jvp"));
534
535     /*
536      * Set Colours tab defaults
537      */
538     protColour.addItem(ResidueColourScheme.NONE);
539     nucColour.addItem(ResidueColourScheme.NONE);
540     for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
541     {
542       String name = cs.getSchemeName();
543       protColour.addItem(name);
544       nucColour.addItem(name);
545     }
546     String oldProp = Cache.getDefault(DEFAULT_COLOUR,
547             ResidueColourScheme.NONE);
548     String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
549     protColour.setSelectedItem(newProp != null ? newProp : oldProp);
550     newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
551     nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
552     minColour.setBackground(
553             Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
554     maxColour.setBackground(
555             Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
556
557     /*
558      * Set overview panel defaults
559      */
560     gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR,
561             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
562     hiddenColour.setBackground(Cache.getDefaultColour(HIDDEN_COLOUR,
563             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
564     useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
565     gapLabel.setEnabled(!useLegacyGap.isSelected());
566     gapColour.setEnabled(!useLegacyGap.isSelected());
567     showHiddenAtStart
568             .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
569
570     /*
571      * Set Structure tab defaults
572      */
573     final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, true);
574     structFromPdb.setSelected(structSelected);
575     addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, true));
576     addSecondaryStructure.setEnabled(structSelected);
577     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, true));
578     addTempFactor.setEnabled(structSelected);
579     /*
580      * set choice of structure viewer, and path if saved as a preference;
581      * default to Jmol (first choice) if an unexpected value is found
582      */
583     String viewerType = ViewerType.JMOL.name();
584     if (!Platform.isJS())
585     {
586       Cache.getDefault(STRUCTURE_DISPLAY,
587             ViewerType.JMOL.name());
588     }
589     // TODO - disable external viewers for JS
590     structViewer.setSelectedItem(viewerType);
591     String viewerPath = "";
592     ViewerType type = null;
593     try
594     {
595       type = ViewerType.valueOf(viewerType);
596       switch (type)
597       {
598       case JMOL:
599         break;
600       case CHIMERA:
601         viewerPath = Cache.getDefault(CHIMERA_PATH, "");
602         break;
603       case CHIMERAX:
604         viewerPath = Cache.getDefault(CHIMERAX_PATH, "");
605         break;
606       case PYMOL:
607         viewerPath = Cache.getDefault(PYMOL_PATH, "");
608         break;
609       }
610     } catch (IllegalArgumentException e)
611     {
612       Cache.log.error("Unknown structure viewer type: " + viewerType
613               + ", defaulting to Jmol");
614       type = ViewerType.JMOL;
615     }
616     structureViewerPath.setText(viewerPath);
617
618     structureViewerPath.addActionListener(new ActionListener()
619     {
620       @Override
621       public void actionPerformed(ActionEvent e)
622       {
623         if (validateViewerPath())
624         {
625           String path = structureViewerPath.getText();
626           try {
627           ViewerType type = ViewerType.valueOf(viewerType);
628           switch (type)
629           {
630           case JMOL:
631             break;
632           case CHIMERA:
633             Cache.setProperty(CHIMERA_PATH, path);
634             break;
635           case CHIMERAX:
636             Cache.setProperty(CHIMERAX_PATH, path);
637             break;
638           case PYMOL:
639             Cache.setProperty(PYMOL_PATH, path);
640             break;
641           }
642         } catch (IllegalArgumentException x)
643         {
644           Cache.log.error("Failed to set path - unknown viewer type",x);
645         }
646         }
647       }
648     });
649
650     if (Cache.getDefault("MAP_WITH_SIFTS", false))
651     {
652       siftsMapping.setSelected(true);
653     }
654     else
655     {
656       nwMapping.setSelected(true);
657     }
658
659     SiftsSettings
660             .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
661
662     /*
663      * Set Connections tab defaults
664      */
665
666     // set up sorting
667     linkUrlTable.setModel(dataModel);
668     final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
669             linkUrlTable.getModel());
670     linkUrlTable.setRowSorter(sorter);
671     List<RowSorter.SortKey> sortKeys = new ArrayList<>();
672
673     UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
674     sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
675             SortOrder.DESCENDING));
676     sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
677             SortOrder.DESCENDING));
678     sortKeys.add(
679             new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
680
681     sorter.setSortKeys(sortKeys);
682     // BH 2018 setSortKeys will do the sort
683     // sorter.sort();
684
685     // set up filtering
686     ActionListener onReset;
687     onReset = new ActionListener()
688     {
689       @Override
690       public void actionPerformed(ActionEvent e)
691       {
692         filterTB.setText("");
693         sorter.setRowFilter(RowFilter.regexFilter(""));
694       }
695
696     };
697     doReset.addActionListener(onReset);
698
699     // filter to display only custom urls
700     final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
701     {
702       @Override
703       public boolean include(
704               Entry<? extends TableModel, ? extends Object> entry)
705       {
706         return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
707       }
708     };
709
710     final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
711             linkUrlTable.getModel());
712     customSorter.setRowFilter(customUrlFilter);
713
714     ActionListener onCustomOnly;
715     onCustomOnly = new ActionListener()
716     {
717       @Override
718       public void actionPerformed(ActionEvent e)
719       {
720         filterTB.setText("");
721         sorter.setRowFilter(customUrlFilter);
722       }
723     };
724     userOnly.addActionListener(onCustomOnly);
725
726     filterTB.getDocument().addDocumentListener(new DocumentListener()
727     {
728       String caseInsensitiveFlag = "(?i)";
729
730       @Override
731       public void changedUpdate(DocumentEvent e)
732       {
733         sorter.setRowFilter(RowFilter
734                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
735       }
736
737       @Override
738       public void removeUpdate(DocumentEvent e)
739       {
740         sorter.setRowFilter(RowFilter
741                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
742       }
743
744       @Override
745       public void insertUpdate(DocumentEvent e)
746       {
747         sorter.setRowFilter(RowFilter
748                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
749       }
750     });
751
752     // set up list selection functionality
753     linkUrlTable.getSelectionModel()
754             .addListSelectionListener(new UrlListSelectionHandler());
755
756     // set up radio buttons
757     int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
758             .getPrimaryColumn();
759     String onClickName = linkUrlTable.getColumnName(onClickCol);
760     linkUrlTable.getColumn(onClickName)
761             .setCellRenderer(new RadioButtonRenderer());
762     linkUrlTable.getColumn(onClickName)
763             .setCellEditor(new RadioButtonEditor());
764
765     // get boolean columns and resize those to min possible
766     for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
767     {
768       if (linkUrlTable.getModel().getColumnClass(column)
769               .equals(Boolean.class))
770       {
771         TableColumn tableColumn = linkUrlTable.getColumnModel()
772                 .getColumn(column);
773         int preferredWidth = tableColumn.getMinWidth();
774
775         TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
776                 column);
777         Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
778         int cwidth = c.getPreferredSize().width
779                 + linkUrlTable.getIntercellSpacing().width;
780         preferredWidth = Math.max(preferredWidth, cwidth);
781
782         tableColumn.setPreferredWidth(preferredWidth);
783       }
784     }
785
786     String proxyTypeString = Cache.getDefault("USE_PROXY", "false");
787     previousProxyType = proxyTypeString;
788     switch (proxyTypeString)
789     {
790     case Cache.PROXYTYPE_NONE:
791       proxyType.setSelected(noProxy.getModel(), true);
792       break;
793     case Cache.PROXYTYPE_SYSTEM:
794       proxyType.setSelected(systemProxy.getModel(), true);
795       break;
796     case Cache.PROXYTYPE_CUSTOM:
797       proxyType.setSelected(customProxy.getModel(), true);
798       break;
799     default:
800       Cache.log.warn(
801               "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
802                       + proxyTypeString);
803     }
804     proxyServerHttpTB.setText(Cache.getDefault("PROXY_SERVER", ""));
805     proxyPortHttpTB.setText(Cache.getDefault("PROXY_PORT", ""));
806     proxyServerHttpsTB.setText(Cache.getDefault("PROXY_SERVER_HTTPS", ""));
807     proxyPortHttpsTB.setText(Cache.getDefault("PROXY_PORT_HTTPS", ""));
808     proxyAuth.setSelected(Cache.getDefault("PROXY_AUTH", false));
809     proxyAuthUsernameTB
810             .setText(Cache.getDefault("PROXY_AUTH_USERNAME", ""));
811     // we are not storing or retrieving proxy password from .jalview_properties
812     proxyAuthPasswordPB.setText(Cache.proxyAuthPassword == null ? ""
813             : new String(Cache.proxyAuthPassword));
814     setCustomProxyEnabled();
815     applyProxyButtonEnabled(false);
816
817     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
818
819     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
820     // note antisense here: default is true
821     questionnaire
822             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
823     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
824
825     /*
826      * Set Output tab defaults
827      */
828     setupOutputCombo(epsRendering, "EPS_RENDERING");
829     setupOutputCombo(htmlRendering, "HTML_RENDERING");
830     setupOutputCombo(svgRendering, "SVG_RENDERING");
831     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
832     userIdWidth.setEnabled(!autoIdWidth.isSelected());
833     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
834     Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
835     userIdWidth.setText(wi == null ? "" : wi.toString());
836     // TODO: refactor to use common enum via FormatAdapter and allow extension
837     // for new flat file formats
838     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
839     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
840     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
841     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
842     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
843     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
844     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
845     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
846     embbedBioJSON
847             .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
848
849     /*
850      * Set Editing tab defaults
851      */
852     autoCalculateConsCheck
853             .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
854     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
855     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
856
857     annotations_actionPerformed(null); // update the display of the annotation
858                                        // settings
859     
860     
861     /*
862      * Set Backups tab defaults
863      */
864     loadLastSavedBackupsOptions();
865   }
866
867   /**
868    * A helper method that sets the items and initial selection in a character
869    * rendering option list (Prompt each time/Lineart/Text)
870    * 
871    * @param comboBox
872    * @param propertyKey
873    */
874   protected void setupOutputCombo(JComboBox<Object> comboBox,
875           String propertyKey)
876   {
877     comboBox.addItem(promptEachTimeOpt);
878     comboBox.addItem(lineArtOpt);
879     comboBox.addItem(textOpt);
880     
881     /*
882      * JalviewJS doesn't support Lineart so force it to Text
883      */
884     String defaultOption = Platform.isJS() ? "Text"
885             : Cache.getDefault(propertyKey, "Prompt each time");
886     if (defaultOption.equalsIgnoreCase("Text"))
887     {
888       comboBox.setSelectedItem(textOpt);
889     }
890     else if (defaultOption.equalsIgnoreCase("Lineart"))
891     {
892       comboBox.setSelectedItem(lineArtOpt);
893     }
894     else
895     {
896       comboBox.setSelectedItem(promptEachTimeOpt);
897     }
898   }
899
900   /**
901    * Save user selections on the Preferences tabs to the Cache and write out to
902    * file.
903    * 
904    * @param e
905    */
906   @Override
907   public void ok_actionPerformed(ActionEvent e)
908   {
909     if (!validateSettings())
910     {
911       return;
912     }
913
914     /* 
915      * Set proxy settings first (to be before web services refresh)
916      */
917     saveProxySettings();
918     /*
919      * Save Visual settings
920      */
921     Cache.setPropertyNoSave("SHOW_JVSUFFIX",
922             Boolean.toString(seqLimit.isSelected()));
923     Cache.setPropertyNoSave("RIGHT_ALIGN_IDS",
924             Boolean.toString(rightAlign.isSelected()));
925     Cache.setPropertyNoSave("SHOW_FULLSCREEN",
926             Boolean.toString(fullScreen.isSelected()));
927     Cache.setPropertyNoSave("SHOW_OVERVIEW",
928             Boolean.toString(openoverv.isSelected()));
929     Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
930             Boolean.toString(annotations.isSelected()));
931     Cache.setPropertyNoSave("SHOW_CONSERVATION",
932             Boolean.toString(conservation.isSelected()));
933     Cache.setPropertyNoSave("SHOW_QUALITY",
934             Boolean.toString(quality.isSelected()));
935     Cache.setPropertyNoSave("SHOW_IDENTITY",
936             Boolean.toString(identity.isSelected()));
937
938     Cache.setPropertyNoSave("GAP_SYMBOL",
939             gapSymbolCB.getSelectedItem().toString());
940
941     Cache.setPropertyNoSave("FONT_NAME",
942             fontNameCB.getSelectedItem().toString());
943     Cache.setPropertyNoSave("FONT_STYLE",
944             fontStyleCB.getSelectedItem().toString());
945     Cache.setPropertyNoSave("FONT_SIZE",
946             fontSizeCB.getSelectedItem().toString());
947
948     Cache.setPropertyNoSave("ID_ITALICS",
949             Boolean.toString(idItalics.isSelected()));
950     Cache.setPropertyNoSave("SHOW_UNCONSERVED",
951             Boolean.toString(showUnconserved.isSelected()));
952     Cache.setPropertyNoSave(SHOW_OCCUPANCY,
953             Boolean.toString(showOccupancy.isSelected()));
954     Cache.setPropertyNoSave("SHOW_GROUP_CONSENSUS",
955             Boolean.toString(showGroupConsensus.isSelected()));
956     Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION",
957             Boolean.toString(showGroupConservation.isSelected()));
958     Cache.setPropertyNoSave("SHOW_CONSENSUS_HISTOGRAM",
959             Boolean.toString(showConsensHistogram.isSelected()));
960     Cache.setPropertyNoSave("SHOW_CONSENSUS_LOGO",
961             Boolean.toString(showConsensLogo.isSelected()));
962     Cache.setPropertyNoSave("SHOW_INFORMATION_HISTOGRAM",
963             Boolean.toString(showConsensHistogram.isSelected()));
964     Cache.setPropertyNoSave("SHOW_HMM_LOGO",
965             Boolean.toString(showHMMLogo.isSelected()));
966     Cache.setPropertyNoSave("ANTI_ALIAS",
967             Boolean.toString(smoothFont.isSelected()));
968     Cache.setPropertyNoSave(SCALE_PROTEIN_TO_CDNA,
969             Boolean.toString(scaleProteinToCdna.isSelected()));
970     Cache.setPropertyNoSave("SHOW_NPFEATS_TOOLTIP",
971             Boolean.toString(showNpTooltip.isSelected()));
972     Cache.setPropertyNoSave("SHOW_DBREFS_TOOLTIP",
973             Boolean.toString(showDbRefTooltip.isSelected()));
974
975     Cache.setPropertyNoSave("WRAP_ALIGNMENT",
976             Boolean.toString(wrap.isSelected()));
977
978     Cache.setPropertyNoSave("STARTUP_FILE",
979             startupFileTextfield.getText());
980     Cache.setPropertyNoSave("SHOW_STARTUP_FILE",
981             Boolean.toString(startupCheckbox.isSelected()));
982
983     Cache.setPropertyNoSave("SORT_ALIGNMENT",
984             sortby.getSelectedItem().toString());
985
986     // convert description of sort order to enum name for save
987     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
988             .forDescription(sortAnnBy.getSelectedItem().toString());
989     if (annSortOrder != null)
990     {
991       Cache.setPropertyNoSave(SORT_ANNOTATIONS,
992               annSortOrder.name());
993     }
994
995     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
996     Cache.setPropertyNoSave(SHOW_AUTOCALC_ABOVE,
997             Boolean.valueOf(showAutocalcFirst).toString());
998
999     /*
1000      * Save Colours settings
1001      */
1002     Cache.setPropertyNoSave(DEFAULT_COLOUR_PROT,
1003             protColour.getSelectedItem().toString());
1004     Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
1005             nucColour.getSelectedItem().toString());
1006     Cache.setColourPropertyNoSave("ANNOTATIONCOLOUR_MIN",
1007             minColour.getBackground());
1008     Cache.setColourPropertyNoSave("ANNOTATIONCOLOUR_MAX",
1009             maxColour.getBackground());
1010
1011     /*
1012      * Save HMMER settings
1013      */
1014     Cache.setPropertyNoSave(HMMALIGN_TRIM_TERMINI,
1015             Boolean.toString(hmmrTrimTermini.isSelected()));
1016     Cache.setPropertyNoSave(HMMINFO_GLOBAL_BACKGROUND,
1017             Boolean.toString(hmmerBackgroundUniprot.isSelected()));
1018     Cache.setPropertyNoSave(HMMSEARCH_SEQCOUNT,
1019             hmmerSequenceCount.getText());
1020     Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
1021     if (cygwinPath != null)
1022     {
1023       Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
1024     }
1025     AlignFrame[] frames = Desktop.getAlignFrames();
1026     if (frames != null && frames.length > 0)
1027     {
1028       for (AlignFrame f : frames)
1029       {
1030         f.updateHMMERStatus();
1031       }
1032     }
1033     
1034     hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
1035     if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
1036     {
1037       hmmerBackgroundUniprot.setSelected(true);
1038     }
1039     else
1040     {
1041       hmmerBackgroundAlignment.setSelected(true);
1042     }
1043     hmmerSequenceCount
1044             .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
1045     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
1046
1047     /*
1048      * Save Overview settings
1049      */
1050     Cache.setColourPropertyNoSave(GAP_COLOUR, gapColour.getBackground());
1051     Cache.setColourPropertyNoSave(HIDDEN_COLOUR, hiddenColour.getBackground());
1052     Cache.setPropertyNoSave(USE_LEGACY_GAP,
1053             Boolean.toString(useLegacyGap.isSelected()));
1054     Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START,
1055             Boolean.toString(showHiddenAtStart.isSelected()));
1056
1057     /*
1058      * Save Structure settings
1059      */
1060     Cache.setPropertyNoSave(ADD_TEMPFACT_ANN,
1061             Boolean.toString(addTempFactor.isSelected()));
1062     Cache.setPropertyNoSave(ADD_SS_ANN,
1063             Boolean.toString(addSecondaryStructure.isSelected()));
1064     Cache.setPropertyNoSave(STRUCT_FROM_PDB,
1065             Boolean.toString(structFromPdb.isSelected()));
1066     if (!Platform.isJS()) {
1067     String viewer = structViewer.getSelectedItem().toString();
1068     String viewerPath = structureViewerPath.getText();
1069     Cache.setPropertyNoSave(STRUCTURE_DISPLAY, viewer);
1070     if (viewer.equals(ViewerType.CHIMERA.name()))
1071     {
1072       Cache.setOrRemove(CHIMERA_PATH, viewerPath);
1073     }
1074     else if (viewer.equals(ViewerType.CHIMERAX.name()))
1075     {
1076       Cache.setOrRemove(CHIMERAX_PATH, viewerPath);
1077     }
1078     else if (viewer.equals(ViewerType.PYMOL.name()))
1079     {
1080       Cache.setOrRemove(PYMOL_PATH, viewerPath);
1081     }
1082     } // nojs
1083     Cache.setPropertyNoSave("MAP_WITH_SIFTS",
1084             Boolean.toString(siftsMapping.isSelected()));
1085     SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
1086
1087     /*
1088      * Save Output settings
1089      */
1090     Cache.setPropertyNoSave("EPS_RENDERING",
1091             ((OptionsParam) epsRendering.getSelectedItem()).getCode());
1092     Cache.setPropertyNoSave("HTML_RENDERING",
1093             ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
1094     Cache.setPropertyNoSave("SVG_RENDERING",
1095             ((OptionsParam) svgRendering.getSelectedItem()).getCode());
1096
1097     /*
1098      * Save Connections settings
1099      */
1100     // Proxy settings were already set first (to catch web services)
1101     Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
1102
1103     jalview.util.BrowserLauncher.resetBrowser();
1104
1105     // save user-defined and selected links
1106     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
1107     if (menuLinks.isEmpty())
1108     {
1109       Cache.removePropertyNoSave("SEQUENCE_LINKS");
1110     }
1111     else
1112     {
1113       Cache.setPropertyNoSave("SEQUENCE_LINKS",
1114               menuLinks.toString());
1115     }
1116
1117     String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
1118     if (nonMenuLinks.isEmpty())
1119     {
1120       Cache.removePropertyNoSave("STORED_LINKS");
1121     }
1122     else
1123     {
1124       Cache.setPropertyNoSave("STORED_LINKS",
1125               nonMenuLinks.toString());
1126     }
1127
1128     Cache.setPropertyNoSave("DEFAULT_URL",
1129             sequenceUrlLinks.getPrimaryUrlId());
1130
1131     Cache.setProperty("VERSION_CHECK",
1132             Boolean.toString(versioncheck.isSelected()));
1133     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
1134     {
1135       // default is false - we only set this if the user has actively agreed
1136       Cache.setProperty("USAGESTATS",
1137               Boolean.toString(usagestats.isSelected()));
1138     }
1139     if (!questionnaire.isSelected())
1140     {
1141       Cache.setProperty("NOQUESTIONNAIRES", "true");
1142     }
1143     else
1144     {
1145       // special - made easy to edit a property file to disable questionnaires
1146       // by just adding the given line
1147       Cache.removeProperty("NOQUESTIONNAIRES");
1148     }
1149
1150     /*
1151      * Save Output settings
1152      */
1153     Cache.setPropertyNoSave("BLC_JVSUFFIX",
1154             Boolean.toString(blcjv.isSelected()));
1155     Cache.setPropertyNoSave("CLUSTAL_JVSUFFIX",
1156             Boolean.toString(clustaljv.isSelected()));
1157     Cache.setPropertyNoSave("FASTA_JVSUFFIX",
1158             Boolean.toString(fastajv.isSelected()));
1159     Cache.setPropertyNoSave("MSF_JVSUFFIX",
1160             Boolean.toString(msfjv.isSelected()));
1161     Cache.setPropertyNoSave("PFAM_JVSUFFIX",
1162             Boolean.toString(pfamjv.isSelected()));
1163     Cache.setPropertyNoSave("PILEUP_JVSUFFIX",
1164             Boolean.toString(pileupjv.isSelected()));
1165     Cache.setPropertyNoSave("PIR_JVSUFFIX",
1166             Boolean.toString(pirjv.isSelected()));
1167     Cache.setPropertyNoSave("PIR_MODELLER",
1168             Boolean.toString(modellerOutput.isSelected()));
1169     Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON",
1170             Boolean.toString(embbedBioJSON.isSelected()));
1171     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
1172
1173     Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH",
1174             Boolean.toString(autoIdWidth.isSelected()));
1175     userIdWidth_actionPerformed();
1176     Cache.setPropertyNoSave("FIGURE_FIXEDIDWIDTH",
1177             userIdWidth.getText());
1178
1179     /*
1180      * Save Editing settings
1181      */
1182     Cache.setPropertyNoSave("AUTO_CALC_CONSENSUS",
1183             Boolean.toString(autoCalculateConsCheck.isSelected()));
1184     Cache.setPropertyNoSave("SORT_BY_TREE",
1185             Boolean.toString(sortByTree.isSelected()));
1186     Cache.setPropertyNoSave("PAD_GAPS",
1187             Boolean.toString(padGaps.isSelected()));
1188
1189     if (!Platform.isJS())
1190     {
1191       wsPrefs.updateAndRefreshWsMenuConfig(false);
1192     }
1193
1194     /*
1195      * Save Backups settings
1196      */
1197     Cache.setPropertyNoSave(BackupFiles.ENABLED,
1198             Boolean.toString(enableBackupFiles.isSelected()));
1199     int preset = getComboIntStringKey(backupfilesPresetsCombo);
1200     Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
1201
1202     if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
1203     {
1204       BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
1205       BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
1206               BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
1207       Cache.applicationProperties
1208               .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
1209                       customBFPE.toString());
1210     }
1211
1212     BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
1213             .get(preset);
1214     Cache.setPropertyNoSave(
1215             BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
1216
1217     Cache.saveProperties();
1218     Desktop.getInstance().doConfigureStructurePrefs();
1219     try
1220     {
1221       frame.setClosed(true);
1222     } catch (Exception ex)
1223     {
1224     }
1225   }
1226   public void saveProxySettings()
1227   {
1228     String newProxyType = customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
1229             : noProxy.isSelected() ? Cache.PROXYTYPE_NONE
1230                     : Cache.PROXYTYPE_SYSTEM;
1231     Cache.setPropertyNoSave("USE_PROXY", newProxyType);
1232     Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText());
1233     Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
1234     Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
1235     Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText());
1236     Cache.setOrRemove("PROXY_AUTH",
1237             Boolean.toString(proxyAuth.isSelected()));
1238     Cache.setOrRemove("PROXY_AUTH_USERNAME", proxyAuthUsernameTB.getText());
1239     Cache.proxyAuthPassword = proxyAuthPasswordPB.getPassword();
1240     Cache.setProxyPropertiesFromPreferences(previousProxyType);
1241     if (newProxyType.equals(Cache.PROXYTYPE_CUSTOM)
1242             || !newProxyType.equals(previousProxyType))
1243     {
1244       // force a re-lookup of ws if proxytype is custom or has changed
1245       wsPrefs.update++;
1246     }
1247     previousProxyType = newProxyType;
1248   }
1249
1250   public static void setAppletDefaults()
1251   {
1252
1253     // http://www.jalview.org/old/v2_8/examples/appletParameters.html
1254
1255     // showConservation true or false Default is true.
1256     // showQuality true or false Default is true.
1257     // showConsensus true or false Default is true.
1258     // showFeatureSettings true or false Shows the feature settings window when
1259     // startin
1260     // showTreeBootstraps true or false (default is true) show or hide branch
1261     // bootstraps
1262     // showTreeDistances true or false (default is true) show or hide branch
1263     // lengths
1264     // showUnlinkedTreeNodes true or false (default is false) indicate if
1265     // unassociated nodes should be highlighted in the tree view
1266     // showUnconserved true of false (default is false) When true, only gaps and
1267     // symbols different to the consensus sequence ions of the alignment
1268     // showGroupConsensus true of false (default is false) When true, shows
1269     // consensus annotation row for any groups on the alignment. (since 2.7)
1270     // showGroupConservation true of false (default is false) When true, shows
1271     // amino-acid property conservation annotation row for any groups on the
1272     // showConsensusHistogram true of false (default is true) When true, shows
1273     // the percentage occurence of the consensus symbol for each column as a
1274     // showSequenceLogo true of false (default is false) When true, shows a
1275     // sequence logo above the consensus sequence (overlaid above the Consensus
1276
1277     Cache.setPropertyNoSave(SHOW_CONSERVATION, "true");
1278     Cache.setPropertyNoSave(SHOW_QUALITY, "false");
1279     Cache.setPropertyNoSave(SHOW_CONSENSUS, "true");
1280     Cache.setPropertyNoSave(SHOW_UNCONSERVED, "false");
1281     Cache.setPropertyNoSave(SHOW_GROUP_CONSERVATION, "false");
1282     Cache.setPropertyNoSave(SHOW_GROUP_CONSENSUS, "false");
1283
1284     // TODO -- just a start here
1285   }
1286  /**
1287    * Do any necessary validation before saving settings. Return focus to the
1288    * first tab which fails validation.
1289    * 
1290    * @return
1291    */
1292   private boolean validateSettings()
1293   {
1294     if (!validateStructure())
1295     {
1296       structureTab.requestFocusInWindow();
1297       return false;
1298     }
1299     return true;
1300   }
1301
1302   @Override
1303   protected boolean validateStructure()
1304   {
1305     return validateViewerPath();
1306
1307   }
1308
1309   /**
1310    * DOCUMENT ME!
1311    */
1312   @Override
1313   public void startupFileTextfield_mouseClicked()
1314   {
1315     // TODO: JAL-3048 not needed for Jalview-JS
1316     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
1317     JalviewFileChooser chooser = JalviewFileChooser
1318             .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
1319     chooser.setFileView(new JalviewFileView());
1320     chooser.setDialogTitle(
1321             MessageManager.getString("label.select_startup_file"));
1322
1323     int value = chooser.showOpenDialog(this);
1324
1325     if (value == JalviewFileChooser.APPROVE_OPTION)
1326     {
1327       FileFormatI format = chooser.getSelectedFormat();
1328       if (format != null)
1329       {
1330         Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
1331                 format.getName());
1332       }
1333       startupFileTextfield
1334               .setText(chooser.getSelectedFile().getAbsolutePath());
1335     }
1336   }
1337
1338   /**
1339    * DOCUMENT ME!
1340    * 
1341    * @param e
1342    *          DOCUMENT ME!
1343    */
1344   @Override
1345   public void cancel_actionPerformed(ActionEvent e)
1346   {
1347     try
1348     {
1349       if (!Platform.isJS())
1350       {
1351         wsPrefs.updateWsMenuConfig(true);
1352         wsPrefs.refreshWs_actionPerformed(e);
1353       }
1354       frame.setClosed(true);
1355     } catch (Exception ex)
1356     {
1357     }
1358   }
1359
1360   /**
1361    * DOCUMENT ME!
1362    * 
1363    * @param e
1364    *          DOCUMENT ME!
1365    */
1366   @Override
1367   public void annotations_actionPerformed(ActionEvent e)
1368   {
1369     conservation.setEnabled(annotations.isSelected());
1370     quality.setEnabled(annotations.isSelected());
1371     identity.setEnabled(annotations.isSelected());
1372     showOccupancy.setEnabled(annotations.isSelected());
1373     showGroupConsensus.setEnabled(annotations.isSelected());
1374     showGroupConservation.setEnabled(annotations.isSelected());
1375     showConsensHistogram.setEnabled(annotations.isSelected()
1376             && (identity.isSelected() || showGroupConsensus.isSelected()));
1377     showConsensLogo.setEnabled(annotations.isSelected()
1378             && (identity.isSelected() || showGroupConsensus.isSelected()));
1379     showInformationHistogram.setEnabled(annotations.isSelected());
1380     showHMMLogo.setEnabled(annotations.isSelected());
1381   }
1382
1383   @Override
1384   public void newLink_actionPerformed(ActionEvent e)
1385   {
1386     GSequenceLink link = new GSequenceLink();
1387     boolean valid = false;
1388     while (!valid)
1389     {
1390       if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1391               MessageManager.getString("label.new_sequence_url_link"),
1392               JvOptionPane.OK_CANCEL_OPTION, -1,
1393               null) == JvOptionPane.OK_OPTION)
1394       {
1395         if (link.checkValid())
1396         {
1397           if (((UrlLinkTableModel) linkUrlTable.getModel())
1398                   .isUniqueName(link.getName()))
1399           {
1400             ((UrlLinkTableModel) linkUrlTable.getModel())
1401                     .insertRow(link.getName(), link.getURL());
1402             valid = true;
1403           }
1404           else
1405           {
1406             link.notifyDuplicate();
1407             continue;
1408           }
1409         }
1410       }
1411       else
1412       {
1413         break;
1414       }
1415     }
1416   }
1417
1418   @Override
1419   public void editLink_actionPerformed(ActionEvent e)
1420   {
1421     GSequenceLink link = new GSequenceLink();
1422
1423     int index = linkUrlTable.getSelectedRow();
1424     if (index == -1)
1425     {
1426       // button no longer enabled if row is not selected
1427       Cache.log.debug("Edit with no row selected in linkUrlTable");
1428       return;
1429     }
1430
1431     int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1432             .getNameColumn();
1433     int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1434             .getUrlColumn();
1435     String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1436     link.setName(oldName);
1437     link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1438
1439     boolean valid = false;
1440     while (!valid)
1441     {
1442       if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1443               MessageManager.getString("label.edit_sequence_url_link"),
1444               JvOptionPane.OK_CANCEL_OPTION, -1,
1445               null) == JvOptionPane.OK_OPTION)
1446       {
1447         if (link.checkValid())
1448         {
1449           if ((oldName.equals(link.getName()))
1450                   || (((UrlLinkTableModel) linkUrlTable.getModel())
1451                           .isUniqueName(link.getName())))
1452           {
1453             linkUrlTable.setValueAt(link.getName(), index, nameCol);
1454             linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1455             valid = true;
1456           }
1457           else
1458           {
1459             link.notifyDuplicate();
1460             continue;
1461           }
1462         }
1463       }
1464       else
1465       {
1466         break;
1467       }
1468     }
1469   }
1470
1471   @Override
1472   public void deleteLink_actionPerformed(ActionEvent e)
1473   {
1474     int index = linkUrlTable.getSelectedRow();
1475     int modelIndex = -1;
1476     if (index == -1)
1477     {
1478       // button no longer enabled if row is not selected
1479       Cache.log.debug("Delete with no row selected in linkUrlTable");
1480       return;
1481     }
1482     else
1483     {
1484       modelIndex = linkUrlTable.convertRowIndexToModel(index);
1485     }
1486
1487     // make sure we use the model index to delete, and not the table index
1488     ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1489   }
1490
1491   @Override
1492   public void defaultBrowser_mouseClicked(MouseEvent e)
1493   {
1494     // TODO: JAL-3048 not needed for j2s
1495     if (!Platform.isJS()) // BH 2019
1496     /**
1497      * Java only
1498      * 
1499      * @j2sIgnore
1500      */
1501     {
1502       JFileChooser chooser = new JFileChooser(".");
1503       chooser.setDialogTitle(
1504               MessageManager.getString("label.select_default_browser"));
1505
1506       int value = chooser.showOpenDialog(this);
1507
1508       if (value == JFileChooser.APPROVE_OPTION)
1509       {
1510         defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1511       }
1512     }
1513   }
1514
1515   /*
1516    * (non-Javadoc)
1517    * 
1518    * @see
1519    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1520    * .ActionEvent)
1521    */
1522   @Override
1523   protected void showunconserved_actionPerformed(ActionEvent e)
1524   {
1525     // TODO Auto-generated method stub
1526     super.showunconserved_actionPerformed(e);
1527   }
1528
1529   public static List<String> getGroupURLLinks()
1530   {
1531     return groupURLLinks;
1532   }
1533
1534   @Override
1535   public void minColour_actionPerformed(JPanel panel)
1536   {
1537     JalviewColourChooser.showColourChooser(this,
1538             MessageManager.getString("label.select_colour_minimum_value"),
1539             panel);
1540   }
1541
1542   @Override
1543   public void maxColour_actionPerformed(JPanel panel)
1544   {
1545     JalviewColourChooser.showColourChooser(this,
1546             MessageManager.getString("label.select_colour_maximum_value"),
1547             panel);
1548   }
1549
1550   @Override
1551   public void gapColour_actionPerformed(JPanel gap)
1552   {
1553     if (!useLegacyGap.isSelected())
1554     {
1555       JalviewColourChooser.showColourChooser(this,
1556               MessageManager.getString("label.select_gap_colour"),
1557               gap);
1558     }
1559   }
1560
1561   @Override
1562   public void hiddenColour_actionPerformed(JPanel hidden)
1563   {
1564     JalviewColourChooser.showColourChooser(this,
1565             MessageManager.getString("label.select_hidden_colour"),
1566             hidden);
1567   }
1568
1569   @Override
1570   protected void useLegacyGaps_actionPerformed(ActionEvent e)
1571   {
1572     boolean enabled = useLegacyGap.isSelected();
1573     if (enabled)
1574     {
1575       gapColour.setBackground(
1576               jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1577     }
1578     else
1579     {
1580       gapColour.setBackground(
1581               jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1582     }
1583     gapColour.setEnabled(!enabled);
1584     gapLabel.setEnabled(!enabled);
1585   }
1586
1587   @Override
1588   protected void resetOvDefaults_actionPerformed(ActionEvent e)
1589   {
1590     useLegacyGap.setSelected(false);
1591     useLegacyGaps_actionPerformed(null);
1592     showHiddenAtStart.setSelected(false);
1593     hiddenColour.setBackground(
1594             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1595   }
1596
1597   @Override
1598   protected void userIdWidth_actionPerformed()
1599   {
1600     try
1601     {
1602       String val = userIdWidth.getText().trim();
1603       if (val.length() > 0)
1604       {
1605         Integer iw = Integer.parseInt(val);
1606         if (iw.intValue() < 12)
1607         {
1608           throw new NumberFormatException();
1609         }
1610         userIdWidth.setText(iw.toString());
1611       }
1612     } catch (NumberFormatException x)
1613     {
1614       userIdWidth.setText("");
1615       JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1616               MessageManager
1617                       .getString("warn.user_defined_width_requirements"),
1618               MessageManager.getString("label.invalid_id_column_width"),
1619               JvOptionPane.WARNING_MESSAGE);
1620     }
1621   }
1622
1623   @Override
1624   protected void autoIdWidth_actionPerformed()
1625   {
1626     userIdWidth.setEnabled(!autoIdWidth.isSelected());
1627     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1628   }
1629
1630   /**
1631    * Returns true if structure viewer path is to a valid executable, else shows an
1632    * error dialog. Does nothing if the path is empty, as is the case for Jmol
1633    * (built in to Jalview) or when Jalview is left to try default paths.
1634    */
1635   private boolean validateViewerPath()
1636   {
1637     if (structureViewerPath.getText().trim().length() > 0)
1638     {
1639       File f = new File(structureViewerPath.getText());
1640       if (!f.canExecute())
1641       {
1642         JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1643                 MessageManager.getString("label.invalid_viewer_path"),
1644                 MessageManager.getString("label.invalid_viewer_path"),
1645                 JvOptionPane.ERROR_MESSAGE);
1646         return false;
1647       }
1648     }
1649     return true;
1650   }
1651   
1652   /**
1653    * Returns true if the given text field contains a path to a folder that
1654    * contains an executable with the given name, else false (after showing a
1655    * warning dialog). The executable name will be tried with .exe appended if not
1656    * found.
1657    * 
1658    * @param textField
1659    * @param executable
1660    */
1661   protected boolean validateExecutablePath(JTextField textField, String executable)
1662   {
1663     String folder = textField.getText().trim();
1664
1665     if (FileUtils.getExecutable(executable, folder) != null)
1666     {
1667       return true;
1668     }
1669     if (folder.length() > 0)
1670     {
1671       JvOptionPane.showInternalMessageDialog(Desktop.getInstance(),
1672               MessageManager.formatMessage("label.executable_not_found",
1673                       executable),
1674               MessageManager.getString("label.invalid_folder"),
1675               JvOptionPane.ERROR_MESSAGE);
1676     }
1677     return false;
1678   }
1679
1680   /**
1681    * Checks if a file can be executed
1682    * 
1683    * @param path
1684    *          the path to the file
1685    * @return
1686    */
1687   public boolean canExecute(String path)
1688   {
1689     File file = new File(path);
1690     if (!file.canExecute())
1691     {
1692       file = new File(path + ".exe");
1693       {
1694         if (!file.canExecute())
1695         {
1696           return false;
1697         }
1698       }
1699     }
1700     return true;
1701   }
1702
1703   /**
1704    * If Chimera or ChimeraX or Pymol is selected, check it can be found on default
1705    * or user-specified path, if not show a warning/help dialog
1706    */
1707   @Override
1708   protected void structureViewer_actionPerformed(String selectedItem)
1709   {
1710     if (selectedItem.equals(ViewerType.JMOL.name()))
1711     {
1712       structureViewerPath.setEnabled(false);
1713       structureViewerPathLabel.setEnabled(false);
1714       return;
1715     }
1716     boolean found = false;
1717     structureViewerPath.setEnabled(true);
1718     structureViewerPathLabel.setEnabled(true);
1719     structureViewerPathLabel.setText(MessageManager
1720             .formatMessage("label.viewer_path", selectedItem));
1721
1722     /*
1723      * Try user-specified and standard paths for structure viewer executable
1724      */
1725     String viewerPath = "";
1726     List<String> paths = null;
1727     try
1728     {
1729       ViewerType viewerType = ViewerType.valueOf(selectedItem);
1730       switch (viewerType)
1731       {
1732       case JMOL:
1733         // dealt with above
1734         break;
1735       case CHIMERA:
1736         viewerPath = Cache.getDefault(CHIMERA_PATH, "");
1737         paths = StructureManager.getChimeraPaths(false);
1738         break;
1739       case CHIMERAX:
1740         viewerPath = Cache.getDefault(CHIMERAX_PATH, "");
1741         paths = StructureManager.getChimeraPaths(true);
1742         break;
1743       case PYMOL:
1744         viewerPath = Cache.getDefault(PYMOL_PATH, "");
1745         paths = PymolManager.getPymolPaths();
1746         break;
1747       }
1748     } catch (IllegalArgumentException e)
1749     {
1750       // only valid entries should be in the drop-down
1751     }
1752     structureViewerPath.setText(viewerPath);
1753
1754     paths.add(0, structureViewerPath.getText());
1755     for (String path : paths)
1756     {
1757       if (new File(path.trim()).canExecute())
1758       {
1759         found = true;
1760         break;
1761       }
1762     }
1763     if (!found)
1764     {
1765       String[] options = { "OK", "Help" };
1766       int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
1767               JvSwingUtils.wrapTooltip(true,
1768                       MessageManager.getString("label.viewer_missing")),
1769               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1770               null, options, options[0]);
1771       if (showHelp == JvOptionPane.NO_OPTION)
1772       {
1773         this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null);
1774         try
1775         {
1776           Help.showHelpWindow(HelpId.StructureViewer);
1777         } catch (HelpSetException e)
1778         {
1779           e.printStackTrace();
1780         }
1781       }
1782       else if (showHelp == JvOptionPane.OK_OPTION)
1783       {
1784         this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null);
1785         CompletableFuture<Void> cf = CompletableFuture.runAsync(() -> {
1786           try
1787           {
1788             for (int i = 0; i < 3; i++)
1789             {
1790               structureViewerPath.setBackground(Color.PINK);
1791               Thread.sleep(500);
1792               structureViewerPath.setBackground(Color.WHITE);
1793               Thread.sleep(500);
1794             }
1795           } catch (InterruptedException e)
1796           {
1797           }
1798         });
1799       }
1800      }
1801   }
1802
1803   @Override
1804   protected void validateHmmerPath()
1805   {
1806     validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1807   }
1808
1809   @Override
1810   protected void validateCygwinPath()
1811   {
1812     validateExecutablePath(cygwinPath, "run");
1813   }
1814
1815   public class OptionsParam
1816   {
1817     private String name;
1818
1819     private String code;
1820
1821     public OptionsParam(String name, String code)
1822     {
1823       this.name = name;
1824       this.code = code;
1825     }
1826
1827     public String getName()
1828     {
1829       return name;
1830     }
1831
1832     public void setName(String name)
1833     {
1834       this.name = name;
1835     }
1836
1837     public String getCode()
1838     {
1839       return code;
1840     }
1841
1842     public void setCode(String code)
1843     {
1844       this.code = code;
1845     }
1846
1847     @Override
1848     public String toString()
1849     {
1850       return name;
1851     }
1852
1853     @Override
1854     public boolean equals(Object that)
1855     {
1856       if (!(that instanceof OptionsParam))
1857       {
1858         return false;
1859       }
1860       return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1861     }
1862
1863     @Override
1864     public int hashCode()
1865     {
1866       return name.hashCode() + code.hashCode();
1867     }
1868   }
1869
1870   private class UrlListSelectionHandler implements ListSelectionListener
1871   {
1872
1873     @Override
1874     public void valueChanged(ListSelectionEvent e)
1875     {
1876       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1877
1878       int index = lsm.getMinSelectionIndex();
1879       if (index == -1)
1880       {
1881         // no selection, so disable delete/edit buttons
1882         editLink.setEnabled(false);
1883         deleteLink.setEnabled(false);
1884         return;
1885       }
1886       int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1887
1888       // enable/disable edit and delete link buttons
1889       if (((UrlLinkTableModel) linkUrlTable.getModel())
1890               .isRowDeletable(modelIndex))
1891       {
1892         deleteLink.setEnabled(true);
1893       }
1894       else
1895       {
1896         deleteLink.setEnabled(false);
1897       }
1898
1899       if (((UrlLinkTableModel) linkUrlTable.getModel())
1900               .isRowEditable(modelIndex))
1901       {
1902         editLink.setEnabled(true);
1903       }
1904       else
1905       {
1906         editLink.setEnabled(false);
1907       }
1908     }
1909   }
1910 }