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 installationLocationField.setText(Cache.getProperty(HMMER_PATH));
220 * Set Visual tab defaults
222 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
223 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
224 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
225 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
227 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
228 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
229 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
230 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
232 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
233 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
234 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
236 showGroupConservation.setSelected(Cache.getDefault(
237 "SHOW_GROUP_CONSERVATION", false));
238 showConsensHistogram.setSelected(Cache.getDefault(
239 "SHOW_CONSENSUS_HISTOGRAM", true));
240 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
242 showInformationHistogram.setSelected(
243 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
244 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
245 showNpTooltip.setSelected(Cache
246 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
247 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
250 String[] fonts = java.awt.GraphicsEnvironment
251 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
252 for (int i = 0; i < fonts.length; i++)
254 fontNameCB.addItem(fonts[i]);
257 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
259 fontSizeCB.addItem(i + "");
262 fontStyleCB.addItem("plain");
263 fontStyleCB.addItem("bold");
264 fontStyleCB.addItem("italic");
266 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
267 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
268 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
271 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
272 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
275 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
277 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
279 gapSymbolCB.addItem("-");
280 gapSymbolCB.addItem(".");
282 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
284 sortby.addItem("No sort");
285 sortby.addItem("Id");
286 sortby.addItem("Pairwise Identity");
287 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
289 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
291 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
293 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
294 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
295 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
296 SequenceAnnotationOrder.NONE.name()));
297 sortAnnBy.setSelectedItem(savedSort.toString());
299 sortAutocalc.addItem("Autocalculated first");
300 sortAutocalc.addItem("Autocalculated last");
301 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
302 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
303 : sortAutocalc.getItemAt(1));
305 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
306 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
307 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
308 + "/examples/exampleFile_2_3.jar"));
311 * Set Colours tab defaults
313 protColour.addItem(ResidueColourScheme.NONE);
314 nucColour.addItem(ResidueColourScheme.NONE);
315 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
317 String name = cs.getSchemeName();
318 protColour.addItem(name);
319 nucColour.addItem(name);
321 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
322 ResidueColourScheme.NONE);
323 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
324 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
325 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
326 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
327 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
329 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
333 * Set Structure tab defaults.
335 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
336 structFromPdb.setSelected(structSelected);
337 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
338 useRnaView.setEnabled(structSelected);
339 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
340 addSecondaryStructure.setEnabled(structSelected);
341 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
342 addTempFactor.setEnabled(structSelected);
343 structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
344 ViewerType.JMOL.name()));
345 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
346 chimeraPath.addActionListener(new ActionListener()
349 public void actionPerformed(ActionEvent e)
351 validateChimeraPath();
355 if (Cache.getDefault("MAP_WITH_SIFTS", false))
357 siftsMapping.setSelected(true);
361 nwMapping.setSelected(true);
365 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
368 * Set Connections tab defaults
372 linkUrlTable.setModel(dataModel);
373 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
374 linkUrlTable.getModel());
375 linkUrlTable.setRowSorter(sorter);
376 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
378 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
379 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
380 SortOrder.DESCENDING));
381 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
382 SortOrder.DESCENDING));
383 sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
384 SortOrder.ASCENDING));
386 sorter.setSortKeys(sortKeys);
390 ActionListener onReset;
391 onReset = new ActionListener()
394 public void actionPerformed(ActionEvent e)
396 filterTB.setText("");
397 sorter.setRowFilter(RowFilter.regexFilter(""));
401 doReset.addActionListener(onReset);
403 // filter to display only custom urls
404 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
407 public boolean include(
408 Entry<? extends TableModel, ? extends Object> entry)
410 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
414 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
415 linkUrlTable.getModel());
416 customSorter.setRowFilter(customUrlFilter);
418 ActionListener onCustomOnly;
419 onCustomOnly = new ActionListener()
422 public void actionPerformed(ActionEvent e)
424 filterTB.setText("");
425 sorter.setRowFilter(customUrlFilter);
428 userOnly.addActionListener(onCustomOnly);
430 filterTB.getDocument().addDocumentListener(new DocumentListener()
432 String caseInsensitiveFlag = "(?i)";
435 public void changedUpdate(DocumentEvent e)
437 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
438 + filterTB.getText()));
442 public void removeUpdate(DocumentEvent e)
444 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
445 + filterTB.getText()));
449 public void insertUpdate(DocumentEvent e)
451 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
452 + filterTB.getText()));
456 // set up list selection functionality
457 linkUrlTable.getSelectionModel().addListSelectionListener(
458 new UrlListSelectionHandler());
460 // set up radio buttons
461 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
463 String onClickName = linkUrlTable.getColumnName(onClickCol);
464 linkUrlTable.getColumn(onClickName).setCellRenderer(
465 new RadioButtonRenderer());
466 linkUrlTable.getColumn(onClickName)
467 .setCellEditor(new RadioButtonEditor());
469 // get boolean columns and resize those to min possible
470 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
472 if (linkUrlTable.getModel().getColumnClass(column)
473 .equals(Boolean.class))
475 TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
477 int preferredWidth = tableColumn.getMinWidth();
479 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
481 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
482 int cwidth = c.getPreferredSize().width
483 + linkUrlTable.getIntercellSpacing().width;
484 preferredWidth = Math.max(preferredWidth, cwidth);
486 tableColumn.setPreferredWidth(preferredWidth);
490 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
491 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
492 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
493 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
495 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
497 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
498 // note antisense here: default is true
500 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
501 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
504 * Set Output tab defaults
506 epsRendering.addItem(promptEachTimeOpt);
507 epsRendering.addItem(lineArtOpt);
508 epsRendering.addItem(textOpt);
509 String defaultEPS = Cache.getDefault("EPS_RENDERING",
511 if (defaultEPS.equalsIgnoreCase("Text"))
513 epsRendering.setSelectedItem(textOpt);
515 else if (defaultEPS.equalsIgnoreCase("Lineart"))
517 epsRendering.setSelectedItem(lineArtOpt);
521 epsRendering.setSelectedItem(promptEachTimeOpt);
523 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
524 userIdWidth.setEnabled(!autoIdWidth.isSelected());
525 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
526 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
527 userIdWidth.setText(wi == null ? "" : wi.toString());
528 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
529 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
530 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
531 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
532 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
533 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
534 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
535 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
536 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
540 * Set Editing tab defaults
542 autoCalculateConsCheck.setSelected(Cache.getDefault(
543 "AUTO_CALC_CONSENSUS", true));
544 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
545 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
547 annotations_actionPerformed(null); // update the display of the annotation
552 * Save user selections on the Preferences tabs to the Cache and write out to
558 public void ok_actionPerformed(ActionEvent e)
560 if (!validateSettings())
566 * Save Visual settings
568 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
569 Boolean.toString(seqLimit.isSelected()));
570 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
571 Boolean.toString(rightAlign.isSelected()));
572 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
573 Boolean.toString(fullScreen.isSelected()));
574 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
575 Boolean.toString(openoverv.isSelected()));
576 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
577 Boolean.toString(annotations.isSelected()));
578 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
579 Boolean.toString(conservation.isSelected()));
580 Cache.applicationProperties.setProperty("SHOW_QUALITY",
581 Boolean.toString(quality.isSelected()));
582 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
583 Boolean.toString(identity.isSelected()));
585 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
586 .getSelectedItem().toString());
588 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
589 .getSelectedItem().toString());
590 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
591 .getSelectedItem().toString());
592 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
593 .getSelectedItem().toString());
595 Cache.applicationProperties.setProperty("ID_ITALICS",
596 Boolean.toString(idItalics.isSelected()));
597 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
598 Boolean.toString(showUnconserved.isSelected()));
599 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
600 Boolean.toString(showOccupancy.isSelected()));
601 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
602 Boolean.toString(showGroupConsensus.isSelected()));
603 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
604 Boolean.toString(showGroupConservation.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
606 Boolean.toString(showConsensHistogram.isSelected()));
607 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
608 Boolean.toString(showConsensLogo.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
610 Boolean.toString(showConsensHistogram.isSelected()));
611 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
612 Boolean.toString(showHMMLogo.isSelected()));
613 Cache.applicationProperties.setProperty("ANTI_ALIAS",
614 Boolean.toString(smoothFont.isSelected()));
615 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
616 Boolean.toString(scaleProteinToCdna.isSelected()));
617 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
618 Boolean.toString(showNpTooltip.isSelected()));
619 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
620 Boolean.toString(showDbRefTooltip.isSelected()));
622 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
623 Boolean.toString(wrap.isSelected()));
625 Cache.applicationProperties.setProperty("STARTUP_FILE",
626 startupFileTextfield.getText());
627 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
628 Boolean.toString(startupCheckbox.isSelected()));
630 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
631 .getSelectedItem().toString());
633 // convert description of sort order to enum name for save
634 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
635 .forDescription(sortAnnBy.getSelectedItem().toString());
636 if (annSortOrder != null)
638 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
639 annSortOrder.name());
642 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
643 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
644 .valueOf(showAutocalcFirst).toString());
647 * Save Colours settings
649 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
650 .getSelectedItem().toString());
651 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
652 .getSelectedItem().toString());
653 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
654 minColour.getBackground());
655 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
656 maxColour.getBackground());
659 * Save HMMER settings
661 Cache.applicationProperties.setProperty("TRIM_TERMINI",
662 Boolean.toString(trimTermini.isSelected()));
663 Cache.applicationProperties.setProperty("USE_UNIPROT",
664 Boolean.toString(uniprot.isSelected()));
665 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
666 numberOfSequencesToKeepField.getText());
667 Cache.applicationProperties.setProperty(HMMER_PATH,
668 installationLocationField.getText());
669 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
670 if (Cache.getDefault("USE_UNIPROT", false))
672 uniprot.setSelected(true);
676 alignment.setSelected(true);
678 numberOfSequencesToKeepField
679 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
680 installationLocationField.setText(Cache.getProperty(HMMER_PATH));
683 * Save Structure settings
685 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
686 Boolean.toString(addTempFactor.isSelected()));
687 Cache.applicationProperties.setProperty(ADD_SS_ANN,
688 Boolean.toString(addSecondaryStructure.isSelected()));
689 Cache.applicationProperties.setProperty(USE_RNAVIEW,
690 Boolean.toString(useRnaView.isSelected()));
691 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
692 Boolean.toString(structFromPdb.isSelected()));
693 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
694 .getSelectedItem().toString());
695 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
696 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
697 Boolean.toString(siftsMapping.isSelected()));
698 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
701 * Save Output settings
703 Cache.applicationProperties.setProperty("EPS_RENDERING",
704 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
707 * Save Connections settings
709 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
711 jalview.util.BrowserLauncher.resetBrowser();
713 // save user-defined and selected links
714 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
715 if (menuLinks.isEmpty())
717 Cache.applicationProperties.remove("SEQUENCE_LINKS");
721 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
722 menuLinks.toString());
725 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
726 if (nonMenuLinks.isEmpty())
728 Cache.applicationProperties.remove("STORED_LINKS");
732 Cache.applicationProperties.setProperty("STORED_LINKS",
733 nonMenuLinks.toString());
736 Cache.applicationProperties.setProperty("DEFAULT_URL",
737 sequenceUrlLinks.getPrimaryUrlId());
739 Cache.applicationProperties.setProperty("USE_PROXY",
740 Boolean.toString(useProxy.isSelected()));
742 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
744 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
746 if (useProxy.isSelected())
748 System.setProperty("http.proxyHost", proxyServerTB.getText());
749 System.setProperty("http.proxyPort", proxyPortTB.getText());
753 System.setProperty("http.proxyHost", "");
754 System.setProperty("http.proxyPort", "");
756 Cache.setProperty("VERSION_CHECK",
757 Boolean.toString(versioncheck.isSelected()));
758 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
760 // default is false - we only set this if the user has actively agreed
761 Cache.setProperty("USAGESTATS",
762 Boolean.toString(usagestats.isSelected()));
764 if (!questionnaire.isSelected())
766 Cache.setProperty("NOQUESTIONNAIRES", "true");
770 // special - made easy to edit a property file to disable questionnaires
771 // by just adding the given line
772 Cache.removeProperty("NOQUESTIONNAIRES");
776 * Save Output settings
778 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
779 Boolean.toString(blcjv.isSelected()));
780 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
781 Boolean.toString(clustaljv.isSelected()));
782 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
783 Boolean.toString(fastajv.isSelected()));
784 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
785 Boolean.toString(msfjv.isSelected()));
786 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
787 Boolean.toString(pfamjv.isSelected()));
788 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
789 Boolean.toString(pileupjv.isSelected()));
790 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
791 Boolean.toString(pirjv.isSelected()));
792 Cache.applicationProperties.setProperty("PIR_MODELLER",
793 Boolean.toString(modellerOutput.isSelected()));
794 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
795 Boolean.toString(embbedBioJSON.isSelected()));
796 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
798 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
799 Boolean.toString(autoIdWidth.isSelected()));
800 userIdWidth_actionPerformed();
801 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
802 userIdWidth.getText());
805 * Save Editing settings
807 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
808 Boolean.toString(autoCalculateConsCheck.isSelected()));
809 Cache.applicationProperties.setProperty("SORT_BY_TREE",
810 Boolean.toString(sortByTree.isSelected()));
811 Cache.applicationProperties.setProperty("PAD_GAPS",
812 Boolean.toString(padGaps.isSelected()));
814 dasSource.saveProperties(Cache.applicationProperties);
815 wsPrefs.updateAndRefreshWsMenuConfig(false);
816 Cache.saveProperties();
817 Desktop.instance.doConfigureStructurePrefs();
820 frame.setClosed(true);
821 } catch (Exception ex)
827 * Do any necessary validation before saving settings. Return focus to the
828 * first tab which fails validation.
832 private boolean validateSettings()
834 if (!validateStructure())
836 structureTab.requestFocusInWindow();
843 protected boolean validateStructure()
845 return validateChimeraPath();
853 public void startupFileTextfield_mouseClicked()
855 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
856 JalviewFileChooser chooser = JalviewFileChooser.forRead(
857 Cache.getProperty("LAST_DIRECTORY"), fileFormat);
858 chooser.setFileView(new JalviewFileView());
859 chooser.setDialogTitle(MessageManager
860 .getString("label.select_startup_file"));
862 int value = chooser.showOpenDialog(this);
864 if (value == JalviewFileChooser.APPROVE_OPTION)
866 FileFormatI format = chooser.getSelectedFormat();
869 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
872 startupFileTextfield.setText(chooser.getSelectedFile()
884 public void cancel_actionPerformed(ActionEvent e)
888 wsPrefs.updateWsMenuConfig(true);
889 wsPrefs.refreshWs_actionPerformed(e);
890 frame.setClosed(true);
891 } catch (Exception ex)
903 public void annotations_actionPerformed(ActionEvent e)
905 conservation.setEnabled(annotations.isSelected());
906 quality.setEnabled(annotations.isSelected());
907 identity.setEnabled(annotations.isSelected());
908 showOccupancy.setEnabled(annotations.isSelected());
909 showGroupConsensus.setEnabled(annotations.isSelected());
910 showGroupConservation.setEnabled(annotations.isSelected());
911 showConsensHistogram.setEnabled(annotations.isSelected()
912 && (identity.isSelected() || showGroupConsensus.isSelected()));
913 showConsensLogo.setEnabled(annotations.isSelected()
914 && (identity.isSelected() || showGroupConsensus.isSelected()));
915 showInformationHistogram.setEnabled(annotations.isSelected());
916 showHMMLogo.setEnabled(annotations.isSelected());
920 public void newLink_actionPerformed(ActionEvent e)
922 GSequenceLink link = new GSequenceLink();
923 boolean valid = false;
926 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
927 MessageManager.getString("label.new_sequence_url_link"),
928 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
930 if (link.checkValid())
932 if (((UrlLinkTableModel) linkUrlTable.getModel())
933 .isUniqueName(link.getName()))
935 ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
936 link.getName(), link.getURL());
941 link.notifyDuplicate();
954 public void editLink_actionPerformed(ActionEvent e)
956 GSequenceLink link = new GSequenceLink();
958 int index = linkUrlTable.getSelectedRow();
961 // button no longer enabled if row is not selected
962 Cache.log.debug("Edit with no row selected in linkUrlTable");
966 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
968 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
970 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
971 link.setName(oldName);
972 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
974 boolean valid = false;
977 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
978 MessageManager.getString("label.edit_sequence_url_link"),
979 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
981 if (link.checkValid())
983 if ((oldName.equals(link.getName()))
984 || (((UrlLinkTableModel) linkUrlTable.getModel())
985 .isUniqueName(link.getName())))
987 linkUrlTable.setValueAt(link.getName(), index, nameCol);
988 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
993 link.notifyDuplicate();
1006 public void deleteLink_actionPerformed(ActionEvent e)
1008 int index = linkUrlTable.getSelectedRow();
1009 int modelIndex = -1;
1012 // button no longer enabled if row is not selected
1013 Cache.log.debug("Delete with no row selected in linkUrlTable");
1018 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1021 // make sure we use the model index to delete, and not the table index
1022 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1027 public void defaultBrowser_mouseClicked(MouseEvent e)
1029 JFileChooser chooser = new JFileChooser(".");
1030 chooser.setDialogTitle(MessageManager
1031 .getString("label.select_default_browser"));
1033 int value = chooser.showOpenDialog(this);
1035 if (value == JFileChooser.APPROVE_OPTION)
1037 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1046 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1050 protected void showunconserved_actionPerformed(ActionEvent e)
1052 // TODO Auto-generated method stub
1053 super.showunconserved_actionPerformed(e);
1056 public static List<String> getGroupURLLinks()
1058 return groupURLLinks;
1062 public void minColour_actionPerformed(JPanel panel)
1064 Color col = JColorChooser.showDialog(this,
1065 MessageManager.getString("label.select_colour_minimum_value"),
1066 minColour.getBackground());
1069 panel.setBackground(col);
1075 public void maxColour_actionPerformed(JPanel panel)
1077 Color col = JColorChooser.showDialog(this,
1078 MessageManager.getString("label.select_colour_maximum_value"),
1079 maxColour.getBackground());
1082 panel.setBackground(col);
1088 protected void userIdWidth_actionPerformed()
1092 String val = userIdWidth.getText().trim();
1093 if (val.length() > 0)
1095 Integer iw = Integer.parseInt(val);
1096 if (iw.intValue() < 12)
1098 throw new NumberFormatException();
1100 userIdWidth.setText(iw.toString());
1102 } catch (NumberFormatException x)
1104 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
1105 .getString("warn.user_defined_width_requirements"),
1106 MessageManager.getString("label.invalid_id_column_width"),
1107 JvOptionPane.WARNING_MESSAGE);
1108 userIdWidth.setText("");
1113 protected void autoIdWidth_actionPerformed()
1115 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1116 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1120 * Returns true if chimera path is to a valid executable, else show an error
1123 private boolean validateChimeraPath()
1125 if (chimeraPath.getText().trim().length() > 0)
1127 File f = new File(chimeraPath.getText());
1128 if (!f.canExecute())
1130 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1131 MessageManager.getString("label.invalid_chimera_path"),
1132 MessageManager.getString("label.invalid_name"),
1133 JvOptionPane.ERROR_MESSAGE);
1141 * Returns true if hmmer path contains the necessary valid executables, else show an error
1144 private boolean validateHMMERPath()
1146 String path = Cache.getProperty("HMMERPATH");
1147 if (path.length() > 0)
1149 File f = new File(path);
1150 if (!f.canExecute())
1152 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1153 MessageManager.getString("label.invalid_hmmer_folder"),
1154 MessageManager.getString("Invalid folder"),
1155 JvOptionPane.ERROR_MESSAGE);
1163 * If Chimera is selected, check it can be found on default or user-specified
1164 * path, if not show a warning/help dialog.
1167 protected void structureViewer_actionPerformed(String selectedItem)
1169 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1173 boolean found = false;
1176 * Try user-specified and standard paths for Chimera executable.
1178 List<String> paths = StructureManager.getChimeraPaths();
1179 paths.add(0, chimeraPath.getText());
1180 for (String path : paths)
1182 if (new File(path.trim()).canExecute())
1190 String[] options = { "OK", "Help" };
1191 int showHelp = JvOptionPane.showInternalOptionDialog(
1193 JvSwingUtils.wrapTooltip(true,
1194 MessageManager.getString("label.chimera_missing")),
1195 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1196 null, options, options[0]);
1197 if (showHelp == JvOptionPane.NO_OPTION)
1201 Help.showHelpWindow(HelpId.StructureViewer);
1202 } catch (HelpSetException e)
1204 e.printStackTrace();
1210 public class OptionsParam
1212 private String name;
1214 private String code;
1216 public OptionsParam(String name, String code)
1222 public String getName()
1227 public void setName(String name)
1232 public String getCode()
1237 public void setCode(String code)
1243 public String toString()
1249 public boolean equals(Object that)
1251 if (!(that instanceof OptionsParam))
1255 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1259 public int hashCode()
1261 return name.hashCode() + code.hashCode();
1265 private class UrlListSelectionHandler implements ListSelectionListener
1269 public void valueChanged(ListSelectionEvent e)
1271 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1273 int index = lsm.getMinSelectionIndex();
1276 // no selection, so disable delete/edit buttons
1277 editLink.setEnabled(false);
1278 deleteLink.setEnabled(false);
1281 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1283 // enable/disable edit and delete link buttons
1284 if (((UrlLinkTableModel) linkUrlTable.getModel())
1285 .isRowDeletable(modelIndex))
1287 deleteLink.setEnabled(true);
1291 deleteLink.setEnabled(false);
1294 if (((UrlLinkTableModel) linkUrlTable.getModel())
1295 .isRowEditable(modelIndex))
1297 editLink.setEnabled(true);
1301 editLink.setEnabled(false);