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));
253 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
255 showGroupConservation.setSelected(Cache.getDefault(
256 "SHOW_GROUP_CONSERVATION", false));
257 showConsensHistogram.setSelected(Cache.getDefault(
258 "SHOW_CONSENSUS_HISTOGRAM", true));
259 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
261 showInformationHistogram.setSelected(
262 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
263 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
264 showNpTooltip.setSelected(Cache
265 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
266 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
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(Cache.getDefault("FONT_STYLE", Font.PLAIN
290 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
291 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
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(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
348 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
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(Cache.getDefault(STRUCTURE_DISPLAY,
363 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));
402 sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
403 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.regexFilter(caseInsensitiveFlag
457 + filterTB.getText()));
461 public void removeUpdate(DocumentEvent e)
463 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
464 + filterTB.getText()));
468 public void insertUpdate(DocumentEvent e)
470 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
471 + filterTB.getText()));
475 // set up list selection functionality
476 linkUrlTable.getSelectionModel().addListSelectionListener(
477 new UrlListSelectionHandler());
479 // set up radio buttons
480 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
482 String onClickName = linkUrlTable.getColumnName(onClickCol);
483 linkUrlTable.getColumn(onClickName).setCellRenderer(
484 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().getColumn(
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));
555 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
559 * Set Editing tab defaults
561 autoCalculateConsCheck.setSelected(Cache.getDefault(
562 "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", gapSymbolCB
605 .getSelectedItem().toString());
607 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
608 .getSelectedItem().toString());
609 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
610 .getSelectedItem().toString());
611 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
612 .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", sortby
650 .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, Boolean
663 .valueOf(showAutocalcFirst).toString());
666 * Save Colours settings
668 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
669 .getSelectedItem().toString());
670 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
671 .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, structViewer
727 .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.forRead(
905 Cache.getProperty("LAST_DIRECTORY"), fileFormat);
906 chooser.setFileView(new JalviewFileView());
907 chooser.setDialogTitle(MessageManager
908 .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",
920 startupFileTextfield.setText(chooser.getSelectedFile()
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, null) == JvOptionPane.OK_OPTION)
978 if (link.checkValid())
980 if (((UrlLinkTableModel) linkUrlTable.getModel())
981 .isUniqueName(link.getName()))
983 ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
984 link.getName(), link.getURL());
989 link.notifyDuplicate();
1002 public void editLink_actionPerformed(ActionEvent e)
1004 GSequenceLink link = new GSequenceLink();
1006 int index = linkUrlTable.getSelectedRow();
1009 // button no longer enabled if row is not selected
1010 Cache.log.debug("Edit with no row selected in linkUrlTable");
1014 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1016 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1018 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1019 link.setName(oldName);
1020 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1022 boolean valid = false;
1025 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1026 MessageManager.getString("label.edit_sequence_url_link"),
1027 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
1029 if (link.checkValid())
1031 if ((oldName.equals(link.getName()))
1032 || (((UrlLinkTableModel) linkUrlTable.getModel())
1033 .isUniqueName(link.getName())))
1035 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1036 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1041 link.notifyDuplicate();
1054 public void deleteLink_actionPerformed(ActionEvent e)
1056 int index = linkUrlTable.getSelectedRow();
1057 int modelIndex = -1;
1060 // button no longer enabled if row is not selected
1061 Cache.log.debug("Delete with no row selected in linkUrlTable");
1066 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1069 // make sure we use the model index to delete, and not the table index
1070 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1075 public void defaultBrowser_mouseClicked(MouseEvent e)
1077 JFileChooser chooser = new JFileChooser(".");
1078 chooser.setDialogTitle(MessageManager
1079 .getString("label.select_default_browser"));
1081 int value = chooser.showOpenDialog(this);
1083 if (value == JFileChooser.APPROVE_OPTION)
1085 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1094 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1098 protected void showunconserved_actionPerformed(ActionEvent e)
1100 // TODO Auto-generated method stub
1101 super.showunconserved_actionPerformed(e);
1104 public static List<String> getGroupURLLinks()
1106 return groupURLLinks;
1110 public void minColour_actionPerformed(JPanel panel)
1112 Color col = JColorChooser.showDialog(this,
1113 MessageManager.getString("label.select_colour_minimum_value"),
1114 minColour.getBackground());
1117 panel.setBackground(col);
1123 public void maxColour_actionPerformed(JPanel panel)
1125 Color col = JColorChooser.showDialog(this,
1126 MessageManager.getString("label.select_colour_maximum_value"),
1127 maxColour.getBackground());
1130 panel.setBackground(col);
1136 protected void userIdWidth_actionPerformed()
1140 String val = userIdWidth.getText().trim();
1141 if (val.length() > 0)
1143 Integer iw = Integer.parseInt(val);
1144 if (iw.intValue() < 12)
1146 throw new NumberFormatException();
1148 userIdWidth.setText(iw.toString());
1150 } catch (NumberFormatException x)
1152 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
1153 .getString("warn.user_defined_width_requirements"),
1154 MessageManager.getString("label.invalid_id_column_width"),
1155 JvOptionPane.WARNING_MESSAGE);
1156 userIdWidth.setText("");
1161 protected void autoIdWidth_actionPerformed()
1163 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1164 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1168 * Returns true if chimera path is to a valid executable, else show an error
1171 private boolean validateChimeraPath()
1173 if (chimeraPath.getText().trim().length() > 0)
1175 File f = new File(chimeraPath.getText());
1176 if (!f.canExecute())
1178 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1179 MessageManager.getString("label.invalid_chimera_path"),
1180 MessageManager.getString("label.invalid_name"),
1181 JvOptionPane.ERROR_MESSAGE);
1189 * Returns true if hmmer path contains the necessary valid executables, else
1190 * show an error dialog (if showing dialog).
1192 private boolean validateHMMERPath(boolean showDialog)
1195 String message = "";
1196 String folder = hmmerPath.getText().trim();
1197 if (folder.length() > 0)
1199 File f = new File(folder);
1204 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1205 MessageManager.getString("label.folder_not_exists"),
1206 MessageManager.getString("label.invalid_folder"),
1207 JvOptionPane.ERROR_MESSAGE);
1211 AlignmentI alignment = new Alignment(
1213 { new Sequence("test", "WLWL", 0, 3) });
1214 if (canExecute(folder + "/hmmbuild"))
1216 validateHMMBuild(alignment);
1220 message += MessageManager.getString("label.hmmbuild_not_found")
1226 if (canExecute(folder + "/hmmalign"))
1232 message += MessageManager.getString("label.hmmalign_not_found")
1238 if (canExecute(folder + "/hmmsearch"))
1244 message += MessageManager.getString("label.hmmsearch_not_found")
1256 JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1257 MessageManager.getString("label.invalid_folder"),
1258 JvOptionPane.ERROR_MESSAGE);
1266 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1267 MessageManager.getString("label.no_binaries"),
1268 MessageManager.getString("label.invalid_folder"),
1269 JvOptionPane.ERROR_MESSAGE);
1280 * Checks if a file can be executed
1283 * the path to the file
1286 public boolean canExecute(String path)
1288 File file = new File(path);
1289 if (!file.canExecute())
1291 file = new File(path + ".exe");
1293 if (!file.canExecute())
1303 * Runs hmmbuild to check if it is working. While doing this it parses the
1309 public boolean validateHMMBuild(AlignmentI alignment)
1311 HMMBuildThread hmmbuild = new HMMBuildThread(alignment);
1312 hmmbuild.hmmbuildWaitTillComplete();
1313 SequenceI hmmSeq = alignment.getSequenceAt(1);
1314 HiddenMarkovModel hmm;
1315 if (hmmSeq.isHMMConsensusSequence() && hmmSeq.getHMM() != null)
1317 hmm = hmmSeq.getHMM();
1319 if (hmm.getNumberOfSymbols() < 1)
1329 String header = hmm.getFileHeader();
1336 Scanner scanner = new Scanner(header);
1338 String string = scanner.next();
1339 String version = string.substring(1);
1340 Cache.setProperty("HMMER_VERSION", version);
1348 private boolean validateHMMERPath()
1350 return validateHMMERPath(true);
1354 * If Chimera is selected, check it can be found on default or user-specified
1355 * path, if not show a warning/help dialog.
1358 protected void structureViewer_actionPerformed(String selectedItem)
1360 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1364 boolean found = false;
1367 * Try user-specified and standard paths for Chimera executable.
1369 List<String> paths = StructureManager.getChimeraPaths();
1370 paths.add(0, chimeraPath.getText());
1371 for (String path : paths)
1373 if (new File(path.trim()).canExecute())
1381 String[] options = { "OK", "Help" };
1382 int showHelp = JvOptionPane.showInternalOptionDialog(
1384 JvSwingUtils.wrapTooltip(true,
1385 MessageManager.getString("label.chimera_missing")),
1386 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1387 null, options, options[0]);
1388 if (showHelp == JvOptionPane.NO_OPTION)
1392 Help.showHelpWindow(HelpId.StructureViewer);
1393 } catch (HelpSetException e)
1395 e.printStackTrace();
1401 public class OptionsParam
1403 private String name;
1405 private String code;
1407 public OptionsParam(String name, String code)
1413 public String getName()
1418 public void setName(String name)
1423 public String getCode()
1428 public void setCode(String code)
1434 public String toString()
1440 public boolean equals(Object that)
1442 if (!(that instanceof OptionsParam))
1446 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1450 public int hashCode()
1452 return name.hashCode() + code.hashCode();
1456 private class UrlListSelectionHandler implements ListSelectionListener
1460 public void valueChanged(ListSelectionEvent e)
1462 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1464 int index = lsm.getMinSelectionIndex();
1467 // no selection, so disable delete/edit buttons
1468 editLink.setEnabled(false);
1469 deleteLink.setEnabled(false);
1472 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1474 // enable/disable edit and delete link buttons
1475 if (((UrlLinkTableModel) linkUrlTable.getModel())
1476 .isRowDeletable(modelIndex))
1478 deleteLink.setEnabled(true);
1482 deleteLink.setEnabled(false);
1485 if (((UrlLinkTableModel) linkUrlTable.getModel())
1486 .isRowEditable(modelIndex))
1488 editLink.setEnabled(true);
1492 editLink.setEnabled(false);