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