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.bin.Instance;
26 import jalview.gui.Help.HelpId;
27 import jalview.gui.StructureViewer.ViewerType;
28 import jalview.io.BackupFiles;
29 import jalview.io.FileFormatI;
30 import jalview.io.JalviewFileChooser;
31 import jalview.io.JalviewFileView;
32 import jalview.jbgui.GPreferences;
33 import jalview.jbgui.GSequenceLink;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.ColourSchemes;
36 import jalview.schemes.ResidueColourScheme;
37 import jalview.urls.UrlLinkTableModel;
38 import jalview.urls.api.UrlProviderFactoryI;
39 import jalview.urls.api.UrlProviderI;
40 import jalview.urls.desktop.DesktopUrlProviderFactory;
41 import jalview.util.BrowserLauncher;
42 import jalview.util.MessageManager;
43 import jalview.util.Platform;
44 import jalview.util.UrlConstants;
45 import jalview.ws.sifts.SiftsSettings;
47 import java.awt.BorderLayout;
48 import java.awt.Color;
49 import java.awt.Component;
50 import java.awt.Dimension;
52 import java.awt.event.ActionEvent;
53 import java.awt.event.ActionListener;
54 import java.awt.event.MouseEvent;
56 import java.util.ArrayList;
57 import java.util.List;
59 import javax.help.HelpSetException;
60 import javax.swing.JComboBox;
61 import javax.swing.JFileChooser;
62 import javax.swing.JInternalFrame;
63 import javax.swing.JPanel;
64 import javax.swing.ListSelectionModel;
65 import javax.swing.RowFilter;
66 import javax.swing.RowSorter;
67 import javax.swing.SortOrder;
68 import javax.swing.event.DocumentEvent;
69 import javax.swing.event.DocumentListener;
70 import javax.swing.event.ListSelectionEvent;
71 import javax.swing.event.ListSelectionListener;
72 import javax.swing.table.TableCellRenderer;
73 import javax.swing.table.TableColumn;
74 import javax.swing.table.TableModel;
75 import javax.swing.table.TableRowSorter;
77 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
85 @SuppressWarnings("serial")
86 public class Preferences extends GPreferences
88 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
90 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
92 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
94 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
96 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
98 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
100 public static final String ADD_SS_ANN = "ADD_SS_ANN";
102 public static final String USE_RNAVIEW = "USE_RNAVIEW";
104 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
106 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
108 public static final String CHIMERA_PATH = "CHIMERA_PATH";
110 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
112 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
114 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
116 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
118 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
120 public static final String GAP_COLOUR = "GAP_COLOUR";
122 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
124 private static final int MIN_FONT_SIZE = 1;
126 private static final int MAX_FONT_SIZE = 30;
129 * Holds name and link separated with | character. Sequence ID must be
130 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
132 public static UrlProviderI sequenceUrlLinks; // must be nonfinal for test
134 public final static UrlLinkTableModel dataModel;
137 * Holds name and link separated with | character. Sequence IDS and Sequences
138 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
139 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
140 * for first and second token specified after a pipe character at end |,|.
141 * (TODO: proper escape for using | to separate ids or sequences
144 public static final List<String> groupURLLinks; // not implemented
148 // get links selected to be in the menu (SEQUENCE_LINKS)
149 // and links entered by the user but not selected (STORED_LINKS)
150 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
151 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
152 String defaultUrl = Cache.getDefault("DEFAULT_URL",
153 UrlConstants.DEFAULT_LABEL);
155 // if both links lists are empty, add the DEFAULT_URL link
156 // otherwise we assume the default link is in one of the lists
157 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
159 inMenuString = UrlConstants.DEFAULT_STRING;
161 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
162 inMenuString, notInMenuString);
163 sequenceUrlLinks = factory.createUrlProvider();
164 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
167 * TODO: reformulate groupURL encoding so two or more can be stored in the
168 * .properties file as '|' separated strings
171 groupURLLinks = new ArrayList<>(); // not implemented
174 JInternalFrame frame;
176 private WsPreferences wsPrefs;
178 private OptionsParam promptEachTimeOpt = new OptionsParam(
179 MessageManager.getString("label.prompt_each_time"),
182 private OptionsParam lineArtOpt = new OptionsParam(
183 MessageManager.getString("label.lineart"), "Lineart");
185 private OptionsParam textOpt = new OptionsParam(
186 MessageManager.getString("action.text"), "Text");
189 * Creates a new Preferences object.
194 frame = new JInternalFrame();
195 frame.setContentPane(this);
196 if (!Platform.isJS())
203 wsPrefs = new WsPreferences();
204 wsTab.add(wsPrefs, BorderLayout.CENTER);
206 int width = 500, height = 450;
207 if (Platform.isAMacAndNotJS())
213 Desktop.addInternalFrame(frame,
214 MessageManager.getString("label.preferences"), width, height);
215 frame.setMinimumSize(new Dimension(width, height));
218 * Set Visual tab defaults
220 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
221 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
222 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
223 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
225 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
226 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
227 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
228 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
230 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
231 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
233 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
234 showGroupConservation.setSelected(
235 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
236 showConsensHistogram.setSelected(
237 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
239 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
241 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
243 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
245 String[] fonts = java.awt.GraphicsEnvironment
246 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
247 for (int i = 0; i < fonts.length; i++)
249 fontNameCB.addItem(fonts[i]);
252 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
254 fontSizeCB.addItem(i + "");
257 fontStyleCB.addItem("plain");
258 fontStyleCB.addItem("bold");
259 fontStyleCB.addItem("italic");
261 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
262 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
263 fontStyleCB.setSelectedItem(
264 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
266 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
268 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
270 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
272 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
274 gapSymbolCB.addItem("-");
275 gapSymbolCB.addItem(".");
277 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
279 sortby.addItem("No sort");
280 sortby.addItem("Id");
281 sortby.addItem("Pairwise Identity");
282 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
284 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
286 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
288 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
289 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
290 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
291 SequenceAnnotationOrder.NONE.name()));
292 sortAnnBy.setSelectedItem(savedSort.toString());
294 sortAutocalc.addItem("Autocalculated first");
295 sortAutocalc.addItem("Autocalculated last");
296 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
297 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
298 : sortAutocalc.getItemAt(1));
300 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
301 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
302 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
303 + "/examples/exampleFile_2_3.jar"));
306 * Set Colours tab defaults
308 protColour.addItem(ResidueColourScheme.NONE);
309 nucColour.addItem(ResidueColourScheme.NONE);
310 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
312 String name = cs.getSchemeName();
313 protColour.addItem(name);
314 nucColour.addItem(name);
316 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
317 ResidueColourScheme.NONE);
318 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
319 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
320 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
321 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
322 minColour.setBackground(
323 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
324 maxColour.setBackground(
325 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
328 * Set overview panel defaults
330 gapColour.setBackground(
331 Cache.getDefaultColour(GAP_COLOUR,
332 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
333 hiddenColour.setBackground(
334 Cache.getDefaultColour(HIDDEN_COLOUR,
335 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
336 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
337 gapLabel.setEnabled(!useLegacyGap.isSelected());
338 gapColour.setEnabled(!useLegacyGap.isSelected());
340 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
343 * Set Structure tab defaults.
345 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
346 structFromPdb.setSelected(structSelected);
347 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
348 useRnaView.setEnabled(structSelected);
349 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
350 addSecondaryStructure.setEnabled(structSelected);
351 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
352 addTempFactor.setEnabled(structSelected);
353 structViewer.setSelectedItem(
354 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
355 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
356 chimeraPath.addActionListener(new ActionListener()
359 public void actionPerformed(ActionEvent e)
361 validateChimeraPath();
365 if (Cache.getDefault("MAP_WITH_SIFTS", false))
367 siftsMapping.setSelected(true);
371 nwMapping.setSelected(true);
375 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
378 * Set Connections tab defaults
382 linkUrlTable.setModel(dataModel);
383 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
384 linkUrlTable.getModel());
385 linkUrlTable.setRowSorter(sorter);
386 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
388 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
389 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
390 SortOrder.DESCENDING));
391 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
392 SortOrder.DESCENDING));
394 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
396 sorter.setSortKeys(sortKeys);
397 // BH 2018 setSortKeys will do the sort
401 ActionListener onReset;
402 onReset = new ActionListener()
405 public void actionPerformed(ActionEvent e)
407 filterTB.setText("");
408 sorter.setRowFilter(RowFilter.regexFilter(""));
412 doReset.addActionListener(onReset);
414 // filter to display only custom urls
415 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
418 public boolean include(
419 Entry<? extends TableModel, ? extends Object> entry)
421 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
425 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
426 linkUrlTable.getModel());
427 customSorter.setRowFilter(customUrlFilter);
429 ActionListener onCustomOnly;
430 onCustomOnly = new ActionListener()
433 public void actionPerformed(ActionEvent e)
435 filterTB.setText("");
436 sorter.setRowFilter(customUrlFilter);
439 userOnly.addActionListener(onCustomOnly);
441 filterTB.getDocument().addDocumentListener(new DocumentListener()
443 String caseInsensitiveFlag = "(?i)";
446 public void changedUpdate(DocumentEvent e)
448 sorter.setRowFilter(RowFilter
449 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
453 public void removeUpdate(DocumentEvent e)
455 sorter.setRowFilter(RowFilter
456 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
460 public void insertUpdate(DocumentEvent e)
462 sorter.setRowFilter(RowFilter
463 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
467 // set up list selection functionality
468 linkUrlTable.getSelectionModel()
469 .addListSelectionListener(new UrlListSelectionHandler());
471 // set up radio buttons
472 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
474 String onClickName = linkUrlTable.getColumnName(onClickCol);
475 linkUrlTable.getColumn(onClickName)
476 .setCellRenderer(new RadioButtonRenderer());
477 linkUrlTable.getColumn(onClickName)
478 .setCellEditor(new RadioButtonEditor());
480 // get boolean columns and resize those to min possible
481 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
483 if (linkUrlTable.getModel().getColumnClass(column)
484 .equals(Boolean.class))
486 TableColumn tableColumn = linkUrlTable.getColumnModel()
488 int preferredWidth = tableColumn.getMinWidth();
490 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
492 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
493 int cwidth = c.getPreferredSize().width
494 + linkUrlTable.getIntercellSpacing().width;
495 preferredWidth = Math.max(preferredWidth, cwidth);
497 tableColumn.setPreferredWidth(preferredWidth);
501 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
502 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
503 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
504 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
506 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
508 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
509 // note antisense here: default is true
511 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
512 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
515 * Set Output tab defaults
517 setupOutputCombo(epsRendering, "EPS_RENDERING");
518 setupOutputCombo(htmlRendering, "HTML_RENDERING");
519 setupOutputCombo(svgRendering, "SVG_RENDERING");
520 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
521 userIdWidth.setEnabled(!autoIdWidth.isSelected());
522 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
523 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
524 userIdWidth.setText(wi == null ? "" : wi.toString());
525 // TODO: refactor to use common enum via FormatAdapter and allow extension
526 // for new flat file formats
527 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
528 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
529 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
530 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
531 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
532 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
533 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
534 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
536 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
539 * Set Editing tab defaults
541 autoCalculateConsCheck
542 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
543 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
544 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
546 annotations_actionPerformed(null); // update the display of the annotation
551 * Set Backups tab defaults
553 loadLastSavedBackupsOptions();
557 * A helper method that sets the items and initial selection in a character
558 * rendering option list (Prompt each time/Lineart/Text)
563 protected void setupOutputCombo(JComboBox<Object> comboBox,
566 comboBox.addItem(promptEachTimeOpt);
567 comboBox.addItem(lineArtOpt);
568 comboBox.addItem(textOpt);
571 * JalviewJS doesn't support Lineart so force it to Text
573 String defaultOption = Platform.isJS() ? "Text"
574 : Cache.getDefault(propertyKey, "Prompt each time");
575 if (defaultOption.equalsIgnoreCase("Text"))
577 comboBox.setSelectedItem(textOpt);
579 else if (defaultOption.equalsIgnoreCase("Lineart"))
581 comboBox.setSelectedItem(lineArtOpt);
585 comboBox.setSelectedItem(promptEachTimeOpt);
590 * Save user selections on the Preferences tabs to the Cache and write out to
596 public void ok_actionPerformed(ActionEvent e)
598 if (!validateSettings())
604 * Save Visual settings
606 Cache.setPropertyNoSave("SHOW_JVSUFFIX",
607 Boolean.toString(seqLimit.isSelected()));
608 Cache.setPropertyNoSave("RIGHT_ALIGN_IDS",
609 Boolean.toString(rightAlign.isSelected()));
610 Cache.setPropertyNoSave("SHOW_FULLSCREEN",
611 Boolean.toString(fullScreen.isSelected()));
612 Cache.setPropertyNoSave("SHOW_OVERVIEW",
613 Boolean.toString(openoverv.isSelected()));
614 Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
615 Boolean.toString(annotations.isSelected()));
616 Cache.setPropertyNoSave("SHOW_CONSERVATION",
617 Boolean.toString(conservation.isSelected()));
618 Cache.setPropertyNoSave("SHOW_QUALITY",
619 Boolean.toString(quality.isSelected()));
620 Cache.setPropertyNoSave("SHOW_IDENTITY",
621 Boolean.toString(identity.isSelected()));
623 Cache.setPropertyNoSave("GAP_SYMBOL",
624 gapSymbolCB.getSelectedItem().toString());
626 Cache.setPropertyNoSave("FONT_NAME",
627 fontNameCB.getSelectedItem().toString());
628 Cache.setPropertyNoSave("FONT_STYLE",
629 fontStyleCB.getSelectedItem().toString());
630 Cache.setPropertyNoSave("FONT_SIZE",
631 fontSizeCB.getSelectedItem().toString());
633 Cache.setPropertyNoSave("ID_ITALICS",
634 Boolean.toString(idItalics.isSelected()));
635 Cache.setPropertyNoSave("SHOW_UNCONSERVED",
636 Boolean.toString(showUnconserved.isSelected()));
637 Cache.setPropertyNoSave(SHOW_OCCUPANCY,
638 Boolean.toString(showOccupancy.isSelected()));
639 Cache.setPropertyNoSave("SHOW_GROUP_CONSENSUS",
640 Boolean.toString(showGroupConsensus.isSelected()));
641 Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION",
642 Boolean.toString(showGroupConservation.isSelected()));
643 Cache.setPropertyNoSave("SHOW_CONSENSUS_HISTOGRAM",
644 Boolean.toString(showConsensHistogram.isSelected()));
645 Cache.setPropertyNoSave("SHOW_CONSENSUS_LOGO",
646 Boolean.toString(showConsensLogo.isSelected()));
647 Cache.setPropertyNoSave("ANTI_ALIAS",
648 Boolean.toString(smoothFont.isSelected()));
649 Cache.setPropertyNoSave(SCALE_PROTEIN_TO_CDNA,
650 Boolean.toString(scaleProteinToCdna.isSelected()));
651 Cache.setPropertyNoSave("SHOW_NPFEATS_TOOLTIP",
652 Boolean.toString(showNpTooltip.isSelected()));
653 Cache.setPropertyNoSave("SHOW_DBREFS_TOOLTIP",
654 Boolean.toString(showDbRefTooltip.isSelected()));
656 Cache.setPropertyNoSave("WRAP_ALIGNMENT",
657 Boolean.toString(wrap.isSelected()));
659 Cache.setPropertyNoSave("STARTUP_FILE",
660 startupFileTextfield.getText());
661 Cache.setPropertyNoSave("SHOW_STARTUP_FILE",
662 Boolean.toString(startupCheckbox.isSelected()));
664 Cache.setPropertyNoSave("SORT_ALIGNMENT",
665 sortby.getSelectedItem().toString());
667 // convert description of sort order to enum name for save
668 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
669 .forDescription(sortAnnBy.getSelectedItem().toString());
670 if (annSortOrder != null)
672 Cache.setPropertyNoSave(SORT_ANNOTATIONS,
673 annSortOrder.name());
676 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
677 Cache.setPropertyNoSave(SHOW_AUTOCALC_ABOVE,
678 Boolean.valueOf(showAutocalcFirst).toString());
681 * Save Colours settings
683 Cache.setPropertyNoSave(DEFAULT_COLOUR_PROT,
684 protColour.getSelectedItem().toString());
685 Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
686 nucColour.getSelectedItem().toString());
687 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
688 minColour.getBackground());
689 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
690 maxColour.getBackground());
693 * Save Overview settings
695 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
696 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
697 Cache.setPropertyNoSave(USE_LEGACY_GAP,
698 Boolean.toString(useLegacyGap.isSelected()));
699 Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START,
700 Boolean.toString(showHiddenAtStart.isSelected()));
703 * Save Structure settings
705 Cache.setPropertyNoSave(ADD_TEMPFACT_ANN,
706 Boolean.toString(addTempFactor.isSelected()));
707 Cache.setPropertyNoSave(ADD_SS_ANN,
708 Boolean.toString(addSecondaryStructure.isSelected()));
709 Cache.setPropertyNoSave(USE_RNAVIEW,
710 Boolean.toString(useRnaView.isSelected()));
711 Cache.setPropertyNoSave(STRUCT_FROM_PDB,
712 Boolean.toString(structFromPdb.isSelected()));
713 Cache.setPropertyNoSave(STRUCTURE_DISPLAY,
714 structViewer.getSelectedItem().toString());
715 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
716 Cache.setPropertyNoSave("MAP_WITH_SIFTS",
717 Boolean.toString(siftsMapping.isSelected()));
718 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
721 * Save Output settings
723 Cache.setPropertyNoSave("EPS_RENDERING",
724 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
725 Cache.setPropertyNoSave("HTML_RENDERING",
726 ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
727 Cache.setPropertyNoSave("SVG_RENDERING",
728 ((OptionsParam) svgRendering.getSelectedItem()).getCode());
730 if (!Platform.isJS())
736 // Save Connections settings
737 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
738 BrowserLauncher.resetBrowser();
741 // save user-defined and selected links
742 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
743 if (menuLinks.isEmpty())
745 Cache.removePropertyNoSave("SEQUENCE_LINKS");
749 Cache.setPropertyNoSave("SEQUENCE_LINKS",
750 menuLinks.toString());
753 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
754 if (nonMenuLinks.isEmpty())
756 Cache.removePropertyNoSave("STORED_LINKS");
760 Cache.setPropertyNoSave("STORED_LINKS",
761 nonMenuLinks.toString());
764 Cache.setPropertyNoSave("DEFAULT_URL",
765 sequenceUrlLinks.getPrimaryUrlId());
767 Cache.setPropertyNoSave("USE_PROXY",
768 Boolean.toString(useProxy.isSelected()));
770 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
772 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
774 if (useProxy.isSelected())
776 System.setProperty("http.proxyHost", proxyServerTB.getText());
777 System.setProperty("http.proxyPort", proxyPortTB.getText());
781 System.setProperty("http.proxyHost", "");
782 System.setProperty("http.proxyPort", "");
784 Cache.setProperty("VERSION_CHECK",
785 Boolean.toString(versioncheck.isSelected()));
786 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
788 // default is false - we only set this if the user has actively agreed
789 Cache.setProperty("USAGESTATS",
790 Boolean.toString(usagestats.isSelected()));
792 if (!questionnaire.isSelected())
794 Cache.setProperty("NOQUESTIONNAIRES", "true");
798 // special - made easy to edit a property file to disable questionnaires
799 // by just adding the given line
800 Cache.removeProperty("NOQUESTIONNAIRES");
804 * Save Output settings
806 Cache.setPropertyNoSave("BLC_JVSUFFIX",
807 Boolean.toString(blcjv.isSelected()));
808 Cache.setPropertyNoSave("CLUSTAL_JVSUFFIX",
809 Boolean.toString(clustaljv.isSelected()));
810 Cache.setPropertyNoSave("FASTA_JVSUFFIX",
811 Boolean.toString(fastajv.isSelected()));
812 Cache.setPropertyNoSave("MSF_JVSUFFIX",
813 Boolean.toString(msfjv.isSelected()));
814 Cache.setPropertyNoSave("PFAM_JVSUFFIX",
815 Boolean.toString(pfamjv.isSelected()));
816 Cache.setPropertyNoSave("PILEUP_JVSUFFIX",
817 Boolean.toString(pileupjv.isSelected()));
818 Cache.setPropertyNoSave("PIR_JVSUFFIX",
819 Boolean.toString(pirjv.isSelected()));
820 Cache.setPropertyNoSave("PIR_MODELLER",
821 Boolean.toString(modellerOutput.isSelected()));
822 Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON",
823 Boolean.toString(embbedBioJSON.isSelected()));
824 Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH",
825 Boolean.toString(autoIdWidth.isSelected()));
826 userIdWidth_actionPerformed();
827 Cache.setPropertyNoSave("FIGURE_FIXEDIDWIDTH",
828 userIdWidth.getText());
831 * Save Editing settings
833 Cache.setPropertyNoSave("AUTO_CALC_CONSENSUS",
834 Boolean.toString(autoCalculateConsCheck.isSelected()));
835 Cache.setPropertyNoSave("SORT_BY_TREE",
836 Boolean.toString(sortByTree.isSelected()));
837 Cache.setPropertyNoSave("PAD_GAPS",
838 Boolean.toString(padGaps.isSelected()));
840 if (!Platform.isJS())
842 wsPrefs.updateAndRefreshWsMenuConfig(false);
846 * Save Backups settings
848 Cache.setPropertyNoSave(BackupFiles.CONFIRM_DELETE_OLD,
849 Boolean.toString(backupfilesConfirmDelete.isSelected()));
850 Cache.setPropertyNoSave(BackupFiles.ENABLED,
851 Boolean.toString(enableBackupFiles.isSelected()));
852 Cache.setPropertyNoSave(BackupFiles.NO_MAX,
853 Boolean.toString(backupfilesKeepAll.isSelected()));
854 Cache.setPropertyNoSave(BackupFiles.REVERSE_ORDER,
855 Boolean.toString(suffixReverse.isSelected()));
856 Cache.setPropertyNoSave(BackupFiles.SUFFIX,
857 suffixTemplate.getText());
858 Cache.setPropertyNoSave(BackupFiles.ROLL_MAX,
859 Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
860 Cache.setPropertyNoSave(BackupFiles.SUFFIX_DIGITS,
861 Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
862 Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET",
863 Integer.toString(getComboIntStringKey(backupfilesPresetsCombo)));
865 Cache.saveProperties();
866 Instance.getDesktop().doConfigureStructurePrefs();
869 frame.setClosed(true);
870 } catch (Exception ex)
876 * Do any necessary validation before saving settings. Return focus to the
877 * first tab which fails validation.
881 private boolean validateSettings()
883 if (!validateStructure())
885 structureTab.requestFocusInWindow();
892 protected boolean validateStructure()
894 return validateChimeraPath();
902 public void startupFileTextfield_mouseClicked()
904 // TODO: JAL-3048 not needed for Jalview-JS
905 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
906 JalviewFileChooser chooser = JalviewFileChooser
907 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
908 chooser.setFileView(new JalviewFileView());
909 chooser.setDialogTitle(
910 MessageManager.getString("label.select_startup_file"));
912 int value = chooser.showOpenDialog(this);
914 if (value == JalviewFileChooser.APPROVE_OPTION)
916 FileFormatI format = chooser.getSelectedFormat();
919 Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
923 .setText(chooser.getSelectedFile().getAbsolutePath());
934 public void cancel_actionPerformed(ActionEvent e)
938 if (!Platform.isJS())
940 wsPrefs.updateWsMenuConfig(true);
941 wsPrefs.refreshWs_actionPerformed(e);
943 frame.setClosed(true);
944 } catch (Exception ex)
956 public void annotations_actionPerformed(ActionEvent e)
958 conservation.setEnabled(annotations.isSelected());
959 quality.setEnabled(annotations.isSelected());
960 identity.setEnabled(annotations.isSelected());
961 showOccupancy.setEnabled(annotations.isSelected());
962 showGroupConsensus.setEnabled(annotations.isSelected());
963 showGroupConservation.setEnabled(annotations.isSelected());
964 showConsensHistogram.setEnabled(annotations.isSelected()
965 && (identity.isSelected() || showGroupConsensus.isSelected()));
966 showConsensLogo.setEnabled(annotations.isSelected()
967 && (identity.isSelected() || showGroupConsensus.isSelected()));
971 public void newLink_actionPerformed(ActionEvent e)
973 GSequenceLink link = new GSequenceLink();
974 boolean valid = false;
977 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
978 MessageManager.getString("label.new_sequence_url_link"),
979 JvOptionPane.OK_CANCEL_OPTION, -1,
980 null) == JvOptionPane.OK_OPTION)
982 if (link.checkValid())
984 if (((UrlLinkTableModel) linkUrlTable.getModel())
985 .isUniqueName(link.getName()))
987 ((UrlLinkTableModel) linkUrlTable.getModel())
988 .insertRow(link.getName(), link.getURL());
993 link.notifyDuplicate();
1006 public void editLink_actionPerformed(ActionEvent e)
1008 GSequenceLink link = new GSequenceLink();
1010 int index = linkUrlTable.getSelectedRow();
1013 // button no longer enabled if row is not selected
1014 Cache.log.debug("Edit with no row selected in linkUrlTable");
1018 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1020 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1022 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1023 link.setName(oldName);
1024 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1026 boolean valid = false;
1029 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1030 MessageManager.getString("label.edit_sequence_url_link"),
1031 JvOptionPane.OK_CANCEL_OPTION, -1,
1032 null) == JvOptionPane.OK_OPTION)
1034 if (link.checkValid())
1036 if ((oldName.equals(link.getName()))
1037 || (((UrlLinkTableModel) linkUrlTable.getModel())
1038 .isUniqueName(link.getName())))
1040 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1041 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1046 link.notifyDuplicate();
1059 public void deleteLink_actionPerformed(ActionEvent e)
1061 int index = linkUrlTable.getSelectedRow();
1062 int modelIndex = -1;
1065 // button no longer enabled if row is not selected
1066 Cache.log.debug("Delete with no row selected in linkUrlTable");
1071 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1074 // make sure we use the model index to delete, and not the table index
1075 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1079 public void defaultBrowser_mouseClicked(MouseEvent e)
1081 // TODO: JAL-3048 not needed for j2s
1082 if (!Platform.isJS()) // BH 2019
1089 JFileChooser chooser = new JFileChooser(".");
1090 chooser.setDialogTitle(
1091 MessageManager.getString("label.select_default_browser"));
1093 int value = chooser.showOpenDialog(this);
1095 if (value == JFileChooser.APPROVE_OPTION)
1097 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1106 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1110 protected void showunconserved_actionPerformed(ActionEvent e)
1112 // TODO Auto-generated method stub
1113 super.showunconserved_actionPerformed(e);
1117 * not implemented -- returns empty list
1121 public static List<String> getGroupURLLinks()
1123 return groupURLLinks;
1127 public void minColour_actionPerformed(JPanel panel)
1129 JalviewColourChooser.showColourChooser(this,
1130 MessageManager.getString("label.select_colour_minimum_value"),
1135 public void maxColour_actionPerformed(JPanel panel)
1137 JalviewColourChooser.showColourChooser(this,
1138 MessageManager.getString("label.select_colour_maximum_value"),
1143 public void gapColour_actionPerformed(JPanel gap)
1145 if (!useLegacyGap.isSelected())
1147 JalviewColourChooser.showColourChooser(this,
1148 MessageManager.getString("label.select_gap_colour"),
1154 public void hiddenColour_actionPerformed(JPanel hidden)
1156 JalviewColourChooser.showColourChooser(this,
1157 MessageManager.getString("label.select_hidden_colour"),
1162 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1164 boolean enabled = useLegacyGap.isSelected();
1167 gapColour.setBackground(
1168 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1172 gapColour.setBackground(
1173 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1175 gapColour.setEnabled(!enabled);
1176 gapLabel.setEnabled(!enabled);
1180 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1182 useLegacyGap.setSelected(false);
1183 useLegacyGaps_actionPerformed(null);
1184 showHiddenAtStart.setSelected(false);
1185 hiddenColour.setBackground(
1186 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1190 protected void userIdWidth_actionPerformed()
1194 String val = userIdWidth.getText().trim();
1195 if (val.length() > 0)
1197 Integer iw = Integer.parseInt(val);
1198 if (iw.intValue() < 12)
1200 throw new NumberFormatException();
1202 userIdWidth.setText(iw.toString());
1204 } catch (NumberFormatException x)
1206 userIdWidth.setText("");
1207 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1209 .getString("warn.user_defined_width_requirements"),
1210 MessageManager.getString("label.invalid_id_column_width"),
1211 JvOptionPane.WARNING_MESSAGE);
1216 protected void autoIdWidth_actionPerformed()
1218 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1219 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1223 * Returns true if chimera path is to a valid executable, else show an error
1226 protected boolean validateChimeraPath()
1228 if (chimeraPath.getText().trim().length() > 0)
1230 File f = new File(chimeraPath.getText());
1231 if (!f.canExecute())
1233 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1234 MessageManager.getString("label.invalid_chimera_path"),
1235 MessageManager.getString("label.invalid_name"),
1236 JvOptionPane.ERROR_MESSAGE);
1244 * If Chimera is selected, check it can be found on default or user-specified
1245 * path, if not show a warning/help dialog.
1248 protected void structureViewer_actionPerformed(String selectedItem)
1250 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1254 boolean found = false;
1257 * Try user-specified and standard paths for Chimera executable.
1259 List<String> paths = StructureManager.getChimeraPaths();
1260 paths.add(0, chimeraPath.getText());
1261 for (String path : paths)
1263 if (new File(path.trim()).canExecute())
1271 String[] options = { "OK", "Help" };
1272 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
1273 JvSwingUtils.wrapTooltip(true,
1274 MessageManager.getString("label.chimera_missing")),
1275 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1276 null, options, options[0]);
1277 if (showHelp == JvOptionPane.NO_OPTION)
1281 Help.showHelpWindow(HelpId.StructureViewer);
1282 } catch (HelpSetException e)
1284 e.printStackTrace();
1290 public class OptionsParam
1292 private String name;
1294 private String code;
1296 public OptionsParam(String name, String code)
1302 public String getName()
1307 public void setName(String name)
1312 public String getCode()
1317 public void setCode(String code)
1323 public String toString()
1329 public boolean equals(Object that)
1331 if (!(that instanceof OptionsParam))
1335 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1339 public int hashCode()
1341 return name.hashCode() + code.hashCode();
1345 protected class UrlListSelectionHandler implements ListSelectionListener
1349 public void valueChanged(ListSelectionEvent e)
1351 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1353 int index = lsm.getMinSelectionIndex();
1356 // no selection, so disable delete/edit buttons
1357 editLink.setEnabled(false);
1358 deleteLink.setEnabled(false);
1361 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1363 // enable/disable edit and delete link buttons
1364 if (((UrlLinkTableModel) linkUrlTable.getModel())
1365 .isRowDeletable(modelIndex))
1367 deleteLink.setEnabled(true);
1371 deleteLink.setEnabled(false);
1374 if (((UrlLinkTableModel) linkUrlTable.getModel())
1375 .isRowEditable(modelIndex))
1377 editLink.setEnabled(true);
1381 editLink.setEnabled(false);