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