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