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 // suggested list delimiter character
90 public static final String COMMA = ",";
92 public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT";
94 public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND";
96 public static final String HMMALIGN_TRIM_TERMINI = "HMMALIGN_TRIM_TERMINI";
98 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
100 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
102 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
104 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
106 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
108 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
110 public static final String ADD_SS_ANN = "ADD_SS_ANN";
112 public static final String USE_RNAVIEW = "USE_RNAVIEW";
114 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
116 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
118 public static final String CHIMERA_PATH = "CHIMERA_PATH";
120 public static final String HMMER_PATH = "HMMER_PATH";
122 public static final String CYGWIN_PATH = "CYGWIN_PATH";
124 public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
126 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
128 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
130 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
132 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
134 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
136 public static final String GAP_COLOUR = "GAP_COLOUR";
138 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
140 private static final int MIN_FONT_SIZE = 1;
142 private static final int MAX_FONT_SIZE = 30;
145 * Holds name and link separated with | character. Sequence ID must be
146 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
148 public static UrlProviderI sequenceUrlLinks;
150 public static UrlLinkTableModel dataModel;
153 * Holds name and link separated with | character. Sequence IDS and Sequences
154 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
155 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
156 * for first and second token specified after a pipe character at end |,|.
157 * (TODO: proper escape for using | to separate ids or sequences
160 public static List<String> groupURLLinks;
163 // get links selected to be in the menu (SEQUENCE_LINKS)
164 // and links entered by the user but not selected (STORED_LINKS)
165 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
166 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
167 String defaultUrl = Cache.getDefault("DEFAULT_URL",
168 UrlConstants.DEFAULT_LABEL);
170 // if both links lists are empty, add the DEFAULT_URL link
171 // otherwise we assume the default link is in one of the lists
172 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
174 inMenuString = UrlConstants.DEFAULT_STRING;
176 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
177 inMenuString, notInMenuString);
178 sequenceUrlLinks = factory.createUrlProvider();
179 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
182 * TODO: reformulate groupURL encoding so two or more can be stored in the
183 * .properties file as '|' separated strings
186 groupURLLinks = new ArrayList<>();
189 JInternalFrame frame;
191 private WsPreferences wsPrefs;
193 private OptionsParam promptEachTimeOpt = new OptionsParam(
194 MessageManager.getString("label.prompt_each_time"),
197 private OptionsParam lineArtOpt = new OptionsParam(
198 MessageManager.getString("label.lineart"), "Lineart");
200 private OptionsParam textOpt = new OptionsParam(
201 MessageManager.getString("action.text"), "Text");
204 * Creates a new Preferences object.
209 frame = new JInternalFrame();
210 frame.setContentPane(this);
211 wsPrefs = new WsPreferences();
212 wsTab.add(wsPrefs, BorderLayout.CENTER);
213 int width = 500, height = 450;
214 new jalview.util.Platform();
215 if (Platform.isAMac())
221 Desktop.addInternalFrame(frame,
222 MessageManager.getString("label.preferences"), width, height);
223 frame.setMinimumSize(new Dimension(width, height));
226 * Set HMMER tab defaults
228 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
229 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
231 hmmerBackgroundUniprot.setSelected(true);
235 hmmerBackgroundAlignment.setSelected(true);
238 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
239 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
240 hmmerPath.addActionListener(new ActionListener()
243 public void actionPerformed(ActionEvent e)
248 hmmerPath.addFocusListener(new FocusAdapter()
251 public void focusLost(FocusEvent e)
256 if (cygwinPath != null)
258 String path = Cache.getProperty(CYGWIN_PATH);
261 path = FileUtils.getPathTo("bash");
263 cygwinPath.setText(path);
264 cygwinPath.addActionListener(new ActionListener()
267 public void actionPerformed(ActionEvent e)
269 validateCygwinPath();
272 cygwinPath.addFocusListener(new FocusAdapter()
275 public void focusLost(FocusEvent e)
277 validateCygwinPath();
283 * Set Visual tab defaults
285 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
286 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
287 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
288 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
290 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
291 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
292 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
293 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
295 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
296 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
298 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
299 showGroupConservation.setSelected(
300 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
301 showConsensHistogram.setSelected(
302 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
304 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
305 showInformationHistogram.setSelected(
306 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
307 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
309 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
311 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
313 String[] fonts = java.awt.GraphicsEnvironment
314 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
315 for (int i = 0; i < fonts.length; i++)
317 fontNameCB.addItem(fonts[i]);
320 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
322 fontSizeCB.addItem(i + "");
325 fontStyleCB.addItem("plain");
326 fontStyleCB.addItem("bold");
327 fontStyleCB.addItem("italic");
329 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
330 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
331 fontStyleCB.setSelectedItem(
332 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
334 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
336 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
338 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
340 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
342 gapSymbolCB.addItem("-");
343 gapSymbolCB.addItem(".");
345 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
347 sortby.addItem("No sort");
348 sortby.addItem("Id");
349 sortby.addItem("Pairwise Identity");
350 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
352 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
354 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
356 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
357 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
358 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
359 SequenceAnnotationOrder.NONE.name()));
360 sortAnnBy.setSelectedItem(savedSort.toString());
362 sortAutocalc.addItem("Autocalculated first");
363 sortAutocalc.addItem("Autocalculated last");
364 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
365 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
366 : sortAutocalc.getItemAt(1));
368 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
369 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
370 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
371 + "/examples/exampleFile_2_3.jar"));
374 * Set Colours tab defaults
376 protColour.addItem(ResidueColourScheme.NONE);
377 nucColour.addItem(ResidueColourScheme.NONE);
378 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
380 String name = cs.getSchemeName();
381 protColour.addItem(name);
382 nucColour.addItem(name);
384 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
385 ResidueColourScheme.NONE);
386 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
387 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
388 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
389 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
390 minColour.setBackground(
391 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
392 maxColour.setBackground(
393 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
396 * Set overview panel defaults
398 gapColour.setBackground(
399 Cache.getDefaultColour(GAP_COLOUR,
400 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
401 hiddenColour.setBackground(
402 Cache.getDefaultColour(HIDDEN_COLOUR,
403 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
404 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
405 gapLabel.setEnabled(!useLegacyGap.isSelected());
406 gapColour.setEnabled(!useLegacyGap.isSelected());
408 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
411 * Set Structure tab defaults.
413 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
414 structFromPdb.setSelected(structSelected);
415 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
416 useRnaView.setEnabled(structSelected);
417 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
418 addSecondaryStructure.setEnabled(structSelected);
419 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
420 addTempFactor.setEnabled(structSelected);
421 structViewer.setSelectedItem(
422 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
423 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
424 chimeraPath.addActionListener(new ActionListener()
427 public void actionPerformed(ActionEvent e)
429 validateChimeraPath();
433 if (Cache.getDefault("MAP_WITH_SIFTS", false))
435 siftsMapping.setSelected(true);
439 nwMapping.setSelected(true);
443 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
446 * Set Connections tab defaults
450 linkUrlTable.setModel(dataModel);
451 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
452 linkUrlTable.getModel());
453 linkUrlTable.setRowSorter(sorter);
454 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
456 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
457 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
458 SortOrder.DESCENDING));
459 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
460 SortOrder.DESCENDING));
462 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
464 sorter.setSortKeys(sortKeys);
468 ActionListener onReset;
469 onReset = new ActionListener()
472 public void actionPerformed(ActionEvent e)
474 filterTB.setText("");
475 sorter.setRowFilter(RowFilter.regexFilter(""));
479 doReset.addActionListener(onReset);
481 // filter to display only custom urls
482 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
485 public boolean include(
486 Entry<? extends TableModel, ? extends Object> entry)
488 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
492 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
493 linkUrlTable.getModel());
494 customSorter.setRowFilter(customUrlFilter);
496 ActionListener onCustomOnly;
497 onCustomOnly = new ActionListener()
500 public void actionPerformed(ActionEvent e)
502 filterTB.setText("");
503 sorter.setRowFilter(customUrlFilter);
506 userOnly.addActionListener(onCustomOnly);
508 filterTB.getDocument().addDocumentListener(new DocumentListener()
510 String caseInsensitiveFlag = "(?i)";
513 public void changedUpdate(DocumentEvent e)
515 sorter.setRowFilter(RowFilter
516 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
520 public void removeUpdate(DocumentEvent e)
522 sorter.setRowFilter(RowFilter
523 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
527 public void insertUpdate(DocumentEvent e)
529 sorter.setRowFilter(RowFilter
530 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
534 // set up list selection functionality
535 linkUrlTable.getSelectionModel()
536 .addListSelectionListener(new UrlListSelectionHandler());
538 // set up radio buttons
539 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
541 String onClickName = linkUrlTable.getColumnName(onClickCol);
542 linkUrlTable.getColumn(onClickName)
543 .setCellRenderer(new RadioButtonRenderer());
544 linkUrlTable.getColumn(onClickName)
545 .setCellEditor(new RadioButtonEditor());
547 // get boolean columns and resize those to min possible
548 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
550 if (linkUrlTable.getModel().getColumnClass(column)
551 .equals(Boolean.class))
553 TableColumn tableColumn = linkUrlTable.getColumnModel()
555 int preferredWidth = tableColumn.getMinWidth();
557 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
559 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
560 int cwidth = c.getPreferredSize().width
561 + linkUrlTable.getIntercellSpacing().width;
562 preferredWidth = Math.max(preferredWidth, cwidth);
564 tableColumn.setPreferredWidth(preferredWidth);
568 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
569 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
570 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
571 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
573 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
575 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
576 // note antisense here: default is true
578 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
579 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
582 * Set Output tab defaults
584 epsRendering.addItem(promptEachTimeOpt);
585 epsRendering.addItem(lineArtOpt);
586 epsRendering.addItem(textOpt);
587 String defaultEPS = Cache.getDefault("EPS_RENDERING",
589 if (defaultEPS.equalsIgnoreCase("Text"))
591 epsRendering.setSelectedItem(textOpt);
593 else if (defaultEPS.equalsIgnoreCase("Lineart"))
595 epsRendering.setSelectedItem(lineArtOpt);
599 epsRendering.setSelectedItem(promptEachTimeOpt);
601 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
602 userIdWidth.setEnabled(!autoIdWidth.isSelected());
603 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
604 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
605 userIdWidth.setText(wi == null ? "" : wi.toString());
606 // TODO: refactor to use common enum via FormatAdapter and allow extension
607 // for new flat file formats
608 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
609 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
610 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
611 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
612 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
613 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
614 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
615 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
617 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
620 * Set Editing tab defaults
622 autoCalculateConsCheck
623 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
624 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
625 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
627 annotations_actionPerformed(null); // update the display of the annotation
632 * Save user selections on the Preferences tabs to the Cache and write out to
638 public void ok_actionPerformed(ActionEvent e)
640 if (!validateSettings())
646 * Save Visual settings
648 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
649 Boolean.toString(seqLimit.isSelected()));
650 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
651 Boolean.toString(rightAlign.isSelected()));
652 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
653 Boolean.toString(fullScreen.isSelected()));
654 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
655 Boolean.toString(openoverv.isSelected()));
656 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
657 Boolean.toString(annotations.isSelected()));
658 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
659 Boolean.toString(conservation.isSelected()));
660 Cache.applicationProperties.setProperty("SHOW_QUALITY",
661 Boolean.toString(quality.isSelected()));
662 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
663 Boolean.toString(identity.isSelected()));
665 Cache.applicationProperties.setProperty("GAP_SYMBOL",
666 gapSymbolCB.getSelectedItem().toString());
668 Cache.applicationProperties.setProperty("FONT_NAME",
669 fontNameCB.getSelectedItem().toString());
670 Cache.applicationProperties.setProperty("FONT_STYLE",
671 fontStyleCB.getSelectedItem().toString());
672 Cache.applicationProperties.setProperty("FONT_SIZE",
673 fontSizeCB.getSelectedItem().toString());
675 Cache.applicationProperties.setProperty("ID_ITALICS",
676 Boolean.toString(idItalics.isSelected()));
677 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
678 Boolean.toString(showUnconserved.isSelected()));
679 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
680 Boolean.toString(showOccupancy.isSelected()));
681 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
682 Boolean.toString(showGroupConsensus.isSelected()));
683 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
684 Boolean.toString(showGroupConservation.isSelected()));
685 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
686 Boolean.toString(showConsensHistogram.isSelected()));
687 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
688 Boolean.toString(showConsensLogo.isSelected()));
689 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
690 Boolean.toString(showConsensHistogram.isSelected()));
691 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
692 Boolean.toString(showHMMLogo.isSelected()));
693 Cache.applicationProperties.setProperty("ANTI_ALIAS",
694 Boolean.toString(smoothFont.isSelected()));
695 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
696 Boolean.toString(scaleProteinToCdna.isSelected()));
697 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
698 Boolean.toString(showNpTooltip.isSelected()));
699 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
700 Boolean.toString(showDbRefTooltip.isSelected()));
702 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
703 Boolean.toString(wrap.isSelected()));
705 Cache.applicationProperties.setProperty("STARTUP_FILE",
706 startupFileTextfield.getText());
707 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
708 Boolean.toString(startupCheckbox.isSelected()));
710 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
711 sortby.getSelectedItem().toString());
713 // convert description of sort order to enum name for save
714 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
715 .forDescription(sortAnnBy.getSelectedItem().toString());
716 if (annSortOrder != null)
718 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
719 annSortOrder.name());
722 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
723 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
724 Boolean.valueOf(showAutocalcFirst).toString());
727 * Save Colours settings
729 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
730 protColour.getSelectedItem().toString());
731 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
732 nucColour.getSelectedItem().toString());
733 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
734 minColour.getBackground());
735 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
736 maxColour.getBackground());
739 * Save HMMER settings
741 Cache.applicationProperties.setProperty(HMMALIGN_TRIM_TERMINI,
742 Boolean.toString(hmmrTrimTermini.isSelected()));
743 Cache.applicationProperties.setProperty(HMMINFO_GLOBAL_BACKGROUND,
744 Boolean.toString(hmmerBackgroundUniprot.isSelected()));
745 Cache.applicationProperties.setProperty(HMMSEARCH_SEQCOUNT,
746 hmmerSequenceCount.getText());
747 Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
748 if (cygwinPath != null)
750 Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
752 AlignFrame[] frames = Desktop.getAlignFrames();
753 if (frames != null && frames.length > 0)
755 for (AlignFrame f : frames)
757 f.updateHMMERStatus();
761 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
762 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
764 hmmerBackgroundUniprot.setSelected(true);
768 hmmerBackgroundAlignment.setSelected(true);
771 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
772 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
775 * Save Overview settings
777 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
778 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
779 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
780 Boolean.toString(useLegacyGap.isSelected()));
781 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
782 Boolean.toString(showHiddenAtStart.isSelected()));
785 * Save Structure settings
787 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
788 Boolean.toString(addTempFactor.isSelected()));
789 Cache.applicationProperties.setProperty(ADD_SS_ANN,
790 Boolean.toString(addSecondaryStructure.isSelected()));
791 Cache.applicationProperties.setProperty(USE_RNAVIEW,
792 Boolean.toString(useRnaView.isSelected()));
793 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
794 Boolean.toString(structFromPdb.isSelected()));
795 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
796 structViewer.getSelectedItem().toString());
797 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
798 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
799 Boolean.toString(siftsMapping.isSelected()));
800 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
803 * Save Output settings
805 Cache.applicationProperties.setProperty("EPS_RENDERING",
806 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
809 * Save Connections settings
811 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
813 jalview.util.BrowserLauncher.resetBrowser();
815 // save user-defined and selected links
816 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
817 if (menuLinks.isEmpty())
819 Cache.applicationProperties.remove("SEQUENCE_LINKS");
823 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
824 menuLinks.toString());
827 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
828 if (nonMenuLinks.isEmpty())
830 Cache.applicationProperties.remove("STORED_LINKS");
834 Cache.applicationProperties.setProperty("STORED_LINKS",
835 nonMenuLinks.toString());
838 Cache.applicationProperties.setProperty("DEFAULT_URL",
839 sequenceUrlLinks.getPrimaryUrlId());
841 Cache.applicationProperties.setProperty("USE_PROXY",
842 Boolean.toString(useProxy.isSelected()));
844 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
846 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
848 if (useProxy.isSelected())
850 System.setProperty("http.proxyHost", proxyServerTB.getText());
851 System.setProperty("http.proxyPort", proxyPortTB.getText());
855 System.setProperty("http.proxyHost", "");
856 System.setProperty("http.proxyPort", "");
858 Cache.setProperty("VERSION_CHECK",
859 Boolean.toString(versioncheck.isSelected()));
860 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
862 // default is false - we only set this if the user has actively agreed
863 Cache.setProperty("USAGESTATS",
864 Boolean.toString(usagestats.isSelected()));
866 if (!questionnaire.isSelected())
868 Cache.setProperty("NOQUESTIONNAIRES", "true");
872 // special - made easy to edit a property file to disable questionnaires
873 // by just adding the given line
874 Cache.removeProperty("NOQUESTIONNAIRES");
878 * Save Output settings
880 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
881 Boolean.toString(blcjv.isSelected()));
882 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
883 Boolean.toString(clustaljv.isSelected()));
884 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
885 Boolean.toString(fastajv.isSelected()));
886 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
887 Boolean.toString(msfjv.isSelected()));
888 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
889 Boolean.toString(pfamjv.isSelected()));
890 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
891 Boolean.toString(pileupjv.isSelected()));
892 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
893 Boolean.toString(pirjv.isSelected()));
894 Cache.applicationProperties.setProperty("PIR_MODELLER",
895 Boolean.toString(modellerOutput.isSelected()));
896 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
897 Boolean.toString(embbedBioJSON.isSelected()));
898 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
900 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
901 Boolean.toString(autoIdWidth.isSelected()));
902 userIdWidth_actionPerformed();
903 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
904 userIdWidth.getText());
907 * Save Editing settings
909 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
910 Boolean.toString(autoCalculateConsCheck.isSelected()));
911 Cache.applicationProperties.setProperty("SORT_BY_TREE",
912 Boolean.toString(sortByTree.isSelected()));
913 Cache.applicationProperties.setProperty("PAD_GAPS",
914 Boolean.toString(padGaps.isSelected()));
916 wsPrefs.updateAndRefreshWsMenuConfig(false);
917 Cache.saveProperties();
918 Desktop.instance.doConfigureStructurePrefs();
921 frame.setClosed(true);
922 } catch (Exception ex)
928 * Do any necessary validation before saving settings. Return focus to the
929 * first tab which fails validation.
933 private boolean validateSettings()
935 if (!validateStructure())
937 structureTab.requestFocusInWindow();
944 protected boolean validateStructure()
946 return validateChimeraPath();
954 public void startupFileTextfield_mouseClicked()
956 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
957 JalviewFileChooser chooser = JalviewFileChooser
958 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
959 chooser.setFileView(new JalviewFileView());
960 chooser.setDialogTitle(
961 MessageManager.getString("label.select_startup_file"));
963 int value = chooser.showOpenDialog(this);
965 if (value == JalviewFileChooser.APPROVE_OPTION)
967 FileFormatI format = chooser.getSelectedFormat();
970 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
974 .setText(chooser.getSelectedFile().getAbsolutePath());
985 public void cancel_actionPerformed(ActionEvent e)
989 wsPrefs.updateWsMenuConfig(true);
990 wsPrefs.refreshWs_actionPerformed(e);
991 frame.setClosed(true);
992 } catch (Exception ex)
1004 public void annotations_actionPerformed(ActionEvent e)
1006 conservation.setEnabled(annotations.isSelected());
1007 quality.setEnabled(annotations.isSelected());
1008 identity.setEnabled(annotations.isSelected());
1009 showOccupancy.setEnabled(annotations.isSelected());
1010 showGroupConsensus.setEnabled(annotations.isSelected());
1011 showGroupConservation.setEnabled(annotations.isSelected());
1012 showConsensHistogram.setEnabled(annotations.isSelected()
1013 && (identity.isSelected() || showGroupConsensus.isSelected()));
1014 showConsensLogo.setEnabled(annotations.isSelected()
1015 && (identity.isSelected() || showGroupConsensus.isSelected()));
1016 showInformationHistogram.setEnabled(annotations.isSelected());
1017 showHMMLogo.setEnabled(annotations.isSelected());
1021 public void newLink_actionPerformed(ActionEvent e)
1023 GSequenceLink link = new GSequenceLink();
1024 boolean valid = false;
1027 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1028 MessageManager.getString("label.new_sequence_url_link"),
1029 JvOptionPane.OK_CANCEL_OPTION, -1,
1030 null) == JvOptionPane.OK_OPTION)
1032 if (link.checkValid())
1034 if (((UrlLinkTableModel) linkUrlTable.getModel())
1035 .isUniqueName(link.getName()))
1037 ((UrlLinkTableModel) linkUrlTable.getModel())
1038 .insertRow(link.getName(), link.getURL());
1043 link.notifyDuplicate();
1056 public void editLink_actionPerformed(ActionEvent e)
1058 GSequenceLink link = new GSequenceLink();
1060 int index = linkUrlTable.getSelectedRow();
1063 // button no longer enabled if row is not selected
1064 Cache.log.debug("Edit with no row selected in linkUrlTable");
1068 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1070 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1072 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1073 link.setName(oldName);
1074 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1076 boolean valid = false;
1079 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1080 MessageManager.getString("label.edit_sequence_url_link"),
1081 JvOptionPane.OK_CANCEL_OPTION, -1,
1082 null) == JvOptionPane.OK_OPTION)
1084 if (link.checkValid())
1086 if ((oldName.equals(link.getName()))
1087 || (((UrlLinkTableModel) linkUrlTable.getModel())
1088 .isUniqueName(link.getName())))
1090 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1091 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1096 link.notifyDuplicate();
1109 public void deleteLink_actionPerformed(ActionEvent e)
1111 int index = linkUrlTable.getSelectedRow();
1112 int modelIndex = -1;
1115 // button no longer enabled if row is not selected
1116 Cache.log.debug("Delete with no row selected in linkUrlTable");
1121 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1124 // make sure we use the model index to delete, and not the table index
1125 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1129 public void defaultBrowser_mouseClicked(MouseEvent e)
1131 JFileChooser chooser = new JFileChooser(".");
1132 chooser.setDialogTitle(
1133 MessageManager.getString("label.select_default_browser"));
1135 int value = chooser.showOpenDialog(this);
1137 if (value == JFileChooser.APPROVE_OPTION)
1139 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1148 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1152 protected void showunconserved_actionPerformed(ActionEvent e)
1154 // TODO Auto-generated method stub
1155 super.showunconserved_actionPerformed(e);
1158 public static List<String> getGroupURLLinks()
1160 return groupURLLinks;
1164 public void minColour_actionPerformed(JPanel panel)
1166 Color col = JColorChooser.showDialog(this,
1167 MessageManager.getString("label.select_colour_minimum_value"),
1168 minColour.getBackground());
1171 panel.setBackground(col);
1177 public void maxColour_actionPerformed(JPanel panel)
1179 Color col = JColorChooser.showDialog(this,
1180 MessageManager.getString("label.select_colour_maximum_value"),
1181 maxColour.getBackground());
1184 panel.setBackground(col);
1190 public void gapColour_actionPerformed(JPanel gap)
1192 if (!useLegacyGap.isSelected())
1194 Color col = JColorChooser.showDialog(this,
1195 MessageManager.getString("label.select_gap_colour"),
1196 gapColour.getBackground());
1199 gap.setBackground(col);
1206 public void hiddenColour_actionPerformed(JPanel hidden)
1208 Color col = JColorChooser.showDialog(this,
1209 MessageManager.getString("label.select_hidden_colour"),
1210 hiddenColour.getBackground());
1213 hidden.setBackground(col);
1219 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1221 boolean enabled = useLegacyGap.isSelected();
1224 gapColour.setBackground(
1225 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1229 gapColour.setBackground(
1230 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1232 gapColour.setEnabled(!enabled);
1233 gapLabel.setEnabled(!enabled);
1237 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1239 useLegacyGap.setSelected(false);
1240 useLegacyGaps_actionPerformed(null);
1241 showHiddenAtStart.setSelected(true);
1242 hiddenColour.setBackground(
1243 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1247 protected void userIdWidth_actionPerformed()
1251 String val = userIdWidth.getText().trim();
1252 if (val.length() > 0)
1254 Integer iw = Integer.parseInt(val);
1255 if (iw.intValue() < 12)
1257 throw new NumberFormatException();
1259 userIdWidth.setText(iw.toString());
1261 } catch (NumberFormatException x)
1263 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1265 .getString("warn.user_defined_width_requirements"),
1266 MessageManager.getString("label.invalid_id_column_width"),
1267 JvOptionPane.WARNING_MESSAGE);
1268 userIdWidth.setText("");
1273 protected void autoIdWidth_actionPerformed()
1275 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1276 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1280 * Returns true if chimera path is to a valid executable, else show an error
1283 private boolean validateChimeraPath()
1285 if (chimeraPath.getText().trim().length() > 0)
1287 File f = new File(chimeraPath.getText());
1288 if (!f.canExecute())
1290 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1291 MessageManager.getString("label.invalid_chimera_path"),
1292 MessageManager.getString("label.invalid_name"),
1293 JvOptionPane.ERROR_MESSAGE);
1301 * Returns true if the given text field contains a path to a folder that
1302 * contains an executable with the given name, else false (after showing a
1303 * warning dialog). The executable name will be tried with .exe appended if not
1309 protected boolean validateExecutablePath(JTextField textField, String executable)
1311 String folder = textField.getText().trim();
1313 if (FileUtils.getExecutable(executable, folder) != null)
1317 if (folder.length() > 0)
1319 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1320 MessageManager.formatMessage("label.executable_not_found",
1322 MessageManager.getString("label.invalid_folder"),
1323 JvOptionPane.ERROR_MESSAGE);
1329 * Checks if a file can be executed
1332 * the path to the file
1335 public boolean canExecute(String path)
1337 File file = new File(path);
1338 if (!file.canExecute())
1340 file = new File(path + ".exe");
1342 if (!file.canExecute())
1352 * If Chimera is selected, check it can be found on default or user-specified
1353 * path, if not show a warning/help dialog.
1356 protected void structureViewer_actionPerformed(String selectedItem)
1358 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1362 boolean found = false;
1365 * Try user-specified and standard paths for Chimera executable.
1367 List<String> paths = StructureManager.getChimeraPaths();
1368 paths.add(0, chimeraPath.getText());
1369 for (String path : paths)
1371 if (new File(path.trim()).canExecute())
1379 String[] options = { "OK", "Help" };
1380 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1381 JvSwingUtils.wrapTooltip(true,
1382 MessageManager.getString("label.chimera_missing")),
1383 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1384 null, options, options[0]);
1385 if (showHelp == JvOptionPane.NO_OPTION)
1389 Help.showHelpWindow(HelpId.StructureViewer);
1390 } catch (HelpSetException e)
1392 e.printStackTrace();
1399 protected void validateHmmerPath()
1401 validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1405 protected void validateCygwinPath()
1407 validateExecutablePath(cygwinPath, "run");
1410 public class OptionsParam
1412 private String name;
1414 private String code;
1416 public OptionsParam(String name, String code)
1422 public String getName()
1427 public void setName(String name)
1432 public String getCode()
1437 public void setCode(String code)
1443 public String toString()
1449 public boolean equals(Object that)
1451 if (!(that instanceof OptionsParam))
1455 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1459 public int hashCode()
1461 return name.hashCode() + code.hashCode();
1465 private class UrlListSelectionHandler implements ListSelectionListener
1469 public void valueChanged(ListSelectionEvent e)
1471 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1473 int index = lsm.getMinSelectionIndex();
1476 // no selection, so disable delete/edit buttons
1477 editLink.setEnabled(false);
1478 deleteLink.setEnabled(false);
1481 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1483 // enable/disable edit and delete link buttons
1484 if (((UrlLinkTableModel) linkUrlTable.getModel())
1485 .isRowDeletable(modelIndex))
1487 deleteLink.setEnabled(true);
1491 deleteLink.setEnabled(false);
1494 if (((UrlLinkTableModel) linkUrlTable.getModel())
1495 .isRowEditable(modelIndex))
1497 editLink.setEnabled(true);
1501 editLink.setEnabled(false);