Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:38:20 GMT
  2. Package jalview.gui

File Preferences.java

 

Coverage histogram

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

Code metrics

132
569
45
3
1,630
1,217
140
0.25
12.64
15
3.11

Classes

Class Line # Actions
Preferences 90 545 127
0.0184397161.8%
Preferences.OptionsParam 1535 11 9
0.00%
Preferences.UrlListSelectionHandler 1590 13 4
0.00%
 

Contributing tests

This file is covered by 1 test. .

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  5 toggle static
160    {
161    // don't populate with session properties
162  5 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  5 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
167  5 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
168  5 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  5 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
174    {
175  5 inMenuString = UrlConstants.DEFAULT_STRING;
176    }
177  5 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
178    inMenuString, notInMenuString);
179  5 sequenceUrlLinks = factory.createUrlProvider();
180  5 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  5 groupURLLinks = new ArrayList<>();
188   
189    // reenable
190  5 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 @Override
1052    public void saveProxySettings()
1053    {
1054  0 Cache.disableSessionProperties();
1055   
1056  0 String newProxyType = customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
1057  0 : noProxy.isSelected() ? Cache.PROXYTYPE_NONE
1058    : Cache.PROXYTYPE_SYSTEM;
1059  0 Cache.applicationProperties.setProperty("USE_PROXY", newProxyType);
1060  0 Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText());
1061  0 Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
1062  0 Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
1063  0 Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText());
1064  0 Cache.setOrRemove("PROXY_AUTH",
1065    Boolean.toString(proxyAuth.isSelected()));
1066  0 Cache.setOrRemove("PROXY_AUTH_USERNAME", proxyAuthUsernameTB.getText());
1067  0 Cache.proxyAuthPassword = proxyAuthPasswordPB.getPassword();
1068  0 Cache.setProxyPropertiesFromPreferences(previousProxyType);
1069  0 if (newProxyType.equals(Cache.PROXYTYPE_CUSTOM)
1070    || !newProxyType.equals(previousProxyType))
1071    {
1072    // force a re-lookup of ws if proxytype is custom or has changed
1073  0 wsPrefs.update++;
1074    }
1075  0 previousProxyType = newProxyType;
1076   
1077  0 Cache.enableSessionProperties();
1078    }
1079   
1080    /**
1081    * Do any necessary validation before saving settings. Return focus to the
1082    * first tab which fails validation.
1083    *
1084    * @return
1085    */
 
1086  0 toggle private boolean validateSettings()
1087    {
1088  0 if (!validateStructure())
1089    {
1090  0 structureTab.requestFocusInWindow();
1091  0 return false;
1092    }
1093  0 return true;
1094    }
1095   
 
1096  0 toggle @Override
1097    protected boolean validateStructure()
1098    {
1099  0 return validateViewerPath();
1100   
1101    }
1102   
1103    /**
1104    * DOCUMENT ME!
1105    */
 
1106  0 toggle @Override
1107    public void startupFileTextfield_mouseClicked()
1108    {
1109  0 Cache.disableSessionProperties();
1110   
1111    // TODO: JAL-3048 not needed for Jalview-JS
1112    // default file format now determined by JalviewFileChooser
1113  0 JalviewFileChooser chooser = JalviewFileChooser
1114    .forRead(Cache.getProperty("LAST_DIRECTORY"), null);
1115  0 chooser.setFileView(new JalviewFileView());
1116  0 chooser.setDialogTitle(
1117    MessageManager.getString("label.select_startup_file"));
1118   
1119  0 int value = chooser.showOpenDialog(this);
1120   
1121  0 if (value == JalviewFileChooser.APPROVE_OPTION)
1122    {
1123  0 FileFormatI format = chooser.getSelectedFormat();
1124  0 if (format != null)
1125    {
1126  0 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
1127    format.getName());
1128    }
1129  0 startupFileTextfield
1130    .setText(chooser.getSelectedFile().getAbsolutePath());
1131    }
1132   
1133  0 Cache.enableSessionProperties();
1134    }
1135   
1136    /**
1137    * DOCUMENT ME!
1138    *
1139    * @param e
1140    * DOCUMENT ME!
1141    */
 
