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.MessageManager;
41 import jalview.util.Platform;
42 import jalview.util.UrlConstants;
43 import jalview.ws.sifts.SiftsSettings;
45 import java.awt.BorderLayout;
46 import java.awt.Color;
47 import java.awt.Component;
48 import java.awt.Dimension;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.MouseEvent;
54 import java.util.ArrayList;
55 import java.util.List;
57 import javax.help.HelpSetException;
58 import javax.swing.JComboBox;
59 import javax.swing.JFileChooser;
60 import javax.swing.JInternalFrame;
61 import javax.swing.JPanel;
62 import javax.swing.ListSelectionModel;
63 import javax.swing.RowFilter;
64 import javax.swing.RowSorter;
65 import javax.swing.SortOrder;
66 import javax.swing.event.DocumentEvent;
67 import javax.swing.event.DocumentListener;
68 import javax.swing.event.ListSelectionEvent;
69 import javax.swing.event.ListSelectionListener;
70 import javax.swing.table.TableCellRenderer;
71 import javax.swing.table.TableColumn;
72 import javax.swing.table.TableModel;
73 import javax.swing.table.TableRowSorter;
75 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
83 @SuppressWarnings("serial")
84 public class Preferences extends GPreferences
86 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
88 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
90 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
92 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
94 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
96 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
98 public static final String ADD_SS_ANN = "ADD_SS_ANN";
100 public static final String USE_RNAVIEW = "USE_RNAVIEW";
102 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
104 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
106 public static final String CHIMERA_PATH = "CHIMERA_PATH";
108 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
110 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
112 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
114 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
116 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
118 public static final String GAP_COLOUR = "GAP_COLOUR";
120 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
122 private static final int MIN_FONT_SIZE = 1;
124 private static final int MAX_FONT_SIZE = 30;
127 * Holds name and link separated with | character. Sequence ID must be
128 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
130 public static UrlProviderI sequenceUrlLinks; // must be nonfinal for test
132 public final static UrlLinkTableModel dataModel;
135 * Holds name and link separated with | character. Sequence IDS and Sequences
136 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
137 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
138 * for first and second token specified after a pipe character at end |,|.
139 * (TODO: proper escape for using | to separate ids or sequences
142 public static final List<String> groupURLLinks;
145 // get links selected to be in the menu (SEQUENCE_LINKS)
146 // and links entered by the user but not selected (STORED_LINKS)
147 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
148 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
149 String defaultUrl = Cache.getDefault("DEFAULT_URL",
150 UrlConstants.DEFAULT_LABEL);
152 // if both links lists are empty, add the DEFAULT_URL link
153 // otherwise we assume the default link is in one of the lists
154 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
156 inMenuString = UrlConstants.DEFAULT_STRING;
158 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
159 inMenuString, notInMenuString);
160 sequenceUrlLinks = factory.createUrlProvider();
161 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
164 * TODO: reformulate groupURL encoding so two or more can be stored in the
165 * .properties file as '|' separated strings
168 groupURLLinks = new ArrayList<>();
171 JInternalFrame frame;
173 private WsPreferences wsPrefs;
175 private OptionsParam promptEachTimeOpt = new OptionsParam(
176 MessageManager.getString("label.prompt_each_time"),
179 private OptionsParam lineArtOpt = new OptionsParam(
180 MessageManager.getString("label.lineart"), "Lineart");
182 private OptionsParam textOpt = new OptionsParam(
183 MessageManager.getString("action.text"), "Text");
186 * Creates a new Preferences object.
191 frame = new JInternalFrame();
192 frame.setContentPane(this);
193 if (!Platform.isJS())
200 wsPrefs = new WsPreferences();
201 wsTab.add(wsPrefs, BorderLayout.CENTER);
203 int width = 500, height = 450;
204 if (Platform.isAMacAndNotJS())
210 Desktop.addInternalFrame(frame,
211 MessageManager.getString("label.preferences"), width, height);
212 frame.setMinimumSize(new Dimension(width, height));
215 * Set Visual tab defaults
217 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
218 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
219 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
220 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
222 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
223 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
224 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
225 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
227 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
228 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
230 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
231 showGroupConservation.setSelected(
232 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
233 showConsensHistogram.setSelected(
234 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
236 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
238 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
240 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
242 String[] fonts = java.awt.GraphicsEnvironment
243 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
244 for (int i = 0; i < fonts.length; i++)
246 fontNameCB.addItem(fonts[i]);
249 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
251 fontSizeCB.addItem(i + "");
254 fontStyleCB.addItem("plain");
255 fontStyleCB.addItem("bold");
256 fontStyleCB.addItem("italic");
258 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
259 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
260 fontStyleCB.setSelectedItem(
261 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
263 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
265 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
267 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
269 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
271 gapSymbolCB.addItem("-");
272 gapSymbolCB.addItem(".");
274 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
276 sortby.addItem("No sort");
277 sortby.addItem("Id");
278 sortby.addItem("Pairwise Identity");
279 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
281 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
283 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
285 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
286 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
287 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
288 SequenceAnnotationOrder.NONE.name()));
289 sortAnnBy.setSelectedItem(savedSort.toString());
291 sortAutocalc.addItem("Autocalculated first");
292 sortAutocalc.addItem("Autocalculated last");
293 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
294 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
295 : sortAutocalc.getItemAt(1));
297 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
298 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
299 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
300 + "/examples/exampleFile_2_3.jar"));
303 * Set Colours tab defaults
305 protColour.addItem(ResidueColourScheme.NONE);
306 nucColour.addItem(ResidueColourScheme.NONE);
307 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
309 String name = cs.getSchemeName();
310 protColour.addItem(name);
311 nucColour.addItem(name);
313 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
314 ResidueColourScheme.NONE);
315 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
316 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
317 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
318 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
319 minColour.setBackground(
320 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
321 maxColour.setBackground(
322 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
325 * Set overview panel defaults
327 gapColour.setBackground(
328 Cache.getDefaultColour(GAP_COLOUR,
329 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
330 hiddenColour.setBackground(
331 Cache.getDefaultColour(HIDDEN_COLOUR,
332 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
333 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
334 gapLabel.setEnabled(!useLegacyGap.isSelected());
335 gapColour.setEnabled(!useLegacyGap.isSelected());
337 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
340 * Set Structure tab defaults.
342 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
343 structFromPdb.setSelected(structSelected);
344 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
345 useRnaView.setEnabled(structSelected);
346 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
347 addSecondaryStructure.setEnabled(structSelected);
348 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
349 addTempFactor.setEnabled(structSelected);
350 structViewer.setSelectedItem(
351 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
352 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
353 chimeraPath.addActionListener(new ActionListener()
356 public void actionPerformed(ActionEvent e)
358 validateChimeraPath();
362 if (Cache.getDefault("MAP_WITH_SIFTS", false))
364 siftsMapping.setSelected(true);
368 nwMapping.setSelected(true);
372 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
375 * Set Connections tab defaults
379 linkUrlTable.setModel(dataModel);
380 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
381 linkUrlTable.getModel());
382 linkUrlTable.setRowSorter(sorter);
383 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
385 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
386 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
387 SortOrder.DESCENDING));
388 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
389 SortOrder.DESCENDING));
391 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
393 sorter.setSortKeys(sortKeys);
394 // BH 2018 setSortKeys will do the sort
398 ActionListener onReset;
399 onReset = new ActionListener()
402 public void actionPerformed(ActionEvent e)
404 filterTB.setText("");
405 sorter.setRowFilter(RowFilter.regexFilter(""));
409 doReset.addActionListener(onReset);
411 // filter to display only custom urls
412 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
415 public boolean include(
416 Entry<? extends TableModel, ? extends Object> entry)
418 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
422 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
423 linkUrlTable.getModel());
424 customSorter.setRowFilter(customUrlFilter);
426 ActionListener onCustomOnly;
427 onCustomOnly = new ActionListener()
430 public void actionPerformed(ActionEvent e)
432 filterTB.setText("");
433 sorter.setRowFilter(customUrlFilter);
436 userOnly.addActionListener(onCustomOnly);
438 filterTB.getDocument().addDocumentListener(new DocumentListener()
440 String caseInsensitiveFlag = "(?i)";
443 public void changedUpdate(DocumentEvent e)
445 sorter.setRowFilter(RowFilter
446 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
450 public void removeUpdate(DocumentEvent e)
452 sorter.setRowFilter(RowFilter
453 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
457 public void insertUpdate(DocumentEvent e)
459 sorter.setRowFilter(RowFilter
460 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
464 // set up list selection functionality
465 linkUrlTable.getSelectionModel()
466 .addListSelectionListener(new UrlListSelectionHandler());
468 // set up radio buttons
469 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
471 String onClickName = linkUrlTable.getColumnName(onClickCol);
472 linkUrlTable.getColumn(onClickName)
473 .setCellRenderer(new RadioButtonRenderer());
474 linkUrlTable.getColumn(onClickName)
475 .setCellEditor(new RadioButtonEditor());
477 // get boolean columns and resize those to min possible
478 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
480 if (linkUrlTable.getModel().getColumnClass(column)
481 .equals(Boolean.class))
483 TableColumn tableColumn = linkUrlTable.getColumnModel()
485 int preferredWidth = tableColumn.getMinWidth();
487 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
489 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
490 int cwidth = c.getPreferredSize().width
491 + linkUrlTable.getIntercellSpacing().width;
492 preferredWidth = Math.max(preferredWidth, cwidth);
494 tableColumn.setPreferredWidth(preferredWidth);
498 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
499 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
500 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
501 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
503 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
505 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
506 // note antisense here: default is true
508 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
509 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
512 * Set Output tab defaults
514 setupOutputCombo(epsRendering, "EPS_RENDERING");
515 setupOutputCombo(htmlRendering, "HTML_RENDERING");
516 setupOutputCombo(svgRendering, "SVG_RENDERING");
517 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
518 userIdWidth.setEnabled(!autoIdWidth.isSelected());
519 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
520 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
521 userIdWidth.setText(wi == null ? "" : wi.toString());
522 // TODO: refactor to use common enum via FormatAdapter and allow extension
523 // for new flat file formats
524 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
525 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
526 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
527 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
528 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
529 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
530 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
531 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
533 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
536 * Set Editing tab defaults
538 autoCalculateConsCheck
539 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
540 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
541 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
543 annotations_actionPerformed(null); // update the display of the annotation
548 * Set Backups tab defaults
550 loadLastSavedBackupsOptions();
554 * A helper method that sets the items and initial selection in a character
555 * rendering option list (Prompt each time/Lineart/Text)
560 protected void setupOutputCombo(JComboBox<Object> comboBox,
563 comboBox.addItem(promptEachTimeOpt);
564 comboBox.addItem(lineArtOpt);
565 comboBox.addItem(textOpt);
568 * JalviewJS doesn't support Lineart so force it to Text
570 String defaultOption = Platform.isJS() ? "Text"
571 : Cache.getDefault(propertyKey, "Prompt each time");
572 if (defaultOption.equalsIgnoreCase("Text"))
574 comboBox.setSelectedItem(textOpt);
576 else if (defaultOption.equalsIgnoreCase("Lineart"))
578 comboBox.setSelectedItem(lineArtOpt);
582 comboBox.setSelectedItem(promptEachTimeOpt);
587 * Save user selections on the Preferences tabs to the Cache and write out to
593 public void ok_actionPerformed(ActionEvent e)
595 if (!validateSettings())
601 * Save Visual settings
603 Cache.setPropertyNoSave("SHOW_JVSUFFIX",
604 Boolean.toString(seqLimit.isSelected()));
605 Cache.setPropertyNoSave("RIGHT_ALIGN_IDS",
606 Boolean.toString(rightAlign.isSelected()));
607 Cache.setPropertyNoSave("SHOW_FULLSCREEN",
608 Boolean.toString(fullScreen.isSelected()));
609 Cache.setPropertyNoSave("SHOW_OVERVIEW",
610 Boolean.toString(openoverv.isSelected()));
611 Cache.setPropertyNoSave("SHOW_ANNOTATIONS",
612 Boolean.toString(annotations.isSelected()));
613 Cache.setPropertyNoSave("SHOW_CONSERVATION",
614 Boolean.toString(conservation.isSelected()));
615 Cache.setPropertyNoSave("SHOW_QUALITY",
616 Boolean.toString(quality.isSelected()));
617 Cache.setPropertyNoSave("SHOW_IDENTITY",
618 Boolean.toString(identity.isSelected()));
620 Cache.setPropertyNoSave("GAP_SYMBOL",
621 gapSymbolCB.getSelectedItem().toString());
623 Cache.setPropertyNoSave("FONT_NAME",
624 fontNameCB.getSelectedItem().toString());
625 Cache.setPropertyNoSave("FONT_STYLE",
626 fontStyleCB.getSelectedItem().toString());
627 Cache.setPropertyNoSave("FONT_SIZE",
628 fontSizeCB.getSelectedItem().toString());
630 Cache.setPropertyNoSave("ID_ITALICS",
631 Boolean.toString(idItalics.isSelected()));
632 Cache.setPropertyNoSave("SHOW_UNCONSERVED",
633 Boolean.toString(showUnconserved.isSelected()));
634 Cache.setPropertyNoSave(SHOW_OCCUPANCY,
635 Boolean.toString(showOccupancy.isSelected()));
636 Cache.setPropertyNoSave("SHOW_GROUP_CONSENSUS",
637 Boolean.toString(showGroupConsensus.isSelected()));
638 Cache.setPropertyNoSave("SHOW_GROUP_CONSERVATION",
639 Boolean.toString(showGroupConservation.isSelected()));
640 Cache.setPropertyNoSave("SHOW_CONSENSUS_HISTOGRAM",
641 Boolean.toString(showConsensHistogram.isSelected()));
642 Cache.setPropertyNoSave("SHOW_CONSENSUS_LOGO",
643 Boolean.toString(showConsensLogo.isSelected()));
644 Cache.setPropertyNoSave("ANTI_ALIAS",
645 Boolean.toString(smoothFont.isSelected()));
646 Cache.setPropertyNoSave(SCALE_PROTEIN_TO_CDNA,
647 Boolean.toString(scaleProteinToCdna.isSelected()));
648 Cache.setPropertyNoSave("SHOW_NPFEATS_TOOLTIP",
649 Boolean.toString(showNpTooltip.isSelected()));
650 Cache.setPropertyNoSave("SHOW_DBREFS_TOOLTIP",
651 Boolean.toString(showDbRefTooltip.isSelected()));
653 Cache.setPropertyNoSave("WRAP_ALIGNMENT",
654 Boolean.toString(wrap.isSelected()));
656 Cache.setPropertyNoSave("STARTUP_FILE",
657 startupFileTextfield.getText());
658 Cache.setPropertyNoSave("SHOW_STARTUP_FILE",
659 Boolean.toString(startupCheckbox.isSelected()));
661 Cache.setPropertyNoSave("SORT_ALIGNMENT",
662 sortby.getSelectedItem().toString());
664 // convert description of sort order to enum name for save
665 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
666 .forDescription(sortAnnBy.getSelectedItem().toString());
667 if (annSortOrder != null)
669 Cache.setPropertyNoSave(SORT_ANNOTATIONS,
670 annSortOrder.name());
673 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
674 Cache.setPropertyNoSave(SHOW_AUTOCALC_ABOVE,
675 Boolean.valueOf(showAutocalcFirst).toString());
678 * Save Colours settings
680 Cache.setPropertyNoSave(DEFAULT_COLOUR_PROT,
681 protColour.getSelectedItem().toString());
682 Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
683 nucColour.getSelectedItem().toString());
684 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
685 minColour.getBackground());
686 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
687 maxColour.getBackground());
690 * Save Overview settings
692 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
693 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
694 Cache.setPropertyNoSave(USE_LEGACY_GAP,
695 Boolean.toString(useLegacyGap.isSelected()));
696 Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START,
697 Boolean.toString(showHiddenAtStart.isSelected()));
700 * Save Structure settings
702 Cache.setPropertyNoSave(ADD_TEMPFACT_ANN,
703 Boolean.toString(addTempFactor.isSelected()));
704 Cache.setPropertyNoSave(ADD_SS_ANN,
705 Boolean.toString(addSecondaryStructure.isSelected()));
706 Cache.setPropertyNoSave(USE_RNAVIEW,
707 Boolean.toString(useRnaView.isSelected()));
708 Cache.setPropertyNoSave(STRUCT_FROM_PDB,
709 Boolean.toString(structFromPdb.isSelected()));
710 Cache.setPropertyNoSave(STRUCTURE_DISPLAY,
711 structViewer.getSelectedItem().toString());
712 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
713 Cache.setPropertyNoSave("MAP_WITH_SIFTS",
714 Boolean.toString(siftsMapping.isSelected()));
715 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
718 * Save Output settings
720 Cache.setPropertyNoSave("EPS_RENDERING",
721 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
722 Cache.setPropertyNoSave("HTML_RENDERING",
723 ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
724 Cache.setPropertyNoSave("SVG_RENDERING",
725 ((OptionsParam) svgRendering.getSelectedItem()).getCode());
728 * Save Connections settings
730 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
732 jalview.util.BrowserLauncher.resetBrowser();
734 // save user-defined and selected links
735 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
736 if (menuLinks.isEmpty())
738 Cache.removePropertyNoSave("SEQUENCE_LINKS");
742 Cache.setPropertyNoSave("SEQUENCE_LINKS",
743 menuLinks.toString());
746 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
747 if (nonMenuLinks.isEmpty())
749 Cache.removePropertyNoSave("STORED_LINKS");
753 Cache.setPropertyNoSave("STORED_LINKS",
754 nonMenuLinks.toString());
757 Cache.setPropertyNoSave("DEFAULT_URL",
758 sequenceUrlLinks.getPrimaryUrlId());
760 Cache.setPropertyNoSave("USE_PROXY",
761 Boolean.toString(useProxy.isSelected()));
763 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
765 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
767 if (useProxy.isSelected())
769 System.setProperty("http.proxyHost", proxyServerTB.getText());
770 System.setProperty("http.proxyPort", proxyPortTB.getText());
774 System.setProperty("http.proxyHost", "");
775 System.setProperty("http.proxyPort", "");
777 Cache.setProperty("VERSION_CHECK",
778 Boolean.toString(versioncheck.isSelected()));
779 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
781 // default is false - we only set this if the user has actively agreed
782 Cache.setProperty("USAGESTATS",
783 Boolean.toString(usagestats.isSelected()));
785 if (!questionnaire.isSelected())
787 Cache.setProperty("NOQUESTIONNAIRES", "true");
791 // special - made easy to edit a property file to disable questionnaires
792 // by just adding the given line
793 Cache.removeProperty("NOQUESTIONNAIRES");
797 * Save Output settings
799 Cache.setPropertyNoSave("BLC_JVSUFFIX",
800 Boolean.toString(blcjv.isSelected()));
801 Cache.setPropertyNoSave("CLUSTAL_JVSUFFIX",
802 Boolean.toString(clustaljv.isSelected()));
803 Cache.setPropertyNoSave("FASTA_JVSUFFIX",
804 Boolean.toString(fastajv.isSelected()));
805 Cache.setPropertyNoSave("MSF_JVSUFFIX",
806 Boolean.toString(msfjv.isSelected()));
807 Cache.setPropertyNoSave("PFAM_JVSUFFIX",
808 Boolean.toString(pfamjv.isSelected()));
809 Cache.setPropertyNoSave("PILEUP_JVSUFFIX",
810 Boolean.toString(pileupjv.isSelected()));
811 Cache.setPropertyNoSave("PIR_JVSUFFIX",
812 Boolean.toString(pirjv.isSelected()));
813 Cache.setPropertyNoSave("PIR_MODELLER",
814 Boolean.toString(modellerOutput.isSelected()));
815 Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON",
816 Boolean.toString(embbedBioJSON.isSelected()));
817 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
819 Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH",
820 Boolean.toString(autoIdWidth.isSelected()));
821 userIdWidth_actionPerformed();
822 Cache.setPropertyNoSave("FIGURE_FIXEDIDWIDTH",
823 userIdWidth.getText());
826 * Save Editing settings
828 Cache.setPropertyNoSave("AUTO_CALC_CONSENSUS",
829 Boolean.toString(autoCalculateConsCheck.isSelected()));
830 Cache.setPropertyNoSave("SORT_BY_TREE",
831 Boolean.toString(sortByTree.isSelected()));
832 Cache.setPropertyNoSave("PAD_GAPS",
833 Boolean.toString(padGaps.isSelected()));
835 if (!Platform.isJS())
837 wsPrefs.updateAndRefreshWsMenuConfig(false);
841 * Save Backups settings
843 Cache.setPropertyNoSave(BackupFiles.CONFIRM_DELETE_OLD,
844 Boolean.toString(backupfilesConfirmDelete.isSelected()));
845 Cache.setPropertyNoSave(BackupFiles.ENABLED,
846 Boolean.toString(enableBackupFiles.isSelected()));
847 Cache.setPropertyNoSave(BackupFiles.NO_MAX,
848 Boolean.toString(backupfilesKeepAll.isSelected()));
849 Cache.setPropertyNoSave(BackupFiles.REVERSE_ORDER,
850 Boolean.toString(suffixReverse.isSelected()));
851 Cache.setPropertyNoSave(BackupFiles.SUFFIX,
852 suffixTemplate.getText());
853 Cache.setPropertyNoSave(BackupFiles.ROLL_MAX,
854 Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
855 Cache.setPropertyNoSave(BackupFiles.SUFFIX_DIGITS,
856 Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
857 Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET",
858 Integer.toString(getComboIntStringKey(backupfilesPresetsCombo)));
860 Cache.saveProperties();
861 Desktop.getInstance().doConfigureStructurePrefs();
864 frame.setClosed(true);
865 } catch (Exception ex)
871 * Do any necessary validation before saving settings. Return focus to the
872 * first tab which fails validation.
876 private boolean validateSettings()
878 if (!validateStructure())
880 structureTab.requestFocusInWindow();
887 protected boolean validateStructure()
889 return validateChimeraPath();
897 public void startupFileTextfield_mouseClicked()
899 // TODO: JAL-3048 not needed for Jalview-JS
900 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
901 JalviewFileChooser chooser = JalviewFileChooser
902 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
903 chooser.setFileView(new JalviewFileView());
904 chooser.setDialogTitle(
905 MessageManager.getString("label.select_startup_file"));
907 int value = chooser.showOpenDialog(this);
909 if (value == JalviewFileChooser.APPROVE_OPTION)
911 FileFormatI format = chooser.getSelectedFormat();
914 Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
918 .setText(chooser.getSelectedFile().getAbsolutePath());
929 public void cancel_actionPerformed(ActionEvent e)
933 if (!Platform.isJS())
935 wsPrefs.updateWsMenuConfig(true);
936 wsPrefs.refreshWs_actionPerformed(e);
938 frame.setClosed(true);
939 } catch (Exception ex)
951 public void annotations_actionPerformed(ActionEvent e)
953 conservation.setEnabled(annotations.isSelected());
954 quality.setEnabled(annotations.isSelected());
955 identity.setEnabled(annotations.isSelected());
956 showOccupancy.setEnabled(annotations.isSelected());
957 showGroupConsensus.setEnabled(annotations.isSelected());
958 showGroupConservation.setEnabled(annotations.isSelected());
959 showConsensHistogram.setEnabled(annotations.isSelected()
960 && (identity.isSelected() || showGroupConsensus.isSelected()));
961 showConsensLogo.setEnabled(annotations.isSelected()
962 && (identity.isSelected() || showGroupConsensus.isSelected()));
966 public void newLink_actionPerformed(ActionEvent e)
968 GSequenceLink link = new GSequenceLink();
969 boolean valid = false;
972 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
973 MessageManager.getString("label.new_sequence_url_link"),
974 JvOptionPane.OK_CANCEL_OPTION, -1,
975 null) == JvOptionPane.OK_OPTION)
977 if (link.checkValid())
979 if (((UrlLinkTableModel) linkUrlTable.getModel())
980 .isUniqueName(link.getName()))
982 ((UrlLinkTableModel) linkUrlTable.getModel())
983 .insertRow(link.getName(), link.getURL());
988 link.notifyDuplicate();
1001 public void editLink_actionPerformed(ActionEvent e)
1003 GSequenceLink link = new GSequenceLink();
1005 int index = linkUrlTable.getSelectedRow();
1008 // button no longer enabled if row is not selected
1009 Cache.log.debug("Edit with no row selected in linkUrlTable");
1013 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1015 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1017 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1018 link.setName(oldName);
1019 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1021 boolean valid = false;
1024 if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link,
1025 MessageManager.getString("label.edit_sequence_url_link"),
1026 JvOptionPane.OK_CANCEL_OPTION, -1,
1027 null) == JvOptionPane.OK_OPTION)
1029 if (link.checkValid())
1031 if ((oldName.equals(link.getName()))
1032 || (((UrlLinkTableModel) linkUrlTable.getModel())
1033 .isUniqueName(link.getName())))
1035 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1036 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1041 link.notifyDuplicate();
1054 public void deleteLink_actionPerformed(ActionEvent e)
1056 int index = linkUrlTable.getSelectedRow();
1057 int modelIndex = -1;
1060 // button no longer enabled if row is not selected
1061 Cache.log.debug("Delete with no row selected in linkUrlTable");
1066 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1069 // make sure we use the model index to delete, and not the table index
1070 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1074 public void defaultBrowser_mouseClicked(MouseEvent e)
1076 // TODO: JAL-3048 not needed for j2s
1077 if (!Platform.isJS()) // BH 2019
1084 JFileChooser chooser = new JFileChooser(".");
1085 chooser.setDialogTitle(
1086 MessageManager.getString("label.select_default_browser"));
1088 int value = chooser.showOpenDialog(this);
1090 if (value == JFileChooser.APPROVE_OPTION)
1092 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1101 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1105 protected void showunconserved_actionPerformed(ActionEvent e)
1107 // TODO Auto-generated method stub
1108 super.showunconserved_actionPerformed(e);
1111 public static List<String> getGroupURLLinks()
1113 return groupURLLinks;
1117 public void minColour_actionPerformed(JPanel panel)
1119 JalviewColourChooser.showColourChooser(this,
1120 MessageManager.getString("label.select_colour_minimum_value"),
1125 public void maxColour_actionPerformed(JPanel panel)
1127 JalviewColourChooser.showColourChooser(this,
1128 MessageManager.getString("label.select_colour_maximum_value"),
1133 public void gapColour_actionPerformed(JPanel gap)
1135 if (!useLegacyGap.isSelected())
1137 JalviewColourChooser.showColourChooser(this,
1138 MessageManager.getString("label.select_gap_colour"),
1144 public void hiddenColour_actionPerformed(JPanel hidden)
1146 JalviewColourChooser.showColourChooser(this,
1147 MessageManager.getString("label.select_hidden_colour"),
1152 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1154 boolean enabled = useLegacyGap.isSelected();
1157 gapColour.setBackground(
1158 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1162 gapColour.setBackground(
1163 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1165 gapColour.setEnabled(!enabled);
1166 gapLabel.setEnabled(!enabled);
1170 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1172 useLegacyGap.setSelected(false);
1173 useLegacyGaps_actionPerformed(null);
1174 showHiddenAtStart.setSelected(false);
1175 hiddenColour.setBackground(
1176 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1180 protected void userIdWidth_actionPerformed()
1184 String val = userIdWidth.getText().trim();
1185 if (val.length() > 0)
1187 Integer iw = Integer.parseInt(val);
1188 if (iw.intValue() < 12)
1190 throw new NumberFormatException();
1192 userIdWidth.setText(iw.toString());
1194 } catch (NumberFormatException x)
1196 userIdWidth.setText("");
1197 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1199 .getString("warn.user_defined_width_requirements"),
1200 MessageManager.getString("label.invalid_id_column_width"),
1201 JvOptionPane.WARNING_MESSAGE);
1206 protected void autoIdWidth_actionPerformed()
1208 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1209 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1213 * Returns true if chimera path is to a valid executable, else show an error
1216 protected boolean validateChimeraPath()
1218 if (chimeraPath.getText().trim().length() > 0)
1220 File f = new File(chimeraPath.getText());
1221 if (!f.canExecute())
1223 JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
1224 MessageManager.getString("label.invalid_chimera_path"),
1225 MessageManager.getString("label.invalid_name"),
1226 JvOptionPane.ERROR_MESSAGE);
1234 * If Chimera is selected, check it can be found on default or user-specified
1235 * path, if not show a warning/help dialog.
1238 protected void structureViewer_actionPerformed(String selectedItem)
1240 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1244 boolean found = false;
1247 * Try user-specified and standard paths for Chimera executable.
1249 List<String> paths = StructureManager.getChimeraPaths();
1250 paths.add(0, chimeraPath.getText());
1251 for (String path : paths)
1253 if (new File(path.trim()).canExecute())
1261 String[] options = { "OK", "Help" };
1262 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(),
1263 JvSwingUtils.wrapTooltip(true,
1264 MessageManager.getString("label.chimera_missing")),
1265 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1266 null, options, options[0]);
1267 if (showHelp == JvOptionPane.NO_OPTION)
1271 Help.showHelpWindow(HelpId.StructureViewer);
1272 } catch (HelpSetException e)
1274 e.printStackTrace();
1280 public class OptionsParam
1282 private String name;
1284 private String code;
1286 public OptionsParam(String name, String code)
1292 public String getName()
1297 public void setName(String name)
1302 public String getCode()
1307 public void setCode(String code)
1313 public String toString()
1319 public boolean equals(Object that)
1321 if (!(that instanceof OptionsParam))
1325 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1329 public int hashCode()
1331 return name.hashCode() + code.hashCode();
1335 protected class UrlListSelectionHandler implements ListSelectionListener
1339 public void valueChanged(ListSelectionEvent e)
1341 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1343 int index = lsm.getMinSelectionIndex();
1346 // no selection, so disable delete/edit buttons
1347 editLink.setEnabled(false);
1348 deleteLink.setEnabled(false);
1351 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1353 // enable/disable edit and delete link buttons
1354 if (((UrlLinkTableModel) linkUrlTable.getModel())
1355 .isRowDeletable(modelIndex))
1357 deleteLink.setEnabled(true);
1361 deleteLink.setEnabled(false);
1364 if (((UrlLinkTableModel) linkUrlTable.getModel())
1365 .isRowEditable(modelIndex))
1367 editLink.setEnabled(true);
1371 editLink.setEnabled(false);