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