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