1142  0 toggle @Override
1143    public void cancel_actionPerformed(ActionEvent e)
1144    {
1145  0 try
1146    {
1147  0 if (!Platform.isJS())
1148    {
1149  0 wsPrefs.updateWsMenuConfig(true);
1150  0 wsPrefs.refreshWs_actionPerformed(e);
1151    }
1152  0 frame.setClosed(true);
1153    } catch (Exception ex)
1154    {
1155    }
1156    }
1157   
1158    /**
1159    * DOCUMENT ME!
1160    *
1161    * @param e
1162    * DOCUMENT ME!
1163    */
 
1164  0 toggle @Override
1165    public void annotations_actionPerformed(ActionEvent e)
1166    {
1167  0 conservation.setEnabled(annotations.isSelected());
1168  0 quality.setEnabled(annotations.isSelected());
1169  0 identity.setEnabled(annotations.isSelected());
1170  0 ssConsensus.setEnabled(annotations.isSelected());
1171  0 showOccupancy.setEnabled(annotations.isSelected());
1172  0 showGroupConsensus.setEnabled(annotations.isSelected());
1173  0 showGroupConservation.setEnabled(annotations.isSelected());
1174  0 showConsensHistogram.setEnabled(annotations.isSelected()
1175    && (identity.isSelected() || showGroupConsensus.isSelected()));
1176  0 showConsensLogo.setEnabled(annotations.isSelected()
1177    && (identity.isSelected() || showGroupConsensus.isSelected()));
1178    }
1179   
 
1180  0 toggle @Override
1181    public void newLink_actionPerformed(ActionEvent e)
1182    {
1183  0 GSequenceLink link = new GSequenceLink();
1184  0 boolean valid = false;
1185  0 while (!valid)
1186    {
1187  0 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1188    MessageManager.getString("label.new_sequence_url_link"),
1189    JvOptionPane.OK_CANCEL_OPTION, -1,
1190    null) == JvOptionPane.OK_OPTION)
1191    {
1192  0 if (link.checkValid())
1193    {
1194  0 if (((UrlLinkTableModel) linkUrlTable.getModel())
1195    .isUniqueName(link.getName()))
1196    {
1197  0 ((UrlLinkTableModel) linkUrlTable.getModel())
1198    .insertRow(link.getName(), link.getURL());
1199  0 valid = true;
1200    }
1201    else
1202    {
1203  0 link.notifyDuplicate();
1204  0 continue;
1205    }
1206    }
1207    }
1208    else
1209    {
1210  0 break;
1211    }
1212    }
1213    }
1214   
 
1215  0 toggle @Override
1216    public void editLink_actionPerformed(ActionEvent e)
1217    {
1218  0 GSequenceLink link = new GSequenceLink();
1219   
1220  0 int index = linkUrlTable.getSelectedRow();
1221  0 if (index == -1)
1222    {
1223    // button no longer enabled if row is not selected
1224  0 Console.debug("Edit with no row selected in linkUrlTable");
1225  0 return;
1226    }
1227   
1228  0 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1229    .getNameColumn();
1230  0 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1231    .getUrlColumn();
1232  0 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1233  0 link.setName(oldName);
1234  0 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1235   
1236  0 boolean valid = false;
1237  0 while (!valid)
1238    {
1239  0 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1240    MessageManager.getString("label.edit_sequence_url_link"),
1241    JvOptionPane.OK_CANCEL_OPTION, -1,
1242    null) == JvOptionPane.OK_OPTION)
1243    {
1244  0 if (link.checkValid())
1245    {
1246  0 if ((oldName.equals(link.getName()))
1247    || (((UrlLinkTableModel) linkUrlTable.getModel())
1248    .isUniqueName(link.getName())))
1249    {
1250  0 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1251  0 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1252  0 valid = true;
1253    }
1254    else
1255    {
1256  0 link.notifyDuplicate();
1257  0 continue;
1258    }
1259    }
1260    }
1261    else
1262    {
1263  0 break;
1264    }
1265    }
1266    }
1267   
 
