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 java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Dimension;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.MouseEvent;
32 import java.util.ArrayList;
33 import java.util.List;
35 import javax.help.HelpSetException;
36 import javax.swing.JColorChooser;
37 import javax.swing.JFileChooser;
38 import javax.swing.JInternalFrame;
39 import javax.swing.JPanel;
40 import javax.swing.ListSelectionModel;
41 import javax.swing.RowFilter;
42 import javax.swing.RowSorter;
43 import javax.swing.SortOrder;
44 import javax.swing.event.DocumentEvent;
45 import javax.swing.event.DocumentListener;
46 import javax.swing.event.ListSelectionEvent;
47 import javax.swing.event.ListSelectionListener;
48 import javax.swing.table.TableCellRenderer;
49 import javax.swing.table.TableColumn;
50 import javax.swing.table.TableModel;
51 import javax.swing.table.TableRowSorter;
53 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
54 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
55 import jalview.bin.Cache;
56 import jalview.ext.pymol.PymolManager;
57 import jalview.gui.Help.HelpId;
58 import jalview.gui.StructureViewer.ViewerType;
59 import jalview.io.BackupFiles;
60 import jalview.io.BackupFilesPresetEntry;
61 import jalview.io.FileFormatI;
62 import jalview.io.JalviewFileChooser;
63 import jalview.io.JalviewFileView;
64 import jalview.jbgui.GPreferences;
65 import jalview.jbgui.GSequenceLink;
66 import jalview.schemes.ColourSchemeI;
67 import jalview.schemes.ColourSchemes;
68 import jalview.schemes.ResidueColourScheme;
69 import jalview.urls.UrlLinkTableModel;
70 import jalview.urls.api.UrlProviderFactoryI;
71 import jalview.urls.api.UrlProviderI;
72 import jalview.urls.desktop.DesktopUrlProviderFactory;
73 import jalview.util.MessageManager;
74 import jalview.util.Platform;
75 import jalview.util.UrlConstants;
76 import jalview.ws.sifts.SiftsSettings;
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);
349 * set choice of structure viewer, and path if saved as a preference;
350 * default to Jmol (first choice) if an unexpected value is found
352 String viewerType = Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name());
353 structViewer.setSelectedItem(viewerType);
354 String viewerPath = "";
355 ViewerType type = null;
358 type = ViewerType.valueOf(viewerType);
364 viewerPath = Cache.getDefault(CHIMERA_PATH, "");
367 viewerPath = Cache.getDefault(CHIMERAX_PATH, "");
370 viewerPath = Cache.getDefault(PYMOL_PATH, "");
373 } catch (IllegalArgumentException e)
375 Cache.log.error("Unknown structure viewer type: " + viewerType
376 + ", defaulting to Jmol");
377 type = ViewerType.JMOL;
379 structureViewerPath.setText(viewerPath);
381 structureViewerPath.addActionListener(new ActionListener()
384 public void actionPerformed(ActionEvent e)
386 if (validateViewerPath())
388 Cache.setProperty(structViewer.getSelectedItem()
389 .equals(ViewerType.CHIMERAX.name())
391 : CHIMERA_PATH, structureViewerPath.getText());
396 if (Cache.getDefault("MAP_WITH_SIFTS", false))
398 siftsMapping.setSelected(true);
402 nwMapping.setSelected(true);
406 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
409 * Set Connections tab defaults
413 linkUrlTable.setModel(dataModel);
414 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
415 linkUrlTable.getModel());
416 linkUrlTable.setRowSorter(sorter);
417 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
419 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
420 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
421 SortOrder.DESCENDING));
422 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
423 SortOrder.DESCENDING));
425 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
427 sorter.setSortKeys(sortKeys);
431 ActionListener onReset;
432 onReset = new ActionListener()
435 public void actionPerformed(ActionEvent e)
437 filterTB.setText("");
438 sorter.setRowFilter(RowFilter.regexFilter(""));
442 doReset.addActionListener(onReset);
444 // filter to display only custom urls
445 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<>()
448 public boolean include(
449 Entry<? extends TableModel, ? extends Object> entry)
451 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
455 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
456 linkUrlTable.getModel());
457 customSorter.setRowFilter(customUrlFilter);
459 ActionListener onCustomOnly;
460 onCustomOnly = new ActionListener()
463 public void actionPerformed(ActionEvent e)
465 filterTB.setText("");
466 sorter.setRowFilter(customUrlFilter);
469 userOnly.addActionListener(onCustomOnly);
471 filterTB.getDocument().addDocumentListener(new DocumentListener()
473 String caseInsensitiveFlag = "(?i)";
476 public void changedUpdate(DocumentEvent e)
478 sorter.setRowFilter(RowFilter
479 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
483 public void removeUpdate(DocumentEvent e)
485 sorter.setRowFilter(RowFilter
486 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
490 public void insertUpdate(DocumentEvent e)
492 sorter.setRowFilter(RowFilter
493 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
497 // set up list selection functionality
498 linkUrlTable.getSelectionModel()
499 .addListSelectionListener(new UrlListSelectionHandler());
501 // set up radio buttons
502 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
504 String onClickName = linkUrlTable.getColumnName(onClickCol);
505 linkUrlTable.getColumn(onClickName)
506 .setCellRenderer(new RadioButtonRenderer());
507 linkUrlTable.getColumn(onClickName)
508 .setCellEditor(new RadioButtonEditor());
510 // get boolean columns and resize those to min possible
511 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
513 if (linkUrlTable.getModel().getColumnClass(column)
514 .equals(Boolean.class))
516 TableColumn tableColumn = linkUrlTable.getColumnModel()
518 int preferredWidth = tableColumn.getMinWidth();
520 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
522 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
523 int cwidth = c.getPreferredSize().width
524 + linkUrlTable.getIntercellSpacing().width;
525 preferredWidth = Math.max(preferredWidth, cwidth);
527 tableColumn.setPreferredWidth(preferredWidth);
531 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
532 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
533 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
534 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
536 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
538 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
539 // note antisense here: default is true
541 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
542 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
545 * Set Output tab defaults
547 epsRendering.addItem(promptEachTimeOpt);
548 epsRendering.addItem(lineArtOpt);
549 epsRendering.addItem(textOpt);
550 String defaultEPS = Cache.getDefault("EPS_RENDERING",
552 if (defaultEPS.equalsIgnoreCase("Text"))
554 epsRendering.setSelectedItem(textOpt);
556 else if (defaultEPS.equalsIgnoreCase("Lineart"))
558 epsRendering.setSelectedItem(lineArtOpt);
562 epsRendering.setSelectedItem(promptEachTimeOpt);
564 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
565 userIdWidth.setEnabled(!autoIdWidth.isSelected());
566 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
567 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
568 userIdWidth.setText(wi == null ? "" : wi.toString());
569 // TODO: refactor to use common enum via FormatAdapter and allow extension
570 // for new flat file formats
571 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
572 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
573 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
574 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
575 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
576 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
577 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
578 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
580 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
583 * Set Editing tab defaults
585 autoCalculateConsCheck
586 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
587 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
588 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
590 annotations_actionPerformed(null); // update the display of the annotation
595 * Set Backups tab defaults
597 loadLastSavedBackupsOptions();
601 * Save user selections on the Preferences tabs to the Cache and write out to
607 public void ok_actionPerformed(ActionEvent e)
609 if (!validateSettings())
615 * Save Visual settings
617 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
618 Boolean.toString(seqLimit.isSelected()));
619 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
620 Boolean.toString(rightAlign.isSelected()));
621 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
622 Boolean.toString(fullScreen.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
624 Boolean.toString(openoverv.isSelected()));
625 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
626 Boolean.toString(annotations.isSelected()));
627 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
628 Boolean.toString(conservation.isSelected()));
629 Cache.applicationProperties.setProperty("SHOW_QUALITY",
630 Boolean.toString(quality.isSelected()));
631 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
632 Boolean.toString(identity.isSelected()));
634 Cache.applicationProperties.setProperty("GAP_SYMBOL",
635 gapSymbolCB.getSelectedItem().toString());
637 Cache.applicationProperties.setProperty("FONT_NAME",
638 fontNameCB.getSelectedItem().toString());
639 Cache.applicationProperties.setProperty("FONT_STYLE",
640 fontStyleCB.getSelectedItem().toString());
641 Cache.applicationProperties.setProperty("FONT_SIZE",
642 fontSizeCB.getSelectedItem().toString());
644 Cache.applicationProperties.setProperty("ID_ITALICS",
645 Boolean.toString(idItalics.isSelected()));
646 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
647 Boolean.toString(showUnconserved.isSelected()));
648 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
649 Boolean.toString(showOccupancy.isSelected()));
650 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
651 Boolean.toString(showGroupConsensus.isSelected()));
652 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
653 Boolean.toString(showGroupConservation.isSelected()));
654 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
655 Boolean.toString(showConsensHistogram.isSelected()));
656 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
657 Boolean.toString(showConsensLogo.isSelected()));
658 Cache.applicationProperties.setProperty("ANTI_ALIAS",
659 Boolean.toString(smoothFont.isSelected()));
660 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
661 Boolean.toString(scaleProteinToCdna.isSelected()));
662 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
663 Boolean.toString(showNpTooltip.isSelected()));
664 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
665 Boolean.toString(showDbRefTooltip.isSelected()));
667 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
668 Boolean.toString(wrap.isSelected()));
670 Cache.applicationProperties.setProperty("STARTUP_FILE",
671 startupFileTextfield.getText());
672 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
673 Boolean.toString(startupCheckbox.isSelected()));
675 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
676 sortby.getSelectedItem().toString());
678 // convert description of sort order to enum name for save
679 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
680 .forDescription(sortAnnBy.getSelectedItem().toString());
681 if (annSortOrder != null)
683 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
684 annSortOrder.name());
687 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
688 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
689 Boolean.valueOf(showAutocalcFirst).toString());
692 * Save Colours settings
694 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
695 protColour.getSelectedItem().toString());
696 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
697 nucColour.getSelectedItem().toString());
698 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
699 minColour.getBackground());
700 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
701 maxColour.getBackground());
704 * Save Overview settings
706 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
707 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
708 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
709 Boolean.toString(useLegacyGap.isSelected()));
710 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
711 Boolean.toString(showHiddenAtStart.isSelected()));
714 * Save Structure settings
716 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
717 Boolean.toString(addTempFactor.isSelected()));
718 Cache.applicationProperties.setProperty(ADD_SS_ANN,
719 Boolean.toString(addSecondaryStructure.isSelected()));
720 Cache.applicationProperties.setProperty(USE_RNAVIEW,
721 Boolean.toString(useRnaView.isSelected()));
722 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
723 Boolean.toString(structFromPdb.isSelected()));
724 String viewer = structViewer.getSelectedItem().toString();
725 String viewerPath = structureViewerPath.getText();
726 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
728 if (viewer.equals(ViewerType.CHIMERA.name()))
730 Cache.setOrRemove(CHIMERA_PATH, viewerPath);
732 else if (viewer.equals(ViewerType.CHIMERAX.name()))
734 Cache.setOrRemove(CHIMERAX_PATH, viewerPath);
736 else if (viewer.equals(ViewerType.PYMOL.name()))
738 Cache.setOrRemove(PYMOL_PATH, viewerPath);
740 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
741 Boolean.toString(siftsMapping.isSelected()));
742 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
745 * Save Output settings
747 Cache.applicationProperties.setProperty("EPS_RENDERING",
748 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
751 * Save Connections settings
753 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
755 jalview.util.BrowserLauncher.resetBrowser();
757 // save user-defined and selected links
758 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
759 if (menuLinks.isEmpty())
761 Cache.applicationProperties.remove("SEQUENCE_LINKS");
765 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
766 menuLinks.toString());
769 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
770 if (nonMenuLinks.isEmpty())
772 Cache.applicationProperties.remove("STORED_LINKS");
776 Cache.applicationProperties.setProperty("STORED_LINKS",
777 nonMenuLinks.toString());
780 Cache.applicationProperties.setProperty("DEFAULT_URL",
781 sequenceUrlLinks.getPrimaryUrlId());
783 Cache.applicationProperties.setProperty("USE_PROXY",
784 Boolean.toString(useProxy.isSelected()));
786 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
788 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
790 if (useProxy.isSelected())
792 System.setProperty("http.proxyHost", proxyServerTB.getText());
793 System.setProperty("http.proxyPort", proxyPortTB.getText());
797 System.setProperty("http.proxyHost", "");
798 System.setProperty("http.proxyPort", "");
800 Cache.setProperty("VERSION_CHECK",
801 Boolean.toString(versioncheck.isSelected()));
802 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
804 // default is false - we only set this if the user has actively agreed
805 Cache.setProperty("USAGESTATS",
806 Boolean.toString(usagestats.isSelected()));
808 if (!questionnaire.isSelected())
810 Cache.setProperty("NOQUESTIONNAIRES", "true");
814 // special - made easy to edit a property file to disable questionnaires
815 // by just adding the given line
816 Cache.removeProperty("NOQUESTIONNAIRES");
820 * Save Output settings
822 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
823 Boolean.toString(blcjv.isSelected()));
824 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
825 Boolean.toString(clustaljv.isSelected()));
826 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
827 Boolean.toString(fastajv.isSelected()));
828 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
829 Boolean.toString(msfjv.isSelected()));
830 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
831 Boolean.toString(pfamjv.isSelected()));
832 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
833 Boolean.toString(pileupjv.isSelected()));
834 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
835 Boolean.toString(pirjv.isSelected()));
836 Cache.applicationProperties.setProperty("PIR_MODELLER",
837 Boolean.toString(modellerOutput.isSelected()));
838 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
839 Boolean.toString(embbedBioJSON.isSelected()));
840 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
842 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
843 Boolean.toString(autoIdWidth.isSelected()));
844 userIdWidth_actionPerformed();
845 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
846 userIdWidth.getText());
849 * Save Editing settings
851 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
852 Boolean.toString(autoCalculateConsCheck.isSelected()));
853 Cache.applicationProperties.setProperty("SORT_BY_TREE",
854 Boolean.toString(sortByTree.isSelected()));
855 Cache.applicationProperties.setProperty("PAD_GAPS",
856 Boolean.toString(padGaps.isSelected()));
858 wsPrefs.updateAndRefreshWsMenuConfig(false);
861 * Save Backups settings
863 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
864 Boolean.toString(enableBackupFiles.isSelected()));
865 int preset = getComboIntStringKey(backupfilesPresetsCombo);
866 Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
868 if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
870 BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
871 BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
872 BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
873 Cache.applicationProperties
874 .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
875 customBFPE.toString());
878 BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
880 Cache.applicationProperties.setProperty(
881 BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
883 Cache.saveProperties();
884 Desktop.instance.doConfigureStructurePrefs();
887 frame.setClosed(true);
888 } catch (Exception ex)
894 * Do any necessary validation before saving settings. Return focus to the
895 * first tab which fails validation.
899 private boolean validateSettings()
901 if (!validateStructure())
903 structureTab.requestFocusInWindow();
910 protected boolean validateStructure()
912 return validateViewerPath();
920 public void startupFileTextfield_mouseClicked()
922 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
923 JalviewFileChooser chooser = JalviewFileChooser
924 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
925 chooser.setFileView(new JalviewFileView());
926 chooser.setDialogTitle(
927 MessageManager.getString("label.select_startup_file"));
929 int value = chooser.showOpenDialog(this);
931 if (value == JalviewFileChooser.APPROVE_OPTION)
933 FileFormatI format = chooser.getSelectedFormat();
936 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
940 .setText(chooser.getSelectedFile().getAbsolutePath());
951 public void cancel_actionPerformed(ActionEvent e)
955 wsPrefs.updateWsMenuConfig(true);
956 wsPrefs.refreshWs_actionPerformed(e);
957 frame.setClosed(true);
958 } catch (Exception ex)
970 public void annotations_actionPerformed(ActionEvent e)
972 conservation.setEnabled(annotations.isSelected());
973 quality.setEnabled(annotations.isSelected());
974 identity.setEnabled(annotations.isSelected());
975 showOccupancy.setEnabled(annotations.isSelected());
976 showGroupConsensus.setEnabled(annotations.isSelected());
977 showGroupConservation.setEnabled(annotations.isSelected());
978 showConsensHistogram.setEnabled(annotations.isSelected()
979 && (identity.isSelected() || showGroupConsensus.isSelected()));
980 showConsensLogo.setEnabled(annotations.isSelected()
981 && (identity.isSelected() || showGroupConsensus.isSelected()));
985 public void newLink_actionPerformed(ActionEvent e)
987 GSequenceLink link = new GSequenceLink();
988 boolean valid = false;
991 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
992 MessageManager.getString("label.new_sequence_url_link"),
993 JvOptionPane.OK_CANCEL_OPTION, -1,
994 null) == JvOptionPane.OK_OPTION)
996 if (link.checkValid())
998 if (((UrlLinkTableModel) linkUrlTable.getModel())
999 .isUniqueName(link.getName()))
1001 ((UrlLinkTableModel) linkUrlTable.getModel())
1002 .insertRow(link.getName(), link.getURL());
1007 link.notifyDuplicate();
1020 public void editLink_actionPerformed(ActionEvent e)
1022 GSequenceLink link = new GSequenceLink();
1024 int index = linkUrlTable.getSelectedRow();
1027 // button no longer enabled if row is not selected
1028 Cache.log.debug("Edit with no row selected in linkUrlTable");
1032 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1034 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1036 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1037 link.setName(oldName);
1038 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1040 boolean valid = false;
1043 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1044 MessageManager.getString("label.edit_sequence_url_link"),
1045 JvOptionPane.OK_CANCEL_OPTION, -1,
1046 null) == JvOptionPane.OK_OPTION)
1048 if (link.checkValid())
1050 if ((oldName.equals(link.getName()))
1051 || (((UrlLinkTableModel) linkUrlTable.getModel())
1052 .isUniqueName(link.getName())))
1054 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1055 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1060 link.notifyDuplicate();
1073 public void deleteLink_actionPerformed(ActionEvent e)
1075 int index = linkUrlTable.getSelectedRow();
1076 int modelIndex = -1;
1079 // button no longer enabled if row is not selected
1080 Cache.log.debug("Delete with no row selected in linkUrlTable");
1085 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1088 // make sure we use the model index to delete, and not the table index
1089 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1093 public void defaultBrowser_mouseClicked(MouseEvent e)
1095 JFileChooser chooser = new JFileChooser(".");
1096 chooser.setDialogTitle(
1097 MessageManager.getString("label.select_default_browser"));
1099 int value = chooser.showOpenDialog(this);
1101 if (value == JFileChooser.APPROVE_OPTION)
1103 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1112 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1116 protected void showunconserved_actionPerformed(ActionEvent e)
1118 // TODO Auto-generated method stub
1119 super.showunconserved_actionPerformed(e);
1122 public static List<String> getGroupURLLinks()
1124 return groupURLLinks;
1128 public void minColour_actionPerformed(JPanel panel)
1130 Color col = JColorChooser.showDialog(this,
1131 MessageManager.getString("label.select_colour_minimum_value"),
1132 minColour.getBackground());
1135 panel.setBackground(col);
1141 public void maxColour_actionPerformed(JPanel panel)
1143 Color col = JColorChooser.showDialog(this,
1144 MessageManager.getString("label.select_colour_maximum_value"),
1145 maxColour.getBackground());
1148 panel.setBackground(col);
1154 public void gapColour_actionPerformed(JPanel gap)
1156 if (!useLegacyGap.isSelected())
1158 Color col = JColorChooser.showDialog(this,
1159 MessageManager.getString("label.select_gap_colour"),
1160 gapColour.getBackground());
1163 gap.setBackground(col);
1170 public void hiddenColour_actionPerformed(JPanel hidden)
1172 Color col = JColorChooser.showDialog(this,
1173 MessageManager.getString("label.select_hidden_colour"),
1174 hiddenColour.getBackground());
1177 hidden.setBackground(col);
1183 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1185 boolean enabled = useLegacyGap.isSelected();
1188 gapColour.setBackground(
1189 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1193 gapColour.setBackground(
1194 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1196 gapColour.setEnabled(!enabled);
1197 gapLabel.setEnabled(!enabled);
1201 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1203 useLegacyGap.setSelected(false);
1204 useLegacyGaps_actionPerformed(null);
1205 showHiddenAtStart.setSelected(false);
1206 hiddenColour.setBackground(
1207 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1211 protected void userIdWidth_actionPerformed()
1215 String val = userIdWidth.getText().trim();
1216 if (val.length() > 0)
1218 Integer iw = Integer.parseInt(val);
1219 if (iw.intValue() < 12)
1221 throw new NumberFormatException();
1223 userIdWidth.setText(iw.toString());
1225 } catch (NumberFormatException x)
1227 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1229 .getString("warn.user_defined_width_requirements"),
1230 MessageManager.getString("label.invalid_id_column_width"),
1231 JvOptionPane.WARNING_MESSAGE);
1232 userIdWidth.setText("");
1237 protected void autoIdWidth_actionPerformed()
1239 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1240 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1244 * Returns true if structure viewer path is to a valid executable, else shows
1245 * an error dialog. Does nothing if the path is empty, as is the case for Jmol
1246 * (built in to Jalview) or when Jalview is left to try default paths.
1248 private boolean validateViewerPath()
1250 if (structureViewerPath.getText().trim().length() > 0)
1252 File f = new File(structureViewerPath.getText());
1253 if (!f.canExecute())
1255 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1256 MessageManager.getString("label.invalid_viewer_path"),
1257 MessageManager.getString("label.invalid_viewer_path"),
1258 JvOptionPane.ERROR_MESSAGE);
1266 * If Chimera or ChimeraX or Pymol is selected, check it can be found on
1267 * default or user-specified path, if not show a warning/help dialog
1270 protected void structureViewer_actionPerformed(String selectedItem)
1272 if (selectedItem.equals(ViewerType.JMOL.name()))
1274 structureViewerPath.setEnabled(false);
1275 structureViewerPathLabel.setEnabled(false);
1278 boolean found = false;
1279 structureViewerPath.setEnabled(true);
1280 structureViewerPathLabel.setEnabled(true);
1281 structureViewerPathLabel.setText(MessageManager
1282 .formatMessage("label.viewer_path", selectedItem));
1285 * Try user-specified and standard paths for structure viewer executable
1287 String viewerPath = "";
1288 List<String> paths = null;
1291 ViewerType viewerType = ViewerType.valueOf(selectedItem);
1298 viewerPath = Cache.getDefault(CHIMERA_PATH, "");
1299 paths = StructureManager.getChimeraPaths(false);
1302 viewerPath = Cache.getDefault(CHIMERAX_PATH, "");
1303 paths = StructureManager.getChimeraPaths(true);
1306 viewerPath = Cache.getDefault(PYMOL_PATH, "");
1307 paths = PymolManager.getPymolPaths();
1310 } catch (IllegalArgumentException e)
1312 // only valid entries should be in the drop-down
1314 structureViewerPath.setText(viewerPath);
1316 paths.add(0, structureViewerPath.getText());
1317 for (String path : paths)
1319 if (new File(path.trim()).canExecute())
1328 String[] options = { "OK", "Help" };
1329 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1330 JvSwingUtils.wrapTooltip(true,
1331 MessageManager.getString("label.viewer_missing")),
1332 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1333 null, options, options[0]);
1334 if (showHelp == JvOptionPane.NO_OPTION)
1338 Help.showHelpWindow(HelpId.StructureViewer);
1339 } catch (HelpSetException e)
1341 e.printStackTrace();
1347 public class OptionsParam
1349 private String name;
1351 private String code;
1353 public OptionsParam(String name, String code)
1359 public String getName()
1364 public void setName(String name)
1369 public String getCode()
1374 public void setCode(String code)
1380 public String toString()
1386 public boolean equals(Object that)
1388 if (!(that instanceof OptionsParam))
1392 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1396 public int hashCode()
1398 return name.hashCode() + code.hashCode();
1402 private class UrlListSelectionHandler implements ListSelectionListener
1406 public void valueChanged(ListSelectionEvent e)
1408 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1410 int index = lsm.getMinSelectionIndex();
1413 // no selection, so disable delete/edit buttons
1414 editLink.setEnabled(false);
1415 deleteLink.setEnabled(false);
1418 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1420 // enable/disable edit and delete link buttons
1421 if (((UrlLinkTableModel) linkUrlTable.getModel())
1422 .isRowDeletable(modelIndex))
1424 deleteLink.setEnabled(true);
1428 deleteLink.setEnabled(false);
1431 if (((UrlLinkTableModel) linkUrlTable.getModel())
1432 .isRowEditable(modelIndex))
1434 editLink.setEnabled(true);
1438 editLink.setEnabled(false);