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.io.FileFormatI;
28 import jalview.io.JalviewFileChooser;
29 import jalview.io.JalviewFileView;
30 import jalview.jbgui.GPreferences;
31 import jalview.jbgui.GSequenceLink;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ColourSchemes;
34 import jalview.schemes.ResidueColourScheme;
35 import jalview.urls.UrlLinkTableModel;
36 import jalview.urls.api.UrlProviderFactoryI;
37 import jalview.urls.api.UrlProviderI;
38 import jalview.urls.desktop.DesktopUrlProviderFactory;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
41 import jalview.util.UrlConstants;
42 import jalview.ws.sifts.SiftsSettings;
44 import java.awt.BorderLayout;
45 import java.awt.Color;
46 import java.awt.Component;
47 import java.awt.Dimension;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
53 import java.util.ArrayList;
54 import java.util.List;
56 import javax.help.HelpSetException;
57 import javax.swing.JColorChooser;
58 import javax.swing.JFileChooser;
59 import javax.swing.JInternalFrame;
60 import javax.swing.JPanel;
61 import javax.swing.ListSelectionModel;
62 import javax.swing.RowFilter;
63 import javax.swing.RowSorter;
64 import javax.swing.SortOrder;
65 import javax.swing.event.DocumentEvent;
66 import javax.swing.event.DocumentListener;
67 import javax.swing.event.ListSelectionEvent;
68 import javax.swing.event.ListSelectionListener;
69 import javax.swing.table.TableCellRenderer;
70 import javax.swing.table.TableColumn;
71 import javax.swing.table.TableModel;
72 import javax.swing.table.TableRowSorter;
74 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
82 public class Preferences extends GPreferences
84 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
86 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
88 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
90 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
92 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
94 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
96 public static final String ADD_SS_ANN = "ADD_SS_ANN";
98 public static final String USE_RNAVIEW = "USE_RNAVIEW";
100 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
102 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
104 public static final String CHIMERA_PATH = "CHIMERA_PATH";
106 public static final String HMMER_PATH = "HMMER_PATH";
108 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
110 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
112 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
114 private static final int MIN_FONT_SIZE = 1;
116 private static final int MAX_FONT_SIZE = 30;
119 * Holds name and link separated with | character. Sequence ID must be
120 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
122 public static UrlProviderI sequenceUrlLinks;
124 public static UrlLinkTableModel dataModel;
127 * Holds name and link separated with | character. Sequence IDS and Sequences
128 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
129 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
130 * for first and second token specified after a pipe character at end |,|.
131 * (TODO: proper escape for using | to separate ids or sequences
134 public static List<String> groupURLLinks;
137 // get links selected to be in the menu (SEQUENCE_LINKS)
138 // and links entered by the user but not selected (STORED_LINKS)
139 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
140 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
141 String defaultUrl = Cache.getDefault("DEFAULT_URL",
142 UrlConstants.DEFAULT_LABEL);
144 // if both links lists are empty, add the DEFAULT_URL link
145 // otherwise we assume the default link is in one of the lists
146 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
148 inMenuString = UrlConstants.DEFAULT_STRING;
150 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
151 inMenuString, notInMenuString);
152 sequenceUrlLinks = factory.createUrlProvider();
153 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
156 * TODO: reformulate groupURL encoding so two or more can be stored in the
157 * .properties file as '|' separated strings
160 groupURLLinks = new ArrayList<>();
163 JInternalFrame frame;
165 DasSourceBrowser dasSource;
167 private WsPreferences wsPrefs;
169 private OptionsParam promptEachTimeOpt = new OptionsParam(
170 MessageManager.getString("label.prompt_each_time"),
173 private OptionsParam lineArtOpt = new OptionsParam(
174 MessageManager.getString("label.lineart"), "Lineart");
176 private OptionsParam textOpt = new OptionsParam(
177 MessageManager.getString("action.text"), "Text");
180 * Creates a new Preferences object.
185 frame = new JInternalFrame();
186 frame.setContentPane(this);
187 dasSource = new DasSourceBrowser();
188 dasTab.add(dasSource, BorderLayout.CENTER);
189 wsPrefs = new WsPreferences();
190 wsTab.add(wsPrefs, BorderLayout.CENTER);
191 int width = 500, height = 450;
192 new jalview.util.Platform();
193 if (Platform.isAMac())
199 Desktop.addInternalFrame(frame,
200 MessageManager.getString("label.preferences"), width, height);
201 frame.setMinimumSize(new Dimension(width, height));
204 * Set HMMER tab defaults
206 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
207 if (Cache.getDefault("USE_UNIPROT", false))
209 uniprot.setSelected(true);
213 alignment.setSelected(true);
215 numberOfSequencesToKeepField
216 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
217 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
218 hmmerPath.addActionListener(new ActionListener()
221 public void actionPerformed(ActionEvent e)
228 * Set Visual tab defaults
230 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
231 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
232 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
233 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
235 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
236 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
237 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
238 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
240 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
241 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
242 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
244 showGroupConservation.setSelected(Cache.getDefault(
245 "SHOW_GROUP_CONSERVATION", false));
246 showConsensHistogram.setSelected(Cache.getDefault(
247 "SHOW_CONSENSUS_HISTOGRAM", true));
248 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
250 showInformationHistogram.setSelected(
251 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
252 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
253 showNpTooltip.setSelected(Cache
254 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
255 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
258 String[] fonts = java.awt.GraphicsEnvironment
259 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
260 for (int i = 0; i < fonts.length; i++)
262 fontNameCB.addItem(fonts[i]);
265 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
267 fontSizeCB.addItem(i + "");
270 fontStyleCB.addItem("plain");
271 fontStyleCB.addItem("bold");
272 fontStyleCB.addItem("italic");
274 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
275 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
276 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
279 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
280 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
283 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
285 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
287 gapSymbolCB.addItem("-");
288 gapSymbolCB.addItem(".");
290 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
292 sortby.addItem("No sort");
293 sortby.addItem("Id");
294 sortby.addItem("Pairwise Identity");
295 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
297 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
299 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
301 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
302 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
303 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
304 SequenceAnnotationOrder.NONE.name()));
305 sortAnnBy.setSelectedItem(savedSort.toString());
307 sortAutocalc.addItem("Autocalculated first");
308 sortAutocalc.addItem("Autocalculated last");
309 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
310 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
311 : sortAutocalc.getItemAt(1));
313 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
314 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
315 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
316 + "/examples/exampleFile_2_3.jar"));
319 * Set Colours tab defaults
321 protColour.addItem(ResidueColourScheme.NONE);
322 nucColour.addItem(ResidueColourScheme.NONE);
323 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
325 String name = cs.getSchemeName();
326 protColour.addItem(name);
327 nucColour.addItem(name);
329 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
330 ResidueColourScheme.NONE);
331 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
332 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
333 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
334 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
335 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
337 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
341 * Set Structure tab defaults.
343 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
344 structFromPdb.setSelected(structSelected);
345 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
346 useRnaView.setEnabled(structSelected);
347 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
348 addSecondaryStructure.setEnabled(structSelected);
349 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
350 addTempFactor.setEnabled(structSelected);
351 structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
352 ViewerType.JMOL.name()));
353 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
354 chimeraPath.addActionListener(new ActionListener()
357 public void actionPerformed(ActionEvent e)
359 validateChimeraPath();
363 if (Cache.getDefault("MAP_WITH_SIFTS", false))
365 siftsMapping.setSelected(true);
369 nwMapping.setSelected(true);
373 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
376 * Set Connections tab defaults
380 linkUrlTable.setModel(dataModel);
381 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
382 linkUrlTable.getModel());
383 linkUrlTable.setRowSorter(sorter);
384 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
386 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
387 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
388 SortOrder.DESCENDING));
389 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
390 SortOrder.DESCENDING));
391 sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
392 SortOrder.ASCENDING));
394 sorter.setSortKeys(sortKeys);
398 ActionListener onReset;
399 onReset = new ActionListener()
402 public void actionPerformed(ActionEvent e)
404 filterTB.setText("");
405 sorter.setRowFilter(RowFilter.regexFilter(""));
409 doReset.addActionListener(onReset);
411 // filter to display only custom urls
412 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
415 public boolean include(
416 Entry<? extends TableModel, ? extends Object> entry)
418 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
422 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
423 linkUrlTable.getModel());
424 customSorter.setRowFilter(customUrlFilter);
426 ActionListener onCustomOnly;
427 onCustomOnly = new ActionListener()
430 public void actionPerformed(ActionEvent e)
432 filterTB.setText("");
433 sorter.setRowFilter(customUrlFilter);
436 userOnly.addActionListener(onCustomOnly);
438 filterTB.getDocument().addDocumentListener(new DocumentListener()
440 String caseInsensitiveFlag = "(?i)";
443 public void changedUpdate(DocumentEvent e)
445 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
446 + filterTB.getText()));
450 public void removeUpdate(DocumentEvent e)
452 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
453 + filterTB.getText()));
457 public void insertUpdate(DocumentEvent e)
459 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
460 + filterTB.getText()));
464 // set up list selection functionality
465 linkUrlTable.getSelectionModel().addListSelectionListener(
466 new UrlListSelectionHandler());
468 // set up radio buttons
469 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
471 String onClickName = linkUrlTable.getColumnName(onClickCol);
472 linkUrlTable.getColumn(onClickName).setCellRenderer(
473 new RadioButtonRenderer());
474 linkUrlTable.getColumn(onClickName)
475 .setCellEditor(new RadioButtonEditor());
477 // get boolean columns and resize those to min possible
478 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
480 if (linkUrlTable.getModel().getColumnClass(column)
481 .equals(Boolean.class))
483 TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
485 int preferredWidth = tableColumn.getMinWidth();
487 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
489 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
490 int cwidth = c.getPreferredSize().width
491 + linkUrlTable.getIntercellSpacing().width;
492 preferredWidth = Math.max(preferredWidth, cwidth);
494 tableColumn.setPreferredWidth(preferredWidth);
498 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
499 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
500 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
501 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
503 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
505 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
506 // note antisense here: default is true
508 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
509 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
512 * Set Output tab defaults
514 epsRendering.addItem(promptEachTimeOpt);
515 epsRendering.addItem(lineArtOpt);
516 epsRendering.addItem(textOpt);
517 String defaultEPS = Cache.getDefault("EPS_RENDERING",
519 if (defaultEPS.equalsIgnoreCase("Text"))
521 epsRendering.setSelectedItem(textOpt);
523 else if (defaultEPS.equalsIgnoreCase("Lineart"))
525 epsRendering.setSelectedItem(lineArtOpt);
529 epsRendering.setSelectedItem(promptEachTimeOpt);
531 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
532 userIdWidth.setEnabled(!autoIdWidth.isSelected());
533 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
534 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
535 userIdWidth.setText(wi == null ? "" : wi.toString());
536 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
537 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
538 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
539 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
540 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
541 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
542 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
543 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
544 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
548 * Set Editing tab defaults
550 autoCalculateConsCheck.setSelected(Cache.getDefault(
551 "AUTO_CALC_CONSENSUS", true));
552 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
553 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
555 annotations_actionPerformed(null); // update the display of the annotation
560 * Save user selections on the Preferences tabs to the Cache and write out to
566 public void ok_actionPerformed(ActionEvent e)
568 if (!validateSettings())
574 * Save Visual settings
576 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
577 Boolean.toString(seqLimit.isSelected()));
578 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
579 Boolean.toString(rightAlign.isSelected()));
580 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
581 Boolean.toString(fullScreen.isSelected()));
582 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
583 Boolean.toString(openoverv.isSelected()));
584 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
585 Boolean.toString(annotations.isSelected()));
586 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
587 Boolean.toString(conservation.isSelected()));
588 Cache.applicationProperties.setProperty("SHOW_QUALITY",
589 Boolean.toString(quality.isSelected()));
590 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
591 Boolean.toString(identity.isSelected()));
593 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
594 .getSelectedItem().toString());
596 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
597 .getSelectedItem().toString());
598 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
599 .getSelectedItem().toString());
600 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
601 .getSelectedItem().toString());
603 Cache.applicationProperties.setProperty("ID_ITALICS",
604 Boolean.toString(idItalics.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
606 Boolean.toString(showUnconserved.isSelected()));
607 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
608 Boolean.toString(showOccupancy.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
610 Boolean.toString(showGroupConsensus.isSelected()));
611 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
612 Boolean.toString(showGroupConservation.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
614 Boolean.toString(showConsensHistogram.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
616 Boolean.toString(showConsensLogo.isSelected()));
617 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
618 Boolean.toString(showConsensHistogram.isSelected()));
619 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
620 Boolean.toString(showHMMLogo.isSelected()));
621 Cache.applicationProperties.setProperty("ANTI_ALIAS",
622 Boolean.toString(smoothFont.isSelected()));
623 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
624 Boolean.toString(scaleProteinToCdna.isSelected()));
625 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
626 Boolean.toString(showNpTooltip.isSelected()));
627 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
628 Boolean.toString(showDbRefTooltip.isSelected()));
630 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
631 Boolean.toString(wrap.isSelected()));
633 Cache.applicationProperties.setProperty("STARTUP_FILE",
634 startupFileTextfield.getText());
635 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
636 Boolean.toString(startupCheckbox.isSelected()));
638 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
639 .getSelectedItem().toString());
641 // convert description of sort order to enum name for save
642 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
643 .forDescription(sortAnnBy.getSelectedItem().toString());
644 if (annSortOrder != null)
646 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
647 annSortOrder.name());
650 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
651 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
652 .valueOf(showAutocalcFirst).toString());
655 * Save Colours settings
657 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
658 .getSelectedItem().toString());
659 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
660 .getSelectedItem().toString());
661 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
662 minColour.getBackground());
663 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
664 maxColour.getBackground());
667 * Save HMMER settings
669 Cache.applicationProperties.setProperty("TRIM_TERMINI",
670 Boolean.toString(trimTermini.isSelected()));
671 Cache.applicationProperties.setProperty("USE_UNIPROT",
672 Boolean.toString(uniprot.isSelected()));
673 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
674 numberOfSequencesToKeepField.getText());
675 Cache.applicationProperties.setProperty(HMMER_PATH,
676 hmmerPath.getText());
677 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
678 if (Cache.getDefault("USE_UNIPROT", false))
680 uniprot.setSelected(true);
684 alignment.setSelected(true);
686 numberOfSequencesToKeepField
687 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
688 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
691 * Save Structure settings
693 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
694 Boolean.toString(addTempFactor.isSelected()));
695 Cache.applicationProperties.setProperty(ADD_SS_ANN,
696 Boolean.toString(addSecondaryStructure.isSelected()));
697 Cache.applicationProperties.setProperty(USE_RNAVIEW,
698 Boolean.toString(useRnaView.isSelected()));
699 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
700 Boolean.toString(structFromPdb.isSelected()));
701 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
702 .getSelectedItem().toString());
703 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
704 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
705 Boolean.toString(siftsMapping.isSelected()));
706 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
709 * Save Output settings
711 Cache.applicationProperties.setProperty("EPS_RENDERING",
712 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
715 * Save Connections settings
717 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
719 jalview.util.BrowserLauncher.resetBrowser();
721 // save user-defined and selected links
722 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
723 if (menuLinks.isEmpty())
725 Cache.applicationProperties.remove("SEQUENCE_LINKS");
729 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
730 menuLinks.toString());
733 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
734 if (nonMenuLinks.isEmpty())
736 Cache.applicationProperties.remove("STORED_LINKS");
740 Cache.applicationProperties.setProperty("STORED_LINKS",
741 nonMenuLinks.toString());
744 Cache.applicationProperties.setProperty("DEFAULT_URL",
745 sequenceUrlLinks.getPrimaryUrlId());
747 Cache.applicationProperties.setProperty("USE_PROXY",
748 Boolean.toString(useProxy.isSelected()));
750 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
752 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
754 if (useProxy.isSelected())
756 System.setProperty("http.proxyHost", proxyServerTB.getText());
757 System.setProperty("http.proxyPort", proxyPortTB.getText());
761 System.setProperty("http.proxyHost", "");
762 System.setProperty("http.proxyPort", "");
764 Cache.setProperty("VERSION_CHECK",
765 Boolean.toString(versioncheck.isSelected()));
766 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
768 // default is false - we only set this if the user has actively agreed
769 Cache.setProperty("USAGESTATS",
770 Boolean.toString(usagestats.isSelected()));
772 if (!questionnaire.isSelected())
774 Cache.setProperty("NOQUESTIONNAIRES", "true");
778 // special - made easy to edit a property file to disable questionnaires
779 // by just adding the given line
780 Cache.removeProperty("NOQUESTIONNAIRES");
784 * Save Output settings
786 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
787 Boolean.toString(blcjv.isSelected()));
788 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
789 Boolean.toString(clustaljv.isSelected()));
790 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
791 Boolean.toString(fastajv.isSelected()));
792 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
793 Boolean.toString(msfjv.isSelected()));
794 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
795 Boolean.toString(pfamjv.isSelected()));
796 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
797 Boolean.toString(pileupjv.isSelected()));
798 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
799 Boolean.toString(pirjv.isSelected()));
800 Cache.applicationProperties.setProperty("PIR_MODELLER",
801 Boolean.toString(modellerOutput.isSelected()));
802 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
803 Boolean.toString(embbedBioJSON.isSelected()));
804 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
806 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
807 Boolean.toString(autoIdWidth.isSelected()));
808 userIdWidth_actionPerformed();
809 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
810 userIdWidth.getText());
813 * Save Editing settings
815 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
816 Boolean.toString(autoCalculateConsCheck.isSelected()));
817 Cache.applicationProperties.setProperty("SORT_BY_TREE",
818 Boolean.toString(sortByTree.isSelected()));
819 Cache.applicationProperties.setProperty("PAD_GAPS",
820 Boolean.toString(padGaps.isSelected()));
822 dasSource.saveProperties(Cache.applicationProperties);
823 wsPrefs.updateAndRefreshWsMenuConfig(false);
824 Cache.saveProperties();
825 Desktop.instance.doConfigureStructurePrefs();
828 frame.setClosed(true);
829 } catch (Exception ex)
835 * Do any necessary validation before saving settings. Return focus to the
836 * first tab which fails validation.
840 private boolean validateSettings()
842 if (!validateStructure())
844 structureTab.requestFocusInWindow();
847 if (!validateHMMER())
849 hmmerTab.requestFocusInWindow();
856 protected boolean validateStructure()
858 return validateChimeraPath();
863 protected boolean validateHMMER()
865 return validateHMMERPath();
873 public void startupFileTextfield_mouseClicked()
875 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
876 JalviewFileChooser chooser = JalviewFileChooser.forRead(
877 Cache.getProperty("LAST_DIRECTORY"), fileFormat);
878 chooser.setFileView(new JalviewFileView());
879 chooser.setDialogTitle(MessageManager
880 .getString("label.select_startup_file"));
882 int value = chooser.showOpenDialog(this);
884 if (value == JalviewFileChooser.APPROVE_OPTION)
886 FileFormatI format = chooser.getSelectedFormat();
889 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
892 startupFileTextfield.setText(chooser.getSelectedFile()
904 public void cancel_actionPerformed(ActionEvent e)
908 wsPrefs.updateWsMenuConfig(true);
909 wsPrefs.refreshWs_actionPerformed(e);
910 frame.setClosed(true);
911 } catch (Exception ex)
923 public void annotations_actionPerformed(ActionEvent e)
925 conservation.setEnabled(annotations.isSelected());
926 quality.setEnabled(annotations.isSelected());
927 identity.setEnabled(annotations.isSelected());
928 showOccupancy.setEnabled(annotations.isSelected());
929 showGroupConsensus.setEnabled(annotations.isSelected());
930 showGroupConservation.setEnabled(annotations.isSelected());
931 showConsensHistogram.setEnabled(annotations.isSelected()
932 && (identity.isSelected() || showGroupConsensus.isSelected()));
933 showConsensLogo.setEnabled(annotations.isSelected()
934 && (identity.isSelected() || showGroupConsensus.isSelected()));
935 showInformationHistogram.setEnabled(annotations.isSelected());
936 showHMMLogo.setEnabled(annotations.isSelected());
940 public void newLink_actionPerformed(ActionEvent e)
942 GSequenceLink link = new GSequenceLink();
943 boolean valid = false;
946 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
947 MessageManager.getString("label.new_sequence_url_link"),
948 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
950 if (link.checkValid())
952 if (((UrlLinkTableModel) linkUrlTable.getModel())
953 .isUniqueName(link.getName()))
955 ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
956 link.getName(), link.getURL());
961 link.notifyDuplicate();
974 public void editLink_actionPerformed(ActionEvent e)
976 GSequenceLink link = new GSequenceLink();
978 int index = linkUrlTable.getSelectedRow();
981 // button no longer enabled if row is not selected
982 Cache.log.debug("Edit with no row selected in linkUrlTable");
986 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
988 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
990 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
991 link.setName(oldName);
992 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
994 boolean valid = false;
997 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
998 MessageManager.getString("label.edit_sequence_url_link"),
999 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
1001 if (link.checkValid())
1003 if ((oldName.equals(link.getName()))
1004 || (((UrlLinkTableModel) linkUrlTable.getModel())
1005 .isUniqueName(link.getName())))
1007 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1008 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1013 link.notifyDuplicate();
1026 public void deleteLink_actionPerformed(ActionEvent e)
1028 int index = linkUrlTable.getSelectedRow();
1029 int modelIndex = -1;
1032 // button no longer enabled if row is not selected
1033 Cache.log.debug("Delete with no row selected in linkUrlTable");
1038 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1041 // make sure we use the model index to delete, and not the table index
1042 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1047 public void defaultBrowser_mouseClicked(MouseEvent e)
1049 JFileChooser chooser = new JFileChooser(".");
1050 chooser.setDialogTitle(MessageManager
1051 .getString("label.select_default_browser"));
1053 int value = chooser.showOpenDialog(this);
1055 if (value == JFileChooser.APPROVE_OPTION)
1057 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1066 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1070 protected void showunconserved_actionPerformed(ActionEvent e)
1072 // TODO Auto-generated method stub
1073 super.showunconserved_actionPerformed(e);
1076 public static List<String> getGroupURLLinks()
1078 return groupURLLinks;
1082 public void minColour_actionPerformed(JPanel panel)
1084 Color col = JColorChooser.showDialog(this,
1085 MessageManager.getString("label.select_colour_minimum_value"),
1086 minColour.getBackground());
1089 panel.setBackground(col);
1095 public void maxColour_actionPerformed(JPanel panel)
1097 Color col = JColorChooser.showDialog(this,
1098 MessageManager.getString("label.select_colour_maximum_value"),
1099 maxColour.getBackground());
1102 panel.setBackground(col);
1108 protected void userIdWidth_actionPerformed()
1112 String val = userIdWidth.getText().trim();
1113 if (val.length() > 0)
1115 Integer iw = Integer.parseInt(val);
1116 if (iw.intValue() < 12)
1118 throw new NumberFormatException();
1120 userIdWidth.setText(iw.toString());
1122 } catch (NumberFormatException x)
1124 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
1125 .getString("warn.user_defined_width_requirements"),
1126 MessageManager.getString("label.invalid_id_column_width"),
1127 JvOptionPane.WARNING_MESSAGE);
1128 userIdWidth.setText("");
1133 protected void autoIdWidth_actionPerformed()
1135 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1136 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1140 * Returns true if chimera path is to a valid executable, else show an error
1143 private boolean validateChimeraPath()
1145 if (chimeraPath.getText().trim().length() > 0)
1147 File f = new File(chimeraPath.getText());
1148 if (!f.canExecute())
1150 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1151 MessageManager.getString("label.invalid_chimera_path"),
1152 MessageManager.getString("label.invalid_name"),
1153 JvOptionPane.ERROR_MESSAGE);
1161 * Returns true if hmmer path contains the necessary valid executables, else show an error
1164 private boolean validateHMMERPath()
1167 String message = "";
1168 String path = hmmerPath.getText();
1169 if (path.length() < 1)
1175 File f = new File(path);
1178 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1179 MessageManager.getString("label.folder_not_exists"),
1180 MessageManager.getString("label.invalid_folder"),
1181 JvOptionPane.ERROR_MESSAGE);
1185 File hmmbuild = new File(path + "/binaries/hmmbuild.exe");
1187 if (!hmmbuild.canExecute())
1189 message += MessageManager.getString("label.hmmbuild_not_found")
1195 File hmmalign = new File(path + "/binaries/hmmalign.exe");
1197 if (!hmmalign.canExecute())
1199 message += MessageManager.getString("label.hmmalign_not_found")
1205 File hmmsearch = new File(path + "/binaries/hmmsearch.exe");
1207 if (!hmmsearch.canExecute())
1209 message += MessageManager.getString("label.hmmsearch_not_found")
1219 JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1220 MessageManager.getString("label.invalid_folder"),
1221 JvOptionPane.ERROR_MESSAGE);
1226 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1227 MessageManager.getString("label.no_binaries"),
1228 MessageManager.getString("label.invalid_folder"),
1229 JvOptionPane.ERROR_MESSAGE);
1239 * If Chimera is selected, check it can be found on default or user-specified
1240 * path, if not show a warning/help dialog.
1243 protected void structureViewer_actionPerformed(String selectedItem)
1245 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1249 boolean found = false;
1252 * Try user-specified and standard paths for Chimera executable.
1254 List<String> paths = StructureManager.getChimeraPaths();
1255 paths.add(0, chimeraPath.getText());
1256 for (String path : paths)
1258 if (new File(path.trim()).canExecute())
1266 String[] options = { "OK", "Help" };
1267 int showHelp = JvOptionPane.showInternalOptionDialog(
1269 JvSwingUtils.wrapTooltip(true,
1270 MessageManager.getString("label.chimera_missing")),
1271 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1272 null, options, options[0]);
1273 if (showHelp == JvOptionPane.NO_OPTION)
1277 Help.showHelpWindow(HelpId.StructureViewer);
1278 } catch (HelpSetException e)
1280 e.printStackTrace();
1286 public class OptionsParam
1288 private String name;
1290 private String code;
1292 public OptionsParam(String name, String code)
1298 public String getName()
1303 public void setName(String name)
1308 public String getCode()
1313 public void setCode(String code)
1319 public String toString()
1325 public boolean equals(Object that)
1327 if (!(that instanceof OptionsParam))
1331 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1335 public int hashCode()
1337 return name.hashCode() + code.hashCode();
1341 private class UrlListSelectionHandler implements ListSelectionListener
1345 public void valueChanged(ListSelectionEvent e)
1347 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1349 int index = lsm.getMinSelectionIndex();
1352 // no selection, so disable delete/edit buttons
1353 editLink.setEnabled(false);
1354 deleteLink.setEnabled(false);
1357 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1359 // enable/disable edit and delete link buttons
1360 if (((UrlLinkTableModel) linkUrlTable.getModel())
1361 .isRowDeletable(modelIndex))
1363 deleteLink.setEnabled(true);
1367 deleteLink.setEnabled(false);
1370 if (((UrlLinkTableModel) linkUrlTable.getModel())
1371 .isRowEditable(modelIndex))
1373 editLink.setEnabled(true);
1377 editLink.setEnabled(false);