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.BackupFilesPresetEntry;
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.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.JColorChooser;
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 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 CHIMERAX_PATH = "CHIMERAX_PATH";
110 public static final String PYMOL_PATH = "PYMOL_PATH";
112 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
114 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
116 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
118 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
120 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
122 public static final String GAP_COLOUR = "GAP_COLOUR";
124 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
126 private static final int MIN_FONT_SIZE = 1;
128 private static final int MAX_FONT_SIZE = 30;
131 * Holds name and link separated with | character. Sequence ID must be
132 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
134 public static UrlProviderI sequenceUrlLinks;
136 public static UrlLinkTableModel dataModel;
139 * Holds name and link separated with | character. Sequence IDS and Sequences
140 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
141 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
142 * for first and second token specified after a pipe character at end |,|.
143 * (TODO: proper escape for using | to separate ids or sequences
146 public static List<String> groupURLLinks;
149 // get links selected to be in the menu (SEQUENCE_LINKS)
150 // and links entered by the user but not selected (STORED_LINKS)
151 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
152 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
153 String defaultUrl = Cache.getDefault("DEFAULT_URL",
154 UrlConstants.DEFAULT_LABEL);
156 // if both links lists are empty, add the DEFAULT_URL link
157 // otherwise we assume the default link is in one of the lists
158 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
160 inMenuString = UrlConstants.DEFAULT_STRING;
162 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
163 inMenuString, notInMenuString);
164 sequenceUrlLinks = factory.createUrlProvider();
165 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
168 * TODO: reformulate groupURL encoding so two or more can be stored in the
169 * .properties file as '|' separated strings
172 groupURLLinks = new ArrayList<>();
175 JInternalFrame frame;
177 private WsPreferences wsPrefs;
179 private OptionsParam promptEachTimeOpt = new OptionsParam(
180 MessageManager.getString("label.prompt_each_time"),
183 private OptionsParam lineArtOpt = new OptionsParam(
184 MessageManager.getString("label.lineart"), "Lineart");
186 private OptionsParam textOpt = new OptionsParam(
187 MessageManager.getString("action.text"), "Text");
190 * Creates a new Preferences object.
195 frame = new JInternalFrame();
196 frame.setContentPane(this);
197 wsPrefs = new WsPreferences();
198 wsTab.add(wsPrefs, BorderLayout.CENTER);
199 int width = 500, height = 450;
200 new jalview.util.Platform();
201 if (Platform.isAMac())
207 Desktop.addInternalFrame(frame,
208 MessageManager.getString("label.preferences"), width, height);
209 frame.setMinimumSize(new Dimension(width, height));
212 * Set Visual tab defaults
214 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
215 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
216 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
217 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
219 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
220 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
221 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
222 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
224 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
225 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
227 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
228 showGroupConservation.setSelected(
229 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
230 showConsensHistogram.setSelected(
231 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
233 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
235 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
237 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
239 String[] fonts = java.awt.GraphicsEnvironment
240 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
241 for (int i = 0; i < fonts.length; i++)
243 fontNameCB.addItem(fonts[i]);
246 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
248 fontSizeCB.addItem(i + "");
251 fontStyleCB.addItem("plain");
252 fontStyleCB.addItem("bold");
253 fontStyleCB.addItem("italic");
255 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
256 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
257 fontStyleCB.setSelectedItem(
258 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
260 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", true));
262 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
264 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
266 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
268 gapSymbolCB.addItem("-");
269 gapSymbolCB.addItem(".");
271 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
273 sortby.addItem("No sort");
274 sortby.addItem("Id");
275 sortby.addItem("Pairwise Identity");
276 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
278 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
280 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
282 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
283 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
284 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
285 SequenceAnnotationOrder.NONE.name()));
286 sortAnnBy.setSelectedItem(savedSort.toString());
288 sortAutocalc.addItem("Autocalculated first");
289 sortAutocalc.addItem("Autocalculated last");
290 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
291 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
292 : sortAutocalc.getItemAt(1));
294 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
295 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
296 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
297 + "/examples/exampleFile_2_3.jar"));
300 * Set Colours tab defaults
302 protColour.addItem(ResidueColourScheme.NONE);
303 nucColour.addItem(ResidueColourScheme.NONE);
304 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
306 String name = cs.getSchemeName();
307 protColour.addItem(name);
308 nucColour.addItem(name);
310 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
311 ResidueColourScheme.NONE);
312 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
313 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
314 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
315 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
316 minColour.setBackground(
317 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
318 maxColour.setBackground(
319 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
322 * Set overview panel defaults
324 gapColour.setBackground(
325 Cache.getDefaultColour(GAP_COLOUR,
326 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
327 hiddenColour.setBackground(
328 Cache.getDefaultColour(HIDDEN_COLOUR,
329 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
330 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
331 gapLabel.setEnabled(!useLegacyGap.isSelected());
332 gapColour.setEnabled(!useLegacyGap.isSelected());
334 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
337 * Set Structure tab defaults.
339 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
340 structFromPdb.setSelected(structSelected);
341 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
342 useRnaView.setEnabled(structSelected);
343 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
344 addSecondaryStructure.setEnabled(structSelected);
345 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
346 addTempFactor.setEnabled(structSelected);
347 String viewerType = Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name());
348 structViewer.setSelectedItem(viewerType);
349 boolean isChimeraX = viewerType.equals(ViewerType.CHIMERAX.name());
350 if (viewerType.equals(ViewerType.JMOL.name()))
352 structureViewerPath.setText("");
356 structureViewerPath.setText(Cache
357 .getDefault(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH, ""));
359 structureViewerPath.addActionListener(new ActionListener()
362 public void actionPerformed(ActionEvent e)
364 if (validateChimeraPath())
366 Cache.setProperty(structViewer.getSelectedItem()
367 .equals(ViewerType.CHIMERAX.name())
369 : CHIMERA_PATH, structureViewerPath.getText());
374 if (Cache.getDefault("MAP_WITH_SIFTS", false))
376 siftsMapping.setSelected(true);
380 nwMapping.setSelected(true);
384 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
387 * Set Connections tab defaults
391 linkUrlTable.setModel(dataModel);
392 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
393 linkUrlTable.getModel());
394 linkUrlTable.setRowSorter(sorter);
395 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
397 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
398 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
399 SortOrder.DESCENDING));
400 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
401 SortOrder.DESCENDING));
403 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
405 sorter.setSortKeys(sortKeys);
409 ActionListener onReset;
410 onReset = new ActionListener()
413 public void actionPerformed(ActionEvent e)
415 filterTB.setText("");
416 sorter.setRowFilter(RowFilter.regexFilter(""));
420 doReset.addActionListener(onReset);
422 // filter to display only custom urls
423 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<>()
426 public boolean include(
427 Entry<? extends TableModel, ? extends Object> entry)
429 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
433 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
434 linkUrlTable.getModel());
435 customSorter.setRowFilter(customUrlFilter);
437 ActionListener onCustomOnly;
438 onCustomOnly = new ActionListener()
441 public void actionPerformed(ActionEvent e)
443 filterTB.setText("");
444 sorter.setRowFilter(customUrlFilter);
447 userOnly.addActionListener(onCustomOnly);
449 filterTB.getDocument().addDocumentListener(new DocumentListener()
451 String caseInsensitiveFlag = "(?i)";
454 public void changedUpdate(DocumentEvent e)
456 sorter.setRowFilter(RowFilter
457 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
461 public void removeUpdate(DocumentEvent e)
463 sorter.setRowFilter(RowFilter
464 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
468 public void insertUpdate(DocumentEvent e)
470 sorter.setRowFilter(RowFilter
471 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
475 // set up list selection functionality
476 linkUrlTable.getSelectionModel()
477 .addListSelectionListener(new UrlListSelectionHandler());
479 // set up radio buttons
480 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
482 String onClickName = linkUrlTable.getColumnName(onClickCol);
483 linkUrlTable.getColumn(onClickName)
484 .setCellRenderer(new RadioButtonRenderer());
485 linkUrlTable.getColumn(onClickName)
486 .setCellEditor(new RadioButtonEditor());
488 // get boolean columns and resize those to min possible
489 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
491 if (linkUrlTable.getModel().getColumnClass(column)
492 .equals(Boolean.class))
494 TableColumn tableColumn = linkUrlTable.getColumnModel()
496 int preferredWidth = tableColumn.getMinWidth();
498 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
500 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
501 int cwidth = c.getPreferredSize().width
502 + linkUrlTable.getIntercellSpacing().width;
503 preferredWidth = Math.max(preferredWidth, cwidth);
505 tableColumn.setPreferredWidth(preferredWidth);
509 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
510 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
511 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
512 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
514 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
516 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
517 // note antisense here: default is true
519 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
520 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
523 * Set Output tab defaults
525 epsRendering.addItem(promptEachTimeOpt);
526 epsRendering.addItem(lineArtOpt);
527 epsRendering.addItem(textOpt);
528 String defaultEPS = Cache.getDefault("EPS_RENDERING",
530 if (defaultEPS.equalsIgnoreCase("Text"))
532 epsRendering.setSelectedItem(textOpt);
534 else if (defaultEPS.equalsIgnoreCase("Lineart"))
536 epsRendering.setSelectedItem(lineArtOpt);
540 epsRendering.setSelectedItem(promptEachTimeOpt);
542 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
543 userIdWidth.setEnabled(!autoIdWidth.isSelected());
544 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
545 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
546 userIdWidth.setText(wi == null ? "" : wi.toString());
547 // TODO: refactor to use common enum via FormatAdapter and allow extension
548 // for new flat file formats
549 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
550 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
551 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
552 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
553 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
554 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
555 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
556 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
558 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
561 * Set Editing tab defaults
563 autoCalculateConsCheck
564 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
565 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
566 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
568 annotations_actionPerformed(null); // update the display of the annotation
573 * Set Backups tab defaults
575 loadLastSavedBackupsOptions();
579 * Save user selections on the Preferences tabs to the Cache and write out to
585 public void ok_actionPerformed(ActionEvent e)
587 if (!validateSettings())
593 * Save Visual settings
595 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
596 Boolean.toString(seqLimit.isSelected()));
597 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
598 Boolean.toString(rightAlign.isSelected()));
599 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
600 Boolean.toString(fullScreen.isSelected()));
601 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
602 Boolean.toString(openoverv.isSelected()));
603 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
604 Boolean.toString(annotations.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
606 Boolean.toString(conservation.isSelected()));
607 Cache.applicationProperties.setProperty("SHOW_QUALITY",
608 Boolean.toString(quality.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
610 Boolean.toString(identity.isSelected()));
612 Cache.applicationProperties.setProperty("GAP_SYMBOL",
613 gapSymbolCB.getSelectedItem().toString());
615 Cache.applicationProperties.setProperty("FONT_NAME",
616 fontNameCB.getSelectedItem().toString());
617 Cache.applicationProperties.setProperty("FONT_STYLE",
618 fontStyleCB.getSelectedItem().toString());
619 Cache.applicationProperties.setProperty("FONT_SIZE",
620 fontSizeCB.getSelectedItem().toString());
622 Cache.applicationProperties.setProperty("ID_ITALICS",
623 Boolean.toString(idItalics.isSelected()));
624 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
625 Boolean.toString(showUnconserved.isSelected()));
626 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
627 Boolean.toString(showOccupancy.isSelected()));
628 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
629 Boolean.toString(showGroupConsensus.isSelected()));
630 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
631 Boolean.toString(showGroupConservation.isSelected()));
632 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
633 Boolean.toString(showConsensHistogram.isSelected()));
634 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
635 Boolean.toString(showConsensLogo.isSelected()));
636 Cache.applicationProperties.setProperty("ANTI_ALIAS",
637 Boolean.toString(smoothFont.isSelected()));
638 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
639 Boolean.toString(scaleProteinToCdna.isSelected()));
640 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
641 Boolean.toString(showNpTooltip.isSelected()));
642 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
643 Boolean.toString(showDbRefTooltip.isSelected()));
645 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
646 Boolean.toString(wrap.isSelected()));
648 Cache.applicationProperties.setProperty("STARTUP_FILE",
649 startupFileTextfield.getText());
650 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
651 Boolean.toString(startupCheckbox.isSelected()));
653 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
654 sortby.getSelectedItem().toString());
656 // convert description of sort order to enum name for save
657 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
658 .forDescription(sortAnnBy.getSelectedItem().toString());
659 if (annSortOrder != null)
661 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
662 annSortOrder.name());
665 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
666 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
667 Boolean.valueOf(showAutocalcFirst).toString());
670 * Save Colours settings
672 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
673 protColour.getSelectedItem().toString());
674 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
675 nucColour.getSelectedItem().toString());
676 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
677 minColour.getBackground());
678 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
679 maxColour.getBackground());
682 * Save Overview settings
684 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
685 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
686 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
687 Boolean.toString(useLegacyGap.isSelected()));
688 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
689 Boolean.toString(showHiddenAtStart.isSelected()));
692 * Save Structure settings
694 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
695 Boolean.toString(addTempFactor.isSelected()));
696 Cache.applicationProperties.setProperty(ADD_SS_ANN,
697 Boolean.toString(addSecondaryStructure.isSelected()));
698 Cache.applicationProperties.setProperty(USE_RNAVIEW,
699 Boolean.toString(useRnaView.isSelected()));
700 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
701 Boolean.toString(structFromPdb.isSelected()));
702 String viewer = structViewer.getSelectedItem().toString();
703 String viewerPath = structureViewerPath.getText();
704 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
706 if (viewer.equals(ViewerType.CHIMERA.name()))
708 Cache.setOrRemove(CHIMERA_PATH, viewerPath);
710 else if (viewer.equals(ViewerType.CHIMERAX.name()))
712 Cache.setOrRemove(CHIMERAX_PATH, viewerPath);
714 else if (viewer.equals(ViewerType.PYMOL.name()))
716 Cache.setOrRemove(PYMOL_PATH, viewerPath);
718 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
719 Boolean.toString(siftsMapping.isSelected()));
720 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
723 * Save Output settings
725 Cache.applicationProperties.setProperty("EPS_RENDERING",
726 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
729 * Save Connections settings
731 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
733 jalview.util.BrowserLauncher.resetBrowser();
735 // save user-defined and selected links
736 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
737 if (menuLinks.isEmpty())
739 Cache.applicationProperties.remove("SEQUENCE_LINKS");
743 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
744 menuLinks.toString());
747 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
748 if (nonMenuLinks.isEmpty())
750 Cache.applicationProperties.remove("STORED_LINKS");
754 Cache.applicationProperties.setProperty("STORED_LINKS",
755 nonMenuLinks.toString());
758 Cache.applicationProperties.setProperty("DEFAULT_URL",
759 sequenceUrlLinks.getPrimaryUrlId());
761 Cache.applicationProperties.setProperty("USE_PROXY",
762 Boolean.toString(useProxy.isSelected()));
764 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
766 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
768 if (useProxy.isSelected())
770 System.setProperty("http.proxyHost", proxyServerTB.getText());
771 System.setProperty("http.proxyPort", proxyPortTB.getText());
775 System.setProperty("http.proxyHost", "");
776 System.setProperty("http.proxyPort", "");
778 Cache.setProperty("VERSION_CHECK",
779 Boolean.toString(versioncheck.isSelected()));
780 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
782 // default is false - we only set this if the user has actively agreed
783 Cache.setProperty("USAGESTATS",
784 Boolean.toString(usagestats.isSelected()));
786 if (!questionnaire.isSelected())
788 Cache.setProperty("NOQUESTIONNAIRES", "true");
792 // special - made easy to edit a property file to disable questionnaires
793 // by just adding the given line
794 Cache.removeProperty("NOQUESTIONNAIRES");
798 * Save Output settings
800 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
801 Boolean.toString(blcjv.isSelected()));
802 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
803 Boolean.toString(clustaljv.isSelected()));
804 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
805 Boolean.toString(fastajv.isSelected()));
806 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
807 Boolean.toString(msfjv.isSelected()));
808 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
809 Boolean.toString(pfamjv.isSelected()));
810 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
811 Boolean.toString(pileupjv.isSelected()));
812 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
813 Boolean.toString(pirjv.isSelected()));
814 Cache.applicationProperties.setProperty("PIR_MODELLER",
815 Boolean.toString(modellerOutput.isSelected()));
816 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
817 Boolean.toString(embbedBioJSON.isSelected()));
818 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
820 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
821 Boolean.toString(autoIdWidth.isSelected()));
822 userIdWidth_actionPerformed();
823 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
824 userIdWidth.getText());
827 * Save Editing settings
829 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
830 Boolean.toString(autoCalculateConsCheck.isSelected()));
831 Cache.applicationProperties.setProperty("SORT_BY_TREE",
832 Boolean.toString(sortByTree.isSelected()));
833 Cache.applicationProperties.setProperty("PAD_GAPS",
834 Boolean.toString(padGaps.isSelected()));
836 wsPrefs.updateAndRefreshWsMenuConfig(false);
839 * Save Backups settings
841 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
842 Boolean.toString(enableBackupFiles.isSelected()));
843 int preset = getComboIntStringKey(backupfilesPresetsCombo);
844 Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
846 if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
848 BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
849 BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
850 BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
851 Cache.applicationProperties
852 .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
853 customBFPE.toString());
856 BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
858 Cache.applicationProperties.setProperty(
859 BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
861 Cache.saveProperties();
862 Desktop.instance.doConfigureStructurePrefs();
865 frame.setClosed(true);
866 } catch (Exception ex)
872 * Do any necessary validation before saving settings. Return focus to the
873 * first tab which fails validation.
877 private boolean validateSettings()
879 if (!validateStructure())
881 structureTab.requestFocusInWindow();
888 protected boolean validateStructure()
890 return validateChimeraPath();
898 public void startupFileTextfield_mouseClicked()
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.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
918 .setText(chooser.getSelectedFile().getAbsolutePath());
929 public void cancel_actionPerformed(ActionEvent e)
933 wsPrefs.updateWsMenuConfig(true);
934 wsPrefs.refreshWs_actionPerformed(e);
935 frame.setClosed(true);
936 } catch (Exception ex)
948 public void annotations_actionPerformed(ActionEvent e)
950 conservation.setEnabled(annotations.isSelected());
951 quality.setEnabled(annotations.isSelected());
952 identity.setEnabled(annotations.isSelected());
953 showOccupancy.setEnabled(annotations.isSelected());
954 showGroupConsensus.setEnabled(annotations.isSelected());
955 showGroupConservation.setEnabled(annotations.isSelected());
956 showConsensHistogram.setEnabled(annotations.isSelected()
957 && (identity.isSelected() || showGroupConsensus.isSelected()));
958 showConsensLogo.setEnabled(annotations.isSelected()
959 && (identity.isSelected() || showGroupConsensus.isSelected()));
963 public void newLink_actionPerformed(ActionEvent e)
965 GSequenceLink link = new GSequenceLink();
966 boolean valid = false;
969 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
970 MessageManager.getString("label.new_sequence_url_link"),
971 JvOptionPane.OK_CANCEL_OPTION, -1,
972 null) == JvOptionPane.OK_OPTION)
974 if (link.checkValid())
976 if (((UrlLinkTableModel) linkUrlTable.getModel())
977 .isUniqueName(link.getName()))
979 ((UrlLinkTableModel) linkUrlTable.getModel())
980 .insertRow(link.getName(), link.getURL());
985 link.notifyDuplicate();
998 public void editLink_actionPerformed(ActionEvent e)
1000 GSequenceLink link = new GSequenceLink();
1002 int index = linkUrlTable.getSelectedRow();
1005 // button no longer enabled if row is not selected
1006 Cache.log.debug("Edit with no row selected in linkUrlTable");
1010 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1012 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1014 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1015 link.setName(oldName);
1016 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1018 boolean valid = false;
1021 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1022 MessageManager.getString("label.edit_sequence_url_link"),
1023 JvOptionPane.OK_CANCEL_OPTION, -1,
1024 null) == JvOptionPane.OK_OPTION)
1026 if (link.checkValid())
1028 if ((oldName.equals(link.getName()))
1029 || (((UrlLinkTableModel) linkUrlTable.getModel())
1030 .isUniqueName(link.getName())))
1032 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1033 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1038 link.notifyDuplicate();
1051 public void deleteLink_actionPerformed(ActionEvent e)
1053 int index = linkUrlTable.getSelectedRow();
1054 int modelIndex = -1;
1057 // button no longer enabled if row is not selected
1058 Cache.log.debug("Delete with no row selected in linkUrlTable");
1063 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1066 // make sure we use the model index to delete, and not the table index
1067 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1071 public void defaultBrowser_mouseClicked(MouseEvent e)
1073 JFileChooser chooser = new JFileChooser(".");
1074 chooser.setDialogTitle(
1075 MessageManager.getString("label.select_default_browser"));
1077 int value = chooser.showOpenDialog(this);
1079 if (value == JFileChooser.APPROVE_OPTION)
1081 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1090 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1094 protected void showunconserved_actionPerformed(ActionEvent e)
1096 // TODO Auto-generated method stub
1097 super.showunconserved_actionPerformed(e);
1100 public static List<String> getGroupURLLinks()
1102 return groupURLLinks;
1106 public void minColour_actionPerformed(JPanel panel)
1108 Color col = JColorChooser.showDialog(this,
1109 MessageManager.getString("label.select_colour_minimum_value"),
1110 minColour.getBackground());
1113 panel.setBackground(col);
1119 public void maxColour_actionPerformed(JPanel panel)
1121 Color col = JColorChooser.showDialog(this,
1122 MessageManager.getString("label.select_colour_maximum_value"),
1123 maxColour.getBackground());
1126 panel.setBackground(col);
1132 public void gapColour_actionPerformed(JPanel gap)
1134 if (!useLegacyGap.isSelected())
1136 Color col = JColorChooser.showDialog(this,
1137 MessageManager.getString("label.select_gap_colour"),
1138 gapColour.getBackground());
1141 gap.setBackground(col);
1148 public void hiddenColour_actionPerformed(JPanel hidden)
1150 Color col = JColorChooser.showDialog(this,
1151 MessageManager.getString("label.select_hidden_colour"),
1152 hiddenColour.getBackground());
1155 hidden.setBackground(col);
1161 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1163 boolean enabled = useLegacyGap.isSelected();
1166 gapColour.setBackground(
1167 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1171 gapColour.setBackground(
1172 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1174 gapColour.setEnabled(!enabled);
1175 gapLabel.setEnabled(!enabled);
1179 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1181 useLegacyGap.setSelected(false);
1182 useLegacyGaps_actionPerformed(null);
1183 showHiddenAtStart.setSelected(false);
1184 hiddenColour.setBackground(
1185 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1189 protected void userIdWidth_actionPerformed()
1193 String val = userIdWidth.getText().trim();
1194 if (val.length() > 0)
1196 Integer iw = Integer.parseInt(val);
1197 if (iw.intValue() < 12)
1199 throw new NumberFormatException();
1201 userIdWidth.setText(iw.toString());
1203 } catch (NumberFormatException x)
1205 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1207 .getString("warn.user_defined_width_requirements"),
1208 MessageManager.getString("label.invalid_id_column_width"),
1209 JvOptionPane.WARNING_MESSAGE);
1210 userIdWidth.setText("");
1215 protected void autoIdWidth_actionPerformed()
1217 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1218 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1222 * Returns true if chimera path is to a valid executable, else show an error
1225 private boolean validateChimeraPath()
1227 if (structureViewerPath.getText().trim().length() > 0)
1229 File f = new File(structureViewerPath.getText());
1230 if (!f.canExecute())
1232 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1233 MessageManager.getString("label.invalid_chimera_path"),
1234 MessageManager.getString("label.invalid_name"),
1235 JvOptionPane.ERROR_MESSAGE);
1243 * If Chimera or ChimeraX or Pymol is selected, check it can be found on
1244 * default or user-specified path, if not show a warning/help dialog
1247 protected void structureViewer_actionPerformed(String selectedItem)
1249 if (selectedItem.equals(ViewerType.JMOL.name()))
1251 structureViewerPath.setEnabled(false);
1252 structureViewerPathLabel.setEnabled(false);
1255 boolean found = false;
1256 structureViewerPath.setEnabled(true);
1257 structureViewerPathLabel.setEnabled(true);
1258 structureViewerPathLabel.setText(MessageManager
1259 .formatMessage("label.chimera_path", selectedItem));
1262 * Try user-specified and standard paths for Chimera executable
1264 boolean isChimeraX = selectedItem.equals(ViewerType.CHIMERAX.name());
1265 structureViewerPath.setText(Cache
1266 .getDefault(isChimeraX ? CHIMERAX_PATH : CHIMERA_PATH, ""));
1268 List<String> paths = StructureManager.getChimeraPaths(isChimeraX);
1269 paths.add(0, structureViewerPath.getText());
1270 for (String path : paths)
1272 if (new File(path.trim()).canExecute())
1280 String[] options = { "OK", "Help" };
1281 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1282 JvSwingUtils.wrapTooltip(true,
1283 MessageManager.getString("label.chimera_missing")),
1284 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1285 null, options, options[0]);
1286 if (showHelp == JvOptionPane.NO_OPTION)
1290 Help.showHelpWindow(HelpId.StructureViewer);
1291 } catch (HelpSetException e)
1293 e.printStackTrace();
1299 public class OptionsParam
1301 private String name;
1303 private String code;
1305 public OptionsParam(String name, String code)
1311 public String getName()
1316 public void setName(String name)
1321 public String getCode()
1326 public void setCode(String code)
1332 public String toString()
1338 public boolean equals(Object that)
1340 if (!(that instanceof OptionsParam))
1344 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1348 public int hashCode()
1350 return name.hashCode() + code.hashCode();
1354 private class UrlListSelectionHandler implements ListSelectionListener
1358 public void valueChanged(ListSelectionEvent e)
1360 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1362 int index = lsm.getMinSelectionIndex();
1365 // no selection, so disable delete/edit buttons
1366 editLink.setEnabled(false);
1367 deleteLink.setEnabled(false);
1370 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1372 // enable/disable edit and delete link buttons
1373 if (((UrlLinkTableModel) linkUrlTable.getModel())
1374 .isRowDeletable(modelIndex))
1376 deleteLink.setEnabled(true);
1380 deleteLink.setEnabled(false);
1383 if (((UrlLinkTableModel) linkUrlTable.getModel())
1384 .isRowEditable(modelIndex))
1386 editLink.setEnabled(true);
1390 editLink.setEnabled(false);