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