1268  0 toggle @Override
1269    public void deleteLink_actionPerformed(ActionEvent e)
1270    {
1271  0 int index = linkUrlTable.getSelectedRow();
1272  0 int modelIndex = -1;
1273  0 if (index == -1)
1274    {
1275    // button no longer enabled if row is not selected
1276  0 Console.debug("Delete with no row selected in linkUrlTable");
1277  0 return;
1278    }
1279    else
1280    {
1281  0 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1282    }
1283   
1284    // make sure we use the model index to delete, and not the table index
1285  0 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1286    }
1287   
1288    /*
1289    * (non-Javadoc)
1290    *
1291    * @see
1292    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1293    * .ActionEvent)
1294    */
 
1295  0 toggle @Override
1296    protected void showunconserved_actionPerformed(ActionEvent e)
1297    {
1298    // TODO Auto-generated method stub
1299  0 super.showunconserved_actionPerformed(e);
1300    }
1301   
 
1302  0 toggle public static List<String> getGroupURLLinks()
1303    {
1304  0 return groupURLLinks;
1305    }
1306   
 
1307  0 toggle @Override
1308    public void minColour_actionPerformed(JPanel panel)
1309    {
1310  0 JalviewColourChooser.showColourChooser(this,
1311    MessageManager.getString("label.select_colour_minimum_value"),
1312    panel);
1313    }
1314   
 
1315  0 toggle @Override
1316    public void maxColour_actionPerformed(JPanel panel)
1317    {
1318  0 JalviewColourChooser.showColourChooser(this,
1319    MessageManager.getString("label.select_colour_maximum_value"),
1320    panel);
1321    }
1322   
 
1323  0 toggle @Override
1324    public void gapColour_actionPerformed(JPanel gap)
1325    {
1326  0 if (!useLegacyGap.isSelected())
1327    {
1328  0 JalviewColourChooser.showColourChooser(this,
1329    MessageManager.getString("label.select_gap_colour"), gap);
1330    }
1331    }
1332   
 
1333  0 toggle @Override
1334    public void hiddenColour_actionPerformed(JPanel hidden)
1335    {
1336  0 JalviewColourChooser.showColourChooser(this,
1337    MessageManager.getString("label.select_hidden_colour"), hidden);
1338    }
1339   
 
1340  0 toggle @Override
1341    protected void useLegacyGaps_actionPerformed(ActionEvent e)
1342    {
1343  0 boolean enabled = useLegacyGap.isSelected();
1344  0 if (enabled)
1345    {
1346  0 gapColour.setBackground(OverviewCanvas.OVERVIEW_DEFAULT_LEGACY_GAP);
1347    }
1348    else
1349    {
1350  0 gapColour.setBackground(OverviewCanvas.OVERVIEW_DEFAULT_GAP);
1351    }
1352  0 gapColour.setEnabled(!enabled);
1353  0 gapLabel.setEnabled(!enabled);
1354    }
1355   
 
1356  0 toggle @Override
1357    protected void resetOvDefaults_actionPerformed(ActionEvent e)
1358    {
1359  0 useLegacyGap.setSelected(false);
1360  0 useLegacyGaps_actionPerformed(null);
1361  0 showHiddenAtStart.setSelected(false);
1362  0 hiddenColour.setBackground(OverviewCanvas.OVERVIEW_DEFAULT_HIDDEN);
1363    }
1364   
 
