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)
874 public static void setAppletDefaults()
877 // http://www.jalview.org/old/v2_8/examples/appletParameters.html
879 // showConservation true or false Default is true.
880 // showQuality true or false Default is true.
881 // showConsensus true or false Default is true.
882 // showFeatureSettings true or false Shows the feature settings window when
884 // showTreeBootstraps true or false (default is true) show or hide branch
886 // showTreeDistances true or false (default is true) show or hide branch
888 // showUnlinkedTreeNodes true or false (default is false) indicate if
889 // unassociated nodes should be highlighted in the tree view
890 // showUnconserved true of false (default is false) When true, only gaps and
891 // symbols different to the consensus sequence ions of the alignment
892 // showGroupConsensus true of false (default is false) When true, shows
893 // consensus annotation row for any groups on the alignment. (since 2.7)
894 // showGroupConservation true of false (default is false) When true, shows
895 // amino-acid property conservation annotation row for any groups on the
896 // showConsensusHistogram true of false (default is true) When true, shows
897 // the percentage occurence of the consensus symbol for each column as a
898 // showSequenceLogo true of false (default is false) When true, shows a
899 // sequence logo above the consensus sequence (overlaid above the Consensus
901 Cache.setPropertyNoSave("SHOW_CONSERVATION", "true");
902 Cache.setPropertyNoSave("SHOW_QUALITY", "false");
903 Cache.setPropertyNoSave("SHOW_CONCENSUS", "true");
904 Cache.setPropertyNoSave("SHOW_UNCONSERVED", "false");
905 Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION", "false");
906 Cache.setPropertyNoSave("SHOW_GROUP_CONCENSUS", "false");
908 // TODO -- just a start here
912 * Do any necessary validation before saving settings. Return focus to the
913 * first tab which fails validation.
917 private boolean validateSettings()
919 if (!validateStructure())
921 structureTab.requestFocusInWindow();
928 protected boolean validateStructure()
930 return validateChimeraPath();
938 public void startupFileTextfield_mouseClicked()
940 // TODO: JAL-3048 not needed for Jalview-JS
941 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
942 JalviewFileChooser chooser = JalviewFileChooser
943 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
944 chooser.setFileView(new JalviewFileView());
945 chooser.setDialogTitle(
946 MessageManager.getString("label.select_startup_file"));
948 int value = chooser.showOpenDialog(this);
950 if (value == JalviewFileChooser.APPROVE_OPTION)
952 FileFormatI format = chooser.getSelectedFormat();
955 Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
959 .setText(chooser.getSelectedFile().getAbsolutePath());
970 public void cancel_actionPerformed(ActionEvent e)
974 if (!Platform.isJS())
976 wsPrefs.updateWsMenuConfig(true);
977 wsPrefs.refreshWs_actionPerformed(e);
979 frame.setClosed(true);
980 } catch (Exception ex)
992 public void annotations_actionPerformed(ActionEvent e)
994 conservation.setEnabled(annotations.isSelected());
995 quality.setEnabled(annotations.isSelected());
996 identity.setEnabled(annotations.isSelected());
997 showOccupancy.setEnabled(annotations.isSelected());
998 showGroupConsensus.setEnabled(annotations.isSelected());
999 showGroupConservation.setEnabled(annotations.isSelected());
1000 showConsensHistogram.setEnabled(annotations.isSelected()
1001 && (identity.isSelected() || showGroupConsensus.isSelected()));
1002 showConsensLogo.setEnabled(annotations.isSelected()
1003 && (identity.isSelected() || showGroupConsensus.isSelected()));
1007 public void newLink_actionPerformed(ActionEvent e)
1009 GSequenceLink link = new GSequenceLink();
1010 boolean valid = false;
1013 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1014 MessageManager.getString("label.new_sequence_url_link"),
1015 JvOptionPane.OK_CANCEL_OPTION, -1,
1016 null) == JvOptionPane.OK_OPTION)
1018 if (link.checkValid())
1020 if (((UrlLinkTableModel) linkUrlTable.getModel())
1021 .isUniqueName(link.getName()))
1023 ((UrlLinkTableModel) linkUrlTable.getModel())
1024 .insertRow(link.getName(), link.getURL());
1029 link.notifyDuplicate();
1042 public void editLink_actionPerformed(ActionEvent e)
1044 GSequenceLink link = new GSequenceLink();
1046 int index = linkUrlTable.getSelectedRow();
1049 // button no longer enabled if row is not selected
1050 Cache.log.debug("Edit with no row selected in linkUrlTable");
1054 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1056 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1058 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1059 link.setName(oldName);
1060 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1062 boolean valid = false;
1065 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1066 MessageManager.getString("label.edit_sequence_url_link"),
1067 JvOptionPane.OK_CANCEL_OPTION, -1,
1068 null) == JvOptionPane.OK_OPTION)
1070 if (link.checkValid())
1072 if ((oldName.equals(link.getName()))
1073 || (((UrlLinkTableModel) linkUrlTable.getModel())
1074 .isUniqueName(link.getName())))
1076 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1077 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1082 link.notifyDuplicate();
1095 public void deleteLink_actionPerformed(ActionEvent e)
1097 int index = linkUrlTable.getSelectedRow();
1098 int modelIndex = -1;
1101 // button no longer enabled if row is not selected
1102 Cache.log.debug("Delete with no row selected in linkUrlTable");
1107 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1110 // make sure we use the model index to delete, and not the table index
1111 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1115 public void defaultBrowser_mouseClicked(MouseEvent e)
1117 // TODO: JAL-3048 not needed for j2s
1118 if (!Platform.isJS()) // BH 2019
1125 JFileChooser chooser = new JFileChooser(".");
1126 chooser.setDialogTitle(
1127 MessageManager.getString("label.select_default_browser"));
1129 int value = chooser.showOpenDialog(this);
1131 if (value == JFileChooser.APPROVE_OPTION)
1133 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1142 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1146 protected void showunconserved_actionPerformed(ActionEvent e)
1148 // TODO Auto-generated method stub
1149 super.showunconserved_actionPerformed(e);
1153 * not implemented -- returns empty list
1157 public static List<String> getGroupURLLinks()
1159 return groupURLLinks;
1163 public void minColour_actionPerformed(JPanel panel)
1165 JalviewColourChooser.showColourChooser(this,
1166 MessageManager.getString("label.select_colour_minimum_value"),
1171 public void maxColour_actionPerformed(JPanel panel)
1173 JalviewColourChooser.showColourChooser(this,
1174 MessageManager.getString("label.select_colour_maximum_value"),
1179 public void gapColour_actionPerformed(JPanel gap)
1181 if (!useLegacyGap.isSelected())
1183 JalviewColourChooser.showColourChooser(this,
1184 MessageManager.getString("label.select_gap_colour"),
1190 public void hiddenColour_actionPerformed(JPanel hidden)
1192 JalviewColourChooser.showColourChooser(this,
1193 MessageManager.getString("label.select_hidden_colour"),
1198 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1200 boolean enabled = useLegacyGap.isSelected();
1203 gapColour.setBackground(
1204 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1208 gapColour.setBackground(
1209 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1211 gapColour.setEnabled(!enabled);
1212 gapLabel.setEnabled(!enabled);
1216 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1218 useLegacyGap.setSelected(false);
1219 useLegacyGaps_actionPerformed(null);
1220 showHiddenAtStart.setSelected(false);
1221 hiddenColour.setBackground(
1222 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1226 protected void userIdWidth_actionPerformed()
1230 String val = userIdWidth.getText().trim();
1231 if (val.length() > 0)
1233 Integer iw = Integer.parseInt(val);
1234 if (iw.intValue() < 12)
1236 throw new NumberFormatException();
1238 userIdWidth.setText(iw.toString());
1240 } catch (NumberFormatException x)
1242 userIdWidth.setText("");
1243 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1245 .getString("warn.user_defined_width_requirements"),
1246 MessageManager.getString("label.invalid_id_column_width"),
1247 JvOptionPane.WARNING_MESSAGE);
1252 protected void autoIdWidth_actionPerformed()
1254 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1255 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1259 * Returns true if chimera path is to a valid executable, else show an error
1262 protected boolean validateChimeraPath()
1264 if (chimeraPath.getText().trim().length() > 0)
1266 File f = new File(chimeraPath.getText());
1267 if (!f.canExecute())
1269 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1270 MessageManager.getString("label.invalid_chimera_path"),
1271 MessageManager.getString("label.invalid_name"),
1272 JvOptionPane.ERROR_MESSAGE);
1280 * If Chimera is selected, check it can be found on default or user-specified
1281 * path, if not show a warning/help dialog.
1284 protected void structureViewer_actionPerformed(String selectedItem)
1286 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1290 boolean found = false;
1293 * Try user-specified and standard paths for Chimera executable.
1295 List<String> paths = StructureManager.getChimeraPaths();
1296 paths.add(0, chimeraPath.getText());
1297 for (String path : paths)
1299 if (new File(path.trim()).canExecute())
1307 String[] options = { "OK", "Help" };
1308 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
1309 JvSwingUtils.wrapTooltip(true,
1310 MessageManager.getString("label.chimera_missing")),
1311 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1312 null, options, options[0]);
1313 if (showHelp == JvOptionPane.NO_OPTION)
1317 Help.showHelpWindow(HelpId.StructureViewer);
1318 } catch (HelpSetException e)
1320 e.printStackTrace();
1326 public class OptionsParam
1328 private String name;
1330 private String code;
1332 public OptionsParam(String name, String code)
1338 public String getName()
1343 public void setName(String name)
1348 public String getCode()
1353 public void setCode(String code)
1359 public String toString()
1365 public boolean equals(Object that)
1367 if (!(that instanceof OptionsParam))
1371 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1375 public int hashCode()
1377 return name.hashCode() + code.hashCode();
1381 protected class UrlListSelectionHandler implements ListSelectionListener
1385 public void valueChanged(ListSelectionEvent e)
1387 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1389 int index = lsm.getMinSelectionIndex();
1392 // no selection, so disable delete/edit buttons
1393 editLink.setEnabled(false);
1394 deleteLink.setEnabled(false);
1397 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1399 // enable/disable edit and delete link buttons
1400 if (((UrlLinkTableModel) linkUrlTable.getModel())
1401 .isRowDeletable(modelIndex))
1403 deleteLink.setEnabled(true);
1407 deleteLink.setEnabled(false);
1410 if (((UrlLinkTableModel) linkUrlTable.getModel())
1411 .isRowEditable(modelIndex))
1413 editLink.setEnabled(true);
1417 editLink.setEnabled(false);