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