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