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.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.HiddenMarkovModel;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.Help.HelpId;
31 import jalview.gui.StructureViewer.ViewerType;
32 import jalview.hmmer.HMMBuildThread;
33 import jalview.io.FileFormatI;
34 import jalview.io.JalviewFileChooser;
35 import jalview.io.JalviewFileView;
36 import jalview.jbgui.GPreferences;
37 import jalview.jbgui.GSequenceLink;
38 import jalview.schemes.ColourSchemeI;
39 import jalview.schemes.ColourSchemes;
40 import jalview.schemes.ResidueColourScheme;
41 import jalview.urls.UrlLinkTableModel;
42 import jalview.urls.api.UrlProviderFactoryI;
43 import jalview.urls.api.UrlProviderI;
44 import jalview.urls.desktop.DesktopUrlProviderFactory;
45 import jalview.util.MessageManager;
46 import jalview.util.Platform;
47 import jalview.util.UrlConstants;
48 import jalview.ws.sifts.SiftsSettings;
50 import java.awt.BorderLayout;
51 import java.awt.Color;
52 import java.awt.Component;
53 import java.awt.Dimension;
55 import java.awt.event.ActionEvent;
56 import java.awt.event.ActionListener;
57 import java.awt.event.MouseEvent;
59 import java.util.ArrayList;
60 import java.util.List;
61 import java.util.Scanner;
63 import javax.help.HelpSetException;
64 import javax.swing.JColorChooser;
65 import javax.swing.JFileChooser;
66 import javax.swing.JInternalFrame;
67 import javax.swing.JPanel;
68 import javax.swing.ListSelectionModel;
69 import javax.swing.RowFilter;
70 import javax.swing.RowSorter;
71 import javax.swing.SortOrder;
72 import javax.swing.event.DocumentEvent;
73 import javax.swing.event.DocumentListener;
74 import javax.swing.event.ListSelectionEvent;
75 import javax.swing.event.ListSelectionListener;
76 import javax.swing.table.TableCellRenderer;
77 import javax.swing.table.TableColumn;
78 import javax.swing.table.TableModel;
79 import javax.swing.table.TableRowSorter;
81 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
89 public class Preferences extends GPreferences
91 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
93 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
95 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
97 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
99 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
101 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
103 public static final String ADD_SS_ANN = "ADD_SS_ANN";
105 public static final String USE_RNAVIEW = "USE_RNAVIEW";
107 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
109 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
111 public static final String CHIMERA_PATH = "CHIMERA_PATH";
113 public static final String HMMER_PATH = "HMMER_PATH";
115 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
117 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
119 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
121 private static final int MIN_FONT_SIZE = 1;
123 private static final int MAX_FONT_SIZE = 30;
126 * Holds name and link separated with | character. Sequence ID must be
127 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
129 public static UrlProviderI sequenceUrlLinks;
131 public static UrlLinkTableModel dataModel;
134 * Holds name and link separated with | character. Sequence IDS and Sequences
135 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
136 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
137 * for first and second token specified after a pipe character at end |,|.
138 * (TODO: proper escape for using | to separate ids or sequences
141 public static List<String> groupURLLinks;
144 // get links selected to be in the menu (SEQUENCE_LINKS)
145 // and links entered by the user but not selected (STORED_LINKS)
146 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
147 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
148 String defaultUrl = Cache.getDefault("DEFAULT_URL",
149 UrlConstants.DEFAULT_LABEL);
151 // if both links lists are empty, add the DEFAULT_URL link
152 // otherwise we assume the default link is in one of the lists
153 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
155 inMenuString = UrlConstants.DEFAULT_STRING;
157 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
158 inMenuString, notInMenuString);
159 sequenceUrlLinks = factory.createUrlProvider();
160 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
163 * TODO: reformulate groupURL encoding so two or more can be stored in the
164 * .properties file as '|' separated strings
167 groupURLLinks = new ArrayList<>();
170 JInternalFrame frame;
172 DasSourceBrowser dasSource;
174 private WsPreferences wsPrefs;
176 private OptionsParam promptEachTimeOpt = new OptionsParam(
177 MessageManager.getString("label.prompt_each_time"),
180 private OptionsParam lineArtOpt = new OptionsParam(
181 MessageManager.getString("label.lineart"), "Lineart");
183 private OptionsParam textOpt = new OptionsParam(
184 MessageManager.getString("action.text"), "Text");
187 * Creates a new Preferences object.
192 frame = new JInternalFrame();
193 frame.setContentPane(this);
194 dasSource = new DasSourceBrowser();
195 dasTab.add(dasSource, BorderLayout.CENTER);
196 wsPrefs = new WsPreferences();
197 wsTab.add(wsPrefs, BorderLayout.CENTER);
198 int width = 500, height = 450;
199 new jalview.util.Platform();
200 if (Platform.isAMac())
206 Desktop.addInternalFrame(frame,
207 MessageManager.getString("label.preferences"), width, height);
208 frame.setMinimumSize(new Dimension(width, height));
211 * Set HMMER tab defaults
213 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
215 .setSelected(Cache.getDefault("HMMER_INSTALLED", false));
216 if (Cache.getDefault("USE_UNIPROT", false))
218 uniprot.setSelected(true);
222 alignment.setSelected(true);
224 numberOfSequencesToKeepField
225 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
226 installationLocation.setEnabled(isHMMERInstalled.isSelected());
227 hmmerPath.setEnabled(isHMMERInstalled.isSelected());
228 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
229 hmmerPath.addActionListener(new ActionListener()
232 public void actionPerformed(ActionEvent e)
239 * Set Visual tab defaults
241 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
242 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
243 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
244 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
246 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
247 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
248 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
249 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
251 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
252 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
254 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
255 showGroupConservation.setSelected(
256 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
257 showConsensHistogram.setSelected(
258 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
260 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
261 showInformationHistogram.setSelected(
262 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
263 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
265 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
267 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
269 String[] fonts = java.awt.GraphicsEnvironment
270 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
271 for (int i = 0; i < fonts.length; i++)
273 fontNameCB.addItem(fonts[i]);
276 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
278 fontSizeCB.addItem(i + "");
281 fontStyleCB.addItem("plain");
282 fontStyleCB.addItem("bold");
283 fontStyleCB.addItem("italic");
285 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
286 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
287 fontStyleCB.setSelectedItem(
288 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
290 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
292 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
294 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
296 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
298 gapSymbolCB.addItem("-");
299 gapSymbolCB.addItem(".");
301 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
303 sortby.addItem("No sort");
304 sortby.addItem("Id");
305 sortby.addItem("Pairwise Identity");
306 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
308 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
310 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
312 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
313 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
314 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
315 SequenceAnnotationOrder.NONE.name()));
316 sortAnnBy.setSelectedItem(savedSort.toString());
318 sortAutocalc.addItem("Autocalculated first");
319 sortAutocalc.addItem("Autocalculated last");
320 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
321 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
322 : sortAutocalc.getItemAt(1));
324 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
325 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
326 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
327 + "/examples/exampleFile_2_3.jar"));
330 * Set Colours tab defaults
332 protColour.addItem(ResidueColourScheme.NONE);
333 nucColour.addItem(ResidueColourScheme.NONE);
334 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
336 String name = cs.getSchemeName();
337 protColour.addItem(name);
338 nucColour.addItem(name);
340 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
341 ResidueColourScheme.NONE);
342 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
343 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
344 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
345 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
346 minColour.setBackground(
347 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
348 maxColour.setBackground(
349 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
352 * Set Structure tab defaults.
354 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
355 structFromPdb.setSelected(structSelected);
356 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
357 useRnaView.setEnabled(structSelected);
358 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
359 addSecondaryStructure.setEnabled(structSelected);
360 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
361 addTempFactor.setEnabled(structSelected);
362 structViewer.setSelectedItem(
363 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
364 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
365 chimeraPath.addActionListener(new ActionListener()
368 public void actionPerformed(ActionEvent e)
370 validateChimeraPath();
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<TableModel, Object>()
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_USERIDWIDTH");
546 userIdWidth.setText(wi == null ? "" : wi.toString());
547 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
548 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
549 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
550 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
551 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
552 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
553 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
554 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
556 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
559 * Set Editing tab defaults
561 autoCalculateConsCheck
562 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
563 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
564 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
566 annotations_actionPerformed(null); // update the display of the annotation
571 * Save user selections on the Preferences tabs to the Cache and write out to
577 public void ok_actionPerformed(ActionEvent e)
579 if (!validateSettings())
585 * Save Visual settings
587 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
588 Boolean.toString(seqLimit.isSelected()));
589 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
590 Boolean.toString(rightAlign.isSelected()));
591 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
592 Boolean.toString(fullScreen.isSelected()));
593 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
594 Boolean.toString(openoverv.isSelected()));
595 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
596 Boolean.toString(annotations.isSelected()));
597 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
598 Boolean.toString(conservation.isSelected()));
599 Cache.applicationProperties.setProperty("SHOW_QUALITY",
600 Boolean.toString(quality.isSelected()));
601 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
602 Boolean.toString(identity.isSelected()));
604 Cache.applicationProperties.setProperty("GAP_SYMBOL",
605 gapSymbolCB.getSelectedItem().toString());
607 Cache.applicationProperties.setProperty("FONT_NAME",
608 fontNameCB.getSelectedItem().toString());
609 Cache.applicationProperties.setProperty("FONT_STYLE",
610 fontStyleCB.getSelectedItem().toString());
611 Cache.applicationProperties.setProperty("FONT_SIZE",
612 fontSizeCB.getSelectedItem().toString());
614 Cache.applicationProperties.setProperty("ID_ITALICS",
615 Boolean.toString(idItalics.isSelected()));
616 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
617 Boolean.toString(showUnconserved.isSelected()));
618 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
619 Boolean.toString(showOccupancy.isSelected()));
620 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
621 Boolean.toString(showGroupConsensus.isSelected()));
622 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
623 Boolean.toString(showGroupConservation.isSelected()));
624 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
625 Boolean.toString(showConsensHistogram.isSelected()));
626 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
627 Boolean.toString(showConsensLogo.isSelected()));
628 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
629 Boolean.toString(showConsensHistogram.isSelected()));
630 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
631 Boolean.toString(showHMMLogo.isSelected()));
632 Cache.applicationProperties.setProperty("ANTI_ALIAS",
633 Boolean.toString(smoothFont.isSelected()));
634 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
635 Boolean.toString(scaleProteinToCdna.isSelected()));
636 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
637 Boolean.toString(showNpTooltip.isSelected()));
638 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
639 Boolean.toString(showDbRefTooltip.isSelected()));
641 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
642 Boolean.toString(wrap.isSelected()));
644 Cache.applicationProperties.setProperty("STARTUP_FILE",
645 startupFileTextfield.getText());
646 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
647 Boolean.toString(startupCheckbox.isSelected()));
649 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
650 sortby.getSelectedItem().toString());
652 // convert description of sort order to enum name for save
653 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
654 .forDescription(sortAnnBy.getSelectedItem().toString());
655 if (annSortOrder != null)
657 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
658 annSortOrder.name());
661 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
662 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
663 Boolean.valueOf(showAutocalcFirst).toString());
666 * Save Colours settings
668 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
669 protColour.getSelectedItem().toString());
670 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
671 nucColour.getSelectedItem().toString());
672 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
673 minColour.getBackground());
674 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
675 maxColour.getBackground());
678 * Save HMMER settings
680 Cache.applicationProperties.setProperty("TRIM_TERMINI",
681 Boolean.toString(trimTermini.isSelected()));
682 Cache.applicationProperties.setProperty("USE_UNIPROT",
683 Boolean.toString(uniprot.isSelected()));
684 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
685 numberOfSequencesToKeepField.getText());
686 Cache.applicationProperties.setProperty(HMMER_PATH,
687 hmmerPath.getText());
688 boolean hmmerInstalled = isHMMERInstalled.isSelected();
689 Cache.applicationProperties.setProperty("HMMER_INSTALLED",
690 Boolean.toString(hmmerInstalled));
691 boolean hmmerFunctioning = validateHMMERPath(false);
692 Cache.applicationProperties.setProperty("HMMER_FUNCTIONING",
693 Boolean.toString(hmmerFunctioning));
694 AlignFrame[] frames = Desktop.getAlignFrames();
695 boolean hmmerStatus = hmmerFunctioning && hmmerInstalled ? true : false;
696 for (AlignFrame frame : frames)
698 frame.updateHMMERStatus(hmmerStatus);
702 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
703 if (Cache.getDefault("USE_UNIPROT", false))
705 uniprot.setSelected(true);
709 alignment.setSelected(true);
711 numberOfSequencesToKeepField
712 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
713 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
716 * Save Structure settings
718 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
719 Boolean.toString(addTempFactor.isSelected()));
720 Cache.applicationProperties.setProperty(ADD_SS_ANN,
721 Boolean.toString(addSecondaryStructure.isSelected()));
722 Cache.applicationProperties.setProperty(USE_RNAVIEW,
723 Boolean.toString(useRnaView.isSelected()));
724 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
725 Boolean.toString(structFromPdb.isSelected()));
726 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
727 structViewer.getSelectedItem().toString());
728 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
729 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
730 Boolean.toString(siftsMapping.isSelected()));
731 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
734 * Save Output settings
736 Cache.applicationProperties.setProperty("EPS_RENDERING",
737 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
740 * Save Connections settings
742 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
744 jalview.util.BrowserLauncher.resetBrowser();
746 // save user-defined and selected links
747 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
748 if (menuLinks.isEmpty())
750 Cache.applicationProperties.remove("SEQUENCE_LINKS");
754 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
755 menuLinks.toString());
758 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
759 if (nonMenuLinks.isEmpty())
761 Cache.applicationProperties.remove("STORED_LINKS");
765 Cache.applicationProperties.setProperty("STORED_LINKS",
766 nonMenuLinks.toString());
769 Cache.applicationProperties.setProperty("DEFAULT_URL",
770 sequenceUrlLinks.getPrimaryUrlId());
772 Cache.applicationProperties.setProperty("USE_PROXY",
773 Boolean.toString(useProxy.isSelected()));
775 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
777 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
779 if (useProxy.isSelected())
781 System.setProperty("http.proxyHost", proxyServerTB.getText());
782 System.setProperty("http.proxyPort", proxyPortTB.getText());
786 System.setProperty("http.proxyHost", "");
787 System.setProperty("http.proxyPort", "");
789 Cache.setProperty("VERSION_CHECK",
790 Boolean.toString(versioncheck.isSelected()));
791 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
793 // default is false - we only set this if the user has actively agreed
794 Cache.setProperty("USAGESTATS",
795 Boolean.toString(usagestats.isSelected()));
797 if (!questionnaire.isSelected())
799 Cache.setProperty("NOQUESTIONNAIRES", "true");
803 // special - made easy to edit a property file to disable questionnaires
804 // by just adding the given line
805 Cache.removeProperty("NOQUESTIONNAIRES");
809 * Save Output settings
811 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
812 Boolean.toString(blcjv.isSelected()));
813 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
814 Boolean.toString(clustaljv.isSelected()));
815 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
816 Boolean.toString(fastajv.isSelected()));
817 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
818 Boolean.toString(msfjv.isSelected()));
819 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
820 Boolean.toString(pfamjv.isSelected()));
821 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
822 Boolean.toString(pileupjv.isSelected()));
823 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
824 Boolean.toString(pirjv.isSelected()));
825 Cache.applicationProperties.setProperty("PIR_MODELLER",
826 Boolean.toString(modellerOutput.isSelected()));
827 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
828 Boolean.toString(embbedBioJSON.isSelected()));
829 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
831 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
832 Boolean.toString(autoIdWidth.isSelected()));
833 userIdWidth_actionPerformed();
834 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
835 userIdWidth.getText());
838 * Save Editing settings
840 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
841 Boolean.toString(autoCalculateConsCheck.isSelected()));
842 Cache.applicationProperties.setProperty("SORT_BY_TREE",
843 Boolean.toString(sortByTree.isSelected()));
844 Cache.applicationProperties.setProperty("PAD_GAPS",
845 Boolean.toString(padGaps.isSelected()));
847 dasSource.saveProperties(Cache.applicationProperties);
848 wsPrefs.updateAndRefreshWsMenuConfig(false);
849 Cache.saveProperties();
850 Desktop.instance.doConfigureStructurePrefs();
853 frame.setClosed(true);
854 } catch (Exception ex)
860 * Do any necessary validation before saving settings. Return focus to the
861 * first tab which fails validation.
865 private boolean validateSettings()
867 if (!validateStructure())
869 structureTab.requestFocusInWindow();
872 if (isHMMERInstalled.isSelected())
874 if (!validateHMMER())
876 hmmerTab.requestFocusInWindow();
884 protected boolean validateStructure()
886 return validateChimeraPath();
891 protected boolean validateHMMER()
893 return validateHMMERPath();
901 public void startupFileTextfield_mouseClicked()
903 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
904 JalviewFileChooser chooser = JalviewFileChooser
905 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
906 chooser.setFileView(new JalviewFileView());
907 chooser.setDialogTitle(
908 MessageManager.getString("label.select_startup_file"));
910 int value = chooser.showOpenDialog(this);
912 if (value == JalviewFileChooser.APPROVE_OPTION)
914 FileFormatI format = chooser.getSelectedFormat();
917 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
921 .setText(chooser.getSelectedFile().getAbsolutePath());
932 public void cancel_actionPerformed(ActionEvent e)
936 wsPrefs.updateWsMenuConfig(true);
937 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()));
963 showInformationHistogram.setEnabled(annotations.isSelected());
964 showHMMLogo.setEnabled(annotations.isSelected());
968 public void newLink_actionPerformed(ActionEvent e)
970 GSequenceLink link = new GSequenceLink();
971 boolean valid = false;
974 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
975 MessageManager.getString("label.new_sequence_url_link"),
976 JvOptionPane.OK_CANCEL_OPTION, -1,
977 null) == JvOptionPane.OK_OPTION)
979 if (link.checkValid())
981 if (((UrlLinkTableModel) linkUrlTable.getModel())
982 .isUniqueName(link.getName()))
984 ((UrlLinkTableModel) linkUrlTable.getModel())
985 .insertRow(link.getName(), link.getURL());
990 link.notifyDuplicate();
1003 public void editLink_actionPerformed(ActionEvent e)
1005 GSequenceLink link = new GSequenceLink();
1007 int index = linkUrlTable.getSelectedRow();
1010 // button no longer enabled if row is not selected
1011 Cache.log.debug("Edit with no row selected in linkUrlTable");
1015 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1017 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1019 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1020 link.setName(oldName);
1021 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1023 boolean valid = false;
1026 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1027 MessageManager.getString("label.edit_sequence_url_link"),
1028 JvOptionPane.OK_CANCEL_OPTION, -1,
1029 null) == JvOptionPane.OK_OPTION)
1031 if (link.checkValid())
1033 if ((oldName.equals(link.getName()))
1034 || (((UrlLinkTableModel) linkUrlTable.getModel())
1035 .isUniqueName(link.getName())))
1037 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1038 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1043 link.notifyDuplicate();
1056 public void deleteLink_actionPerformed(ActionEvent e)
1058 int index = linkUrlTable.getSelectedRow();
1059 int modelIndex = -1;
1062 // button no longer enabled if row is not selected
1063 Cache.log.debug("Delete with no row selected in linkUrlTable");
1068 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1071 // make sure we use the model index to delete, and not the table index
1072 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1076 public void defaultBrowser_mouseClicked(MouseEvent e)
1078 JFileChooser chooser = new JFileChooser(".");
1079 chooser.setDialogTitle(
1080 MessageManager.getString("label.select_default_browser"));
1082 int value = chooser.showOpenDialog(this);
1084 if (value == JFileChooser.APPROVE_OPTION)
1086 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1095 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1099 protected void showunconserved_actionPerformed(ActionEvent e)
1101 // TODO Auto-generated method stub
1102 super.showunconserved_actionPerformed(e);
1105 public static List<String> getGroupURLLinks()
1107 return groupURLLinks;
1111 public void minColour_actionPerformed(JPanel panel)
1113 Color col = JColorChooser.showDialog(this,
1114 MessageManager.getString("label.select_colour_minimum_value"),
1115 minColour.getBackground());
1118 panel.setBackground(col);
1124 public void maxColour_actionPerformed(JPanel panel)
1126 Color col = JColorChooser.showDialog(this,
1127 MessageManager.getString("label.select_colour_maximum_value"),
1128 maxColour.getBackground());
1131 panel.setBackground(col);
1137 protected void userIdWidth_actionPerformed()
1141 String val = userIdWidth.getText().trim();
1142 if (val.length() > 0)
1144 Integer iw = Integer.parseInt(val);
1145 if (iw.intValue() < 12)
1147 throw new NumberFormatException();
1149 userIdWidth.setText(iw.toString());
1151 } catch (NumberFormatException x)
1153 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1155 .getString("warn.user_defined_width_requirements"),
1156 MessageManager.getString("label.invalid_id_column_width"),
1157 JvOptionPane.WARNING_MESSAGE);
1158 userIdWidth.setText("");
1163 protected void autoIdWidth_actionPerformed()
1165 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1166 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1170 * Returns true if chimera path is to a valid executable, else show an error
1173 private boolean validateChimeraPath()
1175 if (chimeraPath.getText().trim().length() > 0)
1177 File f = new File(chimeraPath.getText());
1178 if (!f.canExecute())
1180 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1181 MessageManager.getString("label.invalid_chimera_path"),
1182 MessageManager.getString("label.invalid_name"),
1183 JvOptionPane.ERROR_MESSAGE);
1191 * Returns true if hmmer path contains the necessary valid executables, else
1192 * show an error dialog (if showing dialog).
1194 private boolean validateHMMERPath(boolean showDialog)
1197 String message = "";
1198 String folder = hmmerPath.getText().trim();
1199 if (folder.length() > 0)
1201 File f = new File(folder);
1206 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1207 MessageManager.getString("label.folder_not_exists"),
1208 MessageManager.getString("label.invalid_folder"),
1209 JvOptionPane.ERROR_MESSAGE);
1213 AlignmentI alignment = new Alignment(
1215 { new Sequence("test", "WLWL", 0, 3) });
1216 if (canExecute(folder + "/hmmbuild"))
1218 validateHMMBuild(alignment);
1222 message += MessageManager.getString("label.hmmbuild_not_found")
1228 if (canExecute(folder + "/hmmalign"))
1234 message += MessageManager.getString("label.hmmalign_not_found")
1240 if (canExecute(folder + "/hmmsearch"))
1246 message += MessageManager.getString("label.hmmsearch_not_found")
1258 JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1259 MessageManager.getString("label.invalid_folder"),
1260 JvOptionPane.ERROR_MESSAGE);
1268 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1269 MessageManager.getString("label.no_binaries"),
1270 MessageManager.getString("label.invalid_folder"),
1271 JvOptionPane.ERROR_MESSAGE);
1282 * Checks if a file can be executed
1285 * the path to the file
1288 public boolean canExecute(String path)
1290 File file = new File(path);
1291 if (!file.canExecute())
1293 file = new File(path + ".exe");
1295 if (!file.canExecute())
1305 * Runs hmmbuild to check if it is working. While doing this it parses the
1311 public boolean validateHMMBuild(AlignmentI alignment)
1313 HMMBuildThread hmmbuild = new HMMBuildThread(alignment);
1314 hmmbuild.hmmbuildWaitTillComplete();
1315 SequenceI hmmSeq = alignment.getSequenceAt(1);
1316 HiddenMarkovModel hmm;
1317 if (hmmSeq.isHMMConsensusSequence() && hmmSeq.getHMM() != null)
1319 hmm = hmmSeq.getHMM();
1321 if (hmm.getNumberOfSymbols() < 1)
1331 String header = hmm.getFileHeader();
1338 Scanner scanner = new Scanner(header);
1340 String string = scanner.next();
1341 String version = string.substring(1);
1342 Cache.setProperty("HMMER_VERSION", version);
1350 private boolean validateHMMERPath()
1352 return validateHMMERPath(true);
1356 * If Chimera is selected, check it can be found on default or user-specified
1357 * path, if not show a warning/help dialog.
1360 protected void structureViewer_actionPerformed(String selectedItem)
1362 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1366 boolean found = false;
1369 * Try user-specified and standard paths for Chimera executable.
1371 List<String> paths = StructureManager.getChimeraPaths();
1372 paths.add(0, chimeraPath.getText());
1373 for (String path : paths)
1375 if (new File(path.trim()).canExecute())
1383 String[] options = { "OK", "Help" };
1384 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1385 JvSwingUtils.wrapTooltip(true,
1386 MessageManager.getString("label.chimera_missing")),
1387 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1388 null, options, options[0]);
1389 if (showHelp == JvOptionPane.NO_OPTION)
1393 Help.showHelpWindow(HelpId.StructureViewer);
1394 } catch (HelpSetException e)
1396 e.printStackTrace();
1402 public class OptionsParam
1404 private String name;
1406 private String code;
1408 public OptionsParam(String name, String code)
1414 public String getName()
1419 public void setName(String name)
1424 public String getCode()
1429 public void setCode(String code)
1435 public String toString()
1441 public boolean equals(Object that)
1443 if (!(that instanceof OptionsParam))
1447 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1451 public int hashCode()
1453 return name.hashCode() + code.hashCode();
1457 private class UrlListSelectionHandler implements ListSelectionListener
1461 public void valueChanged(ListSelectionEvent e)
1463 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1465 int index = lsm.getMinSelectionIndex();
1468 // no selection, so disable delete/edit buttons
1469 editLink.setEnabled(false);
1470 deleteLink.setEnabled(false);
1473 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1475 // enable/disable edit and delete link buttons
1476 if (((UrlLinkTableModel) linkUrlTable.getModel())
1477 .isRowDeletable(modelIndex))
1479 deleteLink.setEnabled(true);
1483 deleteLink.setEnabled(false);
1486 if (((UrlLinkTableModel) linkUrlTable.getModel())
1487 .isRowEditable(modelIndex))
1489 editLink.setEnabled(true);
1493 editLink.setEnabled(false);