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