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