2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.bin.Cache;
25 import jalview.gui.Help.HelpId;
26 import jalview.gui.StructureViewer.ViewerType;
27 import jalview.io.BackupFiles;
28 import jalview.io.FileFormatI;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.jbgui.GPreferences;
32 import jalview.jbgui.GSequenceLink;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ColourSchemes;
35 import jalview.schemes.ResidueColourScheme;
36 import jalview.urls.UrlLinkTableModel;
37 import jalview.urls.api.UrlProviderFactoryI;
38 import jalview.urls.api.UrlProviderI;
39 import jalview.urls.desktop.DesktopUrlProviderFactory;
40 import jalview.util.BrowserLauncher;
41 import jalview.util.MessageManager;
42 import jalview.util.Platform;
43 import jalview.util.UrlConstants;
44 import jalview.ws.sifts.SiftsSettings;
46 import java.awt.BorderLayout;
47 import java.awt.Color;
48 import java.awt.Component;
49 import java.awt.Dimension;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ActionListener;
53 import java.awt.event.MouseEvent;
55 import java.util.ArrayList;
56 import java.util.List;
58 import javax.help.HelpSetException;
59 import javax.swing.JComboBox;
60 import javax.swing.JFileChooser;
61 import javax.swing.JInternalFrame;
62 import javax.swing.JPanel;
63 import javax.swing.ListSelectionModel;
64 import javax.swing.RowFilter;
65 import javax.swing.RowSorter;
66 import javax.swing.SortOrder;
67 import javax.swing.event.DocumentEvent;
68 import javax.swing.event.DocumentListener;
69 import javax.swing.event.ListSelectionEvent;
70 import javax.swing.event.ListSelectionListener;
71 import javax.swing.table.TableCellRenderer;
72 import javax.swing.table.TableColumn;
73 import javax.swing.table.TableModel;
74 import javax.swing.table.TableRowSorter;
76 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
84 @SuppressWarnings("serial")
85 public class Preferences extends GPreferences
87 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
89 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
91 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
93 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
95 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
97 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
99 public static final String ADD_SS_ANN = "ADD_SS_ANN";
101 public static final String USE_RNAVIEW = "USE_RNAVIEW";
103 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
105 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
107 public static final String CHIMERA_PATH = "CHIMERA_PATH";
109 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
111 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
113 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
115 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
117 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
119 public static final String GAP_COLOUR = "GAP_COLOUR";
121 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
123 private static final int MIN_FONT_SIZE = 1;
125 private static final int MAX_FONT_SIZE = 30;
128 * Holds name and link separated with | character. Sequence ID must be
129 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
131 public static UrlProviderI sequenceUrlLinks; // must be nonfinal for test
133 public final static UrlLinkTableModel dataModel;
136 * Holds name and link separated with | character. Sequence IDS and Sequences
137 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
138 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
139 * for first and second token specified after a pipe character at end |,|.
140 * (TODO: proper escape for using | to separate ids or sequences
143 public static final List<String> groupURLLinks; // not implemented
147 // get links selected to be in the menu (SEQUENCE_LINKS)
148 // and links entered by the user but not selected (STORED_LINKS)
149 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
150 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
151 String defaultUrl = Cache.getDefault("DEFAULT_URL",
152 UrlConstants.DEFAULT_LABEL);
154 // if both links lists are empty, add the DEFAULT_URL link
155 // otherwise we assume the default link is in one of the lists
156 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
158 inMenuString = UrlConstants.DEFAULT_STRING;
160 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
161 inMenuString, notInMenuString);
162 sequenceUrlLinks = factory.createUrlProvider();
163 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
166 * TODO: reformulate groupURL encoding so two or more can be stored in the
167 * .properties file as '|' separated strings
170 groupURLLinks = new ArrayList<>(); // not implemented
173 JInternalFrame frame;
175 private WsPreferences wsPrefs;
177 private OptionsParam promptEachTimeOpt = new OptionsParam(
178 MessageManager.getString("label.prompt_each_time"),
181 private OptionsParam lineArtOpt = new OptionsParam(
182 MessageManager.getString("label.lineart"), "Lineart");
184 private OptionsParam textOpt = new OptionsParam(
185 MessageManager.getString("action.text"), "Text");
188 * Creates a new Preferences object.
193 frame = new JInternalFrame();
194 frame.setContentPane(this);
195 if (!Platform.isJS())
202 wsPrefs = new WsPreferences();
203 wsTab.add(wsPrefs, BorderLayout.CENTER);
205 int width = 500, height = 450;
206 if (Platform.isAMacAndNotJS())
212 Desktop.addInternalFrame(frame,
213 MessageManager.getString("label.preferences"), width, height);
214 frame.setMinimumSize(new Dimension(width, height));
217 * Set Visual tab defaults
219 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
220 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
221 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
222 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
224 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
225 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
226 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
227 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
229 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
230 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
232 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
233 showGroupConservation.setSelected(
234 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
235 showConsensHistogram.setSelected(
236 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
238 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
240 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
242 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
244 String[] fonts = java.awt.GraphicsEnvironment
245 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
246 for (int i = 0; i < fonts.length; i++)
248 fontNameCB.addItem(fonts[i]);
251 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
253 fontSizeCB.addItem(i + "");
256 fontStyleCB.addItem("plain");
257 fontStyleCB.addItem("bold");
258 fontStyleCB.addItem("italic");
260 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
261 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
262 fontStyleCB.setSelectedItem(
263 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
265 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
267 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
269 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
271 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
273 gapSymbolCB.addItem("-");
274 gapSymbolCB.addItem(".");
276 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
278 sortby.addItem("No sort");
279 sortby.addItem("Id");
280 sortby.addItem("Pairwise Identity");
281 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
283 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
285 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
287 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
288 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
289 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
290 SequenceAnnotationOrder.NONE.name()));
291 sortAnnBy.setSelectedItem(savedSort.toString());
293 sortAutocalc.addItem("Autocalculated first");
294 sortAutocalc.addItem("Autocalculated last");
295 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
296 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
297 : sortAutocalc.getItemAt(1));
299 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
300 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
301 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
302 + "/examples/exampleFile_2_3.jar"));
305 * Set Colours tab defaults
307 protColour.addItem(ResidueColourScheme.NONE);
308 nucColour.addItem(ResidueColourScheme.NONE);
309 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
311 String name = cs.getSchemeName();
312 protColour.addItem(name);
313 nucColour.addItem(name);
315 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
316 ResidueColourScheme.NONE);
317 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
318 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
319 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
320 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
321 minColour.setBackground(
322 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
323 maxColour.setBackground(
324 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
327 * Set overview panel defaults
329 gapColour.setBackground(
330 Cache.getDefaultColour(GAP_COLOUR,
331 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
332 hiddenColour.setBackground(
333 Cache.getDefaultColour(HIDDEN_COLOUR,
334 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
335 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
336 gapLabel.setEnabled(!useLegacyGap.isSelected());
337 gapColour.setEnabled(!useLegacyGap.isSelected());
339 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
342 * Set Structure tab defaults.
344 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
345 structFromPdb.setSelected(structSelected);
346 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
347 useRnaView.setEnabled(structSelected);
348 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
349 addSecondaryStructure.setEnabled(structSelected);
350 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
351 addTempFactor.setEnabled(structSelected);
352 structViewer.setSelectedItem(
353 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
354 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
355 chimeraPath.addActionListener(new ActionListener()
358 public void actionPerformed(ActionEvent e)
360 validateChimeraPath();
364 if (Cache.getDefault("MAP_WITH_SIFTS", false))
366 siftsMapping.setSelected(true);
370 nwMapping.setSelected(true);
374 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
377 * Set Connections tab defaults
381 linkUrlTable.setModel(dataModel);
382 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
383 linkUrlTable.getModel());
384 linkUrlTable.setRowSorter(sorter);
385 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
387 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
388 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
389 SortOrder.DESCENDING));
390 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
391 SortOrder.DESCENDING));
393 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
395 sorter.setSortKeys(sortKeys);
396 // BH 2018 setSortKeys will do the sort
400 ActionListener onReset;
401 onReset = new ActionListener()
404 public void actionPerformed(ActionEvent e)
406 filterTB.setText("");
407 sorter.setRowFilter(RowFilter.regexFilter(""));
411 doReset.addActionListener(onReset);
413 // filter to display only custom urls
414 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
417 public boolean include(
418 Entry<? extends TableModel, ? extends Object> entry)
420 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
424 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
425 linkUrlTable.getModel());
426 customSorter.setRowFilter(customUrlFilter);
428 ActionListener onCustomOnly;
429 onCustomOnly = new ActionListener()
432 public void actionPerformed(ActionEvent e)
434 filterTB.setText("");
435 sorter.setRowFilter(customUrlFilter);
438 userOnly.addActionListener(onCustomOnly);
440 filterTB.getDocument().addDocumentListener(new DocumentListener()
442 String caseInsensitiveFlag = "(?i)";
445 public void changedUpdate(DocumentEvent e)
447 sorter.setRowFilter(RowFilter
448 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
452 public void removeUpdate(DocumentEvent e)
454 sorter.setRowFilter(RowFilter
455 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
459 public void insertUpdate(DocumentEvent e)
461 sorter.setRowFilter(RowFilter
462 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
466 // set up list selection functionality
467 linkUrlTable.getSelectionModel()
468 .addListSelectionListener(new UrlListSelectionHandler());
470 // set up radio buttons
471 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
473 String onClickName = linkUrlTable.getColumnName(onClickCol);
474 linkUrlTable.getColumn(onClickName)
475 .setCellRenderer(new RadioButtonRenderer());
476 linkUrlTable.getColumn(onClickName)
477 .setCellEditor(new RadioButtonEditor());
479 // get boolean columns and resize those to min possible
480 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
482 if (linkUrlTable.getModel().getColumnClass(column)
483 .equals(Boolean.class))
485 TableColumn tableColumn = linkUrlTable.getColumnModel()
487 int preferredWidth = tableColumn.getMinWidth();
489 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
491 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
492 int cwidth = c.getPreferredSize().width
493 + linkUrlTable.getIntercellSpacing().width;
494 preferredWidth = Math.max(preferredWidth, cwidth);
496 tableColumn.setPreferredWidth(preferredWidth);
500 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
501 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
502 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
503 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
505 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
507 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
508 // note antisense here: default is true
510 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
511 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
514 * Set Output tab defaults
516 setupOutputCombo(epsRendering, "EPS_RENDERING");
517 setupOutputCombo(htmlRendering, "HTML_RENDERING");
518 setupOutputCombo(svgRendering, "SVG_RENDERING");
519 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
520 userIdWidth.setEnabled(!autoIdWidth.isSelected());
521 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
522 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
523 userIdWidth.setText(wi == null ? "" : wi.toString());
524 // TODO: refactor to use common enum via FormatAdapter and allow extension
525 // for new flat file formats
526 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
527 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
528 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
529 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
530 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
531 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
532 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
533 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
535 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
538 * Set Editing tab defaults
540 autoCalculateConsCheck
541 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
542 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
543 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
545 annotations_actionPerformed(null); // update the display of the annotation
550 * Set Backups tab defaults
552 loadLastSavedBackupsOptions();
556 * A helper method that sets the items and initial selection in a character
557 * rendering option list (Prompt each time/Lineart/Text)
562 protected void setupOutputCombo(JComboBox<Object> comboBox,
565 comboBox.addItem(promptEachTimeOpt);
566 comboBox.addItem(lineArtOpt);
567 comboBox.addItem(textOpt);
570 * JalviewJS doesn't support Lineart so force it to Text
572 String defaultOption = Platform.isJS() ? "Text"
573 : Cache.getDefault(propertyKey, "Prompt each time");
574 if (defaultOption.equalsIgnoreCase("Text"))
576 comboBox.setSelectedItem(textOpt);
578 else if (defaultOption.equalsIgnoreCase("Lineart"))
580 comboBox.setSelectedItem(lineArtOpt);
584 comboBox.setSelectedItem(promptEachTimeOpt);
589 * Save user selections on the Preferences tabs to the Cache and write out to
595 public void ok_actionPerformed(ActionEvent e)
597 if (!validateSettings())
603 * Save Visual settings
605 Cache.setPropertyNoSave("SHOW_JVSUFFIX",
606 Boolean.toString(seqLimit.isSelected()));
607 Cache.setPropertyNoSave("RIGHT_ALIGN_IDS",
608 Boolean.toString(rightAlign.isSelected()));
609 Cache.setPropertyNoSave("SHOW_FULLSCREEN",
610 Boolean.toString(fullScreen.isSelected()));
611 Cache.setPropertyNoSave("SHOW_OVERVIEW",
612 Boolean.toString(openoverv.isSelected()));
613 Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
614 Boolean.toString(annotations.isSelected()));
615 Cache.setPropertyNoSave("SHOW_CONSERVATION",
616 Boolean.toString(conservation.isSelected()));
617 Cache.setPropertyNoSave("SHOW_QUALITY",
618 Boolean.toString(quality.isSelected()));
619 Cache.setPropertyNoSave("SHOW_IDENTITY",
620 Boolean.toString(identity.isSelected()));
622 Cache.setPropertyNoSave("GAP_SYMBOL",
623 gapSymbolCB.getSelectedItem().toString());
625 Cache.setPropertyNoSave("FONT_NAME",
626 fontNameCB.getSelectedItem().toString());
627 Cache.setPropertyNoSave("FONT_STYLE",
628 fontStyleCB.getSelectedItem().toString());
629 Cache.setPropertyNoSave("FONT_SIZE",
630 fontSizeCB.getSelectedItem().toString());
632 Cache.setPropertyNoSave("ID_ITALICS",
633 Boolean.toString(idItalics.isSelected()));
634 Cache.setPropertyNoSave("SHOW_UNCONSERVED",
635 Boolean.toString(showUnconserved.isSelected()));
636 Cache.setPropertyNoSave(SHOW_OCCUPANCY,
637 Boolean.toString(showOccupancy.isSelected()));
638 Cache.setPropertyNoSave("SHOW_GROUP_CONSENSUS",
639 Boolean.toString(showGroupConsensus.isSelected()));
640 Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION",
641 Boolean.toString(showGroupConservation.isSelected()));
642 Cache.setPropertyNoSave("SHOW_CONSENSUS_HISTOGRAM",
643 Boolean.toString(showConsensHistogram.isSelected()));
644 Cache.setPropertyNoSave("SHOW_CONSENSUS_LOGO",
645 Boolean.toString(showConsensLogo.isSelected()));
646 Cache.setPropertyNoSave("ANTI_ALIAS",
647 Boolean.toString(smoothFont.isSelected()));
648 Cache.setPropertyNoSave(SCALE_PROTEIN_TO_CDNA,
649 Boolean.toString(scaleProteinToCdna.isSelected()));
650 Cache.setPropertyNoSave("SHOW_NPFEATS_TOOLTIP",
651 Boolean.toString(showNpTooltip.isSelected()));
652 Cache.setPropertyNoSave("SHOW_DBREFS_TOOLTIP",
653 Boolean.toString(showDbRefTooltip.isSelected()));
655 Cache.setPropertyNoSave("WRAP_ALIGNMENT",
656 Boolean.toString(wrap.isSelected()));
658 Cache.setPropertyNoSave("STARTUP_FILE",
659 startupFileTextfield.getText());
660 Cache.setPropertyNoSave("SHOW_STARTUP_FILE",
661 Boolean.toString(startupCheckbox.isSelected()));
663 Cache.setPropertyNoSave("SORT_ALIGNMENT",
664 sortby.getSelectedItem().toString());
666 // convert description of sort order to enum name for save
667 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
668 .forDescription(sortAnnBy.getSelectedItem().toString());
669 if (annSortOrder != null)
671 Cache.setPropertyNoSave(SORT_ANNOTATIONS,
672 annSortOrder.name());
675 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
676 Cache.setPropertyNoSave(SHOW_AUTOCALC_ABOVE,
677 Boolean.valueOf(showAutocalcFirst).toString());
680 * Save Colours settings
682 Cache.setPropertyNoSave(DEFAULT_COLOUR_PROT,
683 protColour.getSelectedItem().toString());
684 Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
685 nucColour.getSelectedItem().toString());
686 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
687 minColour.getBackground());
688 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
689 maxColour.getBackground());
692 * Save Overview settings
694 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
695 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
696 Cache.setPropertyNoSave(USE_LEGACY_GAP,
697 Boolean.toString(useLegacyGap.isSelected()));
698 Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START,
699 Boolean.toString(showHiddenAtStart.isSelected()));
702 * Save Structure settings
704 Cache.setPropertyNoSave(ADD_TEMPFACT_ANN,
705 Boolean.toString(addTempFactor.isSelected()));
706 Cache.setPropertyNoSave(ADD_SS_ANN,
707 Boolean.toString(addSecondaryStructure.isSelected()));
708 Cache.setPropertyNoSave(USE_RNAVIEW,
709 Boolean.toString(useRnaView.isSelected()));
710 Cache.setPropertyNoSave(STRUCT_FROM_PDB,
711 Boolean.toString(structFromPdb.isSelected()));
712 Cache.setPropertyNoSave(STRUCTURE_DISPLAY,
713 structViewer.getSelectedItem().toString());
714 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
715 Cache.setPropertyNoSave("MAP_WITH_SIFTS",
716 Boolean.toString(siftsMapping.isSelected()));
717 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
720 * Save Output settings
722 Cache.setPropertyNoSave("EPS_RENDERING",
723 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
724 Cache.setPropertyNoSave("HTML_RENDERING",
725 ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
726 Cache.setPropertyNoSave("SVG_RENDERING",
727 ((OptionsParam) svgRendering.getSelectedItem()).getCode());
729 if (!Platform.isJS())
735 // Save Connections settings
736 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
737 BrowserLauncher.resetBrowser();
740 // save user-defined and selected links
741 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
742 if (menuLinks.isEmpty())
744 Cache.removePropertyNoSave("SEQUENCE_LINKS");
748 Cache.setPropertyNoSave("SEQUENCE_LINKS",
749 menuLinks.toString());
752 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
753 if (nonMenuLinks.isEmpty())
755 Cache.removePropertyNoSave("STORED_LINKS");
759 Cache.setPropertyNoSave("STORED_LINKS",
760 nonMenuLinks.toString());
763 Cache.setPropertyNoSave("DEFAULT_URL",
764 sequenceUrlLinks.getPrimaryUrlId());
766 Cache.setPropertyNoSave("USE_PROXY",
767 Boolean.toString(useProxy.isSelected()));
769 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
771 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
773 if (useProxy.isSelected())
775 System.setProperty("http.proxyHost", proxyServerTB.getText());
776 System.setProperty("http.proxyPort", proxyPortTB.getText());
780 System.setProperty("http.proxyHost", "");
781 System.setProperty("http.proxyPort", "");
783 Cache.setProperty("VERSION_CHECK",
784 Boolean.toString(versioncheck.isSelected()));
785 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
787 // default is false - we only set this if the user has actively agreed
788 Cache.setProperty("USAGESTATS",
789 Boolean.toString(usagestats.isSelected()));
791 if (!questionnaire.isSelected())
793 Cache.setProperty("NOQUESTIONNAIRES", "true");
797 // special - made easy to edit a property file to disable questionnaires
798 // by just adding the given line
799 Cache.removeProperty("NOQUESTIONNAIRES");
803 * Save Output settings
805 Cache.setPropertyNoSave("BLC_JVSUFFIX",
806 Boolean.toString(blcjv.isSelected()));
807 Cache.setPropertyNoSave("CLUSTAL_JVSUFFIX",
808 Boolean.toString(clustaljv.isSelected()));
809 Cache.setPropertyNoSave("FASTA_JVSUFFIX",
810 Boolean.toString(fastajv.isSelected()));
811 Cache.setPropertyNoSave("MSF_JVSUFFIX",
812 Boolean.toString(msfjv.isSelected()));
813 Cache.setPropertyNoSave("PFAM_JVSUFFIX",
814 Boolean.toString(pfamjv.isSelected()));
815 Cache.setPropertyNoSave("PILEUP_JVSUFFIX",
816 Boolean.toString(pileupjv.isSelected()));
817 Cache.setPropertyNoSave("PIR_JVSUFFIX",
818 Boolean.toString(pirjv.isSelected()));
819 Cache.setPropertyNoSave("PIR_MODELLER",
820 Boolean.toString(modellerOutput.isSelected()));
821 Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON",
822 Boolean.toString(embbedBioJSON.isSelected()));
823 Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH",
824 Boolean.toString(autoIdWidth.isSelected()));
825 userIdWidth_actionPerformed();
826 Cache.setPropertyNoSave("FIGURE_FIXEDIDWIDTH",
827 userIdWidth.getText());
830 * Save Editing settings
832 Cache.setPropertyNoSave("AUTO_CALC_CONSENSUS",
833 Boolean.toString(autoCalculateConsCheck.isSelected()));
834 Cache.setPropertyNoSave("SORT_BY_TREE",
835 Boolean.toString(sortByTree.isSelected()));
836 Cache.setPropertyNoSave("PAD_GAPS",
837 Boolean.toString(padGaps.isSelected()));
839 if (!Platform.isJS())
841 wsPrefs.updateAndRefreshWsMenuConfig(false);
845 * Save Backups settings
847 Cache.setPropertyNoSave(BackupFiles.CONFIRM_DELETE_OLD,
848 Boolean.toString(backupfilesConfirmDelete.isSelected()));
849 Cache.setPropertyNoSave(BackupFiles.ENABLED,
850 Boolean.toString(enableBackupFiles.isSelected()));
851 Cache.setPropertyNoSave(BackupFiles.NO_MAX,
852 Boolean.toString(backupfilesKeepAll.isSelected()));
853 Cache.setPropertyNoSave(BackupFiles.REVERSE_ORDER,
854 Boolean.toString(suffixReverse.isSelected()));
855 Cache.setPropertyNoSave(BackupFiles.SUFFIX,
856 suffixTemplate.getText());
857 Cache.setPropertyNoSave(BackupFiles.ROLL_MAX,
858 Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
859 Cache.setPropertyNoSave(BackupFiles.SUFFIX_DIGITS,
860 Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
861 Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET",
862 Integer.toString(getComboIntStringKey(backupfilesPresetsCombo)));
864 Cache.saveProperties();
865 Desktop.getInstance().doConfigureStructurePrefs();
868 frame.setClosed(true);
869 } catch (Exception ex)
875 * Do any necessary validation before saving settings. Return focus to the
876 * first tab which fails validation.
880 private boolean validateSettings()
882 if (!validateStructure())
884 structureTab.requestFocusInWindow();
891 protected boolean validateStructure()
893 return validateChimeraPath();
901 public void startupFileTextfield_mouseClicked()
903 // TODO: JAL-3048 not needed for Jalview-JS
904 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
905 JalviewFileChooser chooser = JalviewFileChooser
906 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
907 chooser.setFileView(new JalviewFileView());
908 chooser.setDialogTitle(
909 MessageManager.getString("label.select_startup_file"));
911 int value = chooser.showOpenDialog(this);
913 if (value == JalviewFileChooser.APPROVE_OPTION)
915 FileFormatI format = chooser.getSelectedFormat();
918 Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
922 .setText(chooser.getSelectedFile().getAbsolutePath());
933 public void cancel_actionPerformed(ActionEvent e)
937 if (!Platform.isJS())
939 wsPrefs.updateWsMenuConfig(true);
940 wsPrefs.refreshWs_actionPerformed(e);
942 frame.setClosed(true);
943 } catch (Exception ex)
955 public void annotations_actionPerformed(ActionEvent e)
957 conservation.setEnabled(annotations.isSelected());
958 quality.setEnabled(annotations.isSelected());
959 identity.setEnabled(annotations.isSelected());
960 showOccupancy.setEnabled(annotations.isSelected());
961 showGroupConsensus.setEnabled(annotations.isSelected());
962 showGroupConservation.setEnabled(annotations.isSelected());
963 showConsensHistogram.setEnabled(annotations.isSelected()
964 && (identity.isSelected() || showGroupConsensus.isSelected()));
965 showConsensLogo.setEnabled(annotations.isSelected()
966 && (identity.isSelected() || showGroupConsensus.isSelected()));
970 public void newLink_actionPerformed(ActionEvent e)
972 GSequenceLink link = new GSequenceLink();
973 boolean valid = false;
976 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
977 MessageManager.getString("label.new_sequence_url_link"),
978 JvOptionPane.OK_CANCEL_OPTION, -1,
979 null) == JvOptionPane.OK_OPTION)
981 if (link.checkValid())
983 if (((UrlLinkTableModel) linkUrlTable.getModel())
984 .isUniqueName(link.getName()))
986 ((UrlLinkTableModel) linkUrlTable.getModel())
987 .insertRow(link.getName(), link.getURL());
992 link.notifyDuplicate();
1005 public void editLink_actionPerformed(ActionEvent e)
1007 GSequenceLink link = new GSequenceLink();
1009 int index = linkUrlTable.getSelectedRow();
1012 // button no longer enabled if row is not selected
1013 Cache.log.debug("Edit with no row selected in linkUrlTable");
1017 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1019 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1021 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1022 link.setName(oldName);
1023 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1025 boolean valid = false;
1028 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1029 MessageManager.getString("label.edit_sequence_url_link"),
1030 JvOptionPane.OK_CANCEL_OPTION, -1,
1031 null) == JvOptionPane.OK_OPTION)
1033 if (link.checkValid())
1035 if ((oldName.equals(link.getName()))
1036 || (((UrlLinkTableModel) linkUrlTable.getModel())
1037 .isUniqueName(link.getName())))
1039 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1040 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1045 link.notifyDuplicate();
1058 public void deleteLink_actionPerformed(ActionEvent e)
1060 int index = linkUrlTable.getSelectedRow();
1061 int modelIndex = -1;
1064 // button no longer enabled if row is not selected
1065 Cache.log.debug("Delete with no row selected in linkUrlTable");
1070 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1073 // make sure we use the model index to delete, and not the table index
1074 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1078 public void defaultBrowser_mouseClicked(MouseEvent e)
1080 // TODO: JAL-3048 not needed for j2s
1081 if (!Platform.isJS()) // BH 2019
1088 JFileChooser chooser = new JFileChooser(".");
1089 chooser.setDialogTitle(
1090 MessageManager.getString("label.select_default_browser"));
1092 int value = chooser.showOpenDialog(this);
1094 if (value == JFileChooser.APPROVE_OPTION)
1096 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1105 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1109 protected void showunconserved_actionPerformed(ActionEvent e)
1111 // TODO Auto-generated method stub
1112 super.showunconserved_actionPerformed(e);
1116 * not implemented -- returns empty list
1120 public static List<String> getGroupURLLinks()
1122 return groupURLLinks;
1126 public void minColour_actionPerformed(JPanel panel)
1128 JalviewColourChooser.showColourChooser(this,
1129 MessageManager.getString("label.select_colour_minimum_value"),
1134 public void maxColour_actionPerformed(JPanel panel)
1136 JalviewColourChooser.showColourChooser(this,
1137 MessageManager.getString("label.select_colour_maximum_value"),
1142 public void gapColour_actionPerformed(JPanel gap)
1144 if (!useLegacyGap.isSelected())
1146 JalviewColourChooser.showColourChooser(this,
1147 MessageManager.getString("label.select_gap_colour"),
1153 public void hiddenColour_actionPerformed(JPanel hidden)
1155 JalviewColourChooser.showColourChooser(this,
1156 MessageManager.getString("label.select_hidden_colour"),
1161 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1163 boolean enabled = useLegacyGap.isSelected();
1166 gapColour.setBackground(
1167 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1171 gapColour.setBackground(
1172 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1174 gapColour.setEnabled(!enabled);
1175 gapLabel.setEnabled(!enabled);
1179 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1181 useLegacyGap.setSelected(false);
1182 useLegacyGaps_actionPerformed(null);
1183 showHiddenAtStart.setSelected(false);
1184 hiddenColour.setBackground(
1185 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1189 protected void userIdWidth_actionPerformed()
1193 String val = userIdWidth.getText().trim();
1194 if (val.length() > 0)
1196 Integer iw = Integer.parseInt(val);
1197 if (iw.intValue() < 12)
1199 throw new NumberFormatException();
1201 userIdWidth.setText(iw.toString());
1203 } catch (NumberFormatException x)
1205 userIdWidth.setText("");
1206 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1208 .getString("warn.user_defined_width_requirements"),
1209 MessageManager.getString("label.invalid_id_column_width"),
1210 JvOptionPane.WARNING_MESSAGE);
1215 protected void autoIdWidth_actionPerformed()
1217 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1218 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1222 * Returns true if chimera path is to a valid executable, else show an error
1225 protected boolean validateChimeraPath()
1227 if (chimeraPath.getText().trim().length() > 0)
1229 File f = new File(chimeraPath.getText());
1230 if (!f.canExecute())
1232 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1233 MessageManager.getString("label.invalid_chimera_path"),
1234 MessageManager.getString("label.invalid_name"),
1235 JvOptionPane.ERROR_MESSAGE);
1243 * If Chimera is selected, check it can be found on default or user-specified
1244 * path, if not show a warning/help dialog.
1247 protected void structureViewer_actionPerformed(String selectedItem)
1249 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1253 boolean found = false;
1256 * Try user-specified and standard paths for Chimera executable.
1258 List<String> paths = StructureManager.getChimeraPaths();
1259 paths.add(0, chimeraPath.getText());
1260 for (String path : paths)
1262 if (new File(path.trim()).canExecute())
1270 String[] options = { "OK", "Help" };
1271 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
1272 JvSwingUtils.wrapTooltip(true,
1273 MessageManager.getString("label.chimera_missing")),
1274 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1275 null, options, options[0]);
1276 if (showHelp == JvOptionPane.NO_OPTION)
1280 Help.showHelpWindow(HelpId.StructureViewer);
1281 } catch (HelpSetException e)
1283 e.printStackTrace();
1289 public class OptionsParam
1291 private String name;
1293 private String code;
1295 public OptionsParam(String name, String code)
1301 public String getName()
1306 public void setName(String name)
1311 public String getCode()
1316 public void setCode(String code)
1322 public String toString()
1328 public boolean equals(Object that)
1330 if (!(that instanceof OptionsParam))
1334 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1338 public int hashCode()
1340 return name.hashCode() + code.hashCode();
1344 protected class UrlListSelectionHandler implements ListSelectionListener
1348 public void valueChanged(ListSelectionEvent e)
1350 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1352 int index = lsm.getMinSelectionIndex();
1355 // no selection, so disable delete/edit buttons
1356 editLink.setEnabled(false);
1357 deleteLink.setEnabled(false);
1360 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1362 // enable/disable edit and delete link buttons
1363 if (((UrlLinkTableModel) linkUrlTable.getModel())
1364 .isRowDeletable(modelIndex))
1366 deleteLink.setEnabled(true);
1370 deleteLink.setEnabled(false);
1373 if (((UrlLinkTableModel) linkUrlTable.getModel())
1374 .isRowEditable(modelIndex))
1376 editLink.setEnabled(true);
1380 editLink.setEnabled(false);