1365  0 toggle @Override
1366    protected void userIdWidth_actionPerformed()
1367    {
1368  0 try
1369    {
1370  0 String val = userIdWidth.getText().trim();
1371  0 if (val.length() > 0)
1372    {
1373  0 Integer iw = Integer.parseInt(val);
1374  0 if (iw.intValue() < 12)
1375    {
1376  0 throw new NumberFormatException();
1377    }
1378  0 userIdWidth.setText(iw.toString());
1379    }
1380    } catch (NumberFormatException x)
1381    {
1382  0 userIdWidth.setText("");
1383  0 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1384    MessageManager
1385    .getString("warn.user_defined_width_requirements"),
1386    MessageManager.getString("label.invalid_id_column_width"),
1387    JvOptionPane.WARNING_MESSAGE);
1388    }
1389    }
1390   
 
1391  0 toggle @Override
1392    protected void autoIdWidth_actionPerformed()
1393    {
1394  0 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1395  0 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1396    }
1397   
1398    /**
1399    * Returns true if structure viewer path is to a valid executable, else shows
1400    * an error dialog. Does nothing if the path is empty, as is the case for Jmol
1401    * (built in to Jalview) or when Jalview is left to try default paths.
1402    */
 
1403  0 toggle private boolean validateViewerPath()
1404    {
1405  0 if (structureViewerPath.getText().trim().length() > 0)
1406    {
1407  0 File f = new File(structureViewerPath.getText());
1408  0 if (!f.canExecute())
1409    {
1410  0 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1411    MessageManager.getString("label.invalid_viewer_path"),
1412    MessageManager.getString("label.invalid_viewer_path"),
1413    JvOptionPane.ERROR_MESSAGE);
1414  0 return false;
1415    }
1416    }
1417  0 return true;
1418    }
1419   
1420    /**
1421    * If Chimera or ChimeraX or Pymol is selected, check it can be found on
1422    * default or user-specified path, if not show a warning/help dialog
1423    */
 
1424  0 toggle @Override
1425    protected void structureViewer_actionPerformed(String selectedItem)
1426    {
1427  0 if (selectedItem.equals(ViewerType.JMOL.name()))
1428    {
1429  0 structureViewerPath.setEnabled(false);
1430  0 structureViewerPathLabel.setEnabled(false);
1431  0 return;
1432    }
1433  0 boolean found = false;
1434  0 structureViewerPath.setEnabled(true);
1435  0 structureViewerPathLabel.setEnabled(true);
1436  0 structureViewerPathLabel.setText(MessageManager
1437    .formatMessage("label.viewer_path", selectedItem));
1438   
1439    /*
1440    * Try user-specified and standard paths for structure viewer executable
1441    */
1442  0 String viewerPath = "";
1443  0 List<String> paths = null;
1444  0 Cache.disableSessionProperties();
1445  0 try
1446    {
1447  0 ViewerType viewerType = ViewerType.valueOf(selectedItem);
1448  0 switch (viewerType)
1449    {
1450  0 case JMOL:
1451    // dealt with above
1452  0 break;
1453  0 case CHIMERA:
1454  0 viewerPath = Cache.getDefault(CHIMERA_PATH, "");
1455  0 paths = StructureManager.getChimeraPaths(false);
1456  0 break;
1457  0 case CHIMERAX:
1458  0 viewerPath = Cache.getDefault(CHIMERAX_PATH, "");
1459  0 paths = StructureManager.getChimeraPaths(true);
1460  0 break;
1461  0 case PYMOL:
1462  0 viewerPath = Cache.getDefault(PYMOL_PATH, "");
1463  0 paths = PymolManager.getPymolPaths();
1464  0 break;
1465    }
1466    } catch (IllegalArgumentException e)
1467    {
1468    // only valid entries should be in the drop-down
1469    }
1470  0 Cache.enableSessionProperties();
1471  0 structureViewerPath.setText(viewerPath);
1472   
1473  0 jalview.bin.Console
1474  0 .debug("Found " + (paths == null ? null : paths.size())
1475    + " paths to look for " + selectedItem.toString());
1476  0 if (paths == null)
1477    {
1478  0 paths = new ArrayList<>();
1479    }
1480  0 paths.add(0, structureViewerPath.getText());
1481  0 for (String path : paths)
1482    {
1483  0 jalview.bin.Console.debug("Looking for " + selectedItem.toString()
1484    + " in " + path.trim());
1485  0 if (new File(path.trim()).canExecute())
1486    {
1487  0 jalview.bin.Console.debug(
1488    "Found " + selectedItem.toString() + " in " + path.trim());
1489  0 found = true;
1490  0 break;
1491    }
1492    }
1493   
1494  0 if (!found)
1495    {
1496  0 String[] options = { "OK", "Help" };
1497  0 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1498    JvSwingUtils.wrapTooltip(true,
1499    MessageManager.getString("label.viewer_missing")),
1500    "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1501    null, options, options[0]);
1502   
1503  0 if (showHelp == JvOptionPane.NO_OPTION)
1504    {
1505  0 this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null);
1506  0 try
1507    {
1508  0 Help.showHelpWindow(HelpId.StructureViewer);
1509    } catch (HelpSetException e)
1510    {
1511  0 e.printStackTrace();
1512    }
1513    }
1514  0 else if (showHelp == JvOptionPane.OK_OPTION)
1515    {
1516  0 this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null);
1517  0 CompletableFuture<Void> cf = CompletableFuture.runAsync(() -> {
1518  0 try
1519    {
1520  0 for (int i = 0; i < 3; i++)
1521    {
1522  0 structureViewerPath.setBackground(Color.PINK);
1523  0 Thread.sleep(500);
1524  0 structureViewerPath.setBackground(Color.WHITE);
1525  0 Thread.sleep(500);
1526    }
1527    } catch (InterruptedException e)
1528    {
1529    }
1530    });
1531    }
1532    }
1533    }
1534   
 
