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