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