1535    public class OptionsParam
1536    {
1537    private String name;
1538   
1539    private String code;
1540   
 
1541  0 toggle public OptionsParam(String name, String code)
1542    {
1543  0 this.name = name;
1544  0 this.code = code;
1545    }
1546   
 
1547  0 toggle public String getName()
1548    {
1549  0 return name;
1550    }
1551   
 
1552  0 toggle public void setName(String name)
1553    {
1554  0 this.name = name;
1555    }
1556   
 
1557  0 toggle public String getCode()
1558    {
1559  0 return code;
1560    }
1561   
 
1562  0 toggle public void setCode(String code)
1563    {
1564  0 this.code = code;
1565    }
1566   
 
1567  0 toggle @Override
1568    public String toString()
1569    {
1570  0 return name;
1571    }
1572   
 
1573  0 toggle @Override
1574    public boolean equals(Object that)
1575    {
1576  0 if (!(that instanceof OptionsParam))
1577    {
1578  0 return false;
1579    }
1580  0 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1581    }
1582   
 
1583  0 toggle @Override
1584    public int hashCode()
1585    {
1586  0 return name.hashCode() + code.hashCode();
1587    }
1588    }
1589   
 
1590    private class UrlListSelectionHandler implements ListSelectionListener
1591    {
1592   
 
1593  0 toggle @Override
1594    public void valueChanged(ListSelectionEvent e)
1595    {
1596  0 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1597   
1598  0 int index = lsm.getMinSelectionIndex();
1599  0 if (index == -1)
1600    {
1601    // no selection, so disable delete/edit buttons
1602  0 editLink.setEnabled(false);
1603  0 deleteLink.setEnabled(false);
1604  0 return;
1605    }
1606  0 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1607   
1608    // enable/disable edit and delete link buttons
1609  0 if (((UrlLinkTableModel) linkUrlTable.getModel())
1610    .isRowDeletable(modelIndex))
1611    {
1612  0 deleteLink.setEnabled(true);
1613    }
1614    else
1615    {
1616  0 deleteLink.setEnabled(false);
1617    }
1618   
1619  0 if (((UrlLinkTableModel) linkUrlTable.getModel())
1620    .isRowEditable(modelIndex))
1621    {
1622  0 editLink.setEnabled(true);
1623    }
1624    else
1625    {
1626  0 editLink.setEnabled(false);
1627    }
1628    }
1629    }
1630    }