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 java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Dimension;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.MouseEvent;
32 import java.util.ArrayList;
33 import java.util.List;
35 import javax.help.HelpSetException;
36 import javax.swing.JColorChooser;
37 import javax.swing.JFileChooser;
38 import javax.swing.JInternalFrame;
39 import javax.swing.JPanel;
40 import javax.swing.ListSelectionModel;
41 import javax.swing.RowFilter;
42 import javax.swing.RowSorter;
43 import javax.swing.SortOrder;
44 import javax.swing.event.DocumentEvent;
45 import javax.swing.event.DocumentListener;
46 import javax.swing.event.ListSelectionEvent;
47 import javax.swing.event.ListSelectionListener;
48 import javax.swing.table.TableCellRenderer;
49 import javax.swing.table.TableColumn;
50 import javax.swing.table.TableModel;
51 import javax.swing.table.TableRowSorter;
53 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
54 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
55 import jalview.bin.Cache;
56 import jalview.gui.Help.HelpId;
57 import jalview.gui.StructureViewer.ViewerType;
58 import jalview.io.BackupFiles;
59 import jalview.io.BackupFilesPresetEntry;
60 import jalview.io.FileFormatI;
61 import jalview.io.JalviewFileChooser;
62 import jalview.io.JalviewFileView;
63 import jalview.jbgui.GPreferences;
64 import jalview.jbgui.GSequenceLink;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.schemes.ColourSchemes;
67 import jalview.schemes.ResidueColourScheme;
68 import jalview.urls.UrlLinkTableModel;
69 import jalview.urls.api.UrlProviderFactoryI;
70 import jalview.urls.api.UrlProviderI;
71 import jalview.urls.desktop.DesktopUrlProviderFactory;
72 import jalview.util.MessageManager;
73 import jalview.util.Platform;
74 import jalview.util.UrlConstants;
75 import jalview.ws.sifts.SiftsSettings;
83 public class Preferences extends GPreferences
85 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
87 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
89 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
91 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
93 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
95 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
97 public static final String ADD_SS_ANN = "ADD_SS_ANN";
99 public static final String USE_RNAVIEW = "USE_RNAVIEW";
101 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
103 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
105 public static final String CHIMERA_PATH = "CHIMERA_PATH";
107 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
109 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
111 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
113 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
115 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
117 public static final String GAP_COLOUR = "GAP_COLOUR";
119 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
121 private static final int MIN_FONT_SIZE = 1;
123 private static final int MAX_FONT_SIZE = 30;
125 private String previousProxyType;
128 * Holds name and link separated with | character. Sequence ID must be
129 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
131 public static UrlProviderI sequenceUrlLinks;
133 public static UrlLinkTableModel dataModel;
136 * Holds name and link separated with | character. Sequence IDS and Sequences
137 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
138 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
139 * for first and second token specified after a pipe character at end |,|.
140 * (TODO: proper escape for using | to separate ids or sequences
143 public static List<String> groupURLLinks;
146 // get links selected to be in the menu (SEQUENCE_LINKS)
147 // and links entered by the user but not selected (STORED_LINKS)
148 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
149 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
150 String defaultUrl = Cache.getDefault("DEFAULT_URL",
151 UrlConstants.DEFAULT_LABEL);
153 // if both links lists are empty, add the DEFAULT_URL link
154 // otherwise we assume the default link is in one of the lists
155 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
157 inMenuString = UrlConstants.DEFAULT_STRING;
159 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
160 inMenuString, notInMenuString);
161 sequenceUrlLinks = factory.createUrlProvider();
162 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
165 * TODO: reformulate groupURL encoding so two or more can be stored in the
166 * .properties file as '|' separated strings
169 groupURLLinks = new ArrayList<>();
172 JInternalFrame frame;
174 private WsPreferences wsPrefs;
176 private OptionsParam promptEachTimeOpt = new OptionsParam(
177 MessageManager.getString("label.prompt_each_time"),
180 private OptionsParam lineArtOpt = new OptionsParam(
181 MessageManager.getString("label.lineart"), "Lineart");
183 private OptionsParam textOpt = new OptionsParam(
184 MessageManager.getString("action.text"), "Text");
187 * Creates a new Preferences object.
194 public Preferences(int selectTab)
196 new Preferences(selectTab, null);
199 public Preferences(int selectTab, String message)
201 super(selectTab, message);
202 frame = new JInternalFrame();
203 frame.setContentPane(this);
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 Visual tab defaults
221 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
222 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
223 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
224 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
226 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
227 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
228 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
229 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
231 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
232 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
234 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
235 showGroupConservation.setSelected(
236 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
237 showConsensHistogram.setSelected(
238 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
240 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
242 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
244 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
246 String[] fonts = java.awt.GraphicsEnvironment
247 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
248 for (int i = 0; i < fonts.length; i++)
250 fontNameCB.addItem(fonts[i]);
253 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
255 fontSizeCB.addItem(i + "");
258 fontStyleCB.addItem("plain");
259 fontStyleCB.addItem("bold");
260 fontStyleCB.addItem("italic");
262 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
263 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
264 fontStyleCB.setSelectedItem(
265 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
267 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", true));
269 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
271 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
273 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
275 gapSymbolCB.addItem("-");
276 gapSymbolCB.addItem(".");
278 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
280 sortby.addItem("No sort");
281 sortby.addItem("Id");
282 sortby.addItem("Pairwise Identity");
283 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
285 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
287 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
289 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
290 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
291 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
292 SequenceAnnotationOrder.NONE.name()));
293 sortAnnBy.setSelectedItem(savedSort.toString());
295 sortAutocalc.addItem("Autocalculated first");
296 sortAutocalc.addItem("Autocalculated last");
297 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
298 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
299 : sortAutocalc.getItemAt(1));
301 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
302 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
303 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
304 + "/examples/exampleFile_2_3.jar"));
307 * Set Colours tab defaults
309 protColour.addItem(ResidueColourScheme.NONE);
310 nucColour.addItem(ResidueColourScheme.NONE);
311 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
313 String name = cs.getSchemeName();
314 protColour.addItem(name);
315 nucColour.addItem(name);
317 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
318 ResidueColourScheme.NONE);
319 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
320 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
321 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
322 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
323 minColour.setBackground(
324 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
325 maxColour.setBackground(
326 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
329 * Set overview panel defaults
331 gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR,
332 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
333 hiddenColour.setBackground(Cache.getDefaultColour(HIDDEN_COLOUR,
334 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
335 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
336 gapLabel.setEnabled(!useLegacyGap.isSelected());
337 gapColour.setEnabled(!useLegacyGap.isSelected());
339 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
342 * Set Structure tab defaults.
344 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
345 structFromPdb.setSelected(structSelected);
346 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
347 useRnaView.setEnabled(structSelected);
348 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
349 addSecondaryStructure.setEnabled(structSelected);
350 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
351 addTempFactor.setEnabled(structSelected);
352 structViewer.setSelectedItem(
353 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
354 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
355 chimeraPath.addActionListener(new ActionListener()
358 public void actionPerformed(ActionEvent e)
360 validateChimeraPath();
364 if (Cache.getDefault("MAP_WITH_SIFTS", false))
366 siftsMapping.setSelected(true);
370 nwMapping.setSelected(true);
374 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
377 * Set Connections tab defaults
381 linkUrlTable.setModel(dataModel);
382 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
383 linkUrlTable.getModel());
384 linkUrlTable.setRowSorter(sorter);
385 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
387 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
388 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
389 SortOrder.DESCENDING));
390 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
391 SortOrder.DESCENDING));
393 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
395 sorter.setSortKeys(sortKeys);
399 ActionListener onReset;
400 onReset = new ActionListener()
403 public void actionPerformed(ActionEvent e)
405 filterTB.setText("");
406 sorter.setRowFilter(RowFilter.regexFilter(""));
410 doReset.addActionListener(onReset);
412 // filter to display only custom urls
413 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
416 public boolean include(
417 Entry<? extends TableModel, ? extends Object> entry)
419 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
423 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
424 linkUrlTable.getModel());
425 customSorter.setRowFilter(customUrlFilter);
427 ActionListener onCustomOnly;
428 onCustomOnly = new ActionListener()
431 public void actionPerformed(ActionEvent e)
433 filterTB.setText("");
434 sorter.setRowFilter(customUrlFilter);
437 userOnly.addActionListener(onCustomOnly);
439 filterTB.getDocument().addDocumentListener(new DocumentListener()
441 String caseInsensitiveFlag = "(?i)";
444 public void changedUpdate(DocumentEvent e)
446 sorter.setRowFilter(RowFilter
447 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
451 public void removeUpdate(DocumentEvent e)
453 sorter.setRowFilter(RowFilter
454 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
458 public void insertUpdate(DocumentEvent e)
460 sorter.setRowFilter(RowFilter
461 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
465 // set up list selection functionality
466 linkUrlTable.getSelectionModel()
467 .addListSelectionListener(new UrlListSelectionHandler());
469 // set up radio buttons
470 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
472 String onClickName = linkUrlTable.getColumnName(onClickCol);
473 linkUrlTable.getColumn(onClickName)
474 .setCellRenderer(new RadioButtonRenderer());
475 linkUrlTable.getColumn(onClickName)
476 .setCellEditor(new RadioButtonEditor());
478 // get boolean columns and resize those to min possible
479 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
481 if (linkUrlTable.getModel().getColumnClass(column)
482 .equals(Boolean.class))
484 TableColumn tableColumn = linkUrlTable.getColumnModel()
486 int preferredWidth = tableColumn.getMinWidth();
488 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
490 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
491 int cwidth = c.getPreferredSize().width
492 + linkUrlTable.getIntercellSpacing().width;
493 preferredWidth = Math.max(preferredWidth, cwidth);
495 tableColumn.setPreferredWidth(preferredWidth);
499 String proxyTypeString = Cache.getDefault("USE_PROXY", "false");
500 previousProxyType = proxyTypeString;
501 switch (proxyTypeString)
503 case Cache.PROXYTYPE_NONE:
504 proxyType.setSelected(noProxy.getModel(), true);
506 case Cache.PROXYTYPE_SYSTEM:
507 proxyType.setSelected(systemProxy.getModel(), true);
509 case Cache.PROXYTYPE_CUSTOM:
510 proxyType.setSelected(customProxy.getModel(), true);
514 "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
517 proxyServerHttpTB.setText(Cache.getDefault("PROXY_SERVER", ""));
518 proxyPortHttpTB.setText(Cache.getDefault("PROXY_PORT", ""));
519 proxyServerHttpsTB.setText(Cache.getDefault("PROXY_SERVER_HTTPS", ""));
520 proxyPortHttpsTB.setText(Cache.getDefault("PROXY_PORT_HTTPS", ""));
521 proxyAuth.setSelected(Cache.getDefault("PROXY_AUTH", false));
523 .setText(Cache.getDefault("PROXY_AUTH_USERNAME", ""));
524 // we are not storing or retrieving proxy password from .jalview_properties
525 proxyAuthPasswordTB.setText(Cache.proxyAuthPassword == null ? ""
526 : new String(Cache.proxyAuthPassword));
527 setCustomProxyEnabled();
529 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
531 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
532 // note antisense here: default is true
534 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
535 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
538 * Set Output tab defaults
540 epsRendering.addItem(promptEachTimeOpt);
541 epsRendering.addItem(lineArtOpt);
542 epsRendering.addItem(textOpt);
543 String defaultEPS = Cache.getDefault("EPS_RENDERING",
545 if (defaultEPS.equalsIgnoreCase("Text"))
547 epsRendering.setSelectedItem(textOpt);
549 else if (defaultEPS.equalsIgnoreCase("Lineart"))
551 epsRendering.setSelectedItem(lineArtOpt);
555 epsRendering.setSelectedItem(promptEachTimeOpt);
557 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
558 userIdWidth.setEnabled(!autoIdWidth.isSelected());
559 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
560 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
561 userIdWidth.setText(wi == null ? "" : wi.toString());
562 // TODO: refactor to use common enum via FormatAdapter and allow extension
563 // for new flat file formats
564 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
565 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
566 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
567 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
568 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
569 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
570 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
571 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
573 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
576 * Set Editing tab defaults
578 autoCalculateConsCheck
579 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
580 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
581 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
583 annotations_actionPerformed(null); // update the display of the annotation
587 * Set Backups tab defaults
589 loadLastSavedBackupsOptions();
593 * Save user selections on the Preferences tabs to the Cache and write out to
599 public void ok_actionPerformed(ActionEvent e)
601 if (!validateSettings())
607 * Save Visual settings
609 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
610 Boolean.toString(seqLimit.isSelected()));
611 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
612 Boolean.toString(rightAlign.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
614 Boolean.toString(fullScreen.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
616 Boolean.toString(openoverv.isSelected()));
617 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
618 Boolean.toString(annotations.isSelected()));
619 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
620 Boolean.toString(conservation.isSelected()));
621 Cache.applicationProperties.setProperty("SHOW_QUALITY",
622 Boolean.toString(quality.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
624 Boolean.toString(identity.isSelected()));
626 Cache.applicationProperties.setProperty("GAP_SYMBOL",
627 gapSymbolCB.getSelectedItem().toString());
629 Cache.applicationProperties.setProperty("FONT_NAME",
630 fontNameCB.getSelectedItem().toString());
631 Cache.applicationProperties.setProperty("FONT_STYLE",
632 fontStyleCB.getSelectedItem().toString());
633 Cache.applicationProperties.setProperty("FONT_SIZE",
634 fontSizeCB.getSelectedItem().toString());
636 Cache.applicationProperties.setProperty("ID_ITALICS",
637 Boolean.toString(idItalics.isSelected()));
638 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
639 Boolean.toString(showUnconserved.isSelected()));
640 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
641 Boolean.toString(showOccupancy.isSelected()));
642 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
643 Boolean.toString(showGroupConsensus.isSelected()));
644 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
645 Boolean.toString(showGroupConservation.isSelected()));
646 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
647 Boolean.toString(showConsensHistogram.isSelected()));
648 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
649 Boolean.toString(showConsensLogo.isSelected()));
650 Cache.applicationProperties.setProperty("ANTI_ALIAS",
651 Boolean.toString(smoothFont.isSelected()));
652 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
653 Boolean.toString(scaleProteinToCdna.isSelected()));
654 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
655 Boolean.toString(showNpTooltip.isSelected()));
656 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
657 Boolean.toString(showDbRefTooltip.isSelected()));
659 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
660 Boolean.toString(wrap.isSelected()));
662 Cache.applicationProperties.setProperty("STARTUP_FILE",
663 startupFileTextfield.getText());
664 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
665 Boolean.toString(startupCheckbox.isSelected()));
667 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
668 sortby.getSelectedItem().toString());
670 // convert description of sort order to enum name for save
671 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
672 .forDescription(sortAnnBy.getSelectedItem().toString());
673 if (annSortOrder != null)
675 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
676 annSortOrder.name());
679 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
680 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
681 Boolean.valueOf(showAutocalcFirst).toString());
684 * Save Colours settings
686 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
687 protColour.getSelectedItem().toString());
688 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
689 nucColour.getSelectedItem().toString());
690 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
691 minColour.getBackground());
692 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
693 maxColour.getBackground());
696 * Save Overview settings
698 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
699 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
700 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
701 Boolean.toString(useLegacyGap.isSelected()));
702 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
703 Boolean.toString(showHiddenAtStart.isSelected()));
706 * Save Structure settings
708 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
709 Boolean.toString(addTempFactor.isSelected()));
710 Cache.applicationProperties.setProperty(ADD_SS_ANN,
711 Boolean.toString(addSecondaryStructure.isSelected()));
712 Cache.applicationProperties.setProperty(USE_RNAVIEW,
713 Boolean.toString(useRnaView.isSelected()));
714 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
715 Boolean.toString(structFromPdb.isSelected()));
716 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
717 structViewer.getSelectedItem().toString());
718 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
719 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
720 Boolean.toString(siftsMapping.isSelected()));
721 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
724 * Save Output settings
726 Cache.applicationProperties.setProperty("EPS_RENDERING",
727 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
730 * Save Connections settings
732 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
734 jalview.util.BrowserLauncher.resetBrowser();
736 // save user-defined and selected links
737 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
738 if (menuLinks.isEmpty())
740 Cache.applicationProperties.remove("SEQUENCE_LINKS");
744 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
745 menuLinks.toString());
748 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
749 if (nonMenuLinks.isEmpty())
751 Cache.applicationProperties.remove("STORED_LINKS");
755 Cache.applicationProperties.setProperty("STORED_LINKS",
756 nonMenuLinks.toString());
759 Cache.applicationProperties.setProperty("DEFAULT_URL",
760 sequenceUrlLinks.getPrimaryUrlId());
765 Cache.setProperty("VERSION_CHECK",
766 Boolean.toString(versioncheck.isSelected()));
767 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
769 // default is false - we only set this if the user has actively agreed
770 Cache.setProperty("USAGESTATS",
771 Boolean.toString(usagestats.isSelected()));
773 if (!questionnaire.isSelected())
775 Cache.setProperty("NOQUESTIONNAIRES", "true");
779 // special - made easy to edit a property file to disable questionnaires
780 // by just adding the given line
781 Cache.removeProperty("NOQUESTIONNAIRES");
785 * Save Output settings
787 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
788 Boolean.toString(blcjv.isSelected()));
789 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
790 Boolean.toString(clustaljv.isSelected()));
791 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
792 Boolean.toString(fastajv.isSelected()));
793 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
794 Boolean.toString(msfjv.isSelected()));
795 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
796 Boolean.toString(pfamjv.isSelected()));
797 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
798 Boolean.toString(pileupjv.isSelected()));
799 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
800 Boolean.toString(pirjv.isSelected()));
801 Cache.applicationProperties.setProperty("PIR_MODELLER",
802 Boolean.toString(modellerOutput.isSelected()));
803 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
804 Boolean.toString(embbedBioJSON.isSelected()));
805 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
807 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
808 Boolean.toString(autoIdWidth.isSelected()));
809 userIdWidth_actionPerformed();
810 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
811 userIdWidth.getText());
814 * Save Editing settings
816 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
817 Boolean.toString(autoCalculateConsCheck.isSelected()));
818 Cache.applicationProperties.setProperty("SORT_BY_TREE",
819 Boolean.toString(sortByTree.isSelected()));
820 Cache.applicationProperties.setProperty("PAD_GAPS",
821 Boolean.toString(padGaps.isSelected()));
823 wsPrefs.updateAndRefreshWsMenuConfig(false);
826 * Save Backups settings
828 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
829 Boolean.toString(enableBackupFiles.isSelected()));
830 int preset = getComboIntStringKey(backupfilesPresetsCombo);
831 Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET",
832 Integer.toString(preset));
834 if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
836 BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
837 BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
838 BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
839 Cache.applicationProperties.setProperty(
840 BackupFilesPresetEntry.CUSTOMCONFIG, customBFPE.toString());
843 BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
845 Cache.applicationProperties.setProperty(
846 BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
848 Cache.saveProperties();
849 Desktop.instance.doConfigureStructurePrefs();
852 frame.setClosed(true);
853 } catch (Exception ex)
858 public void saveProxySettings()
860 Cache.applicationProperties.setProperty("USE_PROXY",
861 customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
862 : noProxy.isSelected() ? Cache.PROXYTYPE_NONE
863 : Cache.PROXYTYPE_SYSTEM);
864 Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText());
865 Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
866 Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
867 Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText());
868 Cache.setOrRemove("PROXY_AUTH",
869 Boolean.toString(proxyAuth.isSelected()));
870 Cache.setOrRemove("PROXY_AUTH_USERNAME", proxyAuthUsernameTB.getText());
871 Cache.proxyAuthPassword = proxyAuthPasswordTB.getPassword();
872 Cache.setProxyPropertiesFromPreferences(previousProxyType);
876 * Do any necessary validation before saving settings. Return focus to the
877 * first tab which fails validation.
881 private boolean validateSettings()
883 if (!validateStructure())
885 structureTab.requestFocusInWindow();
892 protected boolean validateStructure()
894 return validateChimeraPath();
902 public void startupFileTextfield_mouseClicked()
904 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
905 JalviewFileChooser chooser = JalviewFileChooser
906 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
907 chooser.setFileView(new JalviewFileView());
908 chooser.setDialogTitle(
909 MessageManager.getString("label.select_startup_file"));
911 int value = chooser.showOpenDialog(this);
913 if (value == JalviewFileChooser.APPROVE_OPTION)
915 FileFormatI format = chooser.getSelectedFormat();
918 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
922 .setText(chooser.getSelectedFile().getAbsolutePath());
933 public void cancel_actionPerformed(ActionEvent e)
937 wsPrefs.updateWsMenuConfig(true);
938 wsPrefs.refreshWs_actionPerformed(e);
939 frame.setClosed(true);
940 } catch (Exception ex)
952 public void annotations_actionPerformed(ActionEvent e)
954 conservation.setEnabled(annotations.isSelected());
955 quality.setEnabled(annotations.isSelected());
956 identity.setEnabled(annotations.isSelected());
957 showOccupancy.setEnabled(annotations.isSelected());
958 showGroupConsensus.setEnabled(annotations.isSelected());
959 showGroupConservation.setEnabled(annotations.isSelected());
960 showConsensHistogram.setEnabled(annotations.isSelected()
961 && (identity.isSelected() || showGroupConsensus.isSelected()));
962 showConsensLogo.setEnabled(annotations.isSelected()
963 && (identity.isSelected() || showGroupConsensus.isSelected()));
967 public void newLink_actionPerformed(ActionEvent e)
969 GSequenceLink link = new GSequenceLink();
970 boolean valid = false;
973 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
974 MessageManager.getString("label.new_sequence_url_link"),
975 JvOptionPane.OK_CANCEL_OPTION, -1,
976 null) == JvOptionPane.OK_OPTION)
978 if (link.checkValid())
980 if (((UrlLinkTableModel) linkUrlTable.getModel())
981 .isUniqueName(link.getName()))
983 ((UrlLinkTableModel) linkUrlTable.getModel())
984 .insertRow(link.getName(), link.getURL());
989 link.notifyDuplicate();
1002 public void editLink_actionPerformed(ActionEvent e)
1004 GSequenceLink link = new GSequenceLink();
1006 int index = linkUrlTable.getSelectedRow();
1009 // button no longer enabled if row is not selected
1010 Cache.log.debug("Edit with no row selected in linkUrlTable");
1014 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1016 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1018 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1019 link.setName(oldName);
1020 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1022 boolean valid = false;
1025 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1026 MessageManager.getString("label.edit_sequence_url_link"),
1027 JvOptionPane.OK_CANCEL_OPTION, -1,
1028 null) == JvOptionPane.OK_OPTION)
1030 if (link.checkValid())
1032 if ((oldName.equals(link.getName()))
1033 || (((UrlLinkTableModel) linkUrlTable.getModel())
1034 .isUniqueName(link.getName())))
1036 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1037 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1042 link.notifyDuplicate();
1055 public void deleteLink_actionPerformed(ActionEvent e)
1057 int index = linkUrlTable.getSelectedRow();
1058 int modelIndex = -1;
1061 // button no longer enabled if row is not selected
1062 Cache.log.debug("Delete with no row selected in linkUrlTable");
1067 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1070 // make sure we use the model index to delete, and not the table index
1071 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1075 public void defaultBrowser_mouseClicked(MouseEvent e)
1077 JFileChooser chooser = new JFileChooser(".");
1078 chooser.setDialogTitle(
1079 MessageManager.getString("label.select_default_browser"));
1081 int value = chooser.showOpenDialog(this);
1083 if (value == JFileChooser.APPROVE_OPTION)
1085 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1094 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1098 protected void showunconserved_actionPerformed(ActionEvent e)
1100 // TODO Auto-generated method stub
1101 super.showunconserved_actionPerformed(e);
1104 public static List<String> getGroupURLLinks()
1106 return groupURLLinks;
1110 public void minColour_actionPerformed(JPanel panel)
1112 Color col = JColorChooser.showDialog(this,
1113 MessageManager.getString("label.select_colour_minimum_value"),
1114 minColour.getBackground());
1117 panel.setBackground(col);
1123 public void maxColour_actionPerformed(JPanel panel)
1125 Color col = JColorChooser.showDialog(this,
1126 MessageManager.getString("label.select_colour_maximum_value"),
1127 maxColour.getBackground());
1130 panel.setBackground(col);
1136 public void gapColour_actionPerformed(JPanel gap)
1138 if (!useLegacyGap.isSelected())
1140 Color col = JColorChooser.showDialog(this,
1141 MessageManager.getString("label.select_gap_colour"),
1142 gapColour.getBackground());
1145 gap.setBackground(col);
1152 public void hiddenColour_actionPerformed(JPanel hidden)
1154 Color col = JColorChooser.showDialog(this,
1155 MessageManager.getString("label.select_hidden_colour"),
1156 hiddenColour.getBackground());
1159 hidden.setBackground(col);
1165 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1167 boolean enabled = useLegacyGap.isSelected();
1170 gapColour.setBackground(
1171 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1175 gapColour.setBackground(
1176 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1178 gapColour.setEnabled(!enabled);
1179 gapLabel.setEnabled(!enabled);
1183 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1185 useLegacyGap.setSelected(false);
1186 useLegacyGaps_actionPerformed(null);
1187 showHiddenAtStart.setSelected(false);
1188 hiddenColour.setBackground(
1189 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1193 protected void userIdWidth_actionPerformed()
1197 String val = userIdWidth.getText().trim();
1198 if (val.length() > 0)
1200 Integer iw = Integer.parseInt(val);
1201 if (iw.intValue() < 12)
1203 throw new NumberFormatException();
1205 userIdWidth.setText(iw.toString());
1207 } catch (NumberFormatException x)
1209 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1211 .getString("warn.user_defined_width_requirements"),
1212 MessageManager.getString("label.invalid_id_column_width"),
1213 JvOptionPane.WARNING_MESSAGE);
1214 userIdWidth.setText("");
1219 protected void autoIdWidth_actionPerformed()
1221 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1222 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1226 * Returns true if chimera path is to a valid executable, else show an error
1229 private boolean validateChimeraPath()
1231 if (chimeraPath.getText().trim().length() > 0)
1233 File f = new File(chimeraPath.getText());
1234 if (!f.canExecute())
1236 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1237 MessageManager.getString("label.invalid_chimera_path"),
1238 MessageManager.getString("label.invalid_name"),
1239 JvOptionPane.ERROR_MESSAGE);
1247 * If Chimera is selected, check it can be found on default or user-specified
1248 * path, if not show a warning/help dialog.
1251 protected void structureViewer_actionPerformed(String selectedItem)
1253 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1257 boolean found = false;
1260 * Try user-specified and standard paths for Chimera executable.
1262 List<String> paths = StructureManager.getChimeraPaths();
1263 paths.add(0, chimeraPath.getText());
1264 for (String path : paths)
1266 if (new File(path.trim()).canExecute())
1274 String[] options = { "OK", "Help" };
1275 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1276 JvSwingUtils.wrapTooltip(true,
1277 MessageManager.getString("label.chimera_missing")),
1278 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1279 null, options, options[0]);
1280 if (showHelp == JvOptionPane.NO_OPTION)
1284 Help.showHelpWindow(HelpId.StructureViewer);
1285 } catch (HelpSetException e)
1287 e.printStackTrace();
1293 public class OptionsParam
1295 private String name;
1297 private String code;
1299 public OptionsParam(String name, String code)
1305 public String getName()
1310 public void setName(String name)
1315 public String getCode()
1320 public void setCode(String code)
1326 public String toString()
1332 public boolean equals(Object that)
1334 if (!(that instanceof OptionsParam))
1338 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1342 public int hashCode()
1344 return name.hashCode() + code.hashCode();
1348 private class UrlListSelectionHandler implements ListSelectionListener
1352 public void valueChanged(ListSelectionEvent e)
1354 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1356 int index = lsm.getMinSelectionIndex();
1359 // no selection, so disable delete/edit buttons
1360 editLink.setEnabled(false);
1361 deleteLink.setEnabled(false);
1364 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1366 // enable/disable edit and delete link buttons
1367 if (((UrlLinkTableModel) linkUrlTable.getModel())
1368 .isRowDeletable(modelIndex))
1370 deleteLink.setEnabled(true);
1374 deleteLink.setEnabled(false);
1377 if (((UrlLinkTableModel) linkUrlTable.getModel())
1378 .isRowEditable(modelIndex))
1380 editLink.setEnabled(true);
1384 editLink.setEnabled(false);