Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.gui

File Preferences.java

 

Coverage histogram

../../img/srcFileCovDistChart1.png
56% of files have more coverage

Code metrics

128
565
45
3
1,618
1,206
138
0.24
12.56
15
3.07

Classes

Class Line # Actions
Preferences 90 541 125
0.0200860842%
Preferences.OptionsParam 1523 11 9
0.00%
Preferences.UrlListSelectionHandler 1578 13 4
0.00%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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