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