2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.bin.Cache;
25 import jalview.gui.Help.HelpId;
26 import jalview.gui.StructureViewer.ViewerType;
27 import jalview.io.FileFormatI;
28 import jalview.io.JalviewFileChooser;
29 import jalview.io.JalviewFileView;
30 import jalview.jbgui.GPreferences;
31 import jalview.jbgui.GSequenceLink;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ColourSchemes;
34 import jalview.schemes.ResidueColourScheme;
35 import jalview.urls.UrlLinkTableModel;
36 import jalview.urls.api.UrlProviderFactoryI;
37 import jalview.urls.api.UrlProviderI;
38 import jalview.urls.desktop.DesktopUrlProviderFactory;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
41 import jalview.util.UrlConstants;
42 import jalview.ws.sifts.SiftsSettings;
44 import java.awt.BorderLayout;
45 import java.awt.Color;
46 import java.awt.Component;
47 import java.awt.Dimension;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
53 import java.io.IOException;
54 import java.util.ArrayList;
55 import java.util.List;
56 import java.util.Scanner;
58 import javax.help.HelpSetException;
59 import javax.swing.JColorChooser;
60 import javax.swing.JFileChooser;
61 import javax.swing.JInternalFrame;
62 import javax.swing.JPanel;
63 import javax.swing.ListSelectionModel;
64 import javax.swing.RowFilter;
65 import javax.swing.RowSorter;
66 import javax.swing.SortOrder;
67 import javax.swing.event.DocumentEvent;
68 import javax.swing.event.DocumentListener;
69 import javax.swing.event.ListSelectionEvent;
70 import javax.swing.event.ListSelectionListener;
71 import javax.swing.table.TableCellRenderer;
72 import javax.swing.table.TableColumn;
73 import javax.swing.table.TableModel;
74 import javax.swing.table.TableRowSorter;
76 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
84 public class Preferences extends GPreferences
86 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
88 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
90 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
92 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
94 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
96 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
98 public static final String ADD_SS_ANN = "ADD_SS_ANN";
100 public static final String USE_RNAVIEW = "USE_RNAVIEW";
102 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
104 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
106 public static final String CHIMERA_PATH = "CHIMERA_PATH";
108 public static final String HMMER_PATH = "HMMER_PATH";
110 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
112 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
114 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
116 private static final int MIN_FONT_SIZE = 1;
118 private static final int MAX_FONT_SIZE = 30;
121 * Holds name and link separated with | character. Sequence ID must be
122 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
124 public static UrlProviderI sequenceUrlLinks;
126 public static UrlLinkTableModel dataModel;
129 * Holds name and link separated with | character. Sequence IDS and Sequences
130 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
131 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
132 * for first and second token specified after a pipe character at end |,|.
133 * (TODO: proper escape for using | to separate ids or sequences
136 public static List<String> groupURLLinks;
139 // get links selected to be in the menu (SEQUENCE_LINKS)
140 // and links entered by the user but not selected (STORED_LINKS)
141 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
142 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
143 String defaultUrl = Cache.getDefault("DEFAULT_URL",
144 UrlConstants.DEFAULT_LABEL);
146 // if both links lists are empty, add the DEFAULT_URL link
147 // otherwise we assume the default link is in one of the lists
148 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
150 inMenuString = UrlConstants.DEFAULT_STRING;
152 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
153 inMenuString, notInMenuString);
154 sequenceUrlLinks = factory.createUrlProvider();
155 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
158 * TODO: reformulate groupURL encoding so two or more can be stored in the
159 * .properties file as '|' separated strings
162 groupURLLinks = new ArrayList<>();
165 JInternalFrame frame;
167 DasSourceBrowser dasSource;
169 private WsPreferences wsPrefs;
171 private OptionsParam promptEachTimeOpt = new OptionsParam(
172 MessageManager.getString("label.prompt_each_time"),
175 private OptionsParam lineArtOpt = new OptionsParam(
176 MessageManager.getString("label.lineart"), "Lineart");
178 private OptionsParam textOpt = new OptionsParam(
179 MessageManager.getString("action.text"), "Text");
182 * Creates a new Preferences object.
187 frame = new JInternalFrame();
188 frame.setContentPane(this);
189 dasSource = new DasSourceBrowser();
190 dasTab.add(dasSource, BorderLayout.CENTER);
191 wsPrefs = new WsPreferences();
192 wsTab.add(wsPrefs, BorderLayout.CENTER);
193 int width = 500, height = 450;
194 new jalview.util.Platform();
195 if (Platform.isAMac())
201 Desktop.addInternalFrame(frame,
202 MessageManager.getString("label.preferences"), width, height);
203 frame.setMinimumSize(new Dimension(width, height));
206 * Set HMMER tab defaults
208 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
210 .setSelected(Cache.getDefault("HMMER_INSTALLED", false));
211 if (Cache.getDefault("USE_UNIPROT", false))
213 uniprot.setSelected(true);
217 alignment.setSelected(true);
219 numberOfSequencesToKeepField
220 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
221 installationLocation.setEnabled(isHMMERInstalled.isSelected());
222 hmmerPath.setEnabled(isHMMERInstalled.isSelected());
223 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
224 hmmerPath.addActionListener(new ActionListener()
227 public void actionPerformed(ActionEvent e)
234 * Set Visual tab defaults
236 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
237 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
238 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
239 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
241 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
242 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
243 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
244 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
246 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
247 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
248 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
250 showGroupConservation.setSelected(Cache.getDefault(
251 "SHOW_GROUP_CONSERVATION", false));
252 showConsensHistogram.setSelected(Cache.getDefault(
253 "SHOW_CONSENSUS_HISTOGRAM", true));
254 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
256 showInformationHistogram.setSelected(
257 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
258 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
259 showNpTooltip.setSelected(Cache
260 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
261 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
264 String[] fonts = java.awt.GraphicsEnvironment
265 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
266 for (int i = 0; i < fonts.length; i++)
268 fontNameCB.addItem(fonts[i]);
271 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
273 fontSizeCB.addItem(i + "");
276 fontStyleCB.addItem("plain");
277 fontStyleCB.addItem("bold");
278 fontStyleCB.addItem("italic");
280 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
281 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
282 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
285 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
286 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
289 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
291 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
293 gapSymbolCB.addItem("-");
294 gapSymbolCB.addItem(".");
296 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
298 sortby.addItem("No sort");
299 sortby.addItem("Id");
300 sortby.addItem("Pairwise Identity");
301 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
303 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
305 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
307 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
308 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
309 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
310 SequenceAnnotationOrder.NONE.name()));
311 sortAnnBy.setSelectedItem(savedSort.toString());
313 sortAutocalc.addItem("Autocalculated first");
314 sortAutocalc.addItem("Autocalculated last");
315 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
316 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
317 : sortAutocalc.getItemAt(1));
319 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
320 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
321 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
322 + "/examples/exampleFile_2_3.jar"));
325 * Set Colours tab defaults
327 protColour.addItem(ResidueColourScheme.NONE);
328 nucColour.addItem(ResidueColourScheme.NONE);
329 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
331 String name = cs.getSchemeName();
332 protColour.addItem(name);
333 nucColour.addItem(name);
335 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
336 ResidueColourScheme.NONE);
337 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
338 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
339 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
340 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
341 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
343 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
347 * Set Structure tab defaults.
349 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
350 structFromPdb.setSelected(structSelected);
351 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
352 useRnaView.setEnabled(structSelected);
353 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
354 addSecondaryStructure.setEnabled(structSelected);
355 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
356 addTempFactor.setEnabled(structSelected);
357 structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
358 ViewerType.JMOL.name()));
359 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
360 chimeraPath.addActionListener(new ActionListener()
363 public void actionPerformed(ActionEvent e)
365 validateChimeraPath();
369 if (Cache.getDefault("MAP_WITH_SIFTS", false))
371 siftsMapping.setSelected(true);
375 nwMapping.setSelected(true);
379 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
382 * Set Connections tab defaults
386 linkUrlTable.setModel(dataModel);
387 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
388 linkUrlTable.getModel());
389 linkUrlTable.setRowSorter(sorter);
390 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
392 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
393 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
394 SortOrder.DESCENDING));
395 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
396 SortOrder.DESCENDING));
397 sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
398 SortOrder.ASCENDING));
400 sorter.setSortKeys(sortKeys);
404 ActionListener onReset;
405 onReset = new ActionListener()
408 public void actionPerformed(ActionEvent e)
410 filterTB.setText("");
411 sorter.setRowFilter(RowFilter.regexFilter(""));
415 doReset.addActionListener(onReset);
417 // filter to display only custom urls
418 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
421 public boolean include(
422 Entry<? extends TableModel, ? extends Object> entry)
424 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
428 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
429 linkUrlTable.getModel());
430 customSorter.setRowFilter(customUrlFilter);
432 ActionListener onCustomOnly;
433 onCustomOnly = new ActionListener()
436 public void actionPerformed(ActionEvent e)
438 filterTB.setText("");
439 sorter.setRowFilter(customUrlFilter);
442 userOnly.addActionListener(onCustomOnly);
444 filterTB.getDocument().addDocumentListener(new DocumentListener()
446 String caseInsensitiveFlag = "(?i)";
449 public void changedUpdate(DocumentEvent e)
451 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
452 + filterTB.getText()));
456 public void removeUpdate(DocumentEvent e)
458 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
459 + filterTB.getText()));
463 public void insertUpdate(DocumentEvent e)
465 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
466 + filterTB.getText()));
470 // set up list selection functionality
471 linkUrlTable.getSelectionModel().addListSelectionListener(
472 new UrlListSelectionHandler());
474 // set up radio buttons
475 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
477 String onClickName = linkUrlTable.getColumnName(onClickCol);
478 linkUrlTable.getColumn(onClickName).setCellRenderer(
479 new RadioButtonRenderer());
480 linkUrlTable.getColumn(onClickName)
481 .setCellEditor(new RadioButtonEditor());
483 // get boolean columns and resize those to min possible
484 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
486 if (linkUrlTable.getModel().getColumnClass(column)
487 .equals(Boolean.class))
489 TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
491 int preferredWidth = tableColumn.getMinWidth();
493 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
495 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
496 int cwidth = c.getPreferredSize().width
497 + linkUrlTable.getIntercellSpacing().width;
498 preferredWidth = Math.max(preferredWidth, cwidth);
500 tableColumn.setPreferredWidth(preferredWidth);
504 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
505 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
506 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
507 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
509 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
511 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
512 // note antisense here: default is true
514 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
515 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
518 * Set Output tab defaults
520 epsRendering.addItem(promptEachTimeOpt);
521 epsRendering.addItem(lineArtOpt);
522 epsRendering.addItem(textOpt);
523 String defaultEPS = Cache.getDefault("EPS_RENDERING",
525 if (defaultEPS.equalsIgnoreCase("Text"))
527 epsRendering.setSelectedItem(textOpt);
529 else if (defaultEPS.equalsIgnoreCase("Lineart"))
531 epsRendering.setSelectedItem(lineArtOpt);
535 epsRendering.setSelectedItem(promptEachTimeOpt);
537 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
538 userIdWidth.setEnabled(!autoIdWidth.isSelected());
539 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
540 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
541 userIdWidth.setText(wi == null ? "" : wi.toString());
542 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
543 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
544 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
545 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
546 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
547 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
548 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
549 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
550 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
554 * Set Editing tab defaults
556 autoCalculateConsCheck.setSelected(Cache.getDefault(
557 "AUTO_CALC_CONSENSUS", true));
558 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
559 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
561 annotations_actionPerformed(null); // update the display of the annotation
566 * Save user selections on the Preferences tabs to the Cache and write out to
572 public void ok_actionPerformed(ActionEvent e)
574 if (!validateSettings())
580 * Save Visual settings
582 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
583 Boolean.toString(seqLimit.isSelected()));
584 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
585 Boolean.toString(rightAlign.isSelected()));
586 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
587 Boolean.toString(fullScreen.isSelected()));
588 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
589 Boolean.toString(openoverv.isSelected()));
590 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
591 Boolean.toString(annotations.isSelected()));
592 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
593 Boolean.toString(conservation.isSelected()));
594 Cache.applicationProperties.setProperty("SHOW_QUALITY",
595 Boolean.toString(quality.isSelected()));
596 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
597 Boolean.toString(identity.isSelected()));
599 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
600 .getSelectedItem().toString());
602 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
603 .getSelectedItem().toString());
604 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
605 .getSelectedItem().toString());
606 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
607 .getSelectedItem().toString());
609 Cache.applicationProperties.setProperty("ID_ITALICS",
610 Boolean.toString(idItalics.isSelected()));
611 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
612 Boolean.toString(showUnconserved.isSelected()));
613 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
614 Boolean.toString(showOccupancy.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
616 Boolean.toString(showGroupConsensus.isSelected()));
617 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
618 Boolean.toString(showGroupConservation.isSelected()));
619 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
620 Boolean.toString(showConsensHistogram.isSelected()));
621 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
622 Boolean.toString(showConsensLogo.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
624 Boolean.toString(showConsensHistogram.isSelected()));
625 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
626 Boolean.toString(showHMMLogo.isSelected()));
627 Cache.applicationProperties.setProperty("ANTI_ALIAS",
628 Boolean.toString(smoothFont.isSelected()));
629 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
630 Boolean.toString(scaleProteinToCdna.isSelected()));
631 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
632 Boolean.toString(showNpTooltip.isSelected()));
633 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
634 Boolean.toString(showDbRefTooltip.isSelected()));
636 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
637 Boolean.toString(wrap.isSelected()));
639 Cache.applicationProperties.setProperty("STARTUP_FILE",
640 startupFileTextfield.getText());
641 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
642 Boolean.toString(startupCheckbox.isSelected()));
644 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
645 .getSelectedItem().toString());
647 // convert description of sort order to enum name for save
648 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
649 .forDescription(sortAnnBy.getSelectedItem().toString());
650 if (annSortOrder != null)
652 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
653 annSortOrder.name());
656 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
657 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
658 .valueOf(showAutocalcFirst).toString());
661 * Save Colours settings
663 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
664 .getSelectedItem().toString());
665 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
666 .getSelectedItem().toString());
667 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
668 minColour.getBackground());
669 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
670 maxColour.getBackground());
673 * Save HMMER settings
675 Cache.applicationProperties.setProperty("TRIM_TERMINI",
676 Boolean.toString(trimTermini.isSelected()));
677 Cache.applicationProperties.setProperty("USE_UNIPROT",
678 Boolean.toString(uniprot.isSelected()));
679 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
680 numberOfSequencesToKeepField.getText());
681 Cache.applicationProperties.setProperty(HMMER_PATH,
682 hmmerPath.getText());
683 boolean hmmerInstalled = isHMMERInstalled.isSelected();
684 Cache.applicationProperties.setProperty("HMMER_INSTALLED",
685 Boolean.toString(hmmerInstalled));
686 boolean hmmerFunctioning = validateHMMERPath(false);
687 Cache.applicationProperties.setProperty("HMMER_FUNCTIONING",
688 Boolean.toString(hmmerFunctioning));
689 AlignFrame[] frames = Desktop.getAlignFrames();
690 boolean hmmerStatus = hmmerFunctioning && hmmerInstalled ? true : false;
691 for (AlignFrame frame : frames)
693 frame.updateHMMERStatus(hmmerStatus);
697 String ver = getHMMERVersion();
698 Cache.setProperty("HMMER_VERSION", ver);
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 path = hmmerPath.getText().trim();
1197 if (path.length() > 0)
1199 File f = new File(path);
1204 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1205 MessageManager.getString("label.folder_not_exists"),
1206 MessageManager.getString("label.invalid_folder"),
1207 JvOptionPane.ERROR_MESSAGE);
1212 File hmmbuild = new File(path + "/binaries/hmmbuild.exe");
1214 if (!hmmbuild.canExecute())
1216 message += MessageManager.getString("label.hmmbuild_not_found")
1222 File hmmalign = new File(path + "/binaries/hmmalign.exe");
1224 if (!hmmalign.canExecute())
1226 message += MessageManager.getString("label.hmmalign_not_found")
1232 File hmmsearch = new File(path + "/binaries/hmmsearch.exe");
1234 if (!hmmsearch.canExecute())
1236 message += MessageManager.getString("label.hmmsearch_not_found")
1248 JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1249 MessageManager.getString("label.invalid_folder"),
1250 JvOptionPane.ERROR_MESSAGE);
1258 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1259 MessageManager.getString("label.no_binaries"),
1260 MessageManager.getString("label.invalid_folder"),
1261 JvOptionPane.ERROR_MESSAGE);
1272 private String getHMMERVersion()
1274 File file = new File(hmmerPath.getText() + "/release-notes.txt");
1275 Scanner scanner = null;
1278 scanner = new Scanner(file);
1279 } catch (IOException e)
1281 e.printStackTrace();
1285 String res = scanner.next();
1290 private boolean validateHMMERPath()
1292 return validateHMMERPath(true);
1296 * If Chimera is selected, check it can be found on default or user-specified
1297 * path, if not show a warning/help dialog.
1300 protected void structureViewer_actionPerformed(String selectedItem)
1302 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1306 boolean found = false;
1309 * Try user-specified and standard paths for Chimera executable.
1311 List<String> paths = StructureManager.getChimeraPaths();
1312 paths.add(0, chimeraPath.getText());
1313 for (String path : paths)
1315 if (new File(path.trim()).canExecute())
1323 String[] options = { "OK", "Help" };
1324 int showHelp = JvOptionPane.showInternalOptionDialog(
1326 JvSwingUtils.wrapTooltip(true,
1327 MessageManager.getString("label.chimera_missing")),
1328 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1329 null, options, options[0]);
1330 if (showHelp == JvOptionPane.NO_OPTION)
1334 Help.showHelpWindow(HelpId.StructureViewer);
1335 } catch (HelpSetException e)
1337 e.printStackTrace();
1343 public class OptionsParam
1345 private String name;
1347 private String code;
1349 public OptionsParam(String name, String code)
1355 public String getName()
1360 public void setName(String name)
1365 public String getCode()
1370 public void setCode(String code)
1376 public String toString()
1382 public boolean equals(Object that)
1384 if (!(that instanceof OptionsParam))
1388 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1392 public int hashCode()
1394 return name.hashCode() + code.hashCode();
1398 private class UrlListSelectionHandler implements ListSelectionListener
1402 public void valueChanged(ListSelectionEvent e)
1404 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1406 int index = lsm.getMinSelectionIndex();
1409 // no selection, so disable delete/edit buttons
1410 editLink.setEnabled(false);
1411 deleteLink.setEnabled(false);
1414 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1416 // enable/disable edit and delete link buttons
1417 if (((UrlLinkTableModel) linkUrlTable.getModel())
1418 .isRowDeletable(modelIndex))
1420 deleteLink.setEnabled(true);
1424 deleteLink.setEnabled(false);
1427 if (((UrlLinkTableModel) linkUrlTable.getModel())
1428 .isRowEditable(modelIndex))
1430 editLink.setEnabled(true);
1434 editLink.setEnabled(false);