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.hmmer.HmmerCommand;
28 import jalview.io.FileFormatI;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.jbgui.GPreferences;
32 import jalview.jbgui.GSequenceLink;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ColourSchemes;
35 import jalview.schemes.ResidueColourScheme;
36 import jalview.urls.UrlLinkTableModel;
37 import jalview.urls.api.UrlProviderFactoryI;
38 import jalview.urls.api.UrlProviderI;
39 import jalview.urls.desktop.DesktopUrlProviderFactory;
40 import jalview.util.FileUtils;
41 import jalview.util.MessageManager;
42 import jalview.util.Platform;
43 import jalview.util.UrlConstants;
44 import jalview.ws.sifts.SiftsSettings;
46 import java.awt.BorderLayout;
47 import java.awt.Color;
48 import java.awt.Component;
49 import java.awt.Dimension;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ActionListener;
53 import java.awt.event.FocusAdapter;
54 import java.awt.event.FocusEvent;
55 import java.awt.event.MouseEvent;
57 import java.util.ArrayList;
58 import java.util.List;
60 import javax.help.HelpSetException;
61 import javax.swing.JColorChooser;
62 import javax.swing.JFileChooser;
63 import javax.swing.JInternalFrame;
64 import javax.swing.JPanel;
65 import javax.swing.JTextField;
66 import javax.swing.ListSelectionModel;
67 import javax.swing.RowFilter;
68 import javax.swing.RowSorter;
69 import javax.swing.SortOrder;
70 import javax.swing.event.DocumentEvent;
71 import javax.swing.event.DocumentListener;
72 import javax.swing.event.ListSelectionEvent;
73 import javax.swing.event.ListSelectionListener;
74 import javax.swing.table.TableCellRenderer;
75 import javax.swing.table.TableColumn;
76 import javax.swing.table.TableModel;
77 import javax.swing.table.TableRowSorter;
79 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
87 public class Preferences extends GPreferences
89 public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT";
91 public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND";
93 public static final String HMMALIGN_TRIM_TERMINI = "HMMALIGN_TRIM_TERMINI";
95 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
97 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
99 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
101 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
103 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
105 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
107 public static final String ADD_SS_ANN = "ADD_SS_ANN";
109 public static final String USE_RNAVIEW = "USE_RNAVIEW";
111 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
113 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
115 public static final String CHIMERA_PATH = "CHIMERA_PATH";
117 public static final String HMMER_PATH = "HMMER_PATH";
119 public static final String CYGWIN_PATH = "CYGWIN_PATH";
121 public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS";
123 public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
125 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
127 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
129 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
131 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
133 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
135 public static final String GAP_COLOUR = "GAP_COLOUR";
137 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
139 private static final int MIN_FONT_SIZE = 1;
141 private static final int MAX_FONT_SIZE = 30;
144 * Holds name and link separated with | character. Sequence ID must be
145 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
147 public static UrlProviderI sequenceUrlLinks;
149 public static UrlLinkTableModel dataModel;
152 * Holds name and link separated with | character. Sequence IDS and Sequences
153 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
154 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
155 * for first and second token specified after a pipe character at end |,|.
156 * (TODO: proper escape for using | to separate ids or sequences
159 public static List<String> groupURLLinks;
162 // get links selected to be in the menu (SEQUENCE_LINKS)
163 // and links entered by the user but not selected (STORED_LINKS)
164 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
165 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
166 String defaultUrl = Cache.getDefault("DEFAULT_URL",
167 UrlConstants.DEFAULT_LABEL);
169 // if both links lists are empty, add the DEFAULT_URL link
170 // otherwise we assume the default link is in one of the lists
171 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
173 inMenuString = UrlConstants.DEFAULT_STRING;
175 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
176 inMenuString, notInMenuString);
177 sequenceUrlLinks = factory.createUrlProvider();
178 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
181 * TODO: reformulate groupURL encoding so two or more can be stored in the
182 * .properties file as '|' separated strings
185 groupURLLinks = new ArrayList<>();
188 JInternalFrame frame;
190 DasSourceBrowser dasSource;
192 private WsPreferences wsPrefs;
194 private OptionsParam promptEachTimeOpt = new OptionsParam(
195 MessageManager.getString("label.prompt_each_time"),
198 private OptionsParam lineArtOpt = new OptionsParam(
199 MessageManager.getString("label.lineart"), "Lineart");
201 private OptionsParam textOpt = new OptionsParam(
202 MessageManager.getString("action.text"), "Text");
205 * Creates a new Preferences object.
210 frame = new JInternalFrame();
211 frame.setContentPane(this);
212 dasSource = new DasSourceBrowser();
213 dasTab.add(dasSource, BorderLayout.CENTER);
214 wsPrefs = new WsPreferences();
215 wsTab.add(wsPrefs, BorderLayout.CENTER);
216 int width = 500, height = 450;
217 new jalview.util.Platform();
218 if (Platform.isAMac())
224 Desktop.addInternalFrame(frame,
225 MessageManager.getString("label.preferences"), width, height);
226 frame.setMinimumSize(new Dimension(width, height));
229 * Set HMMER tab defaults
231 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
232 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
234 hmmerBackgroundUniprot.setSelected(true);
238 hmmerBackgroundAlignment.setSelected(true);
241 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
242 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
243 hmmerPath.addActionListener(new ActionListener()
246 public void actionPerformed(ActionEvent e)
251 hmmerPath.addFocusListener(new FocusAdapter()
254 public void focusLost(FocusEvent e)
259 if (cygwinPath != null)
261 String path = Cache.getProperty(CYGWIN_PATH);
264 path = FileUtils.getPathTo("bash");
266 cygwinPath.setText(path);
267 cygwinPath.addActionListener(new ActionListener()
270 public void actionPerformed(ActionEvent e)
272 validateCygwinPath();
275 cygwinPath.addFocusListener(new FocusAdapter()
278 public void focusLost(FocusEvent e)
280 validateCygwinPath();
286 * Set Visual tab defaults
288 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
289 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
290 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
291 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
293 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
294 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
295 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
296 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
298 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
299 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
301 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
302 showGroupConservation.setSelected(
303 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
304 showConsensHistogram.setSelected(
305 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
307 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
308 showInformationHistogram.setSelected(
309 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
310 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
312 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
314 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
316 String[] fonts = java.awt.GraphicsEnvironment
317 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
318 for (int i = 0; i < fonts.length; i++)
320 fontNameCB.addItem(fonts[i]);
323 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
325 fontSizeCB.addItem(i + "");
328 fontStyleCB.addItem("plain");
329 fontStyleCB.addItem("bold");
330 fontStyleCB.addItem("italic");
332 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
333 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
334 fontStyleCB.setSelectedItem(
335 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
337 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
339 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
341 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
343 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
345 gapSymbolCB.addItem("-");
346 gapSymbolCB.addItem(".");
348 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
350 sortby.addItem("No sort");
351 sortby.addItem("Id");
352 sortby.addItem("Pairwise Identity");
353 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
355 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
357 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
359 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
360 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
361 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
362 SequenceAnnotationOrder.NONE.name()));
363 sortAnnBy.setSelectedItem(savedSort.toString());
365 sortAutocalc.addItem("Autocalculated first");
366 sortAutocalc.addItem("Autocalculated last");
367 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
368 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
369 : sortAutocalc.getItemAt(1));
371 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
372 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
373 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
374 + "/examples/exampleFile_2_3.jar"));
377 * Set Colours tab defaults
379 protColour.addItem(ResidueColourScheme.NONE);
380 nucColour.addItem(ResidueColourScheme.NONE);
381 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
383 String name = cs.getSchemeName();
384 protColour.addItem(name);
385 nucColour.addItem(name);
387 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
388 ResidueColourScheme.NONE);
389 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
390 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
391 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
392 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
393 minColour.setBackground(
394 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
395 maxColour.setBackground(
396 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
399 * Set overview panel defaults
401 gapColour.setBackground(
402 Cache.getDefaultColour(GAP_COLOUR,
403 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
404 hiddenColour.setBackground(
405 Cache.getDefaultColour(HIDDEN_COLOUR,
406 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
407 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
408 gapLabel.setEnabled(!useLegacyGap.isSelected());
409 gapColour.setEnabled(!useLegacyGap.isSelected());
411 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
414 * Set Structure tab defaults.
416 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
417 structFromPdb.setSelected(structSelected);
418 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
419 useRnaView.setEnabled(structSelected);
420 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
421 addSecondaryStructure.setEnabled(structSelected);
422 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
423 addTempFactor.setEnabled(structSelected);
424 structViewer.setSelectedItem(
425 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
426 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
427 chimeraPath.addActionListener(new ActionListener()
430 public void actionPerformed(ActionEvent e)
432 validateChimeraPath();
436 if (Cache.getDefault("MAP_WITH_SIFTS", false))
438 siftsMapping.setSelected(true);
442 nwMapping.setSelected(true);
446 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
449 * Set Connections tab defaults
453 linkUrlTable.setModel(dataModel);
454 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
455 linkUrlTable.getModel());
456 linkUrlTable.setRowSorter(sorter);
457 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
459 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
460 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
461 SortOrder.DESCENDING));
462 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
463 SortOrder.DESCENDING));
465 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
467 sorter.setSortKeys(sortKeys);
471 ActionListener onReset;
472 onReset = new ActionListener()
475 public void actionPerformed(ActionEvent e)
477 filterTB.setText("");
478 sorter.setRowFilter(RowFilter.regexFilter(""));
482 doReset.addActionListener(onReset);
484 // filter to display only custom urls
485 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
488 public boolean include(
489 Entry<? extends TableModel, ? extends Object> entry)
491 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
495 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
496 linkUrlTable.getModel());
497 customSorter.setRowFilter(customUrlFilter);
499 ActionListener onCustomOnly;
500 onCustomOnly = new ActionListener()
503 public void actionPerformed(ActionEvent e)
505 filterTB.setText("");
506 sorter.setRowFilter(customUrlFilter);
509 userOnly.addActionListener(onCustomOnly);
511 filterTB.getDocument().addDocumentListener(new DocumentListener()
513 String caseInsensitiveFlag = "(?i)";
516 public void changedUpdate(DocumentEvent e)
518 sorter.setRowFilter(RowFilter
519 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
523 public void removeUpdate(DocumentEvent e)
525 sorter.setRowFilter(RowFilter
526 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
530 public void insertUpdate(DocumentEvent e)
532 sorter.setRowFilter(RowFilter
533 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
537 // set up list selection functionality
538 linkUrlTable.getSelectionModel()
539 .addListSelectionListener(new UrlListSelectionHandler());
541 // set up radio buttons
542 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
544 String onClickName = linkUrlTable.getColumnName(onClickCol);
545 linkUrlTable.getColumn(onClickName)
546 .setCellRenderer(new RadioButtonRenderer());
547 linkUrlTable.getColumn(onClickName)
548 .setCellEditor(new RadioButtonEditor());
550 // get boolean columns and resize those to min possible
551 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
553 if (linkUrlTable.getModel().getColumnClass(column)
554 .equals(Boolean.class))
556 TableColumn tableColumn = linkUrlTable.getColumnModel()
558 int preferredWidth = tableColumn.getMinWidth();
560 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
562 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
563 int cwidth = c.getPreferredSize().width
564 + linkUrlTable.getIntercellSpacing().width;
565 preferredWidth = Math.max(preferredWidth, cwidth);
567 tableColumn.setPreferredWidth(preferredWidth);
571 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
572 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
573 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
574 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
576 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
578 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
579 // note antisense here: default is true
581 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
582 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
585 * Set Output tab defaults
587 epsRendering.addItem(promptEachTimeOpt);
588 epsRendering.addItem(lineArtOpt);
589 epsRendering.addItem(textOpt);
590 String defaultEPS = Cache.getDefault("EPS_RENDERING",
592 if (defaultEPS.equalsIgnoreCase("Text"))
594 epsRendering.setSelectedItem(textOpt);
596 else if (defaultEPS.equalsIgnoreCase("Lineart"))
598 epsRendering.setSelectedItem(lineArtOpt);
602 epsRendering.setSelectedItem(promptEachTimeOpt);
604 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
605 userIdWidth.setEnabled(!autoIdWidth.isSelected());
606 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
607 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
608 userIdWidth.setText(wi == null ? "" : wi.toString());
609 // TODO: refactor to use common enum via FormatAdapter and allow extension
610 // for new flat file formats
611 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
612 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
613 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
614 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
615 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
616 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
617 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
618 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
620 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
623 * Set Editing tab defaults
625 autoCalculateConsCheck
626 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
627 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
628 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
630 annotations_actionPerformed(null); // update the display of the annotation
635 * Save user selections on the Preferences tabs to the Cache and write out to
641 public void ok_actionPerformed(ActionEvent e)
643 if (!validateSettings())
649 * Save Visual settings
651 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
652 Boolean.toString(seqLimit.isSelected()));
653 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
654 Boolean.toString(rightAlign.isSelected()));
655 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
656 Boolean.toString(fullScreen.isSelected()));
657 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
658 Boolean.toString(openoverv.isSelected()));
659 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
660 Boolean.toString(annotations.isSelected()));
661 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
662 Boolean.toString(conservation.isSelected()));
663 Cache.applicationProperties.setProperty("SHOW_QUALITY",
664 Boolean.toString(quality.isSelected()));
665 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
666 Boolean.toString(identity.isSelected()));
668 Cache.applicationProperties.setProperty("GAP_SYMBOL",
669 gapSymbolCB.getSelectedItem().toString());
671 Cache.applicationProperties.setProperty("FONT_NAME",
672 fontNameCB.getSelectedItem().toString());
673 Cache.applicationProperties.setProperty("FONT_STYLE",
674 fontStyleCB.getSelectedItem().toString());
675 Cache.applicationProperties.setProperty("FONT_SIZE",
676 fontSizeCB.getSelectedItem().toString());
678 Cache.applicationProperties.setProperty("ID_ITALICS",
679 Boolean.toString(idItalics.isSelected()));
680 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
681 Boolean.toString(showUnconserved.isSelected()));
682 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
683 Boolean.toString(showOccupancy.isSelected()));
684 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
685 Boolean.toString(showGroupConsensus.isSelected()));
686 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
687 Boolean.toString(showGroupConservation.isSelected()));
688 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
689 Boolean.toString(showConsensHistogram.isSelected()));
690 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
691 Boolean.toString(showConsensLogo.isSelected()));
692 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
693 Boolean.toString(showConsensHistogram.isSelected()));
694 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
695 Boolean.toString(showHMMLogo.isSelected()));
696 Cache.applicationProperties.setProperty("ANTI_ALIAS",
697 Boolean.toString(smoothFont.isSelected()));
698 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
699 Boolean.toString(scaleProteinToCdna.isSelected()));
700 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
701 Boolean.toString(showNpTooltip.isSelected()));
702 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
703 Boolean.toString(showDbRefTooltip.isSelected()));
705 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
706 Boolean.toString(wrap.isSelected()));
708 Cache.applicationProperties.setProperty("STARTUP_FILE",
709 startupFileTextfield.getText());
710 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
711 Boolean.toString(startupCheckbox.isSelected()));
713 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
714 sortby.getSelectedItem().toString());
716 // convert description of sort order to enum name for save
717 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
718 .forDescription(sortAnnBy.getSelectedItem().toString());
719 if (annSortOrder != null)
721 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
722 annSortOrder.name());
725 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
726 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
727 Boolean.valueOf(showAutocalcFirst).toString());
730 * Save Colours settings
732 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
733 protColour.getSelectedItem().toString());
734 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
735 nucColour.getSelectedItem().toString());
736 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
737 minColour.getBackground());
738 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
739 maxColour.getBackground());
742 * Save HMMER settings
744 Cache.applicationProperties.setProperty(HMMALIGN_TRIM_TERMINI,
745 Boolean.toString(hmmrTrimTermini.isSelected()));
746 Cache.applicationProperties.setProperty(HMMINFO_GLOBAL_BACKGROUND,
747 Boolean.toString(hmmerBackgroundUniprot.isSelected()));
748 Cache.applicationProperties.setProperty(HMMSEARCH_SEQCOUNT,
749 hmmerSequenceCount.getText());
750 Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
751 if (cygwinPath != null)
753 Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
755 AlignFrame[] frames = Desktop.getAlignFrames();
756 if (frames != null && frames.length > 0)
758 for (AlignFrame f : frames)
760 f.updateHMMERStatus();
764 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
765 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
767 hmmerBackgroundUniprot.setSelected(true);
771 hmmerBackgroundAlignment.setSelected(true);
774 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
775 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
778 * Save Overview settings
780 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
781 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
782 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
783 Boolean.toString(useLegacyGap.isSelected()));
784 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
785 Boolean.toString(showHiddenAtStart.isSelected()));
788 * Save Structure settings
790 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
791 Boolean.toString(addTempFactor.isSelected()));
792 Cache.applicationProperties.setProperty(ADD_SS_ANN,
793 Boolean.toString(addSecondaryStructure.isSelected()));
794 Cache.applicationProperties.setProperty(USE_RNAVIEW,
795 Boolean.toString(useRnaView.isSelected()));
796 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
797 Boolean.toString(structFromPdb.isSelected()));
798 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
799 structViewer.getSelectedItem().toString());
800 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
801 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
802 Boolean.toString(siftsMapping.isSelected()));
803 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
806 * Save Output settings
808 Cache.applicationProperties.setProperty("EPS_RENDERING",
809 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
812 * Save Connections settings
814 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
816 jalview.util.BrowserLauncher.resetBrowser();
818 // save user-defined and selected links
819 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
820 if (menuLinks.isEmpty())
822 Cache.applicationProperties.remove("SEQUENCE_LINKS");
826 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
827 menuLinks.toString());
830 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
831 if (nonMenuLinks.isEmpty())
833 Cache.applicationProperties.remove("STORED_LINKS");
837 Cache.applicationProperties.setProperty("STORED_LINKS",
838 nonMenuLinks.toString());
841 Cache.applicationProperties.setProperty("DEFAULT_URL",
842 sequenceUrlLinks.getPrimaryUrlId());
844 Cache.applicationProperties.setProperty("USE_PROXY",
845 Boolean.toString(useProxy.isSelected()));
847 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
849 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
851 if (useProxy.isSelected())
853 System.setProperty("http.proxyHost", proxyServerTB.getText());
854 System.setProperty("http.proxyPort", proxyPortTB.getText());
858 System.setProperty("http.proxyHost", "");
859 System.setProperty("http.proxyPort", "");
861 Cache.setProperty("VERSION_CHECK",
862 Boolean.toString(versioncheck.isSelected()));
863 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
865 // default is false - we only set this if the user has actively agreed
866 Cache.setProperty("USAGESTATS",
867 Boolean.toString(usagestats.isSelected()));
869 if (!questionnaire.isSelected())
871 Cache.setProperty("NOQUESTIONNAIRES", "true");
875 // special - made easy to edit a property file to disable questionnaires
876 // by just adding the given line
877 Cache.removeProperty("NOQUESTIONNAIRES");
881 * Save Output settings
883 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
884 Boolean.toString(blcjv.isSelected()));
885 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
886 Boolean.toString(clustaljv.isSelected()));
887 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
888 Boolean.toString(fastajv.isSelected()));
889 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
890 Boolean.toString(msfjv.isSelected()));
891 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
892 Boolean.toString(pfamjv.isSelected()));
893 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
894 Boolean.toString(pileupjv.isSelected()));
895 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
896 Boolean.toString(pirjv.isSelected()));
897 Cache.applicationProperties.setProperty("PIR_MODELLER",
898 Boolean.toString(modellerOutput.isSelected()));
899 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
900 Boolean.toString(embbedBioJSON.isSelected()));
901 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
903 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
904 Boolean.toString(autoIdWidth.isSelected()));
905 userIdWidth_actionPerformed();
906 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
907 userIdWidth.getText());
910 * Save Editing settings
912 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
913 Boolean.toString(autoCalculateConsCheck.isSelected()));
914 Cache.applicationProperties.setProperty("SORT_BY_TREE",
915 Boolean.toString(sortByTree.isSelected()));
916 Cache.applicationProperties.setProperty("PAD_GAPS",
917 Boolean.toString(padGaps.isSelected()));
919 dasSource.saveProperties(Cache.applicationProperties);
920 wsPrefs.updateAndRefreshWsMenuConfig(false);
921 Cache.saveProperties();
922 Desktop.instance.doConfigureStructurePrefs();
925 frame.setClosed(true);
926 } catch (Exception ex)
932 * Do any necessary validation before saving settings. Return focus to the
933 * first tab which fails validation.
937 private boolean validateSettings()
939 if (!validateStructure())
941 structureTab.requestFocusInWindow();
948 protected boolean validateStructure()
950 return validateChimeraPath();
958 public void startupFileTextfield_mouseClicked()
960 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
961 JalviewFileChooser chooser = JalviewFileChooser
962 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
963 chooser.setFileView(new JalviewFileView());
964 chooser.setDialogTitle(
965 MessageManager.getString("label.select_startup_file"));
967 int value = chooser.showOpenDialog(this);
969 if (value == JalviewFileChooser.APPROVE_OPTION)
971 FileFormatI format = chooser.getSelectedFormat();
974 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
978 .setText(chooser.getSelectedFile().getAbsolutePath());
989 public void cancel_actionPerformed(ActionEvent e)
993 wsPrefs.updateWsMenuConfig(true);
994 wsPrefs.refreshWs_actionPerformed(e);
995 frame.setClosed(true);
996 } catch (Exception ex)
1008 public void annotations_actionPerformed(ActionEvent e)
1010 conservation.setEnabled(annotations.isSelected());
1011 quality.setEnabled(annotations.isSelected());
1012 identity.setEnabled(annotations.isSelected());
1013 showOccupancy.setEnabled(annotations.isSelected());
1014 showGroupConsensus.setEnabled(annotations.isSelected());
1015 showGroupConservation.setEnabled(annotations.isSelected());
1016 showConsensHistogram.setEnabled(annotations.isSelected()
1017 && (identity.isSelected() || showGroupConsensus.isSelected()));
1018 showConsensLogo.setEnabled(annotations.isSelected()
1019 && (identity.isSelected() || showGroupConsensus.isSelected()));
1020 showInformationHistogram.setEnabled(annotations.isSelected());
1021 showHMMLogo.setEnabled(annotations.isSelected());
1025 public void newLink_actionPerformed(ActionEvent e)
1027 GSequenceLink link = new GSequenceLink();
1028 boolean valid = false;
1031 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1032 MessageManager.getString("label.new_sequence_url_link"),
1033 JvOptionPane.OK_CANCEL_OPTION, -1,
1034 null) == JvOptionPane.OK_OPTION)
1036 if (link.checkValid())
1038 if (((UrlLinkTableModel) linkUrlTable.getModel())
1039 .isUniqueName(link.getName()))
1041 ((UrlLinkTableModel) linkUrlTable.getModel())
1042 .insertRow(link.getName(), link.getURL());
1047 link.notifyDuplicate();
1060 public void editLink_actionPerformed(ActionEvent e)
1062 GSequenceLink link = new GSequenceLink();
1064 int index = linkUrlTable.getSelectedRow();
1067 // button no longer enabled if row is not selected
1068 Cache.log.debug("Edit with no row selected in linkUrlTable");
1072 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1074 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1076 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1077 link.setName(oldName);
1078 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1080 boolean valid = false;
1083 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1084 MessageManager.getString("label.edit_sequence_url_link"),
1085 JvOptionPane.OK_CANCEL_OPTION, -1,
1086 null) == JvOptionPane.OK_OPTION)
1088 if (link.checkValid())
1090 if ((oldName.equals(link.getName()))
1091 || (((UrlLinkTableModel) linkUrlTable.getModel())
1092 .isUniqueName(link.getName())))
1094 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1095 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1100 link.notifyDuplicate();
1113 public void deleteLink_actionPerformed(ActionEvent e)
1115 int index = linkUrlTable.getSelectedRow();
1116 int modelIndex = -1;
1119 // button no longer enabled if row is not selected
1120 Cache.log.debug("Delete with no row selected in linkUrlTable");
1125 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1128 // make sure we use the model index to delete, and not the table index
1129 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1133 public void defaultBrowser_mouseClicked(MouseEvent e)
1135 JFileChooser chooser = new JFileChooser(".");
1136 chooser.setDialogTitle(
1137 MessageManager.getString("label.select_default_browser"));
1139 int value = chooser.showOpenDialog(this);
1141 if (value == JFileChooser.APPROVE_OPTION)
1143 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1152 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1156 protected void showunconserved_actionPerformed(ActionEvent e)
1158 // TODO Auto-generated method stub
1159 super.showunconserved_actionPerformed(e);
1162 public static List<String> getGroupURLLinks()
1164 return groupURLLinks;
1168 public void minColour_actionPerformed(JPanel panel)
1170 Color col = JColorChooser.showDialog(this,
1171 MessageManager.getString("label.select_colour_minimum_value"),
1172 minColour.getBackground());
1175 panel.setBackground(col);
1181 public void maxColour_actionPerformed(JPanel panel)
1183 Color col = JColorChooser.showDialog(this,
1184 MessageManager.getString("label.select_colour_maximum_value"),
1185 maxColour.getBackground());
1188 panel.setBackground(col);
1194 public void gapColour_actionPerformed(JPanel gap)
1196 if (!useLegacyGap.isSelected())
1198 Color col = JColorChooser.showDialog(this,
1199 MessageManager.getString("label.select_gap_colour"),
1200 gapColour.getBackground());
1203 gap.setBackground(col);
1210 public void hiddenColour_actionPerformed(JPanel hidden)
1212 Color col = JColorChooser.showDialog(this,
1213 MessageManager.getString("label.select_hidden_colour"),
1214 hiddenColour.getBackground());
1217 hidden.setBackground(col);
1223 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1225 boolean enabled = useLegacyGap.isSelected();
1228 gapColour.setBackground(
1229 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1233 gapColour.setBackground(
1234 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1236 gapColour.setEnabled(!enabled);
1237 gapLabel.setEnabled(!enabled);
1241 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1243 useLegacyGap.setSelected(false);
1244 useLegacyGaps_actionPerformed(null);
1245 showHiddenAtStart.setSelected(true);
1246 hiddenColour.setBackground(
1247 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1251 protected void userIdWidth_actionPerformed()
1255 String val = userIdWidth.getText().trim();
1256 if (val.length() > 0)
1258 Integer iw = Integer.parseInt(val);
1259 if (iw.intValue() < 12)
1261 throw new NumberFormatException();
1263 userIdWidth.setText(iw.toString());
1265 } catch (NumberFormatException x)
1267 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1269 .getString("warn.user_defined_width_requirements"),
1270 MessageManager.getString("label.invalid_id_column_width"),
1271 JvOptionPane.WARNING_MESSAGE);
1272 userIdWidth.setText("");
1277 protected void autoIdWidth_actionPerformed()
1279 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1280 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1284 * Returns true if chimera path is to a valid executable, else show an error
1287 private boolean validateChimeraPath()
1289 if (chimeraPath.getText().trim().length() > 0)
1291 File f = new File(chimeraPath.getText());
1292 if (!f.canExecute())
1294 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1295 MessageManager.getString("label.invalid_chimera_path"),
1296 MessageManager.getString("label.invalid_name"),
1297 JvOptionPane.ERROR_MESSAGE);
1305 * Returns true if the given text field contains a path to a folder that
1306 * contains an executable with the given name, else false (after showing a
1307 * warning dialog). The executable name will be tried with .exe appended if not
1313 protected boolean validateExecutablePath(JTextField textField, String executable)
1315 String folder = textField.getText().trim();
1317 if (FileUtils.getExecutable(executable, folder) != null)
1321 if (folder.length() > 0)
1323 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1324 MessageManager.formatMessage("label.executable_not_found",
1326 MessageManager.getString("label.invalid_folder"),
1327 JvOptionPane.ERROR_MESSAGE);
1333 * Checks if a file can be executed
1336 * the path to the file
1339 public boolean canExecute(String path)
1341 File file = new File(path);
1342 if (!file.canExecute())
1344 file = new File(path + ".exe");
1346 if (!file.canExecute())
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();
1403 protected void validateHmmerPath()
1405 validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1409 protected void validateCygwinPath()
1411 validateExecutablePath(cygwinPath, "run");
1414 public class OptionsParam
1416 private String name;
1418 private String code;
1420 public OptionsParam(String name, String code)
1426 public String getName()
1431 public void setName(String name)
1436 public String getCode()
1441 public void setCode(String code)
1447 public String toString()
1453 public boolean equals(Object that)
1455 if (!(that instanceof OptionsParam))
1459 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1463 public int hashCode()
1465 return name.hashCode() + code.hashCode();
1469 private class UrlListSelectionHandler implements ListSelectionListener
1473 public void valueChanged(ListSelectionEvent e)
1475 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1477 int index = lsm.getMinSelectionIndex();
1480 // no selection, so disable delete/edit buttons
1481 editLink.setEnabled(false);
1482 deleteLink.setEnabled(false);
1485 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1487 // enable/disable edit and delete link buttons
1488 if (((UrlLinkTableModel) linkUrlTable.getModel())
1489 .isRowDeletable(modelIndex))
1491 deleteLink.setEnabled(true);
1495 deleteLink.setEnabled(false);
1498 if (((UrlLinkTableModel) linkUrlTable.getModel())
1499 .isRowEditable(modelIndex))
1501 editLink.setEnabled(true);
1505 editLink.setEnabled(false);