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 cygwinPath.setText(Cache.getProperty(CYGWIN_PATH));
262 cygwinPath.addActionListener(new ActionListener()
265 public void actionPerformed(ActionEvent e)
267 validateCygwinPath();
270 cygwinPath.addFocusListener(new FocusAdapter()
273 public void focusLost(FocusEvent e)
275 validateCygwinPath();
281 * Set Visual tab defaults
283 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
284 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
285 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
286 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
288 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
289 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
290 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
291 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
293 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
294 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
296 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
297 showGroupConservation.setSelected(
298 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
299 showConsensHistogram.setSelected(
300 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
302 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
303 showInformationHistogram.setSelected(
304 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
305 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
307 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
309 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
311 String[] fonts = java.awt.GraphicsEnvironment
312 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
313 for (int i = 0; i < fonts.length; i++)
315 fontNameCB.addItem(fonts[i]);
318 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
320 fontSizeCB.addItem(i + "");
323 fontStyleCB.addItem("plain");
324 fontStyleCB.addItem("bold");
325 fontStyleCB.addItem("italic");
327 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
328 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
329 fontStyleCB.setSelectedItem(
330 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
332 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
334 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
336 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
338 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
340 gapSymbolCB.addItem("-");
341 gapSymbolCB.addItem(".");
343 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
345 sortby.addItem("No sort");
346 sortby.addItem("Id");
347 sortby.addItem("Pairwise Identity");
348 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
350 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
352 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
354 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
355 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
356 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
357 SequenceAnnotationOrder.NONE.name()));
358 sortAnnBy.setSelectedItem(savedSort.toString());
360 sortAutocalc.addItem("Autocalculated first");
361 sortAutocalc.addItem("Autocalculated last");
362 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
363 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
364 : sortAutocalc.getItemAt(1));
366 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
367 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
368 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
369 + "/examples/exampleFile_2_3.jar"));
372 * Set Colours tab defaults
374 protColour.addItem(ResidueColourScheme.NONE);
375 nucColour.addItem(ResidueColourScheme.NONE);
376 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
378 String name = cs.getSchemeName();
379 protColour.addItem(name);
380 nucColour.addItem(name);
382 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
383 ResidueColourScheme.NONE);
384 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
385 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
386 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
387 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
388 minColour.setBackground(
389 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
390 maxColour.setBackground(
391 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
394 * Set overview panel defaults
396 gapColour.setBackground(
397 Cache.getDefaultColour(GAP_COLOUR,
398 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
399 hiddenColour.setBackground(
400 Cache.getDefaultColour(HIDDEN_COLOUR,
401 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
402 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
403 gapLabel.setEnabled(!useLegacyGap.isSelected());
404 gapColour.setEnabled(!useLegacyGap.isSelected());
406 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
409 * Set Structure tab defaults.
411 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
412 structFromPdb.setSelected(structSelected);
413 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
414 useRnaView.setEnabled(structSelected);
415 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
416 addSecondaryStructure.setEnabled(structSelected);
417 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
418 addTempFactor.setEnabled(structSelected);
419 structViewer.setSelectedItem(
420 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
421 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
422 chimeraPath.addActionListener(new ActionListener()
425 public void actionPerformed(ActionEvent e)
427 validateChimeraPath();
431 if (Cache.getDefault("MAP_WITH_SIFTS", false))
433 siftsMapping.setSelected(true);
437 nwMapping.setSelected(true);
441 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
444 * Set Connections tab defaults
448 linkUrlTable.setModel(dataModel);
449 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
450 linkUrlTable.getModel());
451 linkUrlTable.setRowSorter(sorter);
452 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
454 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
455 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
456 SortOrder.DESCENDING));
457 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
458 SortOrder.DESCENDING));
460 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
462 sorter.setSortKeys(sortKeys);
466 ActionListener onReset;
467 onReset = new ActionListener()
470 public void actionPerformed(ActionEvent e)
472 filterTB.setText("");
473 sorter.setRowFilter(RowFilter.regexFilter(""));
477 doReset.addActionListener(onReset);
479 // filter to display only custom urls
480 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
483 public boolean include(
484 Entry<? extends TableModel, ? extends Object> entry)
486 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
490 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
491 linkUrlTable.getModel());
492 customSorter.setRowFilter(customUrlFilter);
494 ActionListener onCustomOnly;
495 onCustomOnly = new ActionListener()
498 public void actionPerformed(ActionEvent e)
500 filterTB.setText("");
501 sorter.setRowFilter(customUrlFilter);
504 userOnly.addActionListener(onCustomOnly);
506 filterTB.getDocument().addDocumentListener(new DocumentListener()
508 String caseInsensitiveFlag = "(?i)";
511 public void changedUpdate(DocumentEvent e)
513 sorter.setRowFilter(RowFilter
514 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
518 public void removeUpdate(DocumentEvent e)
520 sorter.setRowFilter(RowFilter
521 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
525 public void insertUpdate(DocumentEvent e)
527 sorter.setRowFilter(RowFilter
528 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
532 // set up list selection functionality
533 linkUrlTable.getSelectionModel()
534 .addListSelectionListener(new UrlListSelectionHandler());
536 // set up radio buttons
537 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
539 String onClickName = linkUrlTable.getColumnName(onClickCol);
540 linkUrlTable.getColumn(onClickName)
541 .setCellRenderer(new RadioButtonRenderer());
542 linkUrlTable.getColumn(onClickName)
543 .setCellEditor(new RadioButtonEditor());
545 // get boolean columns and resize those to min possible
546 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
548 if (linkUrlTable.getModel().getColumnClass(column)
549 .equals(Boolean.class))
551 TableColumn tableColumn = linkUrlTable.getColumnModel()
553 int preferredWidth = tableColumn.getMinWidth();
555 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
557 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
558 int cwidth = c.getPreferredSize().width
559 + linkUrlTable.getIntercellSpacing().width;
560 preferredWidth = Math.max(preferredWidth, cwidth);
562 tableColumn.setPreferredWidth(preferredWidth);
566 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
567 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
568 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
569 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
571 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
573 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
574 // note antisense here: default is true
576 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
577 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
580 * Set Output tab defaults
582 epsRendering.addItem(promptEachTimeOpt);
583 epsRendering.addItem(lineArtOpt);
584 epsRendering.addItem(textOpt);
585 String defaultEPS = Cache.getDefault("EPS_RENDERING",
587 if (defaultEPS.equalsIgnoreCase("Text"))
589 epsRendering.setSelectedItem(textOpt);
591 else if (defaultEPS.equalsIgnoreCase("Lineart"))
593 epsRendering.setSelectedItem(lineArtOpt);
597 epsRendering.setSelectedItem(promptEachTimeOpt);
599 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
600 userIdWidth.setEnabled(!autoIdWidth.isSelected());
601 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
602 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
603 userIdWidth.setText(wi == null ? "" : wi.toString());
604 // TODO: refactor to use common enum via FormatAdapter and allow extension
605 // for new flat file formats
606 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
607 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
608 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
609 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
610 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
611 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
612 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
613 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
615 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
618 * Set Editing tab defaults
620 autoCalculateConsCheck
621 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
622 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
623 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
625 annotations_actionPerformed(null); // update the display of the annotation
630 * Save user selections on the Preferences tabs to the Cache and write out to
636 public void ok_actionPerformed(ActionEvent e)
638 if (!validateSettings())
644 * Save Visual settings
646 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
647 Boolean.toString(seqLimit.isSelected()));
648 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
649 Boolean.toString(rightAlign.isSelected()));
650 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
651 Boolean.toString(fullScreen.isSelected()));
652 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
653 Boolean.toString(openoverv.isSelected()));
654 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
655 Boolean.toString(annotations.isSelected()));
656 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
657 Boolean.toString(conservation.isSelected()));
658 Cache.applicationProperties.setProperty("SHOW_QUALITY",
659 Boolean.toString(quality.isSelected()));
660 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
661 Boolean.toString(identity.isSelected()));
663 Cache.applicationProperties.setProperty("GAP_SYMBOL",
664 gapSymbolCB.getSelectedItem().toString());
666 Cache.applicationProperties.setProperty("FONT_NAME",
667 fontNameCB.getSelectedItem().toString());
668 Cache.applicationProperties.setProperty("FONT_STYLE",
669 fontStyleCB.getSelectedItem().toString());
670 Cache.applicationProperties.setProperty("FONT_SIZE",
671 fontSizeCB.getSelectedItem().toString());
673 Cache.applicationProperties.setProperty("ID_ITALICS",
674 Boolean.toString(idItalics.isSelected()));
675 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
676 Boolean.toString(showUnconserved.isSelected()));
677 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
678 Boolean.toString(showOccupancy.isSelected()));
679 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
680 Boolean.toString(showGroupConsensus.isSelected()));
681 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
682 Boolean.toString(showGroupConservation.isSelected()));
683 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
684 Boolean.toString(showConsensHistogram.isSelected()));
685 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
686 Boolean.toString(showConsensLogo.isSelected()));
687 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
688 Boolean.toString(showConsensHistogram.isSelected()));
689 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
690 Boolean.toString(showHMMLogo.isSelected()));
691 Cache.applicationProperties.setProperty("ANTI_ALIAS",
692 Boolean.toString(smoothFont.isSelected()));
693 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
694 Boolean.toString(scaleProteinToCdna.isSelected()));
695 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
696 Boolean.toString(showNpTooltip.isSelected()));
697 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
698 Boolean.toString(showDbRefTooltip.isSelected()));
700 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
701 Boolean.toString(wrap.isSelected()));
703 Cache.applicationProperties.setProperty("STARTUP_FILE",
704 startupFileTextfield.getText());
705 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
706 Boolean.toString(startupCheckbox.isSelected()));
708 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
709 sortby.getSelectedItem().toString());
711 // convert description of sort order to enum name for save
712 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
713 .forDescription(sortAnnBy.getSelectedItem().toString());
714 if (annSortOrder != null)
716 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
717 annSortOrder.name());
720 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
721 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
722 Boolean.valueOf(showAutocalcFirst).toString());
725 * Save Colours settings
727 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
728 protColour.getSelectedItem().toString());
729 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
730 nucColour.getSelectedItem().toString());
731 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
732 minColour.getBackground());
733 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
734 maxColour.getBackground());
737 * Save HMMER settings
739 Cache.applicationProperties.setProperty(HMMALIGN_TRIM_TERMINI,
740 Boolean.toString(hmmrTrimTermini.isSelected()));
741 Cache.applicationProperties.setProperty(HMMINFO_GLOBAL_BACKGROUND,
742 Boolean.toString(hmmerBackgroundUniprot.isSelected()));
743 Cache.applicationProperties.setProperty(HMMSEARCH_SEQCOUNT,
744 hmmerSequenceCount.getText());
745 Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
746 if (cygwinPath != null)
748 Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
750 AlignFrame[] frames = Desktop.getAlignFrames();
751 if (frames != null && frames.length > 0)
753 for (AlignFrame f : frames)
755 f.updateHMMERStatus();
759 hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false));
760 if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false))
762 hmmerBackgroundUniprot.setSelected(true);
766 hmmerBackgroundAlignment.setSelected(true);
769 .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT));
770 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
773 * Save Overview settings
775 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
776 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
777 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
778 Boolean.toString(useLegacyGap.isSelected()));
779 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
780 Boolean.toString(showHiddenAtStart.isSelected()));
783 * Save Structure settings
785 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
786 Boolean.toString(addTempFactor.isSelected()));
787 Cache.applicationProperties.setProperty(ADD_SS_ANN,
788 Boolean.toString(addSecondaryStructure.isSelected()));
789 Cache.applicationProperties.setProperty(USE_RNAVIEW,
790 Boolean.toString(useRnaView.isSelected()));
791 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
792 Boolean.toString(structFromPdb.isSelected()));
793 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
794 structViewer.getSelectedItem().toString());
795 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
796 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
797 Boolean.toString(siftsMapping.isSelected()));
798 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
801 * Save Output settings
803 Cache.applicationProperties.setProperty("EPS_RENDERING",
804 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
807 * Save Connections settings
809 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
811 jalview.util.BrowserLauncher.resetBrowser();
813 // save user-defined and selected links
814 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
815 if (menuLinks.isEmpty())
817 Cache.applicationProperties.remove("SEQUENCE_LINKS");
821 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
822 menuLinks.toString());
825 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
826 if (nonMenuLinks.isEmpty())
828 Cache.applicationProperties.remove("STORED_LINKS");
832 Cache.applicationProperties.setProperty("STORED_LINKS",
833 nonMenuLinks.toString());
836 Cache.applicationProperties.setProperty("DEFAULT_URL",
837 sequenceUrlLinks.getPrimaryUrlId());
839 Cache.applicationProperties.setProperty("USE_PROXY",
840 Boolean.toString(useProxy.isSelected()));
842 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
844 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
846 if (useProxy.isSelected())
848 System.setProperty("http.proxyHost", proxyServerTB.getText());
849 System.setProperty("http.proxyPort", proxyPortTB.getText());
853 System.setProperty("http.proxyHost", "");
854 System.setProperty("http.proxyPort", "");
856 Cache.setProperty("VERSION_CHECK",
857 Boolean.toString(versioncheck.isSelected()));
858 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
860 // default is false - we only set this if the user has actively agreed
861 Cache.setProperty("USAGESTATS",
862 Boolean.toString(usagestats.isSelected()));
864 if (!questionnaire.isSelected())
866 Cache.setProperty("NOQUESTIONNAIRES", "true");
870 // special - made easy to edit a property file to disable questionnaires
871 // by just adding the given line
872 Cache.removeProperty("NOQUESTIONNAIRES");
876 * Save Output settings
878 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
879 Boolean.toString(blcjv.isSelected()));
880 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
881 Boolean.toString(clustaljv.isSelected()));
882 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
883 Boolean.toString(fastajv.isSelected()));
884 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
885 Boolean.toString(msfjv.isSelected()));
886 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
887 Boolean.toString(pfamjv.isSelected()));
888 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
889 Boolean.toString(pileupjv.isSelected()));
890 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
891 Boolean.toString(pirjv.isSelected()));
892 Cache.applicationProperties.setProperty("PIR_MODELLER",
893 Boolean.toString(modellerOutput.isSelected()));
894 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
895 Boolean.toString(embbedBioJSON.isSelected()));
896 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
898 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
899 Boolean.toString(autoIdWidth.isSelected()));
900 userIdWidth_actionPerformed();
901 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
902 userIdWidth.getText());
905 * Save Editing settings
907 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
908 Boolean.toString(autoCalculateConsCheck.isSelected()));
909 Cache.applicationProperties.setProperty("SORT_BY_TREE",
910 Boolean.toString(sortByTree.isSelected()));
911 Cache.applicationProperties.setProperty("PAD_GAPS",
912 Boolean.toString(padGaps.isSelected()));
914 dasSource.saveProperties(Cache.applicationProperties);
915 wsPrefs.updateAndRefreshWsMenuConfig(false);
916 Cache.saveProperties();
917 Desktop.instance.doConfigureStructurePrefs();
920 frame.setClosed(true);
921 } catch (Exception ex)
927 * Do any necessary validation before saving settings. Return focus to the
928 * first tab which fails validation.
932 private boolean validateSettings()
934 if (!validateStructure())
936 structureTab.requestFocusInWindow();
943 protected boolean validateStructure()
945 return validateChimeraPath();
953 public void startupFileTextfield_mouseClicked()
955 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
956 JalviewFileChooser chooser = JalviewFileChooser
957 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
958 chooser.setFileView(new JalviewFileView());
959 chooser.setDialogTitle(
960 MessageManager.getString("label.select_startup_file"));
962 int value = chooser.showOpenDialog(this);
964 if (value == JalviewFileChooser.APPROVE_OPTION)
966 FileFormatI format = chooser.getSelectedFormat();
969 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
973 .setText(chooser.getSelectedFile().getAbsolutePath());
984 public void cancel_actionPerformed(ActionEvent e)
988 wsPrefs.updateWsMenuConfig(true);
989 wsPrefs.refreshWs_actionPerformed(e);
990 frame.setClosed(true);
991 } catch (Exception ex)
1003 public void annotations_actionPerformed(ActionEvent e)
1005 conservation.setEnabled(annotations.isSelected());
1006 quality.setEnabled(annotations.isSelected());
1007 identity.setEnabled(annotations.isSelected());
1008 showOccupancy.setEnabled(annotations.isSelected());
1009 showGroupConsensus.setEnabled(annotations.isSelected());
1010 showGroupConservation.setEnabled(annotations.isSelected());
1011 showConsensHistogram.setEnabled(annotations.isSelected()
1012 && (identity.isSelected() || showGroupConsensus.isSelected()));
1013 showConsensLogo.setEnabled(annotations.isSelected()
1014 && (identity.isSelected() || showGroupConsensus.isSelected()));
1015 showInformationHistogram.setEnabled(annotations.isSelected());
1016 showHMMLogo.setEnabled(annotations.isSelected());
1020 public void newLink_actionPerformed(ActionEvent e)
1022 GSequenceLink link = new GSequenceLink();
1023 boolean valid = false;
1026 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1027 MessageManager.getString("label.new_sequence_url_link"),
1028 JvOptionPane.OK_CANCEL_OPTION, -1,
1029 null) == JvOptionPane.OK_OPTION)
1031 if (link.checkValid())
1033 if (((UrlLinkTableModel) linkUrlTable.getModel())
1034 .isUniqueName(link.getName()))
1036 ((UrlLinkTableModel) linkUrlTable.getModel())
1037 .insertRow(link.getName(), link.getURL());
1042 link.notifyDuplicate();
1055 public void editLink_actionPerformed(ActionEvent e)
1057 GSequenceLink link = new GSequenceLink();
1059 int index = linkUrlTable.getSelectedRow();
1062 // button no longer enabled if row is not selected
1063 Cache.log.debug("Edit with no row selected in linkUrlTable");
1067 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1069 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1071 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1072 link.setName(oldName);
1073 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1075 boolean valid = false;
1078 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1079 MessageManager.getString("label.edit_sequence_url_link"),
1080 JvOptionPane.OK_CANCEL_OPTION, -1,
1081 null) == JvOptionPane.OK_OPTION)
1083 if (link.checkValid())
1085 if ((oldName.equals(link.getName()))
1086 || (((UrlLinkTableModel) linkUrlTable.getModel())
1087 .isUniqueName(link.getName())))
1089 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1090 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1095 link.notifyDuplicate();
1108 public void deleteLink_actionPerformed(ActionEvent e)
1110 int index = linkUrlTable.getSelectedRow();
1111 int modelIndex = -1;
1114 // button no longer enabled if row is not selected
1115 Cache.log.debug("Delete with no row selected in linkUrlTable");
1120 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1123 // make sure we use the model index to delete, and not the table index
1124 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1128 public void defaultBrowser_mouseClicked(MouseEvent e)
1130 JFileChooser chooser = new JFileChooser(".");
1131 chooser.setDialogTitle(
1132 MessageManager.getString("label.select_default_browser"));
1134 int value = chooser.showOpenDialog(this);
1136 if (value == JFileChooser.APPROVE_OPTION)
1138 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1147 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1151 protected void showunconserved_actionPerformed(ActionEvent e)
1153 // TODO Auto-generated method stub
1154 super.showunconserved_actionPerformed(e);
1157 public static List<String> getGroupURLLinks()
1159 return groupURLLinks;
1163 public void minColour_actionPerformed(JPanel panel)
1165 Color col = JColorChooser.showDialog(this,
1166 MessageManager.getString("label.select_colour_minimum_value"),
1167 minColour.getBackground());
1170 panel.setBackground(col);
1176 public void maxColour_actionPerformed(JPanel panel)
1178 Color col = JColorChooser.showDialog(this,
1179 MessageManager.getString("label.select_colour_maximum_value"),
1180 maxColour.getBackground());
1183 panel.setBackground(col);
1189 public void gapColour_actionPerformed(JPanel gap)
1191 if (!useLegacyGap.isSelected())
1193 Color col = JColorChooser.showDialog(this,
1194 MessageManager.getString("label.select_gap_colour"),
1195 gapColour.getBackground());
1198 gap.setBackground(col);
1205 public void hiddenColour_actionPerformed(JPanel hidden)
1207 Color col = JColorChooser.showDialog(this,
1208 MessageManager.getString("label.select_hidden_colour"),
1209 hiddenColour.getBackground());
1212 hidden.setBackground(col);
1218 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1220 boolean enabled = useLegacyGap.isSelected();
1223 gapColour.setBackground(
1224 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1228 gapColour.setBackground(
1229 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1231 gapColour.setEnabled(!enabled);
1232 gapLabel.setEnabled(!enabled);
1236 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1238 useLegacyGap.setSelected(false);
1239 useLegacyGaps_actionPerformed(null);
1240 showHiddenAtStart.setSelected(true);
1241 hiddenColour.setBackground(
1242 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1246 protected void userIdWidth_actionPerformed()
1250 String val = userIdWidth.getText().trim();
1251 if (val.length() > 0)
1253 Integer iw = Integer.parseInt(val);
1254 if (iw.intValue() < 12)
1256 throw new NumberFormatException();
1258 userIdWidth.setText(iw.toString());
1260 } catch (NumberFormatException x)
1262 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1264 .getString("warn.user_defined_width_requirements"),
1265 MessageManager.getString("label.invalid_id_column_width"),
1266 JvOptionPane.WARNING_MESSAGE);
1267 userIdWidth.setText("");
1272 protected void autoIdWidth_actionPerformed()
1274 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1275 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1279 * Returns true if chimera path is to a valid executable, else show an error
1282 private boolean validateChimeraPath()
1284 if (chimeraPath.getText().trim().length() > 0)
1286 File f = new File(chimeraPath.getText());
1287 if (!f.canExecute())
1289 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1290 MessageManager.getString("label.invalid_chimera_path"),
1291 MessageManager.getString("label.invalid_name"),
1292 JvOptionPane.ERROR_MESSAGE);
1300 * Returns true if the given text field contains a path to a folder that
1301 * contains an executable with the given name, else false (after showing a
1302 * warning dialog). The executable name will be tried with .exe appended if not
1308 protected boolean validateExecutablePath(JTextField textField, String executable)
1310 String folder = textField.getText().trim();
1312 if (FileUtils.getExecutable(executable, folder) != null)
1316 if (folder.length() > 0)
1318 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1319 MessageManager.formatMessage("label.executable_not_found",
1321 MessageManager.getString("label.invalid_folder"),
1322 JvOptionPane.ERROR_MESSAGE);
1328 * Checks if a file can be executed
1331 * the path to the file
1334 public boolean canExecute(String path)
1336 File file = new File(path);
1337 if (!file.canExecute())
1339 file = new File(path + ".exe");
1341 if (!file.canExecute())
1351 * If Chimera is selected, check it can be found on default or user-specified
1352 * path, if not show a warning/help dialog.
1355 protected void structureViewer_actionPerformed(String selectedItem)
1357 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1361 boolean found = false;
1364 * Try user-specified and standard paths for Chimera executable.
1366 List<String> paths = StructureManager.getChimeraPaths();
1367 paths.add(0, chimeraPath.getText());
1368 for (String path : paths)
1370 if (new File(path.trim()).canExecute())
1378 String[] options = { "OK", "Help" };
1379 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1380 JvSwingUtils.wrapTooltip(true,
1381 MessageManager.getString("label.chimera_missing")),
1382 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1383 null, options, options[0]);
1384 if (showHelp == JvOptionPane.NO_OPTION)
1388 Help.showHelpWindow(HelpId.StructureViewer);
1389 } catch (HelpSetException e)
1391 e.printStackTrace();
1398 protected void validateHmmerPath()
1400 validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1404 protected void validateCygwinPath()
1406 validateExecutablePath(cygwinPath, "run");
1409 public class OptionsParam
1411 private String name;
1413 private String code;
1415 public OptionsParam(String name, String code)
1421 public String getName()
1426 public void setName(String name)
1431 public String getCode()
1436 public void setCode(String code)
1442 public String toString()
1448 public boolean equals(Object that)
1450 if (!(that instanceof OptionsParam))
1454 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1458 public int hashCode()
1460 return name.hashCode() + code.hashCode();
1464 private class UrlListSelectionHandler implements ListSelectionListener
1468 public void valueChanged(ListSelectionEvent e)
1470 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1472 int index = lsm.getMinSelectionIndex();
1475 // no selection, so disable delete/edit buttons
1476 editLink.setEnabled(false);
1477 deleteLink.setEnabled(false);
1480 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1482 // enable/disable edit and delete link buttons
1483 if (((UrlLinkTableModel) linkUrlTable.getModel())
1484 .isRowDeletable(modelIndex))
1486 deleteLink.setEnabled(true);
1490 deleteLink.setEnabled(false);
1493 if (((UrlLinkTableModel) linkUrlTable.getModel())
1494 .isRowEditable(modelIndex))
1496 editLink.setEnabled(true);
1500 editLink.setEnabled(false);