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