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.BackupFiles;
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.MouseEvent;
54 import java.util.ArrayList;
55 import java.util.List;
57 import javax.help.HelpSetException;
58 import javax.swing.JColorChooser;
59 import javax.swing.JFileChooser;
60 import javax.swing.JInternalFrame;
61 import javax.swing.JPanel;
62 import javax.swing.ListSelectionModel;
63 import javax.swing.RowFilter;
64 import javax.swing.RowSorter;
65 import javax.swing.SortOrder;
66 import javax.swing.event.DocumentEvent;
67 import javax.swing.event.DocumentListener;
68 import javax.swing.event.ListSelectionEvent;
69 import javax.swing.event.ListSelectionListener;
70 import javax.swing.table.TableCellRenderer;
71 import javax.swing.table.TableColumn;
72 import javax.swing.table.TableModel;
73 import javax.swing.table.TableRowSorter;
75 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
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;
126 * Holds name and link separated with | character. Sequence ID must be
127 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
129 public static UrlProviderI sequenceUrlLinks;
131 public static UrlLinkTableModel dataModel;
134 * Holds name and link separated with | character. Sequence IDS and Sequences
135 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
136 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
137 * for first and second token specified after a pipe character at end |,|.
138 * (TODO: proper escape for using | to separate ids or sequences
141 public static List<String> groupURLLinks;
144 // get links selected to be in the menu (SEQUENCE_LINKS)
145 // and links entered by the user but not selected (STORED_LINKS)
146 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
147 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
148 String defaultUrl = Cache.getDefault("DEFAULT_URL",
149 UrlConstants.DEFAULT_LABEL);
151 // if both links lists are empty, add the DEFAULT_URL link
152 // otherwise we assume the default link is in one of the lists
153 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
155 inMenuString = UrlConstants.DEFAULT_STRING;
157 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
158 inMenuString, notInMenuString);
159 sequenceUrlLinks = factory.createUrlProvider();
160 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
163 * TODO: reformulate groupURL encoding so two or more can be stored in the
164 * .properties file as '|' separated strings
167 groupURLLinks = new ArrayList<>();
170 JInternalFrame frame;
172 private WsPreferences wsPrefs;
174 private OptionsParam promptEachTimeOpt = new OptionsParam(
175 MessageManager.getString("label.prompt_each_time"),
178 private OptionsParam lineArtOpt = new OptionsParam(
179 MessageManager.getString("label.lineart"), "Lineart");
181 private OptionsParam textOpt = new OptionsParam(
182 MessageManager.getString("action.text"), "Text");
185 * Creates a new Preferences object.
190 frame = new JInternalFrame();
191 frame.setContentPane(this);
192 wsPrefs = new WsPreferences();
193 wsTab.add(wsPrefs, BorderLayout.CENTER);
194 int width = 500, height = 450;
195 new jalview.util.Platform();
196 if (Platform.isAMac())
202 Desktop.addInternalFrame(frame,
203 MessageManager.getString("label.preferences"), width, height);
204 frame.setMinimumSize(new Dimension(width, height));
207 * Set Visual tab defaults
209 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
210 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
211 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
212 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
214 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
215 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
216 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
217 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
219 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
220 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
222 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
223 showGroupConservation.setSelected(
224 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
225 showConsensHistogram.setSelected(
226 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
228 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
230 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
232 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
234 String[] fonts = java.awt.GraphicsEnvironment
235 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
236 for (int i = 0; i < fonts.length; i++)
238 fontNameCB.addItem(fonts[i]);
241 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
243 fontSizeCB.addItem(i + "");
246 fontStyleCB.addItem("plain");
247 fontStyleCB.addItem("bold");
248 fontStyleCB.addItem("italic");
250 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
251 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
252 fontStyleCB.setSelectedItem(
253 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
255 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
257 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
259 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
261 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
263 gapSymbolCB.addItem("-");
264 gapSymbolCB.addItem(".");
266 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
268 sortby.addItem("No sort");
269 sortby.addItem("Id");
270 sortby.addItem("Pairwise Identity");
271 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
273 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
275 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
277 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
278 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
279 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
280 SequenceAnnotationOrder.NONE.name()));
281 sortAnnBy.setSelectedItem(savedSort.toString());
283 sortAutocalc.addItem("Autocalculated first");
284 sortAutocalc.addItem("Autocalculated last");
285 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
286 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
287 : sortAutocalc.getItemAt(1));
289 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
290 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
291 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
292 + "/examples/exampleFile_2_3.jar"));
295 * Set Colours tab defaults
297 protColour.addItem(ResidueColourScheme.NONE);
298 nucColour.addItem(ResidueColourScheme.NONE);
299 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
301 String name = cs.getSchemeName();
302 protColour.addItem(name);
303 nucColour.addItem(name);
305 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
306 ResidueColourScheme.NONE);
307 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
308 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
309 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
310 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
311 minColour.setBackground(
312 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
313 maxColour.setBackground(
314 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
317 * Set overview panel defaults
319 gapColour.setBackground(
320 Cache.getDefaultColour(GAP_COLOUR,
321 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
322 hiddenColour.setBackground(
323 Cache.getDefaultColour(HIDDEN_COLOUR,
324 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
325 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
326 gapLabel.setEnabled(!useLegacyGap.isSelected());
327 gapColour.setEnabled(!useLegacyGap.isSelected());
329 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
332 * Set Structure tab defaults.
334 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
335 structFromPdb.setSelected(structSelected);
336 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
337 useRnaView.setEnabled(structSelected);
338 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
339 addSecondaryStructure.setEnabled(structSelected);
340 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
341 addTempFactor.setEnabled(structSelected);
342 structViewer.setSelectedItem(
343 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
344 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
345 chimeraPath.addActionListener(new ActionListener()
348 public void actionPerformed(ActionEvent e)
350 validateChimeraPath();
354 if (Cache.getDefault("MAP_WITH_SIFTS", false))
356 siftsMapping.setSelected(true);
360 nwMapping.setSelected(true);
364 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
367 * Set Connections tab defaults
371 linkUrlTable.setModel(dataModel);
372 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
373 linkUrlTable.getModel());
374 linkUrlTable.setRowSorter(sorter);
375 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
377 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
378 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
379 SortOrder.DESCENDING));
380 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
381 SortOrder.DESCENDING));
383 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
385 sorter.setSortKeys(sortKeys);
389 ActionListener onReset;
390 onReset = new ActionListener()
393 public void actionPerformed(ActionEvent e)
395 filterTB.setText("");
396 sorter.setRowFilter(RowFilter.regexFilter(""));
400 doReset.addActionListener(onReset);
402 // filter to display only custom urls
403 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
406 public boolean include(
407 Entry<? extends TableModel, ? extends Object> entry)
409 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
413 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
414 linkUrlTable.getModel());
415 customSorter.setRowFilter(customUrlFilter);
417 ActionListener onCustomOnly;
418 onCustomOnly = new ActionListener()
421 public void actionPerformed(ActionEvent e)
423 filterTB.setText("");
424 sorter.setRowFilter(customUrlFilter);
427 userOnly.addActionListener(onCustomOnly);
429 filterTB.getDocument().addDocumentListener(new DocumentListener()
431 String caseInsensitiveFlag = "(?i)";
434 public void changedUpdate(DocumentEvent e)
436 sorter.setRowFilter(RowFilter
437 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
441 public void removeUpdate(DocumentEvent e)
443 sorter.setRowFilter(RowFilter
444 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
448 public void insertUpdate(DocumentEvent e)
450 sorter.setRowFilter(RowFilter
451 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
455 // set up list selection functionality
456 linkUrlTable.getSelectionModel()
457 .addListSelectionListener(new UrlListSelectionHandler());
459 // set up radio buttons
460 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
462 String onClickName = linkUrlTable.getColumnName(onClickCol);
463 linkUrlTable.getColumn(onClickName)
464 .setCellRenderer(new RadioButtonRenderer());
465 linkUrlTable.getColumn(onClickName)
466 .setCellEditor(new RadioButtonEditor());
468 // get boolean columns and resize those to min possible
469 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
471 if (linkUrlTable.getModel().getColumnClass(column)
472 .equals(Boolean.class))
474 TableColumn tableColumn = linkUrlTable.getColumnModel()
476 int preferredWidth = tableColumn.getMinWidth();
478 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
480 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
481 int cwidth = c.getPreferredSize().width
482 + linkUrlTable.getIntercellSpacing().width;
483 preferredWidth = Math.max(preferredWidth, cwidth);
485 tableColumn.setPreferredWidth(preferredWidth);
489 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
490 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
491 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
492 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
494 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
496 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
497 // note antisense here: default is true
499 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
500 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
503 * Set Output tab defaults
505 epsRendering.addItem(promptEachTimeOpt);
506 epsRendering.addItem(lineArtOpt);
507 epsRendering.addItem(textOpt);
508 String defaultEPS = Cache.getDefault("EPS_RENDERING",
510 if (defaultEPS.equalsIgnoreCase("Text"))
512 epsRendering.setSelectedItem(textOpt);
514 else if (defaultEPS.equalsIgnoreCase("Lineart"))
516 epsRendering.setSelectedItem(lineArtOpt);
520 epsRendering.setSelectedItem(promptEachTimeOpt);
522 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
523 userIdWidth.setEnabled(!autoIdWidth.isSelected());
524 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
525 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
526 userIdWidth.setText(wi == null ? "" : wi.toString());
527 // TODO: refactor to use common enum via FormatAdapter and allow extension
528 // for new flat file formats
529 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
530 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
531 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
532 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
533 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
534 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
535 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
536 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
538 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
541 * Set Editing tab defaults
543 autoCalculateConsCheck
544 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
545 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
546 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
548 annotations_actionPerformed(null); // update the display of the annotation
553 * Set Backups tab defaults
556 .setSelected(Cache.getDefault(BackupFiles.ENABLED, true));
557 suffixTemplate.setText(Cache.getDefault(BackupFiles.SUFFIX,
558 ".v" + BackupFiles.NUM_PLACEHOLDER));
560 .setValue(Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3));
561 suffixReverse.setSelected(
562 Cache.getDefault(BackupFiles.REVERSE_ORDER, false));
564 .setSelected(Cache.getDefault(BackupFiles.NO_MAX, false));
565 backupfilesRollMaxSpinner
566 .setValue(Cache.getDefault(BackupFiles.ROLL_MAX, 4));
567 backupfilesConfirmDelete.setSelected(
568 Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true));
569 setComboIntStringKey(backupfilesPresetsCombo, Cache.getDefault(BackupFiles.NS+"_PRESET", 0));
570 backupsOptionsSetEnabled(enableBackupFiles.isSelected());
572 updateBackupFilesExampleLabel();
574 suffixPanel.setPreferredSize(
575 new Dimension(width, suffixPanel.getHeight()));
576 keepfilesPanel.setPreferredSize(
577 new Dimension(width, keepfilesPanel.getHeight()));
578 exampleFilesPanel.setPreferredSize(
579 new Dimension(width, exampleFilesPanel.getHeight()));
585 * Save user selections on the Preferences tabs to the Cache and write out to
591 public void ok_actionPerformed(ActionEvent e)
593 if (!validateSettings())
599 * Save Visual settings
601 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
602 Boolean.toString(seqLimit.isSelected()));
603 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
604 Boolean.toString(rightAlign.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
606 Boolean.toString(fullScreen.isSelected()));
607 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
608 Boolean.toString(openoverv.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
610 Boolean.toString(annotations.isSelected()));
611 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
612 Boolean.toString(conservation.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_QUALITY",
614 Boolean.toString(quality.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
616 Boolean.toString(identity.isSelected()));
618 Cache.applicationProperties.setProperty("GAP_SYMBOL",
619 gapSymbolCB.getSelectedItem().toString());
621 Cache.applicationProperties.setProperty("FONT_NAME",
622 fontNameCB.getSelectedItem().toString());
623 Cache.applicationProperties.setProperty("FONT_STYLE",
624 fontStyleCB.getSelectedItem().toString());
625 Cache.applicationProperties.setProperty("FONT_SIZE",
626 fontSizeCB.getSelectedItem().toString());
628 Cache.applicationProperties.setProperty("ID_ITALICS",
629 Boolean.toString(idItalics.isSelected()));
630 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
631 Boolean.toString(showUnconserved.isSelected()));
632 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
633 Boolean.toString(showOccupancy.isSelected()));
634 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
635 Boolean.toString(showGroupConsensus.isSelected()));
636 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
637 Boolean.toString(showGroupConservation.isSelected()));
638 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
639 Boolean.toString(showConsensHistogram.isSelected()));
640 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
641 Boolean.toString(showConsensLogo.isSelected()));
642 Cache.applicationProperties.setProperty("ANTI_ALIAS",
643 Boolean.toString(smoothFont.isSelected()));
644 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
645 Boolean.toString(scaleProteinToCdna.isSelected()));
646 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
647 Boolean.toString(showNpTooltip.isSelected()));
648 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
649 Boolean.toString(showDbRefTooltip.isSelected()));
651 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
652 Boolean.toString(wrap.isSelected()));
654 Cache.applicationProperties.setProperty("STARTUP_FILE",
655 startupFileTextfield.getText());
656 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
657 Boolean.toString(startupCheckbox.isSelected()));
659 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
660 sortby.getSelectedItem().toString());
662 // convert description of sort order to enum name for save
663 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
664 .forDescription(sortAnnBy.getSelectedItem().toString());
665 if (annSortOrder != null)
667 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
668 annSortOrder.name());
671 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
672 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
673 Boolean.valueOf(showAutocalcFirst).toString());
676 * Save Colours settings
678 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
679 protColour.getSelectedItem().toString());
680 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
681 nucColour.getSelectedItem().toString());
682 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
683 minColour.getBackground());
684 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
685 maxColour.getBackground());
688 * Save Overview settings
690 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
691 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
692 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
693 Boolean.toString(useLegacyGap.isSelected()));
694 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
695 Boolean.toString(showHiddenAtStart.isSelected()));
698 * Save Structure settings
700 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
701 Boolean.toString(addTempFactor.isSelected()));
702 Cache.applicationProperties.setProperty(ADD_SS_ANN,
703 Boolean.toString(addSecondaryStructure.isSelected()));
704 Cache.applicationProperties.setProperty(USE_RNAVIEW,
705 Boolean.toString(useRnaView.isSelected()));
706 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
707 Boolean.toString(structFromPdb.isSelected()));
708 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
709 structViewer.getSelectedItem().toString());
710 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
711 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
712 Boolean.toString(siftsMapping.isSelected()));
713 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
716 * Save Output settings
718 Cache.applicationProperties.setProperty("EPS_RENDERING",
719 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
722 * Save Connections settings
724 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
726 jalview.util.BrowserLauncher.resetBrowser();
728 // save user-defined and selected links
729 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
730 if (menuLinks.isEmpty())
732 Cache.applicationProperties.remove("SEQUENCE_LINKS");
736 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
737 menuLinks.toString());
740 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
741 if (nonMenuLinks.isEmpty())
743 Cache.applicationProperties.remove("STORED_LINKS");
747 Cache.applicationProperties.setProperty("STORED_LINKS",
748 nonMenuLinks.toString());
751 Cache.applicationProperties.setProperty("DEFAULT_URL",
752 sequenceUrlLinks.getPrimaryUrlId());
754 Cache.applicationProperties.setProperty("USE_PROXY",
755 Boolean.toString(useProxy.isSelected()));
757 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
759 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
761 if (useProxy.isSelected())
763 System.setProperty("http.proxyHost", proxyServerTB.getText());
764 System.setProperty("http.proxyPort", proxyPortTB.getText());
768 System.setProperty("http.proxyHost", "");
769 System.setProperty("http.proxyPort", "");
771 Cache.setProperty("VERSION_CHECK",
772 Boolean.toString(versioncheck.isSelected()));
773 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
775 // default is false - we only set this if the user has actively agreed
776 Cache.setProperty("USAGESTATS",
777 Boolean.toString(usagestats.isSelected()));
779 if (!questionnaire.isSelected())
781 Cache.setProperty("NOQUESTIONNAIRES", "true");
785 // special - made easy to edit a property file to disable questionnaires
786 // by just adding the given line
787 Cache.removeProperty("NOQUESTIONNAIRES");
791 * Save Output settings
793 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
794 Boolean.toString(blcjv.isSelected()));
795 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
796 Boolean.toString(clustaljv.isSelected()));
797 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
798 Boolean.toString(fastajv.isSelected()));
799 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
800 Boolean.toString(msfjv.isSelected()));
801 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
802 Boolean.toString(pfamjv.isSelected()));
803 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
804 Boolean.toString(pileupjv.isSelected()));
805 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
806 Boolean.toString(pirjv.isSelected()));
807 Cache.applicationProperties.setProperty("PIR_MODELLER",
808 Boolean.toString(modellerOutput.isSelected()));
809 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
810 Boolean.toString(embbedBioJSON.isSelected()));
811 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
813 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
814 Boolean.toString(autoIdWidth.isSelected()));
815 userIdWidth_actionPerformed();
816 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
817 userIdWidth.getText());
820 * Save Editing settings
822 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
823 Boolean.toString(autoCalculateConsCheck.isSelected()));
824 Cache.applicationProperties.setProperty("SORT_BY_TREE",
825 Boolean.toString(sortByTree.isSelected()));
826 Cache.applicationProperties.setProperty("PAD_GAPS",
827 Boolean.toString(padGaps.isSelected()));
829 wsPrefs.updateAndRefreshWsMenuConfig(false);
832 * Save Backups settings
834 Cache.applicationProperties.setProperty(BackupFiles.CONFIRM_DELETE_OLD,
835 Boolean.toString(backupfilesConfirmDelete.isSelected()));
836 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
837 Boolean.toString(enableBackupFiles.isSelected()));
838 Cache.applicationProperties.setProperty(BackupFiles.NO_MAX,
839 Boolean.toString(backupfilesKeepAll.isSelected()));
840 Cache.applicationProperties.setProperty(BackupFiles.REVERSE_ORDER,
841 Boolean.toString(suffixReverse.isSelected()));
842 Cache.applicationProperties.setProperty(BackupFiles.SUFFIX,
843 suffixTemplate.getText());
844 Cache.applicationProperties.setProperty(BackupFiles.ROLL_MAX,
845 Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
846 Cache.applicationProperties.setProperty(BackupFiles.SUFFIX_DIGITS,
847 Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
848 Cache.applicationProperties.setProperty(BackupFiles.NS+"_PRESET",
849 Integer.toString(getComboIntStringKey(backupfilesPresetsCombo)));
851 Cache.saveProperties();
852 Desktop.instance.doConfigureStructurePrefs();
855 frame.setClosed(true);
856 } catch (Exception ex)
862 * Do any necessary validation before saving settings. Return focus to the
863 * first tab which fails validation.
867 private boolean validateSettings()
869 if (!validateStructure())
871 structureTab.requestFocusInWindow();
878 protected boolean validateStructure()
880 return validateChimeraPath();
888 public void startupFileTextfield_mouseClicked()
890 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
891 JalviewFileChooser chooser = JalviewFileChooser
892 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
893 chooser.setFileView(new JalviewFileView());
894 chooser.setDialogTitle(
895 MessageManager.getString("label.select_startup_file"));
897 int value = chooser.showOpenDialog(this);
899 if (value == JalviewFileChooser.APPROVE_OPTION)
901 FileFormatI format = chooser.getSelectedFormat();
904 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
908 .setText(chooser.getSelectedFile().getAbsolutePath());
919 public void cancel_actionPerformed(ActionEvent e)
923 wsPrefs.updateWsMenuConfig(true);
924 wsPrefs.refreshWs_actionPerformed(e);
925 frame.setClosed(true);
926 } catch (Exception ex)
938 public void annotations_actionPerformed(ActionEvent e)
940 conservation.setEnabled(annotations.isSelected());
941 quality.setEnabled(annotations.isSelected());
942 identity.setEnabled(annotations.isSelected());
943 showOccupancy.setEnabled(annotations.isSelected());
944 showGroupConsensus.setEnabled(annotations.isSelected());
945 showGroupConservation.setEnabled(annotations.isSelected());
946 showConsensHistogram.setEnabled(annotations.isSelected()
947 && (identity.isSelected() || showGroupConsensus.isSelected()));
948 showConsensLogo.setEnabled(annotations.isSelected()
949 && (identity.isSelected() || showGroupConsensus.isSelected()));
953 public void newLink_actionPerformed(ActionEvent e)
955 GSequenceLink link = new GSequenceLink();
956 boolean valid = false;
959 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
960 MessageManager.getString("label.new_sequence_url_link"),
961 JvOptionPane.OK_CANCEL_OPTION, -1,
962 null) == JvOptionPane.OK_OPTION)
964 if (link.checkValid())
966 if (((UrlLinkTableModel) linkUrlTable.getModel())
967 .isUniqueName(link.getName()))
969 ((UrlLinkTableModel) linkUrlTable.getModel())
970 .insertRow(link.getName(), link.getURL());
975 link.notifyDuplicate();
988 public void editLink_actionPerformed(ActionEvent e)
990 GSequenceLink link = new GSequenceLink();
992 int index = linkUrlTable.getSelectedRow();
995 // button no longer enabled if row is not selected
996 Cache.log.debug("Edit with no row selected in linkUrlTable");
1000 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1002 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1004 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1005 link.setName(oldName);
1006 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1008 boolean valid = false;
1011 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1012 MessageManager.getString("label.edit_sequence_url_link"),
1013 JvOptionPane.OK_CANCEL_OPTION, -1,
1014 null) == JvOptionPane.OK_OPTION)
1016 if (link.checkValid())
1018 if ((oldName.equals(link.getName()))
1019 || (((UrlLinkTableModel) linkUrlTable.getModel())
1020 .isUniqueName(link.getName())))
1022 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1023 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1028 link.notifyDuplicate();
1041 public void deleteLink_actionPerformed(ActionEvent e)
1043 int index = linkUrlTable.getSelectedRow();
1044 int modelIndex = -1;
1047 // button no longer enabled if row is not selected
1048 Cache.log.debug("Delete with no row selected in linkUrlTable");
1053 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1056 // make sure we use the model index to delete, and not the table index
1057 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1061 public void defaultBrowser_mouseClicked(MouseEvent e)
1063 JFileChooser chooser = new JFileChooser(".");
1064 chooser.setDialogTitle(
1065 MessageManager.getString("label.select_default_browser"));
1067 int value = chooser.showOpenDialog(this);
1069 if (value == JFileChooser.APPROVE_OPTION)
1071 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1080 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1084 protected void showunconserved_actionPerformed(ActionEvent e)
1086 // TODO Auto-generated method stub
1087 super.showunconserved_actionPerformed(e);
1090 public static List<String> getGroupURLLinks()
1092 return groupURLLinks;
1096 public void minColour_actionPerformed(JPanel panel)
1098 Color col = JColorChooser.showDialog(this,
1099 MessageManager.getString("label.select_colour_minimum_value"),
1100 minColour.getBackground());
1103 panel.setBackground(col);
1109 public void maxColour_actionPerformed(JPanel panel)
1111 Color col = JColorChooser.showDialog(this,
1112 MessageManager.getString("label.select_colour_maximum_value"),
1113 maxColour.getBackground());
1116 panel.setBackground(col);
1122 public void gapColour_actionPerformed(JPanel gap)
1124 if (!useLegacyGap.isSelected())
1126 Color col = JColorChooser.showDialog(this,
1127 MessageManager.getString("label.select_gap_colour"),
1128 gapColour.getBackground());
1131 gap.setBackground(col);
1138 public void hiddenColour_actionPerformed(JPanel hidden)
1140 Color col = JColorChooser.showDialog(this,
1141 MessageManager.getString("label.select_hidden_colour"),
1142 hiddenColour.getBackground());
1145 hidden.setBackground(col);
1151 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1153 boolean enabled = useLegacyGap.isSelected();
1156 gapColour.setBackground(
1157 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1161 gapColour.setBackground(
1162 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1164 gapColour.setEnabled(!enabled);
1165 gapLabel.setEnabled(!enabled);
1169 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1171 useLegacyGap.setSelected(false);
1172 useLegacyGaps_actionPerformed(null);
1173 showHiddenAtStart.setSelected(true);
1174 hiddenColour.setBackground(
1175 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1179 protected void userIdWidth_actionPerformed()
1183 String val = userIdWidth.getText().trim();
1184 if (val.length() > 0)
1186 Integer iw = Integer.parseInt(val);
1187 if (iw.intValue() < 12)
1189 throw new NumberFormatException();
1191 userIdWidth.setText(iw.toString());
1193 } catch (NumberFormatException x)
1195 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1197 .getString("warn.user_defined_width_requirements"),
1198 MessageManager.getString("label.invalid_id_column_width"),
1199 JvOptionPane.WARNING_MESSAGE);
1200 userIdWidth.setText("");
1205 protected void autoIdWidth_actionPerformed()
1207 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1208 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1212 * Returns true if chimera path is to a valid executable, else show an error
1215 private boolean validateChimeraPath()
1217 if (chimeraPath.getText().trim().length() > 0)
1219 File f = new File(chimeraPath.getText());
1220 if (!f.canExecute())
1222 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1223 MessageManager.getString("label.invalid_chimera_path"),
1224 MessageManager.getString("label.invalid_name"),
1225 JvOptionPane.ERROR_MESSAGE);
1233 * If Chimera is selected, check it can be found on default or user-specified
1234 * path, if not show a warning/help dialog.
1237 protected void structureViewer_actionPerformed(String selectedItem)
1239 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1243 boolean found = false;
1246 * Try user-specified and standard paths for Chimera executable.
1248 List<String> paths = StructureManager.getChimeraPaths();
1249 paths.add(0, chimeraPath.getText());
1250 for (String path : paths)
1252 if (new File(path.trim()).canExecute())
1260 String[] options = { "OK", "Help" };
1261 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1262 JvSwingUtils.wrapTooltip(true,
1263 MessageManager.getString("label.chimera_missing")),
1264 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1265 null, options, options[0]);
1266 if (showHelp == JvOptionPane.NO_OPTION)
1270 Help.showHelpWindow(HelpId.StructureViewer);
1271 } catch (HelpSetException e)
1273 e.printStackTrace();
1279 public class OptionsParam
1281 private String name;
1283 private String code;
1285 public OptionsParam(String name, String code)
1291 public String getName()
1296 public void setName(String name)
1301 public String getCode()
1306 public void setCode(String code)
1312 public String toString()
1318 public boolean equals(Object that)
1320 if (!(that instanceof OptionsParam))
1324 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1328 public int hashCode()
1330 return name.hashCode() + code.hashCode();
1334 private class UrlListSelectionHandler implements ListSelectionListener
1338 public void valueChanged(ListSelectionEvent e)
1340 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1342 int index = lsm.getMinSelectionIndex();
1345 // no selection, so disable delete/edit buttons
1346 editLink.setEnabled(false);
1347 deleteLink.setEnabled(false);
1350 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1352 // enable/disable edit and delete link buttons
1353 if (((UrlLinkTableModel) linkUrlTable.getModel())
1354 .isRowDeletable(modelIndex))
1356 deleteLink.setEnabled(true);
1360 deleteLink.setEnabled(false);
1363 if (((UrlLinkTableModel) linkUrlTable.getModel())
1364 .isRowEditable(modelIndex))
1366 editLink.setEnabled(true);
1370 editLink.setEnabled(false);