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 ANNOTATIONCOLOUR_MAX = "ANNOTATIONCOLOUR_MAX";
89 public static final String ANNOTATIONCOLOUR_MIN = "ANNOTATIONCOLOUR_MIN";
91 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
93 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
95 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
97 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
99 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
101 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
103 public static final String ADD_SS_ANN = "ADD_SS_ANN";
105 public static final String USE_RNAVIEW = "USE_RNAVIEW";
107 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
109 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
111 public static final String CHIMERA_PATH = "CHIMERA_PATH";
113 public static final String SORT_ALIGNMENT = "SORT_ALIGNMENT";
115 public static final String WRAP_ALIGNMENT = "WRAP_ALIGNMENT";
117 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
119 public static final String SORT_BY_TREE = "SORT_BY_TREE";
121 public static final String SHOW_ANNOTATIONS = "SHOW_ANNOTATIONS";
123 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
125 public static final String SHOW_CONSERVATION = "SHOW_CONSERVATION";
127 public static final String SHOW_QUALITY = "SHOW_QUALITY";
129 public static final String SHOW_CONSENSUS_HISTOGRAM = "SHOW_CONSENSUS_HISTOGRAM";
131 public static final String SHOW_CONSENSUS = "SHOW_CONSENSUS";
133 public static final String SHOW_CONSENSUS_LOGO = "SHOW_CONSENSUS_LOGO";
135 public static final String SHOW_GROUP_CONSENSUS = "SHOW_GROUP_CONSENSUS";
137 public static final String SHOW_GROUP_CONSERVATION = "SHOW_GROUP_CONSERVATION";
139 public static final String NORMALISE_CONSENSUS_LOGO = "NORMALISE_CONSENSUS_LOGO";
141 public static final String NORMALISE_LOGO = "NORMALISE_LOGO";
143 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
145 public static final String SHOW_OVERVIEW = "SHOW_OVERVIEW";
147 public static final String SHOW_UNCONSERVED = "SHOW_UNCONSERVED";
149 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
151 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
153 public static final String GAP_COLOUR = "GAP_COLOUR";
155 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
157 private static final int MIN_FONT_SIZE = 1;
159 private static final int MAX_FONT_SIZE = 30;
162 * Holds name and link separated with | character. Sequence ID must be
163 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
165 public static UrlProviderI sequenceUrlLinks; // must be nonfinal for test
167 public final static UrlLinkTableModel dataModel;
170 * Holds name and link separated with | character. Sequence IDS and Sequences
171 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
172 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
173 * for first and second token specified after a pipe character at end |,|.
174 * (TODO: proper escape for using | to separate ids or sequences
177 public static final List<String> groupURLLinks; // not implemented
181 // get links selected to be in the menu (SEQUENCE_LINKS)
182 // and links entered by the user but not selected (STORED_LINKS)
183 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
184 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
185 String defaultUrl = Cache.getDefault("DEFAULT_URL",
186 UrlConstants.DEFAULT_LABEL);
188 // if both links lists are empty, add the DEFAULT_URL link
189 // otherwise we assume the default link is in one of the lists
190 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
192 inMenuString = UrlConstants.DEFAULT_STRING;
194 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
195 inMenuString, notInMenuString);
196 sequenceUrlLinks = factory.createUrlProvider();
197 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
200 * TODO: reformulate groupURL encoding so two or more can be stored in the
201 * .properties file as '|' separated strings
204 groupURLLinks = new ArrayList<>(); // not implemented
207 JInternalFrame frame;
209 private WsPreferences wsPrefs;
211 private OptionsParam promptEachTimeOpt = new OptionsParam(
212 MessageManager.getString("label.prompt_each_time"),
215 private OptionsParam lineArtOpt = new OptionsParam(
216 MessageManager.getString("label.lineart"), "Lineart");
218 private OptionsParam textOpt = new OptionsParam(
219 MessageManager.getString("action.text"), "Text");
222 * Creates a new Preferences object.
227 frame = new JInternalFrame();
228 frame.setContentPane(this);
229 if (!Platform.isJS())
236 wsPrefs = new WsPreferences();
237 wsTab.add(wsPrefs, BorderLayout.CENTER);
239 int width = 500, height = 450;
240 if (Platform.isAMacAndNotJS())
246 Desktop.addInternalFrame(frame,
247 MessageManager.getString("label.preferences"), width, height);
248 frame.setMinimumSize(new Dimension(width, height));
251 * Set Visual tab defaults
253 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
254 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
255 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
256 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
258 conservation.setSelected(Cache.getDefault(SHOW_CONSERVATION, true));
259 quality.setSelected(Cache.getDefault(SHOW_QUALITY, true));
260 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
261 openoverv.setSelected(Cache.getDefault(SHOW_OVERVIEW, false));
263 .setSelected(Cache.getDefault(SHOW_UNCONSERVED, false));
264 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
266 .setSelected(Cache.getDefault(SHOW_GROUP_CONSENSUS, false));
267 showGroupConservation.setSelected(
268 Cache.getDefault(SHOW_GROUP_CONSERVATION, false));
269 showConsensHistogram.setSelected(
270 Cache.getDefault(SHOW_CONSENSUS_HISTOGRAM, true));
272 .setSelected(Cache.getDefault(SHOW_CONSENSUS_LOGO, false));
274 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
276 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
278 String[] fonts = java.awt.GraphicsEnvironment
279 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
280 for (int i = 0; i < fonts.length; i++)
282 fontNameCB.addItem(fonts[i]);
285 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
287 fontSizeCB.addItem(i + "");
290 fontStyleCB.addItem("plain");
291 fontStyleCB.addItem("bold");
292 fontStyleCB.addItem("italic");
294 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
295 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
296 fontStyleCB.setSelectedItem(
297 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
299 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
301 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
303 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
305 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
307 gapSymbolCB.addItem("-");
308 gapSymbolCB.addItem(".");
310 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
312 sortby.addItem("No sort");
313 sortby.addItem("Id");
314 sortby.addItem("Pairwise Identity");
315 sortby.setSelectedItem(Cache.getDefault(SORT_ALIGNMENT, "No sort"));
317 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
319 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
321 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
322 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
323 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
324 SequenceAnnotationOrder.NONE.name()));
325 sortAnnBy.setSelectedItem(savedSort.toString());
327 sortAutocalc.addItem("Autocalculated first");
328 sortAutocalc.addItem("Autocalculated last");
329 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
330 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
331 : sortAutocalc.getItemAt(1));
333 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
334 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
335 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
336 + "/examples/exampleFile_2_3.jar"));
339 * Set Colours tab defaults
341 protColour.addItem(ResidueColourScheme.NONE);
342 nucColour.addItem(ResidueColourScheme.NONE);
343 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
345 String name = cs.getSchemeName();
346 protColour.addItem(name);
347 nucColour.addItem(name);
349 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
350 ResidueColourScheme.NONE);
351 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
352 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
353 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
354 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
355 minColour.setBackground(
356 Cache.getDefaultColour(ANNOTATIONCOLOUR_MIN, Color.orange));
357 maxColour.setBackground(
358 Cache.getDefaultColour(ANNOTATIONCOLOUR_MAX, Color.red));
361 * Set overview panel defaults
363 gapColour.setBackground(
364 Cache.getDefaultColour(GAP_COLOUR,
365 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
366 hiddenColour.setBackground(
367 Cache.getDefaultColour(HIDDEN_COLOUR,
368 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
369 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
370 gapLabel.setEnabled(!useLegacyGap.isSelected());
371 gapColour.setEnabled(!useLegacyGap.isSelected());
373 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
376 * Set Structure tab defaults.
378 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
379 structFromPdb.setSelected(structSelected);
380 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
381 useRnaView.setEnabled(structSelected);
382 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
383 addSecondaryStructure.setEnabled(structSelected);
384 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
385 addTempFactor.setEnabled(structSelected);
386 structViewer.setSelectedItem(
387 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
388 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
389 chimeraPath.addActionListener(new ActionListener()
392 public void actionPerformed(ActionEvent e)
394 validateChimeraPath();
398 if (Cache.getDefault("MAP_WITH_SIFTS", false))
400 siftsMapping.setSelected(true);
404 nwMapping.setSelected(true);
408 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
411 * Set Connections tab defaults
415 linkUrlTable.setModel(dataModel);
416 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
417 linkUrlTable.getModel());
418 linkUrlTable.setRowSorter(sorter);
419 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
421 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
422 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
423 SortOrder.DESCENDING));
424 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
425 SortOrder.DESCENDING));
427 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
429 sorter.setSortKeys(sortKeys);
430 // BH 2018 setSortKeys will do the sort
434 ActionListener onReset;
435 onReset = new ActionListener()
438 public void actionPerformed(ActionEvent e)
440 filterTB.setText("");
441 sorter.setRowFilter(RowFilter.regexFilter(""));
445 doReset.addActionListener(onReset);
447 // filter to display only custom urls
448 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
451 public boolean include(
452 Entry<? extends TableModel, ? extends Object> entry)
454 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
458 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
459 linkUrlTable.getModel());
460 customSorter.setRowFilter(customUrlFilter);
462 ActionListener onCustomOnly;
463 onCustomOnly = new ActionListener()
466 public void actionPerformed(ActionEvent e)
468 filterTB.setText("");
469 sorter.setRowFilter(customUrlFilter);
472 userOnly.addActionListener(onCustomOnly);
474 filterTB.getDocument().addDocumentListener(new DocumentListener()
476 String caseInsensitiveFlag = "(?i)";
479 public void changedUpdate(DocumentEvent e)
481 sorter.setRowFilter(RowFilter
482 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
486 public void removeUpdate(DocumentEvent e)
488 sorter.setRowFilter(RowFilter
489 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
493 public void insertUpdate(DocumentEvent e)
495 sorter.setRowFilter(RowFilter
496 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
500 // set up list selection functionality
501 linkUrlTable.getSelectionModel()
502 .addListSelectionListener(new UrlListSelectionHandler());
504 // set up radio buttons
505 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
507 String onClickName = linkUrlTable.getColumnName(onClickCol);
508 linkUrlTable.getColumn(onClickName)
509 .setCellRenderer(new RadioButtonRenderer());
510 linkUrlTable.getColumn(onClickName)
511 .setCellEditor(new RadioButtonEditor());
513 // get boolean columns and resize those to min possible
514 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
516 if (linkUrlTable.getModel().getColumnClass(column)
517 .equals(Boolean.class))
519 TableColumn tableColumn = linkUrlTable.getColumnModel()
521 int preferredWidth = tableColumn.getMinWidth();
523 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
525 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
526 int cwidth = c.getPreferredSize().width
527 + linkUrlTable.getIntercellSpacing().width;
528 preferredWidth = Math.max(preferredWidth, cwidth);
530 tableColumn.setPreferredWidth(preferredWidth);
534 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
535 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
536 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
537 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
539 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
541 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
542 // note antisense here: default is true
544 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
545 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
548 * Set Output tab defaults
550 setupOutputCombo(epsRendering, "EPS_RENDERING");
551 setupOutputCombo(htmlRendering, "HTML_RENDERING");
552 setupOutputCombo(svgRendering, "SVG_RENDERING");
553 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
554 userIdWidth.setEnabled(!autoIdWidth.isSelected());
555 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
556 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
557 userIdWidth.setText(wi == null ? "" : wi.toString());
558 // TODO: refactor to use common enum via FormatAdapter and allow extension
559 // for new flat file formats
560 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
561 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
562 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
563 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
564 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
565 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
566 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
567 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
569 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
572 * Set Editing tab defaults
574 autoCalculateConsCheck
575 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
576 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
577 sortByTree.setSelected(Cache.getDefault(SORT_BY_TREE, false));
579 annotations_actionPerformed(null); // update the display of the annotation
584 * Set Backups tab defaults
586 loadLastSavedBackupsOptions();
590 * A helper method that sets the items and initial selection in a character
591 * rendering option list (Prompt each time/Lineart/Text)
596 protected void setupOutputCombo(JComboBox<Object> comboBox,
599 comboBox.addItem(promptEachTimeOpt);
600 comboBox.addItem(lineArtOpt);
601 comboBox.addItem(textOpt);
604 * JalviewJS doesn't support Lineart so force it to Text
606 String defaultOption = Platform.isJS() ? "Text"
607 : Cache.getDefault(propertyKey, "Prompt each time");
608 if (defaultOption.equalsIgnoreCase("Text"))
610 comboBox.setSelectedItem(textOpt);
612 else if (defaultOption.equalsIgnoreCase("Lineart"))
614 comboBox.setSelectedItem(lineArtOpt);
618 comboBox.setSelectedItem(promptEachTimeOpt);
623 * Save user selections on the Preferences tabs to the Cache and write out to
629 public void ok_actionPerformed(ActionEvent e)
631 if (!validateSettings())
637 * Save Visual settings
639 Cache.setPropertyNoSave("SHOW_JVSUFFIX",
640 Boolean.toString(seqLimit.isSelected()));
641 Cache.setPropertyNoSave("RIGHT_ALIGN_IDS",
642 Boolean.toString(rightAlign.isSelected()));
643 Cache.setPropertyNoSave("SHOW_FULLSCREEN",
644 Boolean.toString(fullScreen.isSelected()));
645 Cache.setPropertyNoSave("SHOW_OVERVIEW",
646 Boolean.toString(openoverv.isSelected()));
647 Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
648 Boolean.toString(annotations.isSelected()));
649 Cache.setPropertyNoSave(SHOW_CONSERVATION,
650 Boolean.toString(conservation.isSelected()));
651 Cache.setPropertyNoSave(SHOW_QUALITY,
652 Boolean.toString(quality.isSelected()));
653 Cache.setPropertyNoSave("SHOW_IDENTITY",
654 Boolean.toString(identity.isSelected()));
656 Cache.setPropertyNoSave("GAP_SYMBOL",
657 gapSymbolCB.getSelectedItem().toString());
659 Cache.setPropertyNoSave("FONT_NAME",
660 fontNameCB.getSelectedItem().toString());
661 Cache.setPropertyNoSave("FONT_STYLE",
662 fontStyleCB.getSelectedItem().toString());
663 Cache.setPropertyNoSave("FONT_SIZE",
664 fontSizeCB.getSelectedItem().toString());
666 Cache.setPropertyNoSave("ID_ITALICS",
667 Boolean.toString(idItalics.isSelected()));
668 Cache.setPropertyNoSave("SHOW_UNCONSERVED",
669 Boolean.toString(showUnconserved.isSelected()));
670 Cache.setPropertyNoSave(SHOW_OCCUPANCY,
671 Boolean.toString(showOccupancy.isSelected()));
672 Cache.setPropertyNoSave(SHOW_GROUP_CONSENSUS,
673 Boolean.toString(showGroupConsensus.isSelected()));
674 Cache.setPropertyNoSave(SHOW_GROUP_CONSERVATION,
675 Boolean.toString(showGroupConservation.isSelected()));
676 Cache.setPropertyNoSave(SHOW_CONSENSUS_HISTOGRAM,
677 Boolean.toString(showConsensHistogram.isSelected()));
678 Cache.setPropertyNoSave(SHOW_CONSENSUS_LOGO,
679 Boolean.toString(showConsensLogo.isSelected()));
680 Cache.setPropertyNoSave("ANTI_ALIAS",
681 Boolean.toString(smoothFont.isSelected()));
682 Cache.setPropertyNoSave(SCALE_PROTEIN_TO_CDNA,
683 Boolean.toString(scaleProteinToCdna.isSelected()));
684 Cache.setPropertyNoSave("SHOW_NPFEATS_TOOLTIP",
685 Boolean.toString(showNpTooltip.isSelected()));
686 Cache.setPropertyNoSave("SHOW_DBREFS_TOOLTIP",
687 Boolean.toString(showDbRefTooltip.isSelected()));
689 Cache.setPropertyNoSave("WRAP_ALIGNMENT",
690 Boolean.toString(wrap.isSelected()));
692 Cache.setPropertyNoSave("STARTUP_FILE",
693 startupFileTextfield.getText());
694 Cache.setPropertyNoSave("SHOW_STARTUP_FILE",
695 Boolean.toString(startupCheckbox.isSelected()));
697 Cache.setPropertyNoSave(SORT_ALIGNMENT,
698 sortby.getSelectedItem().toString());
700 // convert description of sort order to enum name for save
701 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
702 .forDescription(sortAnnBy.getSelectedItem().toString());
703 if (annSortOrder != null)
705 Cache.setPropertyNoSave(SORT_ANNOTATIONS,
706 annSortOrder.name());
709 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
710 Cache.setPropertyNoSave(SHOW_AUTOCALC_ABOVE,
711 Boolean.valueOf(showAutocalcFirst).toString());
714 * Save Colours settings
716 Cache.setPropertyNoSave(DEFAULT_COLOUR_PROT,
717 protColour.getSelectedItem().toString());
718 Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
719 nucColour.getSelectedItem().toString());
720 Cache.setColourProperty(ANNOTATIONCOLOUR_MIN,
721 minColour.getBackground());
722 Cache.setColourProperty(ANNOTATIONCOLOUR_MAX,
723 maxColour.getBackground());
726 * Save Overview settings
728 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
729 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
730 Cache.setPropertyNoSave(USE_LEGACY_GAP,
731 Boolean.toString(useLegacyGap.isSelected()));
732 Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START,
733 Boolean.toString(showHiddenAtStart.isSelected()));
736 * Save Structure settings
738 Cache.setPropertyNoSave(ADD_TEMPFACT_ANN,
739 Boolean.toString(addTempFactor.isSelected()));
740 Cache.setPropertyNoSave(ADD_SS_ANN,
741 Boolean.toString(addSecondaryStructure.isSelected()));
742 Cache.setPropertyNoSave(USE_RNAVIEW,
743 Boolean.toString(useRnaView.isSelected()));
744 Cache.setPropertyNoSave(STRUCT_FROM_PDB,
745 Boolean.toString(structFromPdb.isSelected()));
746 Cache.setPropertyNoSave(STRUCTURE_DISPLAY,
747 structViewer.getSelectedItem().toString());
748 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
749 Cache.setPropertyNoSave("MAP_WITH_SIFTS",
750 Boolean.toString(siftsMapping.isSelected()));
751 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
754 * Save Output settings
756 Cache.setPropertyNoSave("EPS_RENDERING",
757 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
758 Cache.setPropertyNoSave("HTML_RENDERING",
759 ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
760 Cache.setPropertyNoSave("SVG_RENDERING",
761 ((OptionsParam) svgRendering.getSelectedItem()).getCode());
763 if (!Platform.isJS())
769 // Save Connections settings
770 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
771 BrowserLauncher.resetBrowser();
774 // save user-defined and selected links
775 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
776 if (menuLinks.isEmpty())
778 Cache.removePropertyNoSave("SEQUENCE_LINKS");
782 Cache.setPropertyNoSave("SEQUENCE_LINKS",
783 menuLinks.toString());
786 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
787 if (nonMenuLinks.isEmpty())
789 Cache.removePropertyNoSave("STORED_LINKS");
793 Cache.setPropertyNoSave("STORED_LINKS",
794 nonMenuLinks.toString());
797 Cache.setPropertyNoSave("DEFAULT_URL",
798 sequenceUrlLinks.getPrimaryUrlId());
800 Cache.setPropertyNoSave("USE_PROXY",
801 Boolean.toString(useProxy.isSelected()));
803 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
805 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
807 if (useProxy.isSelected())
809 System.setProperty("http.proxyHost", proxyServerTB.getText());
810 System.setProperty("http.proxyPort", proxyPortTB.getText());
814 System.setProperty("http.proxyHost", "");
815 System.setProperty("http.proxyPort", "");
817 Cache.setProperty("VERSION_CHECK",
818 Boolean.toString(versioncheck.isSelected()));
819 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
821 // default is false - we only set this if the user has actively agreed
822 Cache.setProperty("USAGESTATS",
823 Boolean.toString(usagestats.isSelected()));
825 if (!questionnaire.isSelected())
827 Cache.setProperty("NOQUESTIONNAIRES", "true");
831 // special - made easy to edit a property file to disable questionnaires
832 // by just adding the given line
833 Cache.removeProperty("NOQUESTIONNAIRES");
837 * Save Output settings
839 Cache.setPropertyNoSave("BLC_JVSUFFIX",
840 Boolean.toString(blcjv.isSelected()));
841 Cache.setPropertyNoSave("CLUSTAL_JVSUFFIX",
842 Boolean.toString(clustaljv.isSelected()));
843 Cache.setPropertyNoSave("FASTA_JVSUFFIX",
844 Boolean.toString(fastajv.isSelected()));
845 Cache.setPropertyNoSave("MSF_JVSUFFIX",
846 Boolean.toString(msfjv.isSelected()));
847 Cache.setPropertyNoSave("PFAM_JVSUFFIX",
848 Boolean.toString(pfamjv.isSelected()));
849 Cache.setPropertyNoSave("PILEUP_JVSUFFIX",
850 Boolean.toString(pileupjv.isSelected()));
851 Cache.setPropertyNoSave("PIR_JVSUFFIX",
852 Boolean.toString(pirjv.isSelected()));
853 Cache.setPropertyNoSave("PIR_MODELLER",
854 Boolean.toString(modellerOutput.isSelected()));
855 Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON",
856 Boolean.toString(embbedBioJSON.isSelected()));
857 Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH",
858 Boolean.toString(autoIdWidth.isSelected()));
859 userIdWidth_actionPerformed();
860 Cache.setPropertyNoSave("FIGURE_FIXEDIDWIDTH",
861 userIdWidth.getText());
864 * Save Editing settings
866 Cache.setPropertyNoSave("AUTO_CALC_CONSENSUS",
867 Boolean.toString(autoCalculateConsCheck.isSelected()));
868 Cache.setPropertyNoSave("SORT_BY_TREE",
869 Boolean.toString(sortByTree.isSelected()));
870 Cache.setPropertyNoSave("PAD_GAPS",
871 Boolean.toString(padGaps.isSelected()));
873 if (!Platform.isJS())
875 wsPrefs.updateAndRefreshWsMenuConfig(false);
879 * Save Backups settings
881 Cache.setPropertyNoSave(BackupFiles.CONFIRM_DELETE_OLD,
882 Boolean.toString(backupfilesConfirmDelete.isSelected()));
883 Cache.setPropertyNoSave(BackupFiles.ENABLED,
884 Boolean.toString(enableBackupFiles.isSelected()));
885 Cache.setPropertyNoSave(BackupFiles.NO_MAX,
886 Boolean.toString(backupfilesKeepAll.isSelected()));
887 Cache.setPropertyNoSave(BackupFiles.REVERSE_ORDER,
888 Boolean.toString(suffixReverse.isSelected()));
889 Cache.setPropertyNoSave(BackupFiles.SUFFIX,
890 suffixTemplate.getText());
891 Cache.setPropertyNoSave(BackupFiles.ROLL_MAX,
892 Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
893 Cache.setPropertyNoSave(BackupFiles.SUFFIX_DIGITS,
894 Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
895 Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET",
896 Integer.toString(getComboIntStringKey(backupfilesPresetsCombo)));
898 Cache.saveProperties();
899 Desktop.getInstance().doConfigureStructurePrefs();
902 frame.setClosed(true);
903 } catch (Exception ex)
908 public static void setAppletDefaults()
911 // http://www.jalview.org/old/v2_8/examples/appletParameters.html
913 // showConservation true or false Default is true.
914 // showQuality true or false Default is true.
915 // showConsensus true or false Default is true.
916 // showFeatureSettings true or false Shows the feature settings window when
918 // showTreeBootstraps true or false (default is true) show or hide branch
920 // showTreeDistances true or false (default is true) show or hide branch
922 // showUnlinkedTreeNodes true or false (default is false) indicate if
923 // unassociated nodes should be highlighted in the tree view
924 // showUnconserved true of false (default is false) When true, only gaps and
925 // symbols different to the consensus sequence ions of the alignment
926 // showGroupConsensus true of false (default is false) When true, shows
927 // consensus annotation row for any groups on the alignment. (since 2.7)
928 // showGroupConservation true of false (default is false) When true, shows
929 // amino-acid property conservation annotation row for any groups on the
930 // showConsensusHistogram true of false (default is true) When true, shows
931 // the percentage occurence of the consensus symbol for each column as a
932 // showSequenceLogo true of false (default is false) When true, shows a
933 // sequence logo above the consensus sequence (overlaid above the Consensus
935 Cache.setPropertyNoSave(SHOW_CONSERVATION, "true");
936 Cache.setPropertyNoSave(SHOW_QUALITY, "false");
937 Cache.setPropertyNoSave(SHOW_CONSENSUS, "true");
938 Cache.setPropertyNoSave("SHOW_UNCONSERVED", "false");
939 Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION", "false");
940 Cache.setPropertyNoSave("SHOW_GROUP_CONCENSUS", "false");
942 // TODO -- just a start here
946 * Do any necessary validation before saving settings. Return focus to the
947 * first tab which fails validation.
951 private boolean validateSettings()
953 if (!validateStructure())
955 structureTab.requestFocusInWindow();
962 protected boolean validateStructure()
964 return validateChimeraPath();
972 public void startupFileTextfield_mouseClicked()
974 // TODO: JAL-3048 not needed for Jalview-JS
975 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
976 JalviewFileChooser chooser = JalviewFileChooser
977 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
978 chooser.setFileView(new JalviewFileView());
979 chooser.setDialogTitle(
980 MessageManager.getString("label.select_startup_file"));
982 int value = chooser.showOpenDialog(this);
984 if (value == JalviewFileChooser.APPROVE_OPTION)
986 FileFormatI format = chooser.getSelectedFormat();
989 Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
993 .setText(chooser.getSelectedFile().getAbsolutePath());
1004 public void cancel_actionPerformed(ActionEvent e)
1008 if (!Platform.isJS())
1010 wsPrefs.updateWsMenuConfig(true);
1011 wsPrefs.refreshWs_actionPerformed(e);
1013 frame.setClosed(true);
1014 } catch (Exception ex)
1026 public void annotations_actionPerformed(ActionEvent e)
1028 conservation.setEnabled(annotations.isSelected());
1029 quality.setEnabled(annotations.isSelected());
1030 identity.setEnabled(annotations.isSelected());
1031 showOccupancy.setEnabled(annotations.isSelected());
1032 showGroupConsensus.setEnabled(annotations.isSelected());
1033 showGroupConservation.setEnabled(annotations.isSelected());
1034 showConsensHistogram.setEnabled(annotations.isSelected()
1035 && (identity.isSelected() || showGroupConsensus.isSelected()));
1036 showConsensLogo.setEnabled(annotations.isSelected()
1037 && (identity.isSelected() || showGroupConsensus.isSelected()));
1041 public void newLink_actionPerformed(ActionEvent e)
1043 GSequenceLink link = new GSequenceLink();
1044 boolean valid = false;
1047 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1048 MessageManager.getString("label.new_sequence_url_link"),
1049 JvOptionPane.OK_CANCEL_OPTION, -1,
1050 null) == JvOptionPane.OK_OPTION)
1052 if (link.checkValid())
1054 if (((UrlLinkTableModel) linkUrlTable.getModel())
1055 .isUniqueName(link.getName()))
1057 ((UrlLinkTableModel) linkUrlTable.getModel())
1058 .insertRow(link.getName(), link.getURL());
1063 link.notifyDuplicate();
1076 public void editLink_actionPerformed(ActionEvent e)
1078 GSequenceLink link = new GSequenceLink();
1080 int index = linkUrlTable.getSelectedRow();
1083 // button no longer enabled if row is not selected
1084 Cache.log.debug("Edit with no row selected in linkUrlTable");
1088 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1090 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1092 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1093 link.setName(oldName);
1094 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1096 boolean valid = false;
1099 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1100 MessageManager.getString("label.edit_sequence_url_link"),
1101 JvOptionPane.OK_CANCEL_OPTION, -1,
1102 null) == JvOptionPane.OK_OPTION)
1104 if (link.checkValid())
1106 if ((oldName.equals(link.getName()))
1107 || (((UrlLinkTableModel) linkUrlTable.getModel())
1108 .isUniqueName(link.getName())))
1110 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1111 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1116 link.notifyDuplicate();
1129 public void deleteLink_actionPerformed(ActionEvent e)
1131 int index = linkUrlTable.getSelectedRow();
1132 int modelIndex = -1;
1135 // button no longer enabled if row is not selected
1136 Cache.log.debug("Delete with no row selected in linkUrlTable");
1141 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1144 // make sure we use the model index to delete, and not the table index
1145 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1149 public void defaultBrowser_mouseClicked(MouseEvent e)
1151 // TODO: JAL-3048 not needed for j2s
1152 if (!Platform.isJS()) // BH 2019
1159 JFileChooser chooser = new JFileChooser(".");
1160 chooser.setDialogTitle(
1161 MessageManager.getString("label.select_default_browser"));
1163 int value = chooser.showOpenDialog(this);
1165 if (value == JFileChooser.APPROVE_OPTION)
1167 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1176 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1180 protected void showunconserved_actionPerformed(ActionEvent e)
1182 // TODO Auto-generated method stub
1183 super.showunconserved_actionPerformed(e);
1187 * not implemented -- returns empty list
1191 public static List<String> getGroupURLLinks()
1193 return groupURLLinks;
1197 public void minColour_actionPerformed(JPanel panel)
1199 JalviewColourChooser.showColourChooser(this,
1200 MessageManager.getString("label.select_colour_minimum_value"),
1205 public void maxColour_actionPerformed(JPanel panel)
1207 JalviewColourChooser.showColourChooser(this,
1208 MessageManager.getString("label.select_colour_maximum_value"),
1213 public void gapColour_actionPerformed(JPanel gap)
1215 if (!useLegacyGap.isSelected())
1217 JalviewColourChooser.showColourChooser(this,
1218 MessageManager.getString("label.select_gap_colour"),
1224 public void hiddenColour_actionPerformed(JPanel hidden)
1226 JalviewColourChooser.showColourChooser(this,
1227 MessageManager.getString("label.select_hidden_colour"),
1232 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1234 boolean enabled = useLegacyGap.isSelected();
1237 gapColour.setBackground(
1238 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1242 gapColour.setBackground(
1243 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1245 gapColour.setEnabled(!enabled);
1246 gapLabel.setEnabled(!enabled);
1250 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1252 useLegacyGap.setSelected(false);
1253 useLegacyGaps_actionPerformed(null);
1254 showHiddenAtStart.setSelected(false);
1255 hiddenColour.setBackground(
1256 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1260 protected void userIdWidth_actionPerformed()
1264 String val = userIdWidth.getText().trim();
1265 if (val.length() > 0)
1267 Integer iw = Integer.parseInt(val);
1268 if (iw.intValue() < 12)
1270 throw new NumberFormatException();
1272 userIdWidth.setText(iw.toString());
1274 } catch (NumberFormatException x)
1276 userIdWidth.setText("");
1277 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1279 .getString("warn.user_defined_width_requirements"),
1280 MessageManager.getString("label.invalid_id_column_width"),
1281 JvOptionPane.WARNING_MESSAGE);
1286 protected void autoIdWidth_actionPerformed()
1288 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1289 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1293 * Returns true if chimera path is to a valid executable, else show an error
1296 protected boolean validateChimeraPath()
1298 if (chimeraPath.getText().trim().length() > 0)
1300 File f = new File(chimeraPath.getText());
1301 if (!f.canExecute())
1303 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1304 MessageManager.getString("label.invalid_chimera_path"),
1305 MessageManager.getString("label.invalid_name"),
1306 JvOptionPane.ERROR_MESSAGE);
1314 * If Chimera is selected, check it can be found on default or user-specified
1315 * path, if not show a warning/help dialog.
1318 protected void structureViewer_actionPerformed(String selectedItem)
1320 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1324 boolean found = false;
1327 * Try user-specified and standard paths for Chimera executable.
1329 List<String> paths = StructureManager.getChimeraPaths();
1330 paths.add(0, chimeraPath.getText());
1331 for (String path : paths)
1333 if (new File(path.trim()).canExecute())
1341 String[] options = { "OK", "Help" };
1342 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
1343 JvSwingUtils.wrapTooltip(true,
1344 MessageManager.getString("label.chimera_missing")),
1345 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1346 null, options, options[0]);
1347 if (showHelp == JvOptionPane.NO_OPTION)
1351 Help.showHelpWindow(HelpId.StructureViewer);
1352 } catch (HelpSetException e)
1354 e.printStackTrace();
1360 public class OptionsParam
1362 private String name;
1364 private String code;
1366 public OptionsParam(String name, String code)
1372 public String getName()
1377 public void setName(String name)
1382 public String getCode()
1387 public void setCode(String code)
1393 public String toString()
1399 public boolean equals(Object that)
1401 if (!(that instanceof OptionsParam))
1405 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1409 public int hashCode()
1411 return name.hashCode() + code.hashCode();
1415 protected class UrlListSelectionHandler implements ListSelectionListener
1419 public void valueChanged(ListSelectionEvent e)
1421 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1423 int index = lsm.getMinSelectionIndex();
1426 // no selection, so disable delete/edit buttons
1427 editLink.setEnabled(false);
1428 deleteLink.setEnabled(false);
1431 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1433 // enable/disable edit and delete link buttons
1434 if (((UrlLinkTableModel) linkUrlTable.getModel())
1435 .isRowDeletable(modelIndex))
1437 deleteLink.setEnabled(true);
1441 deleteLink.setEnabled(false);
1444 if (((UrlLinkTableModel) linkUrlTable.getModel())
1445 .isRowEditable(modelIndex))
1447 editLink.setEnabled(true);
1451 editLink.setEnabled(false);