2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.bin.Cache;
25 import jalview.gui.Help.HelpId;
26 import jalview.gui.StructureViewer.ViewerType;
27 import jalview.hmmer.HmmerCommand;
28 import jalview.io.FileFormatI;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.jbgui.GPreferences;
32 import jalview.jbgui.GSequenceLink;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ColourSchemes;
35 import jalview.schemes.ResidueColourScheme;
36 import jalview.urls.UrlLinkTableModel;
37 import jalview.urls.api.UrlProviderFactoryI;
38 import jalview.urls.api.UrlProviderI;
39 import jalview.urls.desktop.DesktopUrlProviderFactory;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.util.UrlConstants;
43 import jalview.ws.sifts.SiftsSettings;
45 import java.awt.BorderLayout;
46 import java.awt.Color;
47 import java.awt.Component;
48 import java.awt.Dimension;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.FocusAdapter;
53 import java.awt.event.FocusEvent;
54 import java.awt.event.MouseEvent;
56 import java.util.ArrayList;
57 import java.util.List;
59 import javax.help.HelpSetException;
60 import javax.swing.JColorChooser;
61 import javax.swing.JFileChooser;
62 import javax.swing.JInternalFrame;
63 import javax.swing.JPanel;
64 import javax.swing.ListSelectionModel;
65 import javax.swing.RowFilter;
66 import javax.swing.RowSorter;
67 import javax.swing.SortOrder;
68 import javax.swing.event.DocumentEvent;
69 import javax.swing.event.DocumentListener;
70 import javax.swing.event.ListSelectionEvent;
71 import javax.swing.event.ListSelectionListener;
72 import javax.swing.table.TableCellRenderer;
73 import javax.swing.table.TableColumn;
74 import javax.swing.table.TableModel;
75 import javax.swing.table.TableRowSorter;
77 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
85 public class Preferences extends GPreferences
87 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
89 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
91 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
93 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
95 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
97 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
99 public static final String ADD_SS_ANN = "ADD_SS_ANN";
101 public static final String USE_RNAVIEW = "USE_RNAVIEW";
103 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
105 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
107 public static final String CHIMERA_PATH = "CHIMERA_PATH";
109 public static final String HMMER_PATH = "HMMER_PATH";
111 public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS";
113 public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
115 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
117 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
119 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
121 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
123 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
125 public static final String GAP_COLOUR = "GAP_COLOUR";
127 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
129 private static final int MIN_FONT_SIZE = 1;
131 private static final int MAX_FONT_SIZE = 30;
134 * Holds name and link separated with | character. Sequence ID must be
135 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
137 public static UrlProviderI sequenceUrlLinks;
139 public static UrlLinkTableModel dataModel;
142 * Holds name and link separated with | character. Sequence IDS and Sequences
143 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
144 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
145 * for first and second token specified after a pipe character at end |,|.
146 * (TODO: proper escape for using | to separate ids or sequences
149 public static List<String> groupURLLinks;
152 // get links selected to be in the menu (SEQUENCE_LINKS)
153 // and links entered by the user but not selected (STORED_LINKS)
154 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
155 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
156 String defaultUrl = Cache.getDefault("DEFAULT_URL",
157 UrlConstants.DEFAULT_LABEL);
159 // if both links lists are empty, add the DEFAULT_URL link
160 // otherwise we assume the default link is in one of the lists
161 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
163 inMenuString = UrlConstants.DEFAULT_STRING;
165 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
166 inMenuString, notInMenuString);
167 sequenceUrlLinks = factory.createUrlProvider();
168 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
171 * TODO: reformulate groupURL encoding so two or more can be stored in the
172 * .properties file as '|' separated strings
175 groupURLLinks = new ArrayList<>();
178 JInternalFrame frame;
180 DasSourceBrowser dasSource;
182 private WsPreferences wsPrefs;
184 private OptionsParam promptEachTimeOpt = new OptionsParam(
185 MessageManager.getString("label.prompt_each_time"),
188 private OptionsParam lineArtOpt = new OptionsParam(
189 MessageManager.getString("label.lineart"), "Lineart");
191 private OptionsParam textOpt = new OptionsParam(
192 MessageManager.getString("action.text"), "Text");
195 * Creates a new Preferences object.
200 frame = new JInternalFrame();
201 frame.setContentPane(this);
202 dasSource = new DasSourceBrowser();
203 dasTab.add(dasSource, BorderLayout.CENTER);
204 wsPrefs = new WsPreferences();
205 wsTab.add(wsPrefs, BorderLayout.CENTER);
206 int width = 500, height = 450;
207 new jalview.util.Platform();
208 if (Platform.isAMac())
214 Desktop.addInternalFrame(frame,
215 MessageManager.getString("label.preferences"), width, height);
216 frame.setMinimumSize(new Dimension(width, height));
219 * Set HMMER tab defaults
221 hmmrTrimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
222 if (Cache.getDefault("USE_UNIPROT", false))
224 hmmerBackgroundUniprot.setSelected(true);
228 hmmerBackgroundAlignment.setSelected(true);
231 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
232 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
233 hmmerPath.addActionListener(new ActionListener()
236 public void actionPerformed(ActionEvent e)
238 validateHMMERPath(true);
241 hmmerPath.addFocusListener(new FocusAdapter()
244 public void focusLost(FocusEvent e)
246 validateHMMERPath(true);
251 * Set Visual tab defaults
253 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
254 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
255 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
256 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
258 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
259 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
260 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
261 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
263 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
264 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
266 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
267 showGroupConservation.setSelected(
268 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
269 showConsensHistogram.setSelected(
270 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
272 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
273 showInformationHistogram.setSelected(
274 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
275 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
277 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
279 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
281 String[] fonts = java.awt.GraphicsEnvironment
282 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
283 for (int i = 0; i < fonts.length; i++)
285 fontNameCB.addItem(fonts[i]);
288 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
290 fontSizeCB.addItem(i + "");
293 fontStyleCB.addItem("plain");
294 fontStyleCB.addItem("bold");
295 fontStyleCB.addItem("italic");
297 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
298 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
299 fontStyleCB.setSelectedItem(
300 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
302 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
304 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
306 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
308 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
310 gapSymbolCB.addItem("-");
311 gapSymbolCB.addItem(".");
313 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
315 sortby.addItem("No sort");
316 sortby.addItem("Id");
317 sortby.addItem("Pairwise Identity");
318 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
320 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
322 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
324 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
325 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
326 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
327 SequenceAnnotationOrder.NONE.name()));
328 sortAnnBy.setSelectedItem(savedSort.toString());
330 sortAutocalc.addItem("Autocalculated first");
331 sortAutocalc.addItem("Autocalculated last");
332 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
333 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
334 : sortAutocalc.getItemAt(1));
336 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
337 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
338 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
339 + "/examples/exampleFile_2_3.jar"));
342 * Set Colours tab defaults
344 protColour.addItem(ResidueColourScheme.NONE);
345 nucColour.addItem(ResidueColourScheme.NONE);
346 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
348 String name = cs.getSchemeName();
349 protColour.addItem(name);
350 nucColour.addItem(name);
352 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
353 ResidueColourScheme.NONE);
354 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
355 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
356 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
357 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
358 minColour.setBackground(
359 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
360 maxColour.setBackground(
361 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
364 * Set overview panel defaults
366 gapColour.setBackground(
367 Cache.getDefaultColour(GAP_COLOUR,
368 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
369 hiddenColour.setBackground(
370 Cache.getDefaultColour(HIDDEN_COLOUR,
371 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
372 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
373 gapLabel.setEnabled(!useLegacyGap.isSelected());
374 gapColour.setEnabled(!useLegacyGap.isSelected());
376 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
379 * Set Structure tab defaults.
381 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
382 structFromPdb.setSelected(structSelected);
383 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
384 useRnaView.setEnabled(structSelected);
385 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
386 addSecondaryStructure.setEnabled(structSelected);
387 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
388 addTempFactor.setEnabled(structSelected);
389 structViewer.setSelectedItem(
390 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
391 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
392 chimeraPath.addActionListener(new ActionListener()
395 public void actionPerformed(ActionEvent e)
397 validateChimeraPath();
401 if (Cache.getDefault("MAP_WITH_SIFTS", false))
403 siftsMapping.setSelected(true);
407 nwMapping.setSelected(true);
411 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
414 * Set Connections tab defaults
418 linkUrlTable.setModel(dataModel);
419 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
420 linkUrlTable.getModel());
421 linkUrlTable.setRowSorter(sorter);
422 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
424 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
425 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
426 SortOrder.DESCENDING));
427 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
428 SortOrder.DESCENDING));
430 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
432 sorter.setSortKeys(sortKeys);
436 ActionListener onReset;
437 onReset = new ActionListener()
440 public void actionPerformed(ActionEvent e)
442 filterTB.setText("");
443 sorter.setRowFilter(RowFilter.regexFilter(""));
447 doReset.addActionListener(onReset);
449 // filter to display only custom urls
450 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
453 public boolean include(
454 Entry<? extends TableModel, ? extends Object> entry)
456 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
460 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
461 linkUrlTable.getModel());
462 customSorter.setRowFilter(customUrlFilter);
464 ActionListener onCustomOnly;
465 onCustomOnly = new ActionListener()
468 public void actionPerformed(ActionEvent e)
470 filterTB.setText("");
471 sorter.setRowFilter(customUrlFilter);
474 userOnly.addActionListener(onCustomOnly);
476 filterTB.getDocument().addDocumentListener(new DocumentListener()
478 String caseInsensitiveFlag = "(?i)";
481 public void changedUpdate(DocumentEvent e)
483 sorter.setRowFilter(RowFilter
484 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
488 public void removeUpdate(DocumentEvent e)
490 sorter.setRowFilter(RowFilter
491 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
495 public void insertUpdate(DocumentEvent e)
497 sorter.setRowFilter(RowFilter
498 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
502 // set up list selection functionality
503 linkUrlTable.getSelectionModel()
504 .addListSelectionListener(new UrlListSelectionHandler());
506 // set up radio buttons
507 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
509 String onClickName = linkUrlTable.getColumnName(onClickCol);
510 linkUrlTable.getColumn(onClickName)
511 .setCellRenderer(new RadioButtonRenderer());
512 linkUrlTable.getColumn(onClickName)
513 .setCellEditor(new RadioButtonEditor());
515 // get boolean columns and resize those to min possible
516 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
518 if (linkUrlTable.getModel().getColumnClass(column)
519 .equals(Boolean.class))
521 TableColumn tableColumn = linkUrlTable.getColumnModel()
523 int preferredWidth = tableColumn.getMinWidth();
525 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
527 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
528 int cwidth = c.getPreferredSize().width
529 + linkUrlTable.getIntercellSpacing().width;
530 preferredWidth = Math.max(preferredWidth, cwidth);
532 tableColumn.setPreferredWidth(preferredWidth);
536 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
537 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
538 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
539 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
541 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
543 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
544 // note antisense here: default is true
546 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
547 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
550 * Set Output tab defaults
552 epsRendering.addItem(promptEachTimeOpt);
553 epsRendering.addItem(lineArtOpt);
554 epsRendering.addItem(textOpt);
555 String defaultEPS = Cache.getDefault("EPS_RENDERING",
557 if (defaultEPS.equalsIgnoreCase("Text"))
559 epsRendering.setSelectedItem(textOpt);
561 else if (defaultEPS.equalsIgnoreCase("Lineart"))
563 epsRendering.setSelectedItem(lineArtOpt);
567 epsRendering.setSelectedItem(promptEachTimeOpt);
569 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
570 userIdWidth.setEnabled(!autoIdWidth.isSelected());
571 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
572 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
573 userIdWidth.setText(wi == null ? "" : wi.toString());
574 // TODO: refactor to use common enum via FormatAdapter and allow extension
575 // for new flat file formats
576 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
577 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
578 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
579 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
580 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
581 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
582 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
583 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
585 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
588 * Set Editing tab defaults
590 autoCalculateConsCheck
591 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
592 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
593 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
595 annotations_actionPerformed(null); // update the display of the annotation
600 * Save user selections on the Preferences tabs to the Cache and write out to
606 public void ok_actionPerformed(ActionEvent e)
608 if (!validateSettings())
614 * Save Visual settings
616 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
617 Boolean.toString(seqLimit.isSelected()));
618 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
619 Boolean.toString(rightAlign.isSelected()));
620 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
621 Boolean.toString(fullScreen.isSelected()));
622 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
623 Boolean.toString(openoverv.isSelected()));
624 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
625 Boolean.toString(annotations.isSelected()));
626 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
627 Boolean.toString(conservation.isSelected()));
628 Cache.applicationProperties.setProperty("SHOW_QUALITY",
629 Boolean.toString(quality.isSelected()));
630 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
631 Boolean.toString(identity.isSelected()));
633 Cache.applicationProperties.setProperty("GAP_SYMBOL",
634 gapSymbolCB.getSelectedItem().toString());
636 Cache.applicationProperties.setProperty("FONT_NAME",
637 fontNameCB.getSelectedItem().toString());
638 Cache.applicationProperties.setProperty("FONT_STYLE",
639 fontStyleCB.getSelectedItem().toString());
640 Cache.applicationProperties.setProperty("FONT_SIZE",
641 fontSizeCB.getSelectedItem().toString());
643 Cache.applicationProperties.setProperty("ID_ITALICS",
644 Boolean.toString(idItalics.isSelected()));
645 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
646 Boolean.toString(showUnconserved.isSelected()));
647 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
648 Boolean.toString(showOccupancy.isSelected()));
649 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
650 Boolean.toString(showGroupConsensus.isSelected()));
651 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
652 Boolean.toString(showGroupConservation.isSelected()));
653 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
654 Boolean.toString(showConsensHistogram.isSelected()));
655 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
656 Boolean.toString(showConsensLogo.isSelected()));
657 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
658 Boolean.toString(showConsensHistogram.isSelected()));
659 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
660 Boolean.toString(showHMMLogo.isSelected()));
661 Cache.applicationProperties.setProperty("ANTI_ALIAS",
662 Boolean.toString(smoothFont.isSelected()));
663 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
664 Boolean.toString(scaleProteinToCdna.isSelected()));
665 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
666 Boolean.toString(showNpTooltip.isSelected()));
667 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
668 Boolean.toString(showDbRefTooltip.isSelected()));
670 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
671 Boolean.toString(wrap.isSelected()));
673 Cache.applicationProperties.setProperty("STARTUP_FILE",
674 startupFileTextfield.getText());
675 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
676 Boolean.toString(startupCheckbox.isSelected()));
678 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
679 sortby.getSelectedItem().toString());
681 // convert description of sort order to enum name for save
682 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
683 .forDescription(sortAnnBy.getSelectedItem().toString());
684 if (annSortOrder != null)
686 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
687 annSortOrder.name());
690 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
691 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
692 Boolean.valueOf(showAutocalcFirst).toString());
695 * Save Colours settings
697 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
698 protColour.getSelectedItem().toString());
699 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
700 nucColour.getSelectedItem().toString());
701 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
702 minColour.getBackground());
703 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
704 maxColour.getBackground());
707 * Save HMMER settings
709 Cache.applicationProperties.setProperty("TRIM_TERMINI",
710 Boolean.toString(hmmrTrimTermini.isSelected()));
711 Cache.applicationProperties.setProperty("USE_UNIPROT",
712 Boolean.toString(hmmerBackgroundUniprot.isSelected()));
713 Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
714 hmmerSequenceCount.getText());
715 Cache.applicationProperties.setProperty(HMMER_PATH,
716 hmmerPath.getText());
717 AlignFrame[] frames = Desktop.getAlignFrames();
718 if (frames != null && frames.length > 0)
720 for (AlignFrame f : frames)
722 f.updateHMMERStatus();
726 hmmrTrimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
727 if (Cache.getDefault("USE_UNIPROT", false))
729 hmmerBackgroundUniprot.setSelected(true);
733 hmmerBackgroundAlignment.setSelected(true);
736 .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
737 hmmerPath.setText(Cache.getProperty(HMMER_PATH));
740 * Save Overview settings
742 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
743 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
744 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
745 Boolean.toString(useLegacyGap.isSelected()));
746 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
747 Boolean.toString(showHiddenAtStart.isSelected()));
750 * Save Structure settings
752 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
753 Boolean.toString(addTempFactor.isSelected()));
754 Cache.applicationProperties.setProperty(ADD_SS_ANN,
755 Boolean.toString(addSecondaryStructure.isSelected()));
756 Cache.applicationProperties.setProperty(USE_RNAVIEW,
757 Boolean.toString(useRnaView.isSelected()));
758 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
759 Boolean.toString(structFromPdb.isSelected()));
760 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
761 structViewer.getSelectedItem().toString());
762 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
763 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
764 Boolean.toString(siftsMapping.isSelected()));
765 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
768 * Save Output settings
770 Cache.applicationProperties.setProperty("EPS_RENDERING",
771 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
774 * Save Connections settings
776 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
778 jalview.util.BrowserLauncher.resetBrowser();
780 // save user-defined and selected links
781 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
782 if (menuLinks.isEmpty())
784 Cache.applicationProperties.remove("SEQUENCE_LINKS");
788 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
789 menuLinks.toString());
792 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
793 if (nonMenuLinks.isEmpty())
795 Cache.applicationProperties.remove("STORED_LINKS");
799 Cache.applicationProperties.setProperty("STORED_LINKS",
800 nonMenuLinks.toString());
803 Cache.applicationProperties.setProperty("DEFAULT_URL",
804 sequenceUrlLinks.getPrimaryUrlId());
806 Cache.applicationProperties.setProperty("USE_PROXY",
807 Boolean.toString(useProxy.isSelected()));
809 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
811 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
813 if (useProxy.isSelected())
815 System.setProperty("http.proxyHost", proxyServerTB.getText());
816 System.setProperty("http.proxyPort", proxyPortTB.getText());
820 System.setProperty("http.proxyHost", "");
821 System.setProperty("http.proxyPort", "");
823 Cache.setProperty("VERSION_CHECK",
824 Boolean.toString(versioncheck.isSelected()));
825 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
827 // default is false - we only set this if the user has actively agreed
828 Cache.setProperty("USAGESTATS",
829 Boolean.toString(usagestats.isSelected()));
831 if (!questionnaire.isSelected())
833 Cache.setProperty("NOQUESTIONNAIRES", "true");
837 // special - made easy to edit a property file to disable questionnaires
838 // by just adding the given line
839 Cache.removeProperty("NOQUESTIONNAIRES");
843 * Save Output settings
845 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
846 Boolean.toString(blcjv.isSelected()));
847 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
848 Boolean.toString(clustaljv.isSelected()));
849 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
850 Boolean.toString(fastajv.isSelected()));
851 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
852 Boolean.toString(msfjv.isSelected()));
853 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
854 Boolean.toString(pfamjv.isSelected()));
855 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
856 Boolean.toString(pileupjv.isSelected()));
857 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
858 Boolean.toString(pirjv.isSelected()));
859 Cache.applicationProperties.setProperty("PIR_MODELLER",
860 Boolean.toString(modellerOutput.isSelected()));
861 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
862 Boolean.toString(embbedBioJSON.isSelected()));
863 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
865 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
866 Boolean.toString(autoIdWidth.isSelected()));
867 userIdWidth_actionPerformed();
868 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
869 userIdWidth.getText());
872 * Save Editing settings
874 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
875 Boolean.toString(autoCalculateConsCheck.isSelected()));
876 Cache.applicationProperties.setProperty("SORT_BY_TREE",
877 Boolean.toString(sortByTree.isSelected()));
878 Cache.applicationProperties.setProperty("PAD_GAPS",
879 Boolean.toString(padGaps.isSelected()));
881 dasSource.saveProperties(Cache.applicationProperties);
882 wsPrefs.updateAndRefreshWsMenuConfig(false);
883 Cache.saveProperties();
884 Desktop.instance.doConfigureStructurePrefs();
887 frame.setClosed(true);
888 } catch (Exception ex)
894 * Do any necessary validation before saving settings. Return focus to the
895 * first tab which fails validation.
899 private boolean validateSettings()
901 if (!validateStructure())
903 structureTab.requestFocusInWindow();
910 protected boolean validateStructure()
912 return validateChimeraPath();
920 public void startupFileTextfield_mouseClicked()
922 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
923 JalviewFileChooser chooser = JalviewFileChooser
924 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
925 chooser.setFileView(new JalviewFileView());
926 chooser.setDialogTitle(
927 MessageManager.getString("label.select_startup_file"));
929 int value = chooser.showOpenDialog(this);
931 if (value == JalviewFileChooser.APPROVE_OPTION)
933 FileFormatI format = chooser.getSelectedFormat();
936 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
940 .setText(chooser.getSelectedFile().getAbsolutePath());
951 public void cancel_actionPerformed(ActionEvent e)
955 wsPrefs.updateWsMenuConfig(true);
956 wsPrefs.refreshWs_actionPerformed(e);
957 frame.setClosed(true);
958 } catch (Exception ex)
970 public void annotations_actionPerformed(ActionEvent e)
972 conservation.setEnabled(annotations.isSelected());
973 quality.setEnabled(annotations.isSelected());
974 identity.setEnabled(annotations.isSelected());
975 showOccupancy.setEnabled(annotations.isSelected());
976 showGroupConsensus.setEnabled(annotations.isSelected());
977 showGroupConservation.setEnabled(annotations.isSelected());
978 showConsensHistogram.setEnabled(annotations.isSelected()
979 && (identity.isSelected() || showGroupConsensus.isSelected()));
980 showConsensLogo.setEnabled(annotations.isSelected()
981 && (identity.isSelected() || showGroupConsensus.isSelected()));
982 showInformationHistogram.setEnabled(annotations.isSelected());
983 showHMMLogo.setEnabled(annotations.isSelected());
987 public void newLink_actionPerformed(ActionEvent e)
989 GSequenceLink link = new GSequenceLink();
990 boolean valid = false;
993 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
994 MessageManager.getString("label.new_sequence_url_link"),
995 JvOptionPane.OK_CANCEL_OPTION, -1,
996 null) == JvOptionPane.OK_OPTION)
998 if (link.checkValid())
1000 if (((UrlLinkTableModel) linkUrlTable.getModel())
1001 .isUniqueName(link.getName()))
1003 ((UrlLinkTableModel) linkUrlTable.getModel())
1004 .insertRow(link.getName(), link.getURL());
1009 link.notifyDuplicate();
1022 public void editLink_actionPerformed(ActionEvent e)
1024 GSequenceLink link = new GSequenceLink();
1026 int index = linkUrlTable.getSelectedRow();
1029 // button no longer enabled if row is not selected
1030 Cache.log.debug("Edit with no row selected in linkUrlTable");
1034 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1036 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1038 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1039 link.setName(oldName);
1040 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1042 boolean valid = false;
1045 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1046 MessageManager.getString("label.edit_sequence_url_link"),
1047 JvOptionPane.OK_CANCEL_OPTION, -1,
1048 null) == JvOptionPane.OK_OPTION)
1050 if (link.checkValid())
1052 if ((oldName.equals(link.getName()))
1053 || (((UrlLinkTableModel) linkUrlTable.getModel())
1054 .isUniqueName(link.getName())))
1056 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1057 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1062 link.notifyDuplicate();
1075 public void deleteLink_actionPerformed(ActionEvent e)
1077 int index = linkUrlTable.getSelectedRow();
1078 int modelIndex = -1;
1081 // button no longer enabled if row is not selected
1082 Cache.log.debug("Delete with no row selected in linkUrlTable");
1087 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1090 // make sure we use the model index to delete, and not the table index
1091 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1095 public void defaultBrowser_mouseClicked(MouseEvent e)
1097 JFileChooser chooser = new JFileChooser(".");
1098 chooser.setDialogTitle(
1099 MessageManager.getString("label.select_default_browser"));
1101 int value = chooser.showOpenDialog(this);
1103 if (value == JFileChooser.APPROVE_OPTION)
1105 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1114 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1118 protected void showunconserved_actionPerformed(ActionEvent e)
1120 // TODO Auto-generated method stub
1121 super.showunconserved_actionPerformed(e);
1124 public static List<String> getGroupURLLinks()
1126 return groupURLLinks;
1130 public void minColour_actionPerformed(JPanel panel)
1132 Color col = JColorChooser.showDialog(this,
1133 MessageManager.getString("label.select_colour_minimum_value"),
1134 minColour.getBackground());
1137 panel.setBackground(col);
1143 public void maxColour_actionPerformed(JPanel panel)
1145 Color col = JColorChooser.showDialog(this,
1146 MessageManager.getString("label.select_colour_maximum_value"),
1147 maxColour.getBackground());
1150 panel.setBackground(col);
1156 public void gapColour_actionPerformed(JPanel gap)
1158 if (!useLegacyGap.isSelected())
1160 Color col = JColorChooser.showDialog(this,
1161 MessageManager.getString("label.select_gap_colour"),
1162 gapColour.getBackground());
1165 gap.setBackground(col);
1172 public void hiddenColour_actionPerformed(JPanel hidden)
1174 Color col = JColorChooser.showDialog(this,
1175 MessageManager.getString("label.select_hidden_colour"),
1176 hiddenColour.getBackground());
1179 hidden.setBackground(col);
1185 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1187 boolean enabled = useLegacyGap.isSelected();
1190 gapColour.setBackground(
1191 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1195 gapColour.setBackground(
1196 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1198 gapColour.setEnabled(!enabled);
1199 gapLabel.setEnabled(!enabled);
1203 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1205 useLegacyGap.setSelected(false);
1206 useLegacyGaps_actionPerformed(null);
1207 showHiddenAtStart.setSelected(true);
1208 hiddenColour.setBackground(
1209 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1213 protected void userIdWidth_actionPerformed()
1217 String val = userIdWidth.getText().trim();
1218 if (val.length() > 0)
1220 Integer iw = Integer.parseInt(val);
1221 if (iw.intValue() < 12)
1223 throw new NumberFormatException();
1225 userIdWidth.setText(iw.toString());
1227 } catch (NumberFormatException x)
1229 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1231 .getString("warn.user_defined_width_requirements"),
1232 MessageManager.getString("label.invalid_id_column_width"),
1233 JvOptionPane.WARNING_MESSAGE);
1234 userIdWidth.setText("");
1239 protected void autoIdWidth_actionPerformed()
1241 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1242 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1246 * Returns true if chimera path is to a valid executable, else show an error
1249 private boolean validateChimeraPath()
1251 if (chimeraPath.getText().trim().length() > 0)
1253 File f = new File(chimeraPath.getText());
1254 if (!f.canExecute())
1256 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1257 MessageManager.getString("label.invalid_chimera_path"),
1258 MessageManager.getString("label.invalid_name"),
1259 JvOptionPane.ERROR_MESSAGE);
1267 * Returns true if hmmer path is to a folder that contains an executable
1268 * hmmbuild or hmmbuild.exe, else false (optionally after showing a warning
1272 protected boolean validateHMMERPath(boolean showWarning)
1274 String folder = hmmerPath.getText().trim();
1276 if (HmmerCommand.getExecutable(HmmerCommand.HMMBUILD, folder) != null)
1280 if (showWarning && folder.length() > 0)
1282 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1283 MessageManager.getString("label.hmmbuild_not_found"),
1284 MessageManager.getString("label.invalid_folder"),
1285 JvOptionPane.ERROR_MESSAGE);
1291 * Checks if a file can be executed
1294 * the path to the file
1297 public boolean canExecute(String path)
1299 File file = new File(path);
1300 if (!file.canExecute())
1302 file = new File(path + ".exe");
1304 if (!file.canExecute())
1314 * If Chimera is selected, check it can be found on default or user-specified
1315 * path, if not show a warning/help dialog.
1318 protected void structureViewer_actionPerformed(String selectedItem)
1320 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1324 boolean found = false;
1327 * Try user-specified and standard paths for Chimera executable.
1329 List<String> paths = StructureManager.getChimeraPaths();
1330 paths.add(0, chimeraPath.getText());
1331 for (String path : paths)
1333 if (new File(path.trim()).canExecute())
1341 String[] options = { "OK", "Help" };
1342 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1343 JvSwingUtils.wrapTooltip(true,
1344 MessageManager.getString("label.chimera_missing")),
1345 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1346 null, options, options[0]);
1347 if (showHelp == JvOptionPane.NO_OPTION)
1351 Help.showHelpWindow(HelpId.StructureViewer);
1352 } catch (HelpSetException e)
1354 e.printStackTrace();
1360 public class OptionsParam
1362 private String name;
1364 private String code;
1366 public OptionsParam(String name, String code)
1372 public String getName()
1377 public void setName(String name)
1382 public String getCode()
1387 public void setCode(String code)
1393 public String toString()
1399 public boolean equals(Object that)
1401 if (!(that instanceof OptionsParam))
1405 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1409 public int hashCode()
1411 return name.hashCode() + code.hashCode();
1415 private class UrlListSelectionHandler implements ListSelectionListener
1419 public void valueChanged(ListSelectionEvent e)
1421 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1423 int index = lsm.getMinSelectionIndex();
1426 // no selection, so disable delete/edit buttons
1427 editLink.setEnabled(false);
1428 deleteLink.setEnabled(false);
1431 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1433 // enable/disable edit and delete link buttons
1434 if (((UrlLinkTableModel) linkUrlTable.getModel())
1435 .isRowDeletable(modelIndex))
1437 deleteLink.setEnabled(true);
1441 deleteLink.setEnabled(false);
1444 if (((UrlLinkTableModel) linkUrlTable.getModel())
1445 .isRowEditable(modelIndex))
1447 editLink.setEnabled(true);
1451 editLink.setEnabled(false);