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