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));
208 .setSelected(Cache.getDefault("HMMER_INSTALLED", false));
209 if (Cache.getDefault("USE_UNIPROT", false))
211 uniprot.setSelected(true);
215 alignment.setSelected(true);
217 numberOfSequencesToKeepField
218 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
219 installationLocation.setEnabled(isHMMERInstalled.isSelected());
220 hmmerPath.setEnabled(isHMMERInstalled.isSelected());
221 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
222 hmmerPath.addActionListener(new ActionListener()
225 public void actionPerformed(ActionEvent e)
232 * Set Visual tab defaults
234 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
235 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
236 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
237 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
239 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
240 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
241 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
242 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
244 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
245 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
246 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
248 showGroupConservation.setSelected(Cache.getDefault(
249 "SHOW_GROUP_CONSERVATION", false));
250 showConsensHistogram.setSelected(Cache.getDefault(
251 "SHOW_CONSENSUS_HISTOGRAM", true));
252 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
254 showInformationHistogram.setSelected(
255 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
256 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
257 showNpTooltip.setSelected(Cache
258 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
259 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
262 String[] fonts = java.awt.GraphicsEnvironment
263 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
264 for (int i = 0; i < fonts.length; i++)
266 fontNameCB.addItem(fonts[i]);
269 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
271 fontSizeCB.addItem(i + "");
274 fontStyleCB.addItem("plain");
275 fontStyleCB.addItem("bold");
276 fontStyleCB.addItem("italic");
278 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
279 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
280 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
283 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
284 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
287 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
289 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
291 gapSymbolCB.addItem("-");
292 gapSymbolCB.addItem(".");
294 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
296 sortby.addItem("No sort");
297 sortby.addItem("Id");
298 sortby.addItem("Pairwise Identity");
299 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
301 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
303 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
305 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
306 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
307 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
308 SequenceAnnotationOrder.NONE.name()));
309 sortAnnBy.setSelectedItem(savedSort.toString());
311 sortAutocalc.addItem("Autocalculated first");
312 sortAutocalc.addItem("Autocalculated last");
313 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
314 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
315 : sortAutocalc.getItemAt(1));
317 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
318 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
319 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
320 + "/examples/exampleFile_2_3.jar"));
323 * Set Colours tab defaults
325 protColour.addItem(ResidueColourScheme.NONE);
326 nucColour.addItem(ResidueColourScheme.NONE);
327 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
329 String name = cs.getSchemeName();
330 protColour.addItem(name);
331 nucColour.addItem(name);
333 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
334 ResidueColourScheme.NONE);
335 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
336 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
337 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
338 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
339 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
341 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
345 * Set Structure tab defaults.
347 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
348 structFromPdb.setSelected(structSelected);
349 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
350 useRnaView.setEnabled(structSelected);
351 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
352 addSecondaryStructure.setEnabled(structSelected);
353 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
354 addTempFactor.setEnabled(structSelected);
355 structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
356 ViewerType.JMOL.name()));
357 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
358 chimeraPath.addActionListener(new ActionListener()
361 public void actionPerformed(ActionEvent e)
363 validateChimeraPath();
367 if (Cache.getDefault("MAP_WITH_SIFTS", false))
369 siftsMapping.setSelected(true);
373 nwMapping.setSelected(true);
377 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
380 * Set Connections tab defaults
384 linkUrlTable.setModel(dataModel);
385 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
386 linkUrlTable.getModel());
387 linkUrlTable.setRowSorter(sorter);
388 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
390 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
391 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
392 SortOrder.DESCENDING));
393 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
394 SortOrder.DESCENDING));
395 sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
396 SortOrder.ASCENDING));
398 sorter.setSortKeys(sortKeys);
402 ActionListener onReset;
403 onReset = new ActionListener()
406 public void actionPerformed(ActionEvent e)
408 filterTB.setText("");
409 sorter.setRowFilter(RowFilter.regexFilter(""));
413 doReset.addActionListener(onReset);
415 // filter to display only custom urls
416 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
419 public boolean include(
420 Entry<? extends TableModel, ? extends Object> entry)
422 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
426 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
427 linkUrlTable.getModel());
428 customSorter.setRowFilter(customUrlFilter);
430 ActionListener onCustomOnly;
431 onCustomOnly = new ActionListener()
434 public void actionPerformed(ActionEvent e)
436 filterTB.setText("");
437 sorter.setRowFilter(customUrlFilter);
440 userOnly.addActionListener(onCustomOnly);
442 filterTB.getDocument().addDocumentListener(new DocumentListener()
444 String caseInsensitiveFlag = "(?i)";
447 public void changedUpdate(DocumentEvent e)
449 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
450 + filterTB.getText()));
454 public void removeUpdate(DocumentEvent e)
456 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
457 + filterTB.getText()));
461 public void insertUpdate(DocumentEvent e)
463 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
464 + filterTB.getText()));
468 // set up list selection functionality
469 linkUrlTable.getSelectionModel().addListSelectionListener(
470 new UrlListSelectionHandler());
472 // set up radio buttons
473 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
475 String onClickName = linkUrlTable.getColumnName(onClickCol);
476 linkUrlTable.getColumn(onClickName).setCellRenderer(
477 new RadioButtonRenderer());
478 linkUrlTable.getColumn(onClickName)
479 .setCellEditor(new RadioButtonEditor());
481 // get boolean columns and resize those to min possible
482 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
484 if (linkUrlTable.getModel().getColumnClass(column)
485 .equals(Boolean.class))
487 TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
489 int preferredWidth = tableColumn.getMinWidth();
491 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
493 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
494 int cwidth = c.getPreferredSize().width
495 + linkUrlTable.getIntercellSpacing().width;
496 preferredWidth = Math.max(preferredWidth, cwidth);
498 tableColumn.setPreferredWidth(preferredWidth);
502 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
503 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
504 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
505 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
507 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
509 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
510 // note antisense here: default is true
512 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
513 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
516 * Set Output tab defaults
518 epsRendering.addItem(promptEachTimeOpt);
519 epsRendering.addItem(lineArtOpt);
520 epsRendering.addItem(textOpt);
521 String defaultEPS = Cache.getDefault("EPS_RENDERING",
523 if (defaultEPS.equalsIgnoreCase("Text"))
525 epsRendering.setSelectedItem(textOpt);
527 else if (defaultEPS.equalsIgnoreCase("Lineart"))
529 epsRendering.setSelectedItem(lineArtOpt);
533 epsRendering.setSelectedItem(promptEachTimeOpt);
535 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
536 userIdWidth.setEnabled(!autoIdWidth.isSelected());
537 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
538 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
539 userIdWidth.setText(wi == null ? "" : wi.toString());
540 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
541 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
542 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
543 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
544 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
545 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
546 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
547 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
548 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
552 * Set Editing tab defaults
554 autoCalculateConsCheck.setSelected(Cache.getDefault(
555 "AUTO_CALC_CONSENSUS", true));
556 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
557 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
559 annotations_actionPerformed(null); // update the display of the annotation
564 * Save user selections on the Preferences tabs to the Cache and write out to
570 public void ok_actionPerformed(ActionEvent e)
572 if (!validateSettings())
578 * Save Visual settings
580 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
581 Boolean.toString(seqLimit.isSelected()));
582 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
583 Boolean.toString(rightAlign.isSelected()));
584 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
585 Boolean.toString(fullScreen.isSelected()));
586 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
587 Boolean.toString(openoverv.isSelected()));
588 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
589 Boolean.toString(annotations.isSelected()));
590 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
591 Boolean.toString(conservation.isSelected()));
592 Cache.applicationProperties.setProperty("SHOW_QUALITY",
593 Boolean.toString(quality.isSelected()));
594 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
595 Boolean.toString(identity.isSelected()));
597 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
598 .getSelectedItem().toString());
600 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
601 .getSelectedItem().toString());
602 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
603 .getSelectedItem().toString());
604 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
605 .getSelectedItem().toString());
607 Cache.applicationProperties.setProperty("ID_ITALICS",
608 Boolean.toString(idItalics.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
610 Boolean.toString(showUnconserved.isSelected()));
611 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
612 Boolean.toString(showOccupancy.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
614 Boolean.toString(showGroupConsensus.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
616 Boolean.toString(showGroupConservation.isSelected()));
617 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
618 Boolean.toString(showConsensHistogram.isSelected()));
619 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
620 Boolean.toString(showConsensLogo.isSelected()));
621 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
622 Boolean.toString(showConsensHistogram.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
624 Boolean.toString(showHMMLogo.isSelected()));
625 Cache.applicationProperties.setProperty("ANTI_ALIAS",
626 Boolean.toString(smoothFont.isSelected()));
627 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
628 Boolean.toString(scaleProteinToCdna.isSelected()));
629 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
630 Boolean.toString(showNpTooltip.isSelected()));
631 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
632 Boolean.toString(showDbRefTooltip.isSelected()));
634 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
635 Boolean.toString(wrap.isSelected()));
637 Cache.applicationProperties.setProperty("STARTUP_FILE",
638 startupFileTextfield.getText());
639 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
640 Boolean.toString(startupCheckbox.isSelected()));
642 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
643 .getSelectedItem().toString());
645 // convert description of sort order to enum name for save
646 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
647 .forDescription(sortAnnBy.getSelectedItem().toString());
648 if (annSortOrder != null)
650 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
651 annSortOrder.name());
654 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
655 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
656 .valueOf(showAutocalcFirst).toString());
659 * Save Colours settings
661 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
662 .getSelectedItem().toString());
663 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
664 .getSelectedItem().toString());
665 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
666 minColour.getBackground());
667 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
668 maxColour.getBackground());
671 * Save HMMER settings
673 Cache.applicationProperties.setProperty("TRIM_TERMINI",
674 Boolean.toString(trimTermini.isSelected()));
675 Cache.applicationProperties.setProperty("USE_UNIPROT",
676 Boolean.toString(uniprot.isSelected()));
677 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
678 numberOfSequencesToKeepField.getText());
679 Cache.applicationProperties.setProperty(HMMER_PATH,
680 hmmerPath.getText());
681 boolean hmmerInstalled = isHMMERInstalled.isSelected();
682 Cache.applicationProperties.setProperty("HMMER_INSTALLED",
683 Boolean.toString(hmmerInstalled));
684 boolean hmmerFunctioning = validateHMMERPath(false);
685 Cache.applicationProperties.setProperty("HMMER_FUNCTIONING",
686 Boolean.toString(hmmerFunctioning));
687 AlignFrame[] frames = Desktop.getAlignFrames();
688 boolean hmmerStatus = hmmerFunctioning && hmmerInstalled ? true : false;
689 for (AlignFrame frame : frames)
691 frame.updateHMMERStatus(hmmerStatus);
695 trimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
696 if (Cache.getDefault("USE_UNIPROT", false))
698 uniprot.setSelected(true);
702 alignment.setSelected(true);
704 numberOfSequencesToKeepField
705 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
706 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
709 * Save Structure settings
711 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
712 Boolean.toString(addTempFactor.isSelected()));
713 Cache.applicationProperties.setProperty(ADD_SS_ANN,
714 Boolean.toString(addSecondaryStructure.isSelected()));
715 Cache.applicationProperties.setProperty(USE_RNAVIEW,
716 Boolean.toString(useRnaView.isSelected()));
717 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
718 Boolean.toString(structFromPdb.isSelected()));
719 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
720 .getSelectedItem().toString());
721 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
722 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
723 Boolean.toString(siftsMapping.isSelected()));
724 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
727 * Save Output settings
729 Cache.applicationProperties.setProperty("EPS_RENDERING",
730 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
733 * Save Connections settings
735 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
737 jalview.util.BrowserLauncher.resetBrowser();
739 // save user-defined and selected links
740 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
741 if (menuLinks.isEmpty())
743 Cache.applicationProperties.remove("SEQUENCE_LINKS");
747 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
748 menuLinks.toString());
751 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
752 if (nonMenuLinks.isEmpty())
754 Cache.applicationProperties.remove("STORED_LINKS");
758 Cache.applicationProperties.setProperty("STORED_LINKS",
759 nonMenuLinks.toString());
762 Cache.applicationProperties.setProperty("DEFAULT_URL",
763 sequenceUrlLinks.getPrimaryUrlId());
765 Cache.applicationProperties.setProperty("USE_PROXY",
766 Boolean.toString(useProxy.isSelected()));
768 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
770 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
772 if (useProxy.isSelected())
774 System.setProperty("http.proxyHost", proxyServerTB.getText());
775 System.setProperty("http.proxyPort", proxyPortTB.getText());
779 System.setProperty("http.proxyHost", "");
780 System.setProperty("http.proxyPort", "");
782 Cache.setProperty("VERSION_CHECK",
783 Boolean.toString(versioncheck.isSelected()));
784 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
786 // default is false - we only set this if the user has actively agreed
787 Cache.setProperty("USAGESTATS",
788 Boolean.toString(usagestats.isSelected()));
790 if (!questionnaire.isSelected())
792 Cache.setProperty("NOQUESTIONNAIRES", "true");
796 // special - made easy to edit a property file to disable questionnaires
797 // by just adding the given line
798 Cache.removeProperty("NOQUESTIONNAIRES");
802 * Save Output settings
804 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
805 Boolean.toString(blcjv.isSelected()));
806 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
807 Boolean.toString(clustaljv.isSelected()));
808 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
809 Boolean.toString(fastajv.isSelected()));
810 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
811 Boolean.toString(msfjv.isSelected()));
812 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
813 Boolean.toString(pfamjv.isSelected()));
814 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
815 Boolean.toString(pileupjv.isSelected()));
816 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
817 Boolean.toString(pirjv.isSelected()));
818 Cache.applicationProperties.setProperty("PIR_MODELLER",
819 Boolean.toString(modellerOutput.isSelected()));
820 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
821 Boolean.toString(embbedBioJSON.isSelected()));
822 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
824 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
825 Boolean.toString(autoIdWidth.isSelected()));
826 userIdWidth_actionPerformed();
827 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
828 userIdWidth.getText());
831 * Save Editing settings
833 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
834 Boolean.toString(autoCalculateConsCheck.isSelected()));
835 Cache.applicationProperties.setProperty("SORT_BY_TREE",
836 Boolean.toString(sortByTree.isSelected()));
837 Cache.applicationProperties.setProperty("PAD_GAPS",
838 Boolean.toString(padGaps.isSelected()));
840 dasSource.saveProperties(Cache.applicationProperties);
841 wsPrefs.updateAndRefreshWsMenuConfig(false);
842 Cache.saveProperties();
843 Desktop.instance.doConfigureStructurePrefs();
846 frame.setClosed(true);
847 } catch (Exception ex)
853 * Do any necessary validation before saving settings. Return focus to the
854 * first tab which fails validation.
858 private boolean validateSettings()
860 if (!validateStructure())
862 structureTab.requestFocusInWindow();
865 if (isHMMERInstalled.isSelected())
867 if (!validateHMMER())
869 hmmerTab.requestFocusInWindow();
877 protected boolean validateStructure()
879 return validateChimeraPath();
884 protected boolean validateHMMER()
886 return validateHMMERPath();
894 public void startupFileTextfield_mouseClicked()
896 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
897 JalviewFileChooser chooser = JalviewFileChooser.forRead(
898 Cache.getProperty("LAST_DIRECTORY"), fileFormat);
899 chooser.setFileView(new JalviewFileView());
900 chooser.setDialogTitle(MessageManager
901 .getString("label.select_startup_file"));
903 int value = chooser.showOpenDialog(this);
905 if (value == JalviewFileChooser.APPROVE_OPTION)
907 FileFormatI format = chooser.getSelectedFormat();
910 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
913 startupFileTextfield.setText(chooser.getSelectedFile()
925 public void cancel_actionPerformed(ActionEvent e)
929 wsPrefs.updateWsMenuConfig(true);
930 wsPrefs.refreshWs_actionPerformed(e);
931 frame.setClosed(true);
932 } catch (Exception ex)
944 public void annotations_actionPerformed(ActionEvent e)
946 conservation.setEnabled(annotations.isSelected());
947 quality.setEnabled(annotations.isSelected());
948 identity.setEnabled(annotations.isSelected());
949 showOccupancy.setEnabled(annotations.isSelected());
950 showGroupConsensus.setEnabled(annotations.isSelected());
951 showGroupConservation.setEnabled(annotations.isSelected());
952 showConsensHistogram.setEnabled(annotations.isSelected()
953 && (identity.isSelected() || showGroupConsensus.isSelected()));
954 showConsensLogo.setEnabled(annotations.isSelected()
955 && (identity.isSelected() || showGroupConsensus.isSelected()));
956 showInformationHistogram.setEnabled(annotations.isSelected());
957 showHMMLogo.setEnabled(annotations.isSelected());
961 public void newLink_actionPerformed(ActionEvent e)
963 GSequenceLink link = new GSequenceLink();
964 boolean valid = false;
967 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
968 MessageManager.getString("label.new_sequence_url_link"),
969 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
971 if (link.checkValid())
973 if (((UrlLinkTableModel) linkUrlTable.getModel())
974 .isUniqueName(link.getName()))
976 ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
977 link.getName(), link.getURL());
982 link.notifyDuplicate();
995 public void editLink_actionPerformed(ActionEvent e)
997 GSequenceLink link = new GSequenceLink();
999 int index = linkUrlTable.getSelectedRow();
1002 // button no longer enabled if row is not selected
1003 Cache.log.debug("Edit with no row selected in linkUrlTable");
1007 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1009 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1011 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1012 link.setName(oldName);
1013 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1015 boolean valid = false;
1018 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1019 MessageManager.getString("label.edit_sequence_url_link"),
1020 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
1022 if (link.checkValid())
1024 if ((oldName.equals(link.getName()))
1025 || (((UrlLinkTableModel) linkUrlTable.getModel())
1026 .isUniqueName(link.getName())))
1028 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1029 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1034 link.notifyDuplicate();
1047 public void deleteLink_actionPerformed(ActionEvent e)
1049 int index = linkUrlTable.getSelectedRow();
1050 int modelIndex = -1;
1053 // button no longer enabled if row is not selected
1054 Cache.log.debug("Delete with no row selected in linkUrlTable");
1059 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1062 // make sure we use the model index to delete, and not the table index
1063 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1068 public void defaultBrowser_mouseClicked(MouseEvent e)
1070 JFileChooser chooser = new JFileChooser(".");
1071 chooser.setDialogTitle(MessageManager
1072 .getString("label.select_default_browser"));
1074 int value = chooser.showOpenDialog(this);
1076 if (value == JFileChooser.APPROVE_OPTION)
1078 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1087 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1091 protected void showunconserved_actionPerformed(ActionEvent e)
1093 // TODO Auto-generated method stub
1094 super.showunconserved_actionPerformed(e);
1097 public static List<String> getGroupURLLinks()
1099 return groupURLLinks;
1103 public void minColour_actionPerformed(JPanel panel)
1105 Color col = JColorChooser.showDialog(this,
1106 MessageManager.getString("label.select_colour_minimum_value"),
1107 minColour.getBackground());
1110 panel.setBackground(col);
1116 public void maxColour_actionPerformed(JPanel panel)
1118 Color col = JColorChooser.showDialog(this,
1119 MessageManager.getString("label.select_colour_maximum_value"),
1120 maxColour.getBackground());
1123 panel.setBackground(col);
1129 protected void userIdWidth_actionPerformed()
1133 String val = userIdWidth.getText().trim();
1134 if (val.length() > 0)
1136 Integer iw = Integer.parseInt(val);
1137 if (iw.intValue() < 12)
1139 throw new NumberFormatException();
1141 userIdWidth.setText(iw.toString());
1143 } catch (NumberFormatException x)
1145 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
1146 .getString("warn.user_defined_width_requirements"),
1147 MessageManager.getString("label.invalid_id_column_width"),
1148 JvOptionPane.WARNING_MESSAGE);
1149 userIdWidth.setText("");
1154 protected void autoIdWidth_actionPerformed()
1156 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1157 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1161 * Returns true if chimera path is to a valid executable, else show an error
1164 private boolean validateChimeraPath()
1166 if (chimeraPath.getText().trim().length() > 0)
1168 File f = new File(chimeraPath.getText());
1169 if (!f.canExecute())
1171 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1172 MessageManager.getString("label.invalid_chimera_path"),
1173 MessageManager.getString("label.invalid_name"),
1174 JvOptionPane.ERROR_MESSAGE);
1182 * Returns true if hmmer path contains the necessary valid executables, else
1183 * show an error dialog (if showing dialog).
1185 private boolean validateHMMERPath(boolean showDialog)
1188 String message = "";
1189 String path = hmmerPath.getText().trim();
1190 if (path.length() > 0)
1192 File f = new File(path);
1197 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1198 MessageManager.getString("label.folder_not_exists"),
1199 MessageManager.getString("label.invalid_folder"),
1200 JvOptionPane.ERROR_MESSAGE);
1205 File hmmbuild = new File(path + "/binaries/hmmbuild.exe");
1207 if (!hmmbuild.canExecute())
1209 message += MessageManager.getString("label.hmmbuild_not_found")
1215 File hmmalign = new File(path + "/binaries/hmmalign.exe");
1217 if (!hmmalign.canExecute())
1219 message += MessageManager.getString("label.hmmalign_not_found")
1225 File hmmsearch = new File(path + "/binaries/hmmsearch.exe");
1227 if (!hmmsearch.canExecute())
1229 message += MessageManager.getString("label.hmmsearch_not_found")
1241 JvOptionPane.showInternalMessageDialog(Desktop.desktop, message,
1242 MessageManager.getString("label.invalid_folder"),
1243 JvOptionPane.ERROR_MESSAGE);
1251 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1252 MessageManager.getString("label.no_binaries"),
1253 MessageManager.getString("label.invalid_folder"),
1254 JvOptionPane.ERROR_MESSAGE);
1265 private boolean validateHMMERPath()
1267 return validateHMMERPath(true);
1271 * If Chimera is selected, check it can be found on default or user-specified
1272 * path, if not show a warning/help dialog.
1275 protected void structureViewer_actionPerformed(String selectedItem)
1277 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1281 boolean found = false;
1284 * Try user-specified and standard paths for Chimera executable.
1286 List<String> paths = StructureManager.getChimeraPaths();
1287 paths.add(0, chimeraPath.getText());
1288 for (String path : paths)
1290 if (new File(path.trim()).canExecute())
1298 String[] options = { "OK", "Help" };
1299 int showHelp = JvOptionPane.showInternalOptionDialog(
1301 JvSwingUtils.wrapTooltip(true,
1302 MessageManager.getString("label.chimera_missing")),
1303 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1304 null, options, options[0]);
1305 if (showHelp == JvOptionPane.NO_OPTION)
1309 Help.showHelpWindow(HelpId.StructureViewer);
1310 } catch (HelpSetException e)
1312 e.printStackTrace();
1318 public class OptionsParam
1320 private String name;
1322 private String code;
1324 public OptionsParam(String name, String code)
1330 public String getName()
1335 public void setName(String name)
1340 public String getCode()
1345 public void setCode(String code)
1351 public String toString()
1357 public boolean equals(Object that)
1359 if (!(that instanceof OptionsParam))
1363 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1367 public int hashCode()
1369 return name.hashCode() + code.hashCode();
1373 private class UrlListSelectionHandler implements ListSelectionListener
1377 public void valueChanged(ListSelectionEvent e)
1379 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1381 int index = lsm.getMinSelectionIndex();
1384 // no selection, so disable delete/edit buttons
1385 editLink.setEnabled(false);
1386 deleteLink.setEnabled(false);
1389 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1391 // enable/disable edit and delete link buttons
1392 if (((UrlLinkTableModel) linkUrlTable.getModel())
1393 .isRowDeletable(modelIndex))
1395 deleteLink.setEnabled(true);
1399 deleteLink.setEnabled(false);
1402 if (((UrlLinkTableModel) linkUrlTable.getModel())
1403 .isRowEditable(modelIndex))
1405 editLink.setEnabled(true);
1409 editLink.setEnabled(false);