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 DasSourceBrowser dasSource;
193 private WsPreferences wsPrefs;
195 private OptionsParam promptEachTimeOpt = new OptionsParam(
196 MessageManager.getString("label.prompt_each_time"),
199 private OptionsParam lineArtOpt = new OptionsParam(
200 MessageManager.getString("label.lineart"), "Lineart");
202 private OptionsParam textOpt = new OptionsParam(
203 MessageManager.getString("action.text"), "Text");
206 * Creates a new Preferences object.
211 frame = new JInternalFrame();
212 frame.setContentPane(this);
213 dasSource = new DasSourceBrowser();
214 dasTab.add(dasSource, BorderLayout.CENTER);
215 wsPrefs = new WsPreferences();
216 wsTab.add(wsPrefs, BorderLayout.CENTER);
217 int width = 500, height = 450;
218 new jalview.util.Platform();
219 if (Platform.isAMac())
225 Desktop.addInternalFrame(frame,
226 MessageManager.getString("label.preferences"), width, height);
227 frame.setMinimumSize(new Dimension(width, height));
230 * Set HMMER tab defaults
232 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
233 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
235 hmmerBackgroundUniprot.setSelected(true);
239 hmmerBackgroundAlignment.setSelected(true);
242 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
243 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
244 hmmerPath.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
252 hmmerPath.addFocusListener(new FocusAdapter()
255 public void focusLost(FocusEvent e)
260 if (cygwinPath != null)
262 String path = Cache.getProperty(CYGWIN_PATH);
265 path = FileUtils.getPathTo("bash");
267 cygwinPath.setText(path);
268 cygwinPath.addActionListener(new ActionListener()
271 public void actionPerformed(ActionEvent e)
273 validateCygwinPath();
276 cygwinPath.addFocusListener(new FocusAdapter()
279 public void focusLost(FocusEvent e)
281 validateCygwinPath();
287 * Set Visual tab defaults
289 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
290 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
291 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
292 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
294 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
295 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
296 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
297 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
299 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
300 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
302 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
303 showGroupConservation.setSelected(
304 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
305 showConsensHistogram.setSelected(
306 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
308 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
309 showInformationHistogram.setSelected(
310 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
311 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
313 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
315 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
317 String[] fonts = java.awt.GraphicsEnvironment
318 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
319 for (int i = 0; i < fonts.length; i++)
321 fontNameCB.addItem(fonts[i]);
324 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
326 fontSizeCB.addItem(i + "");
329 fontStyleCB.addItem("plain");
330 fontStyleCB.addItem("bold");
331 fontStyleCB.addItem("italic");
333 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
334 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
335 fontStyleCB.setSelectedItem(
336 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
338 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
340 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
342 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
344 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
346 gapSymbolCB.addItem("-");
347 gapSymbolCB.addItem(".");
349 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
351 sortby.addItem("No sort");
352 sortby.addItem("Id");
353 sortby.addItem("Pairwise Identity");
354 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
356 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
358 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
360 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
361 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
362 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
363 SequenceAnnotationOrder.NONE.name()));
364 sortAnnBy.setSelectedItem(savedSort.toString());
366 sortAutocalc.addItem("Autocalculated first");
367 sortAutocalc.addItem("Autocalculated last");
368 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
369 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
370 : sortAutocalc.getItemAt(1));
372 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
373 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
374 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
375 + "/examples/exampleFile_2_3.jar"));
378 * Set Colours tab defaults
380 protColour.addItem(ResidueColourScheme.NONE);
381 nucColour.addItem(ResidueColourScheme.NONE);
382 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
384 String name = cs.getSchemeName();
385 protColour.addItem(name);
386 nucColour.addItem(name);
388 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
389 ResidueColourScheme.NONE);
390 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
391 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
392 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
393 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
394 minColour.setBackground(
395 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
396 maxColour.setBackground(
397 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
400 * Set overview panel defaults
402 gapColour.setBackground(
403 Cache.getDefaultColour(GAP_COLOUR,
404 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
405 hiddenColour.setBackground(
406 Cache.getDefaultColour(HIDDEN_COLOUR,
407 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
408 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
409 gapLabel.setEnabled(!useLegacyGap.isSelected());
410 gapColour.setEnabled(!useLegacyGap.isSelected());
412 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
415 * Set Structure tab defaults.
417 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
418 structFromPdb.setSelected(structSelected);
419 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
420 useRnaView.setEnabled(structSelected);
421 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
422 addSecondaryStructure.setEnabled(structSelected);
423 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
424 addTempFactor.setEnabled(structSelected);
425 structViewer.setSelectedItem(
426 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
427 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
428 chimeraPath.addActionListener(new ActionListener()
431 public void actionPerformed(ActionEvent e)
433 validateChimeraPath();
437 if (Cache.getDefault("MAP_WITH_SIFTS", false))
439 siftsMapping.setSelected(true);
443 nwMapping.setSelected(true);
447 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
450 * Set Connections tab defaults
454 linkUrlTable.setModel(dataModel);
455 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
456 linkUrlTable.getModel());
457 linkUrlTable.setRowSorter(sorter);
458 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
460 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
461 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
462 SortOrder.DESCENDING));
463 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
464 SortOrder.DESCENDING));
466 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
468 sorter.setSortKeys(sortKeys);
472 ActionListener onReset;
473 onReset = new ActionListener()
476 public void actionPerformed(ActionEvent e)
478 filterTB.setText("");
479 sorter.setRowFilter(RowFilter.regexFilter(""));
483 doReset.addActionListener(onReset);
485 // filter to display only custom urls
486 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
489 public boolean include(
490 Entry<? extends TableModel, ? extends Object> entry)
492 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
496 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
497 linkUrlTable.getModel());
498 customSorter.setRowFilter(customUrlFilter);
500 ActionListener onCustomOnly;
501 onCustomOnly = new ActionListener()
504 public void actionPerformed(ActionEvent e)
506 filterTB.setText("");
507 sorter.setRowFilter(customUrlFilter);
510 userOnly.addActionListener(onCustomOnly);
512 filterTB.getDocument().addDocumentListener(new DocumentListener()
514 String caseInsensitiveFlag = "(?i)";
517 public void changedUpdate(DocumentEvent e)
519 sorter.setRowFilter(RowFilter
520 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
524 public void removeUpdate(DocumentEvent e)
526 sorter.setRowFilter(RowFilter
527 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
531 public void insertUpdate(DocumentEvent e)
533 sorter.setRowFilter(RowFilter
534 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
538 // set up list selection functionality
539 linkUrlTable.getSelectionModel()
540 .addListSelectionListener(new UrlListSelectionHandler());
542 // set up radio buttons
543 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
545 String onClickName = linkUrlTable.getColumnName(onClickCol);
546 linkUrlTable.getColumn(onClickName)
547 .setCellRenderer(new RadioButtonRenderer());
548 linkUrlTable.getColumn(onClickName)
549 .setCellEditor(new RadioButtonEditor());
551 // get boolean columns and resize those to min possible
552 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
554 if (linkUrlTable.getModel().getColumnClass(column)
555 .equals(Boolean.class))
557 TableColumn tableColumn = linkUrlTable.getColumnModel()
559 int preferredWidth = tableColumn.getMinWidth();
561 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
563 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
564 int cwidth = c.getPreferredSize().width
565 + linkUrlTable.getIntercellSpacing().width;
566 preferredWidth = Math.max(preferredWidth, cwidth);
568 tableColumn.setPreferredWidth(preferredWidth);
572 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
573 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
574 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
575 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
577 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
579 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
580 // note antisense here: default is true
582 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
583 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
586 * Set Output tab defaults
588 epsRendering.addItem(promptEachTimeOpt);
589 epsRendering.addItem(lineArtOpt);
590 epsRendering.addItem(textOpt);
591 String defaultEPS = Cache.getDefault("EPS_RENDERING",
593 if (defaultEPS.equalsIgnoreCase("Text"))
595 epsRendering.setSelectedItem(textOpt);
597 else if (defaultEPS.equalsIgnoreCase("Lineart"))
599 epsRendering.setSelectedItem(lineArtOpt);
603 epsRendering.setSelectedItem(promptEachTimeOpt);
605 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
606 userIdWidth.setEnabled(!autoIdWidth.isSelected());
607 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
608 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
609 userIdWidth.setText(wi == null ? "" : wi.toString());
610 // TODO: refactor to use common enum via FormatAdapter and allow extension
611 // for new flat file formats
612 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
613 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
614 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
615 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
616 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
617 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
618 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
619 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
621 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
624 * Set Editing tab defaults
626 autoCalculateConsCheck
627 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
628 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
629 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
631 annotations_actionPerformed(null); // update the display of the annotation
636 * Save user selections on the Preferences tabs to the Cache and write out to
642 public void ok_actionPerformed(ActionEvent e)
644 if (!validateSettings())
650 * Save Visual settings
652 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
653 Boolean.toString(seqLimit.isSelected()));
654 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
655 Boolean.toString(rightAlign.isSelected()));
656 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
657 Boolean.toString(fullScreen.isSelected()));
658 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
659 Boolean.toString(openoverv.isSelected()));
660 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
661 Boolean.toString(annotations.isSelected()));
662 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
663 Boolean.toString(conservation.isSelected()));
664 Cache.applicationProperties.setProperty("SHOW_QUALITY",
665 Boolean.toString(quality.isSelected()));
666 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
667 Boolean.toString(identity.isSelected()));
669 Cache.applicationProperties.setProperty("GAP_SYMBOL",
670 gapSymbolCB.getSelectedItem().toString());
672 Cache.applicationProperties.setProperty("FONT_NAME",
673 fontNameCB.getSelectedItem().toString());
674 Cache.applicationProperties.setProperty("FONT_STYLE",
675 fontStyleCB.getSelectedItem().toString());
676 Cache.applicationProperties.setProperty("FONT_SIZE",
677 fontSizeCB.getSelectedItem().toString());
679 Cache.applicationProperties.setProperty("ID_ITALICS",
680 Boolean.toString(idItalics.isSelected()));
681 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
682 Boolean.toString(showUnconserved.isSelected()));
683 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
684 Boolean.toString(showOccupancy.isSelected()));
685 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
686 Boolean.toString(showGroupConsensus.isSelected()));
687 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
688 Boolean.toString(showGroupConservation.isSelected()));
689 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
690 Boolean.toString(showConsensHistogram.isSelected()));
691 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
692 Boolean.toString(showConsensLogo.isSelected()));
693 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
694 Boolean.toString(showConsensHistogram.isSelected()));
695 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
696 Boolean.toString(showHMMLogo.isSelected()));
697 Cache.applicationProperties.setProperty("ANTI_ALIAS",
698 Boolean.toString(smoothFont.isSelected()));
699 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
700 Boolean.toString(scaleProteinToCdna.isSelected()));
701 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
702 Boolean.toString(showNpTooltip.isSelected()));
703 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
704 Boolean.toString(showDbRefTooltip.isSelected()));
706 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
707 Boolean.toString(wrap.isSelected()));
709 Cache.applicationProperties.setProperty("STARTUP_FILE",
710 startupFileTextfield.getText());
711 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
712 Boolean.toString(startupCheckbox.isSelected()));
714 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
715 sortby.getSelectedItem().toString());
717 // convert description of sort order to enum name for save
718 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
719 .forDescription(sortAnnBy.getSelectedItem().toString());
720 if (annSortOrder != null)
722 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
723 annSortOrder.name());
726 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
727 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
728 Boolean.valueOf(showAutocalcFirst).toString());
731 * Save Colours settings
733 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
734 protColour.getSelectedItem().toString());
735 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
736 nucColour.getSelectedItem().toString());
737 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
738 minColour.getBackground());
739 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
740 maxColour.getBackground());
743 * Save HMMER settings
745 Cache.applicationProperties.setProperty(HMMALIGN_TRIM_TERMINI,
746 Boolean.toString(hmmrTrimTermini.isSelected()));
747 Cache.applicationProperties.setProperty(HMMINFO_GLOBAL_BACKGROUND,
748 Boolean.toString(hmmerBackgroundUniprot.isSelected()));
749 Cache.applicationProperties.setProperty(HMMSEARCH_SEQCOUNT,
750 hmmerSequenceCount.getText());
751 Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
752 if (cygwinPath != null)
754 Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
756 AlignFrame[] frames = Desktop.getAlignFrames();
757 if (frames != null && frames.length > 0)
759 for (AlignFrame f : frames)
761 f.updateHMMERStatus();
765 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
766 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
768 hmmerBackgroundUniprot.setSelected(true);
772 hmmerBackgroundAlignment.setSelected(true);
775 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
776 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
779 * Save Overview settings
781 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
782 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
783 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
784 Boolean.toString(useLegacyGap.isSelected()));
785 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
786 Boolean.toString(showHiddenAtStart.isSelected()));
789 * Save Structure settings
791 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
792 Boolean.toString(addTempFactor.isSelected()));
793 Cache.applicationProperties.setProperty(ADD_SS_ANN,
794 Boolean.toString(addSecondaryStructure.isSelected()));
795 Cache.applicationProperties.setProperty(USE_RNAVIEW,
796 Boolean.toString(useRnaView.isSelected()));
797 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
798 Boolean.toString(structFromPdb.isSelected()));
799 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
800 structViewer.getSelectedItem().toString());
801 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
802 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
803 Boolean.toString(siftsMapping.isSelected()));
804 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
807 * Save Output settings
809 Cache.applicationProperties.setProperty("EPS_RENDERING",
810 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
813 * Save Connections settings
815 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
817 jalview.util.BrowserLauncher.resetBrowser();
819 // save user-defined and selected links
820 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
821 if (menuLinks.isEmpty())
823 Cache.applicationProperties.remove("SEQUENCE_LINKS");
827 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
828 menuLinks.toString());
831 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
832 if (nonMenuLinks.isEmpty())
834 Cache.applicationProperties.remove("STORED_LINKS");
838 Cache.applicationProperties.setProperty("STORED_LINKS",
839 nonMenuLinks.toString());
842 Cache.applicationProperties.setProperty("DEFAULT_URL",
843 sequenceUrlLinks.getPrimaryUrlId());
845 Cache.applicationProperties.setProperty("USE_PROXY",
846 Boolean.toString(useProxy.isSelected()));
848 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
850 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
852 if (useProxy.isSelected())
854 System.setProperty("http.proxyHost", proxyServerTB.getText());
855 System.setProperty("http.proxyPort", proxyPortTB.getText());
859 System.setProperty("http.proxyHost", "");
860 System.setProperty("http.proxyPort", "");
862 Cache.setProperty("VERSION_CHECK",
863 Boolean.toString(versioncheck.isSelected()));
864 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
866 // default is false - we only set this if the user has actively agreed
867 Cache.setProperty("USAGESTATS",
868 Boolean.toString(usagestats.isSelected()));
870 if (!questionnaire.isSelected())
872 Cache.setProperty("NOQUESTIONNAIRES", "true");
876 // special - made easy to edit a property file to disable questionnaires
877 // by just adding the given line
878 Cache.removeProperty("NOQUESTIONNAIRES");
882 * Save Output settings
884 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
885 Boolean.toString(blcjv.isSelected()));
886 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
887 Boolean.toString(clustaljv.isSelected()));
888 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
889 Boolean.toString(fastajv.isSelected()));
890 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
891 Boolean.toString(msfjv.isSelected()));
892 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
893 Boolean.toString(pfamjv.isSelected()));
894 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
895 Boolean.toString(pileupjv.isSelected()));
896 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
897 Boolean.toString(pirjv.isSelected()));
898 Cache.applicationProperties.setProperty("PIR_MODELLER",
899 Boolean.toString(modellerOutput.isSelected()));
900 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
901 Boolean.toString(embbedBioJSON.isSelected()));
902 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
904 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
905 Boolean.toString(autoIdWidth.isSelected()));
906 userIdWidth_actionPerformed();
907 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
908 userIdWidth.getText());
911 * Save Editing settings
913 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
914 Boolean.toString(autoCalculateConsCheck.isSelected()));
915 Cache.applicationProperties.setProperty("SORT_BY_TREE",
916 Boolean.toString(sortByTree.isSelected()));
917 Cache.applicationProperties.setProperty("PAD_GAPS",
918 Boolean.toString(padGaps.isSelected()));
920 dasSource.saveProperties(Cache.applicationProperties);
921 wsPrefs.updateAndRefreshWsMenuConfig(false);
922 Cache.saveProperties();
923 Desktop.instance.doConfigureStructurePrefs();
926 frame.setClosed(true);
927 } catch (Exception ex)
933 * Do any necessary validation before saving settings. Return focus to the
934 * first tab which fails validation.
938 private boolean validateSettings()
940 if (!validateStructure())
942 structureTab.requestFocusInWindow();
949 protected boolean validateStructure()
951 return validateChimeraPath();
959 public void startupFileTextfield_mouseClicked()
961 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
962 JalviewFileChooser chooser = JalviewFileChooser
963 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
964 chooser.setFileView(new JalviewFileView());
965 chooser.setDialogTitle(
966 MessageManager.getString("label.select_startup_file"));
968 int value = chooser.showOpenDialog(this);
970 if (value == JalviewFileChooser.APPROVE_OPTION)
972 FileFormatI format = chooser.getSelectedFormat();
975 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
979 .setText(chooser.getSelectedFile().getAbsolutePath());
990 public void cancel_actionPerformed(ActionEvent e)
994 wsPrefs.updateWsMenuConfig(true);
995 wsPrefs.refreshWs_actionPerformed(e);
996 frame.setClosed(true);
997 } catch (Exception ex)
1009 public void annotations_actionPerformed(ActionEvent e)
1011 conservation.setEnabled(annotations.isSelected());
1012 quality.setEnabled(annotations.isSelected());
1013 identity.setEnabled(annotations.isSelected());
1014 showOccupancy.setEnabled(annotations.isSelected());
1015 showGroupConsensus.setEnabled(annotations.isSelected());
1016 showGroupConservation.setEnabled(annotations.isSelected());
1017 showConsensHistogram.setEnabled(annotations.isSelected()
1018 && (identity.isSelected() || showGroupConsensus.isSelected()));
1019 showConsensLogo.setEnabled(annotations.isSelected()
1020 && (identity.isSelected() || showGroupConsensus.isSelected()));
1021 showInformationHistogram.setEnabled(annotations.isSelected());
1022 showHMMLogo.setEnabled(annotations.isSelected());
1026 public void newLink_actionPerformed(ActionEvent e)
1028 GSequenceLink link = new GSequenceLink();
1029 boolean valid = false;
1032 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1033 MessageManager.getString("label.new_sequence_url_link"),
1034 JvOptionPane.OK_CANCEL_OPTION, -1,
1035 null) == JvOptionPane.OK_OPTION)
1037 if (link.checkValid())
1039 if (((UrlLinkTableModel) linkUrlTable.getModel())
1040 .isUniqueName(link.getName()))
1042 ((UrlLinkTableModel) linkUrlTable.getModel())
1043 .insertRow(link.getName(), link.getURL());
1048 link.notifyDuplicate();
1061 public void editLink_actionPerformed(ActionEvent e)
1063 GSequenceLink link = new GSequenceLink();
1065 int index = linkUrlTable.getSelectedRow();
1068 // button no longer enabled if row is not selected
1069 Cache.log.debug("Edit with no row selected in linkUrlTable");
1073 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1075 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1077 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1078 link.setName(oldName);
1079 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1081 boolean valid = false;
1084 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1085 MessageManager.getString("label.edit_sequence_url_link"),
1086 JvOptionPane.OK_CANCEL_OPTION, -1,
1087 null) == JvOptionPane.OK_OPTION)
1089 if (link.checkValid())
1091 if ((oldName.equals(link.getName()))
1092 || (((UrlLinkTableModel) linkUrlTable.getModel())
1093 .isUniqueName(link.getName())))
1095 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1096 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1101 link.notifyDuplicate();
1114 public void deleteLink_actionPerformed(ActionEvent e)
1116 int index = linkUrlTable.getSelectedRow();
1117 int modelIndex = -1;
1120 // button no longer enabled if row is not selected
1121 Cache.log.debug("Delete with no row selected in linkUrlTable");
1126 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1129 // make sure we use the model index to delete, and not the table index
1130 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1134 public void defaultBrowser_mouseClicked(MouseEvent e)
1136 JFileChooser chooser = new JFileChooser(".");
1137 chooser.setDialogTitle(
1138 MessageManager.getString("label.select_default_browser"));
1140 int value = chooser.showOpenDialog(this);
1142 if (value == JFileChooser.APPROVE_OPTION)
1144 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1153 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1157 protected void showunconserved_actionPerformed(ActionEvent e)
1159 // TODO Auto-generated method stub
1160 super.showunconserved_actionPerformed(e);
1163 public static List<String> getGroupURLLinks()
1165 return groupURLLinks;
1169 public void minColour_actionPerformed(JPanel panel)
1171 Color col = JColorChooser.showDialog(this,
1172 MessageManager.getString("label.select_colour_minimum_value"),
1173 minColour.getBackground());
1176 panel.setBackground(col);
1182 public void maxColour_actionPerformed(JPanel panel)
1184 Color col = JColorChooser.showDialog(this,
1185 MessageManager.getString("label.select_colour_maximum_value"),
1186 maxColour.getBackground());
1189 panel.setBackground(col);
1195 public void gapColour_actionPerformed(JPanel gap)
1197 if (!useLegacyGap.isSelected())
1199 Color col = JColorChooser.showDialog(this,
1200 MessageManager.getString("label.select_gap_colour"),
1201 gapColour.getBackground());
1204 gap.setBackground(col);
1211 public void hiddenColour_actionPerformed(JPanel hidden)
1213 Color col = JColorChooser.showDialog(this,
1214 MessageManager.getString("label.select_hidden_colour"),
1215 hiddenColour.getBackground());
1218 hidden.setBackground(col);
1224 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1226 boolean enabled = useLegacyGap.isSelected();
1229 gapColour.setBackground(
1230 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1234 gapColour.setBackground(
1235 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1237 gapColour.setEnabled(!enabled);
1238 gapLabel.setEnabled(!enabled);
1242 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1244 useLegacyGap.setSelected(false);
1245 useLegacyGaps_actionPerformed(null);
1246 showHiddenAtStart.setSelected(true);
1247 hiddenColour.setBackground(
1248 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1252 protected void userIdWidth_actionPerformed()
1256 String val = userIdWidth.getText().trim();
1257 if (val.length() > 0)
1259 Integer iw = Integer.parseInt(val);
1260 if (iw.intValue() < 12)
1262 throw new NumberFormatException();
1264 userIdWidth.setText(iw.toString());
1266 } catch (NumberFormatException x)
1268 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1270 .getString("warn.user_defined_width_requirements"),
1271 MessageManager.getString("label.invalid_id_column_width"),
1272 JvOptionPane.WARNING_MESSAGE);
1273 userIdWidth.setText("");
1278 protected void autoIdWidth_actionPerformed()
1280 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1281 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1285 * Returns true if chimera path is to a valid executable, else show an error
1288 private boolean validateChimeraPath()
1290 if (chimeraPath.getText().trim().length() > 0)
1292 File f = new File(chimeraPath.getText());
1293 if (!f.canExecute())
1295 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1296 MessageManager.getString("label.invalid_chimera_path"),
1297 MessageManager.getString("label.invalid_name"),
1298 JvOptionPane.ERROR_MESSAGE);
1306 * Returns true if the given text field contains a path to a folder that
1307 * contains an executable with the given name, else false (after showing a
1308 * warning dialog). The executable name will be tried with .exe appended if not
1314 protected boolean validateExecutablePath(JTextField textField, String executable)
1316 String folder = textField.getText().trim();
1318 if (FileUtils.getExecutable(executable, folder) != null)
1322 if (folder.length() > 0)
1324 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1325 MessageManager.formatMessage("label.executable_not_found",
1327 MessageManager.getString("label.invalid_folder"),
1328 JvOptionPane.ERROR_MESSAGE);
1334 * Checks if a file can be executed
1337 * the path to the file
1340 public boolean canExecute(String path)
1342 File file = new File(path);
1343 if (!file.canExecute())
1345 file = new File(path + ".exe");
1347 if (!file.canExecute())
1357 * If Chimera is selected, check it can be found on default or user-specified
1358 * path, if not show a warning/help dialog.
1361 protected void structureViewer_actionPerformed(String selectedItem)
1363 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1367 boolean found = false;
1370 * Try user-specified and standard paths for Chimera executable.
1372 List<String> paths = StructureManager.getChimeraPaths();
1373 paths.add(0, chimeraPath.getText());
1374 for (String path : paths)
1376 if (new File(path.trim()).canExecute())
1384 String[] options = { "OK", "Help" };
1385 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1386 JvSwingUtils.wrapTooltip(true,
1387 MessageManager.getString("label.chimera_missing")),
1388 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1389 null, options, options[0]);
1390 if (showHelp == JvOptionPane.NO_OPTION)
1394 Help.showHelpWindow(HelpId.StructureViewer);
1395 } catch (HelpSetException e)
1397 e.printStackTrace();
1404 protected void validateHmmerPath()
1406 validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1410 protected void validateCygwinPath()
1412 validateExecutablePath(cygwinPath, "run");
1415 public class OptionsParam
1417 private String name;
1419 private String code;
1421 public OptionsParam(String name, String code)
1427 public String getName()
1432 public void setName(String name)
1437 public String getCode()
1442 public void setCode(String code)
1448 public String toString()
1454 public boolean equals(Object that)
1456 if (!(that instanceof OptionsParam))
1460 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1464 public int hashCode()
1466 return name.hashCode() + code.hashCode();
1470 private class UrlListSelectionHandler implements ListSelectionListener
1474 public void valueChanged(ListSelectionEvent e)
1476 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1478 int index = lsm.getMinSelectionIndex();
1481 // no selection, so disable delete/edit buttons
1482 editLink.setEnabled(false);
1483 deleteLink.setEnabled(false);
1486 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1488 // enable/disable edit and delete link buttons
1489 if (((UrlLinkTableModel) linkUrlTable.getModel())
1490 .isRowDeletable(modelIndex))
1492 deleteLink.setEnabled(true);
1496 deleteLink.setEnabled(false);
1499 if (((UrlLinkTableModel) linkUrlTable.getModel())
1500 .isRowEditable(modelIndex))
1502 editLink.setEnabled(true);
1506 editLink.setEnabled(false);