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