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