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 ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
91 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
93 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
95 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
97 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
99 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
101 public static final String ADD_SS_ANN = "ADD_SS_ANN";
103 public static final String USE_RNAVIEW = "USE_RNAVIEW";
105 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
107 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
109 public static final String CHIMERA_PATH = "CHIMERA_PATH";
111 public static final String HMMER_PATH = "HMMER_PATH";
113 public static final String CYGWIN_PATH = "CYGWIN_PATH";
115 public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS";
117 public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
119 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
121 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
123 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
125 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
127 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
129 public static final String GAP_COLOUR = "GAP_COLOUR";
131 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
133 private static final int MIN_FONT_SIZE = 1;
135 private static final int MAX_FONT_SIZE = 30;
138 * Holds name and link separated with | character. Sequence ID must be
139 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
141 public static UrlProviderI sequenceUrlLinks;
143 public static UrlLinkTableModel dataModel;
146 * Holds name and link separated with | character. Sequence IDS and Sequences
147 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
148 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
149 * for first and second token specified after a pipe character at end |,|.
150 * (TODO: proper escape for using | to separate ids or sequences
153 public static List<String> groupURLLinks;
156 // get links selected to be in the menu (SEQUENCE_LINKS)
157 // and links entered by the user but not selected (STORED_LINKS)
158 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
159 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
160 String defaultUrl = Cache.getDefault("DEFAULT_URL",
161 UrlConstants.DEFAULT_LABEL);
163 // if both links lists are empty, add the DEFAULT_URL link
164 // otherwise we assume the default link is in one of the lists
165 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
167 inMenuString = UrlConstants.DEFAULT_STRING;
169 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
170 inMenuString, notInMenuString);
171 sequenceUrlLinks = factory.createUrlProvider();
172 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
175 * TODO: reformulate groupURL encoding so two or more can be stored in the
176 * .properties file as '|' separated strings
179 groupURLLinks = new ArrayList<>();
182 JInternalFrame frame;
184 DasSourceBrowser dasSource;
186 private WsPreferences wsPrefs;
188 private OptionsParam promptEachTimeOpt = new OptionsParam(
189 MessageManager.getString("label.prompt_each_time"),
192 private OptionsParam lineArtOpt = new OptionsParam(
193 MessageManager.getString("label.lineart"), "Lineart");
195 private OptionsParam textOpt = new OptionsParam(
196 MessageManager.getString("action.text"), "Text");
199 * Creates a new Preferences object.
204 frame = new JInternalFrame();
205 frame.setContentPane(this);
206 dasSource = new DasSourceBrowser();
207 dasTab.add(dasSource, BorderLayout.CENTER);
208 wsPrefs = new WsPreferences();
209 wsTab.add(wsPrefs, BorderLayout.CENTER);
210 int width = 500, height = 450;
211 new jalview.util.Platform();
212 if (Platform.isAMac())
218 Desktop.addInternalFrame(frame,
219 MessageManager.getString("label.preferences"), width, height);
220 frame.setMinimumSize(new Dimension(width, height));
223 * Set HMMER tab defaults
225 hmmrTrimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
226 if (Cache.getDefault("USE_UNIPROT", false))
228 hmmerBackgroundUniprot.setSelected(true);
232 hmmerBackgroundAlignment.setSelected(true);
235 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
236 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
237 hmmerPath.addActionListener(new ActionListener()
240 public void actionPerformed(ActionEvent e)
245 hmmerPath.addFocusListener(new FocusAdapter()
248 public void focusLost(FocusEvent e)
253 cygwinPath.setText(Cache.getProperty(CYGWIN_PATH));
254 cygwinPath.addActionListener(new ActionListener()
257 public void actionPerformed(ActionEvent e)
259 validateCygwinPath();
262 cygwinPath.addFocusListener(new FocusAdapter()
265 public void focusLost(FocusEvent e)
267 validateCygwinPath();
272 * Set Visual tab defaults
274 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
275 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
276 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
277 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
279 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
280 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
281 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
282 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
284 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
285 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
287 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
288 showGroupConservation.setSelected(
289 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
290 showConsensHistogram.setSelected(
291 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
293 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
294 showInformationHistogram.setSelected(
295 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
296 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
298 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
300 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
302 String[] fonts = java.awt.GraphicsEnvironment
303 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
304 for (int i = 0; i < fonts.length; i++)
306 fontNameCB.addItem(fonts[i]);
309 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
311 fontSizeCB.addItem(i + "");
314 fontStyleCB.addItem("plain");
315 fontStyleCB.addItem("bold");
316 fontStyleCB.addItem("italic");
318 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
319 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
320 fontStyleCB.setSelectedItem(
321 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
323 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
325 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
327 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
329 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
331 gapSymbolCB.addItem("-");
332 gapSymbolCB.addItem(".");
334 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
336 sortby.addItem("No sort");
337 sortby.addItem("Id");
338 sortby.addItem("Pairwise Identity");
339 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
341 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
343 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
345 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
346 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
347 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
348 SequenceAnnotationOrder.NONE.name()));
349 sortAnnBy.setSelectedItem(savedSort.toString());
351 sortAutocalc.addItem("Autocalculated first");
352 sortAutocalc.addItem("Autocalculated last");
353 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
354 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
355 : sortAutocalc.getItemAt(1));
357 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
358 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
359 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
360 + "/examples/exampleFile_2_3.jar"));
363 * Set Colours tab defaults
365 protColour.addItem(ResidueColourScheme.NONE);
366 nucColour.addItem(ResidueColourScheme.NONE);
367 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
369 String name = cs.getSchemeName();
370 protColour.addItem(name);
371 nucColour.addItem(name);
373 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
374 ResidueColourScheme.NONE);
375 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
376 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
377 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
378 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
379 minColour.setBackground(
380 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
381 maxColour.setBackground(
382 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
385 * Set overview panel defaults
387 gapColour.setBackground(
388 Cache.getDefaultColour(GAP_COLOUR,
389 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
390 hiddenColour.setBackground(
391 Cache.getDefaultColour(HIDDEN_COLOUR,
392 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
393 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
394 gapLabel.setEnabled(!useLegacyGap.isSelected());
395 gapColour.setEnabled(!useLegacyGap.isSelected());
397 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
400 * Set Structure tab defaults.
402 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
403 structFromPdb.setSelected(structSelected);
404 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
405 useRnaView.setEnabled(structSelected);
406 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
407 addSecondaryStructure.setEnabled(structSelected);
408 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
409 addTempFactor.setEnabled(structSelected);
410 structViewer.setSelectedItem(
411 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
412 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
413 chimeraPath.addActionListener(new ActionListener()
416 public void actionPerformed(ActionEvent e)
418 validateChimeraPath();
422 if (Cache.getDefault("MAP_WITH_SIFTS", false))
424 siftsMapping.setSelected(true);
428 nwMapping.setSelected(true);
432 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
435 * Set Connections tab defaults
439 linkUrlTable.setModel(dataModel);
440 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
441 linkUrlTable.getModel());
442 linkUrlTable.setRowSorter(sorter);
443 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
445 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
446 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
447 SortOrder.DESCENDING));
448 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
449 SortOrder.DESCENDING));
451 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
453 sorter.setSortKeys(sortKeys);
457 ActionListener onReset;
458 onReset = new ActionListener()
461 public void actionPerformed(ActionEvent e)
463 filterTB.setText("");
464 sorter.setRowFilter(RowFilter.regexFilter(""));
468 doReset.addActionListener(onReset);
470 // filter to display only custom urls
471 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
474 public boolean include(
475 Entry<? extends TableModel, ? extends Object> entry)
477 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
481 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
482 linkUrlTable.getModel());
483 customSorter.setRowFilter(customUrlFilter);
485 ActionListener onCustomOnly;
486 onCustomOnly = new ActionListener()
489 public void actionPerformed(ActionEvent e)
491 filterTB.setText("");
492 sorter.setRowFilter(customUrlFilter);
495 userOnly.addActionListener(onCustomOnly);
497 filterTB.getDocument().addDocumentListener(new DocumentListener()
499 String caseInsensitiveFlag = "(?i)";
502 public void changedUpdate(DocumentEvent e)
504 sorter.setRowFilter(RowFilter
505 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
509 public void removeUpdate(DocumentEvent e)
511 sorter.setRowFilter(RowFilter
512 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
516 public void insertUpdate(DocumentEvent e)
518 sorter.setRowFilter(RowFilter
519 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
523 // set up list selection functionality
524 linkUrlTable.getSelectionModel()
525 .addListSelectionListener(new UrlListSelectionHandler());
527 // set up radio buttons
528 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
530 String onClickName = linkUrlTable.getColumnName(onClickCol);
531 linkUrlTable.getColumn(onClickName)
532 .setCellRenderer(new RadioButtonRenderer());
533 linkUrlTable.getColumn(onClickName)
534 .setCellEditor(new RadioButtonEditor());
536 // get boolean columns and resize those to min possible
537 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
539 if (linkUrlTable.getModel().getColumnClass(column)
540 .equals(Boolean.class))
542 TableColumn tableColumn = linkUrlTable.getColumnModel()
544 int preferredWidth = tableColumn.getMinWidth();
546 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
548 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
549 int cwidth = c.getPreferredSize().width
550 + linkUrlTable.getIntercellSpacing().width;
551 preferredWidth = Math.max(preferredWidth, cwidth);
553 tableColumn.setPreferredWidth(preferredWidth);
557 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
558 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
559 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
560 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
562 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
564 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
565 // note antisense here: default is true
567 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
568 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
571 * Set Output tab defaults
573 epsRendering.addItem(promptEachTimeOpt);
574 epsRendering.addItem(lineArtOpt);
575 epsRendering.addItem(textOpt);
576 String defaultEPS = Cache.getDefault("EPS_RENDERING",
578 if (defaultEPS.equalsIgnoreCase("Text"))
580 epsRendering.setSelectedItem(textOpt);
582 else if (defaultEPS.equalsIgnoreCase("Lineart"))
584 epsRendering.setSelectedItem(lineArtOpt);
588 epsRendering.setSelectedItem(promptEachTimeOpt);
590 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
591 userIdWidth.setEnabled(!autoIdWidth.isSelected());
592 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
593 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
594 userIdWidth.setText(wi == null ? "" : wi.toString());
595 // TODO: refactor to use common enum via FormatAdapter and allow extension
596 // for new flat file formats
597 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
598 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
599 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
600 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
601 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
602 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
603 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
604 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
606 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
609 * Set Editing tab defaults
611 autoCalculateConsCheck
612 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
613 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
614 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
616 annotations_actionPerformed(null); // update the display of the annotation
621 * Save user selections on the Preferences tabs to the Cache and write out to
627 public void ok_actionPerformed(ActionEvent e)
629 if (!validateSettings())
635 * Save Visual settings
637 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
638 Boolean.toString(seqLimit.isSelected()));
639 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
640 Boolean.toString(rightAlign.isSelected()));
641 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
642 Boolean.toString(fullScreen.isSelected()));
643 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
644 Boolean.toString(openoverv.isSelected()));
645 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
646 Boolean.toString(annotations.isSelected()));
647 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
648 Boolean.toString(conservation.isSelected()));
649 Cache.applicationProperties.setProperty("SHOW_QUALITY",
650 Boolean.toString(quality.isSelected()));
651 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
652 Boolean.toString(identity.isSelected()));
654 Cache.applicationProperties.setProperty("GAP_SYMBOL",
655 gapSymbolCB.getSelectedItem().toString());
657 Cache.applicationProperties.setProperty("FONT_NAME",
658 fontNameCB.getSelectedItem().toString());
659 Cache.applicationProperties.setProperty("FONT_STYLE",
660 fontStyleCB.getSelectedItem().toString());
661 Cache.applicationProperties.setProperty("FONT_SIZE",
662 fontSizeCB.getSelectedItem().toString());
664 Cache.applicationProperties.setProperty("ID_ITALICS",
665 Boolean.toString(idItalics.isSelected()));
666 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
667 Boolean.toString(showUnconserved.isSelected()));
668 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
669 Boolean.toString(showOccupancy.isSelected()));
670 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
671 Boolean.toString(showGroupConsensus.isSelected()));
672 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
673 Boolean.toString(showGroupConservation.isSelected()));
674 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
675 Boolean.toString(showConsensHistogram.isSelected()));
676 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
677 Boolean.toString(showConsensLogo.isSelected()));
678 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
679 Boolean.toString(showConsensHistogram.isSelected()));
680 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
681 Boolean.toString(showHMMLogo.isSelected()));
682 Cache.applicationProperties.setProperty("ANTI_ALIAS",
683 Boolean.toString(smoothFont.isSelected()));
684 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
685 Boolean.toString(scaleProteinToCdna.isSelected()));
686 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
687 Boolean.toString(showNpTooltip.isSelected()));
688 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
689 Boolean.toString(showDbRefTooltip.isSelected()));
691 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
692 Boolean.toString(wrap.isSelected()));
694 Cache.applicationProperties.setProperty("STARTUP_FILE",
695 startupFileTextfield.getText());
696 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
697 Boolean.toString(startupCheckbox.isSelected()));
699 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
700 sortby.getSelectedItem().toString());
702 // convert description of sort order to enum name for save
703 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
704 .forDescription(sortAnnBy.getSelectedItem().toString());
705 if (annSortOrder != null)
707 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
708 annSortOrder.name());
711 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
712 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
713 Boolean.valueOf(showAutocalcFirst).toString());
716 * Save Colours settings
718 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
719 protColour.getSelectedItem().toString());
720 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
721 nucColour.getSelectedItem().toString());
722 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
723 minColour.getBackground());
724 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
725 maxColour.getBackground());
728 * Save HMMER settings
730 Cache.applicationProperties.setProperty("TRIM_TERMINI",
731 Boolean.toString(hmmrTrimTermini.isSelected()));
732 Cache.applicationProperties.setProperty("USE_UNIPROT",
733 Boolean.toString(hmmerBackgroundUniprot.isSelected()));
734 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
735 hmmerSequenceCount.getText());
736 Cache.setOrRemove(HMMER_PATH, hmmerPath.getText());
737 Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText());
738 AlignFrame[] frames = Desktop.getAlignFrames();
739 if (frames != null && frames.length > 0)
741 for (AlignFrame f : frames)
743 f.updateHMMERStatus();
747 hmmrTrimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
748 if (Cache.getDefault("USE_UNIPROT", false))
750 hmmerBackgroundUniprot.setSelected(true);
754 hmmerBackgroundAlignment.setSelected(true);
757 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
758 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
761 * Save Overview settings
763 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
764 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
765 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
766 Boolean.toString(useLegacyGap.isSelected()));
767 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
768 Boolean.toString(showHiddenAtStart.isSelected()));
771 * Save Structure settings
773 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
774 Boolean.toString(addTempFactor.isSelected()));
775 Cache.applicationProperties.setProperty(ADD_SS_ANN,
776 Boolean.toString(addSecondaryStructure.isSelected()));
777 Cache.applicationProperties.setProperty(USE_RNAVIEW,
778 Boolean.toString(useRnaView.isSelected()));
779 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
780 Boolean.toString(structFromPdb.isSelected()));
781 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
782 structViewer.getSelectedItem().toString());
783 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
784 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
785 Boolean.toString(siftsMapping.isSelected()));
786 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
789 * Save Output settings
791 Cache.applicationProperties.setProperty("EPS_RENDERING",
792 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
795 * Save Connections settings
797 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
799 jalview.util.BrowserLauncher.resetBrowser();
801 // save user-defined and selected links
802 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
803 if (menuLinks.isEmpty())
805 Cache.applicationProperties.remove("SEQUENCE_LINKS");
809 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
810 menuLinks.toString());
813 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
814 if (nonMenuLinks.isEmpty())
816 Cache.applicationProperties.remove("STORED_LINKS");
820 Cache.applicationProperties.setProperty("STORED_LINKS",
821 nonMenuLinks.toString());
824 Cache.applicationProperties.setProperty("DEFAULT_URL",
825 sequenceUrlLinks.getPrimaryUrlId());
827 Cache.applicationProperties.setProperty("USE_PROXY",
828 Boolean.toString(useProxy.isSelected()));
830 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
832 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
834 if (useProxy.isSelected())
836 System.setProperty("http.proxyHost", proxyServerTB.getText());
837 System.setProperty("http.proxyPort", proxyPortTB.getText());
841 System.setProperty("http.proxyHost", "");
842 System.setProperty("http.proxyPort", "");
844 Cache.setProperty("VERSION_CHECK",
845 Boolean.toString(versioncheck.isSelected()));
846 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
848 // default is false - we only set this if the user has actively agreed
849 Cache.setProperty("USAGESTATS",
850 Boolean.toString(usagestats.isSelected()));
852 if (!questionnaire.isSelected())
854 Cache.setProperty("NOQUESTIONNAIRES", "true");
858 // special - made easy to edit a property file to disable questionnaires
859 // by just adding the given line
860 Cache.removeProperty("NOQUESTIONNAIRES");
864 * Save Output settings
866 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
867 Boolean.toString(blcjv.isSelected()));
868 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
869 Boolean.toString(clustaljv.isSelected()));
870 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
871 Boolean.toString(fastajv.isSelected()));
872 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
873 Boolean.toString(msfjv.isSelected()));
874 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
875 Boolean.toString(pfamjv.isSelected()));
876 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
877 Boolean.toString(pileupjv.isSelected()));
878 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
879 Boolean.toString(pirjv.isSelected()));
880 Cache.applicationProperties.setProperty("PIR_MODELLER",
881 Boolean.toString(modellerOutput.isSelected()));
882 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
883 Boolean.toString(embbedBioJSON.isSelected()));
884 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
886 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
887 Boolean.toString(autoIdWidth.isSelected()));
888 userIdWidth_actionPerformed();
889 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
890 userIdWidth.getText());
893 * Save Editing settings
895 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
896 Boolean.toString(autoCalculateConsCheck.isSelected()));
897 Cache.applicationProperties.setProperty("SORT_BY_TREE",
898 Boolean.toString(sortByTree.isSelected()));
899 Cache.applicationProperties.setProperty("PAD_GAPS",
900 Boolean.toString(padGaps.isSelected()));
902 dasSource.saveProperties(Cache.applicationProperties);
903 wsPrefs.updateAndRefreshWsMenuConfig(false);
904 Cache.saveProperties();
905 Desktop.instance.doConfigureStructurePrefs();
908 frame.setClosed(true);
909 } catch (Exception ex)
915 * Do any necessary validation before saving settings. Return focus to the
916 * first tab which fails validation.
920 private boolean validateSettings()
922 if (!validateStructure())
924 structureTab.requestFocusInWindow();
931 protected boolean validateStructure()
933 return validateChimeraPath();
941 public void startupFileTextfield_mouseClicked()
943 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
944 JalviewFileChooser chooser = JalviewFileChooser
945 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
946 chooser.setFileView(new JalviewFileView());
947 chooser.setDialogTitle(
948 MessageManager.getString("label.select_startup_file"));
950 int value = chooser.showOpenDialog(this);
952 if (value == JalviewFileChooser.APPROVE_OPTION)
954 FileFormatI format = chooser.getSelectedFormat();
957 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
961 .setText(chooser.getSelectedFile().getAbsolutePath());
972 public void cancel_actionPerformed(ActionEvent e)
976 wsPrefs.updateWsMenuConfig(true);
977 wsPrefs.refreshWs_actionPerformed(e);
978 frame.setClosed(true);
979 } catch (Exception ex)
991 public void annotations_actionPerformed(ActionEvent e)
993 conservation.setEnabled(annotations.isSelected());
994 quality.setEnabled(annotations.isSelected());
995 identity.setEnabled(annotations.isSelected());
996 showOccupancy.setEnabled(annotations.isSelected());
997 showGroupConsensus.setEnabled(annotations.isSelected());
998 showGroupConservation.setEnabled(annotations.isSelected());
999 showConsensHistogram.setEnabled(annotations.isSelected()
1000 && (identity.isSelected() || showGroupConsensus.isSelected()));
1001 showConsensLogo.setEnabled(annotations.isSelected()
1002 && (identity.isSelected() || showGroupConsensus.isSelected()));
1003 showInformationHistogram.setEnabled(annotations.isSelected());
1004 showHMMLogo.setEnabled(annotations.isSelected());
1008 public void newLink_actionPerformed(ActionEvent e)
1010 GSequenceLink link = new GSequenceLink();
1011 boolean valid = false;
1014 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1015 MessageManager.getString("label.new_sequence_url_link"),
1016 JvOptionPane.OK_CANCEL_OPTION, -1,
1017 null) == JvOptionPane.OK_OPTION)
1019 if (link.checkValid())
1021 if (((UrlLinkTableModel) linkUrlTable.getModel())
1022 .isUniqueName(link.getName()))
1024 ((UrlLinkTableModel) linkUrlTable.getModel())
1025 .insertRow(link.getName(), link.getURL());
1030 link.notifyDuplicate();
1043 public void editLink_actionPerformed(ActionEvent e)
1045 GSequenceLink link = new GSequenceLink();
1047 int index = linkUrlTable.getSelectedRow();
1050 // button no longer enabled if row is not selected
1051 Cache.log.debug("Edit with no row selected in linkUrlTable");
1055 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1057 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1059 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1060 link.setName(oldName);
1061 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1063 boolean valid = false;
1066 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1067 MessageManager.getString("label.edit_sequence_url_link"),
1068 JvOptionPane.OK_CANCEL_OPTION, -1,
1069 null) == JvOptionPane.OK_OPTION)
1071 if (link.checkValid())
1073 if ((oldName.equals(link.getName()))
1074 || (((UrlLinkTableModel) linkUrlTable.getModel())
1075 .isUniqueName(link.getName())))
1077 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1078 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1083 link.notifyDuplicate();
1096 public void deleteLink_actionPerformed(ActionEvent e)
1098 int index = linkUrlTable.getSelectedRow();
1099 int modelIndex = -1;
1102 // button no longer enabled if row is not selected
1103 Cache.log.debug("Delete with no row selected in linkUrlTable");
1108 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1111 // make sure we use the model index to delete, and not the table index
1112 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1116 public void defaultBrowser_mouseClicked(MouseEvent e)
1118 JFileChooser chooser = new JFileChooser(".");
1119 chooser.setDialogTitle(
1120 MessageManager.getString("label.select_default_browser"));
1122 int value = chooser.showOpenDialog(this);
1124 if (value == JFileChooser.APPROVE_OPTION)
1126 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1135 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1139 protected void showunconserved_actionPerformed(ActionEvent e)
1141 // TODO Auto-generated method stub
1142 super.showunconserved_actionPerformed(e);
1145 public static List<String> getGroupURLLinks()
1147 return groupURLLinks;
1151 public void minColour_actionPerformed(JPanel panel)
1153 Color col = JColorChooser.showDialog(this,
1154 MessageManager.getString("label.select_colour_minimum_value"),
1155 minColour.getBackground());
1158 panel.setBackground(col);
1164 public void maxColour_actionPerformed(JPanel panel)
1166 Color col = JColorChooser.showDialog(this,
1167 MessageManager.getString("label.select_colour_maximum_value"),
1168 maxColour.getBackground());
1171 panel.setBackground(col);
1177 public void gapColour_actionPerformed(JPanel gap)
1179 if (!useLegacyGap.isSelected())
1181 Color col = JColorChooser.showDialog(this,
1182 MessageManager.getString("label.select_gap_colour"),
1183 gapColour.getBackground());
1186 gap.setBackground(col);
1193 public void hiddenColour_actionPerformed(JPanel hidden)
1195 Color col = JColorChooser.showDialog(this,
1196 MessageManager.getString("label.select_hidden_colour"),
1197 hiddenColour.getBackground());
1200 hidden.setBackground(col);
1206 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1208 boolean enabled = useLegacyGap.isSelected();
1211 gapColour.setBackground(
1212 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1216 gapColour.setBackground(
1217 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1219 gapColour.setEnabled(!enabled);
1220 gapLabel.setEnabled(!enabled);
1224 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1226 useLegacyGap.setSelected(false);
1227 useLegacyGaps_actionPerformed(null);
1228 showHiddenAtStart.setSelected(true);
1229 hiddenColour.setBackground(
1230 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1234 protected void userIdWidth_actionPerformed()
1238 String val = userIdWidth.getText().trim();
1239 if (val.length() > 0)
1241 Integer iw = Integer.parseInt(val);
1242 if (iw.intValue() < 12)
1244 throw new NumberFormatException();
1246 userIdWidth.setText(iw.toString());
1248 } catch (NumberFormatException x)
1250 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1252 .getString("warn.user_defined_width_requirements"),
1253 MessageManager.getString("label.invalid_id_column_width"),
1254 JvOptionPane.WARNING_MESSAGE);
1255 userIdWidth.setText("");
1260 protected void autoIdWidth_actionPerformed()
1262 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1263 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1267 * Returns true if chimera path is to a valid executable, else show an error
1270 private boolean validateChimeraPath()
1272 if (chimeraPath.getText().trim().length() > 0)
1274 File f = new File(chimeraPath.getText());
1275 if (!f.canExecute())
1277 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1278 MessageManager.getString("label.invalid_chimera_path"),
1279 MessageManager.getString("label.invalid_name"),
1280 JvOptionPane.ERROR_MESSAGE);
1288 * Returns true if the given text field contains a path to a folder that
1289 * contains an executable with the given name, else false (after showing a
1290 * warning dialog). The executable name will be tried with .exe appended if not
1296 protected boolean validateExecutablePath(JTextField textField, String executable)
1298 String folder = textField.getText().trim();
1300 if (FileUtils.getExecutable(executable, folder) != null)
1304 if (folder.length() > 0)
1306 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1307 MessageManager.formatMessage("label.executable_not_found",
1309 MessageManager.getString("label.invalid_folder"),
1310 JvOptionPane.ERROR_MESSAGE);
1316 * Checks if a file can be executed
1319 * the path to the file
1322 public boolean canExecute(String path)
1324 File file = new File(path);
1325 if (!file.canExecute())
1327 file = new File(path + ".exe");
1329 if (!file.canExecute())
1339 * If Chimera is selected, check it can be found on default or user-specified
1340 * path, if not show a warning/help dialog.
1343 protected void structureViewer_actionPerformed(String selectedItem)
1345 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1349 boolean found = false;
1352 * Try user-specified and standard paths for Chimera executable.
1354 List<String> paths = StructureManager.getChimeraPaths();
1355 paths.add(0, chimeraPath.getText());
1356 for (String path : paths)
1358 if (new File(path.trim()).canExecute())
1366 String[] options = { "OK", "Help" };
1367 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1368 JvSwingUtils.wrapTooltip(true,
1369 MessageManager.getString("label.chimera_missing")),
1370 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1371 null, options, options[0]);
1372 if (showHelp == JvOptionPane.NO_OPTION)
1376 Help.showHelpWindow(HelpId.StructureViewer);
1377 } catch (HelpSetException e)
1379 e.printStackTrace();
1386 protected void validateHmmerPath()
1388 validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD);
1392 protected void validateCygwinPath()
1394 validateExecutablePath(cygwinPath, "run");
1397 public class OptionsParam
1399 private String name;
1401 private String code;
1403 public OptionsParam(String name, String code)
1409 public String getName()
1414 public void setName(String name)
1419 public String getCode()
1424 public void setCode(String code)
1430 public String toString()
1436 public boolean equals(Object that)
1438 if (!(that instanceof OptionsParam))
1442 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1446 public int hashCode()
1448 return name.hashCode() + code.hashCode();
1452 private class UrlListSelectionHandler implements ListSelectionListener
1456 public void valueChanged(ListSelectionEvent e)
1458 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1460 int index = lsm.getMinSelectionIndex();
1463 // no selection, so disable delete/edit buttons
1464 editLink.setEnabled(false);
1465 deleteLink.setEnabled(false);
1468 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1470 // enable/disable edit and delete link buttons
1471 if (((UrlLinkTableModel) linkUrlTable.getModel())
1472 .isRowDeletable(modelIndex))
1474 deleteLink.setEnabled(true);
1478 deleteLink.setEnabled(false);
1481 if (((UrlLinkTableModel) linkUrlTable.getModel())
1482 .isRowEditable(modelIndex))
1484 editLink.setEnabled(true);
1488 editLink.setEnabled(false);