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.
192 frame = new JInternalFrame();
193 frame.setContentPane(this);
194 wsPrefs = new WsPreferences();
195 wsTab.add(wsPrefs, BorderLayout.CENTER);
196 int width = 500, height = 450;
197 new jalview.util.Platform();
198 if (Platform.isAMac())
204 Desktop.addInternalFrame(frame,
205 MessageManager.getString("label.preferences"), width, height);
206 frame.setMinimumSize(new Dimension(width, height));
209 * Set Visual tab defaults
211 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
212 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
213 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
214 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
216 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
217 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
218 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
219 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
221 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
222 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
224 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
225 showGroupConservation.setSelected(
226 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
227 showConsensHistogram.setSelected(
228 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
230 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
232 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
234 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
236 String[] fonts = java.awt.GraphicsEnvironment
237 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
238 for (int i = 0; i < fonts.length; i++)
240 fontNameCB.addItem(fonts[i]);
243 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
245 fontSizeCB.addItem(i + "");
248 fontStyleCB.addItem("plain");
249 fontStyleCB.addItem("bold");
250 fontStyleCB.addItem("italic");
252 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
253 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
254 fontStyleCB.setSelectedItem(
255 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
257 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", true));
259 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
261 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
263 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
265 gapSymbolCB.addItem("-");
266 gapSymbolCB.addItem(".");
268 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
270 sortby.addItem("No sort");
271 sortby.addItem("Id");
272 sortby.addItem("Pairwise Identity");
273 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
275 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
277 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
279 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
280 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
281 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
282 SequenceAnnotationOrder.NONE.name()));
283 sortAnnBy.setSelectedItem(savedSort.toString());
285 sortAutocalc.addItem("Autocalculated first");
286 sortAutocalc.addItem("Autocalculated last");
287 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
288 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
289 : sortAutocalc.getItemAt(1));
291 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
292 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
293 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
294 + "/examples/exampleFile_2_3.jar"));
297 * Set Colours tab defaults
299 protColour.addItem(ResidueColourScheme.NONE);
300 nucColour.addItem(ResidueColourScheme.NONE);
301 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
303 String name = cs.getSchemeName();
304 protColour.addItem(name);
305 nucColour.addItem(name);
307 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
308 ResidueColourScheme.NONE);
309 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
310 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
311 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
312 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
313 minColour.setBackground(
314 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
315 maxColour.setBackground(
316 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
319 * Set overview panel defaults
321 gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR,
322 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
323 hiddenColour.setBackground(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, false));
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 String proxyTypeString = Cache.getDefault("USE_PROXY", "false");
490 previousProxyType = proxyTypeString;
491 switch (proxyTypeString)
493 case Cache.PROXYTYPE_NONE:
494 proxyType.setSelected(noProxy.getModel(), true);
496 case Cache.PROXYTYPE_SYSTEM:
497 proxyType.setSelected(systemProxy.getModel(), true);
499 case Cache.PROXYTYPE_CUSTOM:
500 proxyType.setSelected(customProxy.getModel(), true);
503 String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
505 Cache.log.warn(message);
507 proxyServerHttpTB.setText(Cache.getDefault("PROXY_SERVER", ""));
508 proxyPortHttpTB.setText(Cache.getDefault("PROXY_PORT", ""));
509 proxyServerHttpsTB.setText(Cache.getDefault("PROXY_SERVER_HTTPS", ""));
510 proxyPortHttpsTB.setText(Cache.getDefault("PROXY_PORT_HTTPS", ""));
511 proxyAuth.setSelected(Cache.getDefault("PROXY_AUTH", false));
513 .setText(Cache.getDefault("PROXY_AUTH_USERNAME", ""));
515 .setText(Cache.getDefault("PROXY_AUTH_PASSWORD", ""));
516 setCustomProxyEnabled();
518 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
520 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
521 // note antisense here: default is true
523 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
524 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
527 * Set Output tab defaults
529 epsRendering.addItem(promptEachTimeOpt);
530 epsRendering.addItem(lineArtOpt);
531 epsRendering.addItem(textOpt);
532 String defaultEPS = Cache.getDefault("EPS_RENDERING",
534 if (defaultEPS.equalsIgnoreCase("Text"))
536 epsRendering.setSelectedItem(textOpt);
538 else if (defaultEPS.equalsIgnoreCase("Lineart"))
540 epsRendering.setSelectedItem(lineArtOpt);
544 epsRendering.setSelectedItem(promptEachTimeOpt);
546 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
547 userIdWidth.setEnabled(!autoIdWidth.isSelected());
548 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
549 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
550 userIdWidth.setText(wi == null ? "" : wi.toString());
551 // TODO: refactor to use common enum via FormatAdapter and allow extension
552 // for new flat file formats
553 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
554 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
555 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
556 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
557 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
558 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
559 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
560 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
562 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
565 * Set Editing tab defaults
567 autoCalculateConsCheck
568 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
569 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
570 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
572 annotations_actionPerformed(null); // update the display of the annotation
576 * Set Backups tab defaults
578 loadLastSavedBackupsOptions();
582 * Save user selections on the Preferences tabs to the Cache and write out to
588 public void ok_actionPerformed(ActionEvent e)
590 if (!validateSettings())
596 * Save Visual settings
598 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
599 Boolean.toString(seqLimit.isSelected()));
600 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
601 Boolean.toString(rightAlign.isSelected()));
602 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
603 Boolean.toString(fullScreen.isSelected()));
604 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
605 Boolean.toString(openoverv.isSelected()));
606 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
607 Boolean.toString(annotations.isSelected()));
608 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
609 Boolean.toString(conservation.isSelected()));
610 Cache.applicationProperties.setProperty("SHOW_QUALITY",
611 Boolean.toString(quality.isSelected()));
612 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
613 Boolean.toString(identity.isSelected()));
615 Cache.applicationProperties.setProperty("GAP_SYMBOL",
616 gapSymbolCB.getSelectedItem().toString());
618 Cache.applicationProperties.setProperty("FONT_NAME",
619 fontNameCB.getSelectedItem().toString());
620 Cache.applicationProperties.setProperty("FONT_STYLE",
621 fontStyleCB.getSelectedItem().toString());
622 Cache.applicationProperties.setProperty("FONT_SIZE",
623 fontSizeCB.getSelectedItem().toString());
625 Cache.applicationProperties.setProperty("ID_ITALICS",
626 Boolean.toString(idItalics.isSelected()));
627 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
628 Boolean.toString(showUnconserved.isSelected()));
629 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
630 Boolean.toString(showOccupancy.isSelected()));
631 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
632 Boolean.toString(showGroupConsensus.isSelected()));
633 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
634 Boolean.toString(showGroupConservation.isSelected()));
635 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
636 Boolean.toString(showConsensHistogram.isSelected()));
637 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
638 Boolean.toString(showConsensLogo.isSelected()));
639 Cache.applicationProperties.setProperty("ANTI_ALIAS",
640 Boolean.toString(smoothFont.isSelected()));
641 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
642 Boolean.toString(scaleProteinToCdna.isSelected()));
643 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
644 Boolean.toString(showNpTooltip.isSelected()));
645 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
646 Boolean.toString(showDbRefTooltip.isSelected()));
648 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
649 Boolean.toString(wrap.isSelected()));
651 Cache.applicationProperties.setProperty("STARTUP_FILE",
652 startupFileTextfield.getText());
653 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
654 Boolean.toString(startupCheckbox.isSelected()));
656 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
657 sortby.getSelectedItem().toString());
659 // convert description of sort order to enum name for save
660 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
661 .forDescription(sortAnnBy.getSelectedItem().toString());
662 if (annSortOrder != null)
664 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
665 annSortOrder.name());
668 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
669 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
670 Boolean.valueOf(showAutocalcFirst).toString());
673 * Save Colours settings
675 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
676 protColour.getSelectedItem().toString());
677 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
678 nucColour.getSelectedItem().toString());
679 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
680 minColour.getBackground());
681 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
682 maxColour.getBackground());
685 * Save Overview settings
687 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
688 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
689 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
690 Boolean.toString(useLegacyGap.isSelected()));
691 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
692 Boolean.toString(showHiddenAtStart.isSelected()));
695 * Save Structure settings
697 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
698 Boolean.toString(addTempFactor.isSelected()));
699 Cache.applicationProperties.setProperty(ADD_SS_ANN,
700 Boolean.toString(addSecondaryStructure.isSelected()));
701 Cache.applicationProperties.setProperty(USE_RNAVIEW,
702 Boolean.toString(useRnaView.isSelected()));
703 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
704 Boolean.toString(structFromPdb.isSelected()));
705 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
706 structViewer.getSelectedItem().toString());
707 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
708 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
709 Boolean.toString(siftsMapping.isSelected()));
710 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
713 * Save Output settings
715 Cache.applicationProperties.setProperty("EPS_RENDERING",
716 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
719 * Save Connections settings
721 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
723 jalview.util.BrowserLauncher.resetBrowser();
725 // save user-defined and selected links
726 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
727 if (menuLinks.isEmpty())
729 Cache.applicationProperties.remove("SEQUENCE_LINKS");
733 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
734 menuLinks.toString());
737 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
738 if (nonMenuLinks.isEmpty())
740 Cache.applicationProperties.remove("STORED_LINKS");
744 Cache.applicationProperties.setProperty("STORED_LINKS",
745 nonMenuLinks.toString());
748 Cache.applicationProperties.setProperty("DEFAULT_URL",
749 sequenceUrlLinks.getPrimaryUrlId());
752 Cache.applicationProperties.setProperty("USE_PROXY",
753 customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
754 : noProxy.isSelected() ? Cache.PROXYTYPE_NONE
755 : Cache.PROXYTYPE_SYSTEM);
756 Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText());
757 Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
758 Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
759 Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText());
760 Cache.setOrRemove("PROXY_AUTH",
761 Boolean.toString(proxyAuth.isSelected()));
762 Cache.setOrRemove("PROXY_AUTH_USERNAME", proxyAuthUsernameTB.getText());
763 Cache.setOrRemove("PROXY_AUTH_PASSWORD", proxyAuthPasswordTB.getText());
764 setProxyFromSettings();
766 Cache.setProperty("VERSION_CHECK",
767 Boolean.toString(versioncheck.isSelected()));
768 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
770 // default is false - we only set this if the user has actively agreed
771 Cache.setProperty("USAGESTATS",
772 Boolean.toString(usagestats.isSelected()));
774 if (!questionnaire.isSelected())
776 Cache.setProperty("NOQUESTIONNAIRES", "true");
780 // special - made easy to edit a property file to disable questionnaires
781 // by just adding the given line
782 Cache.removeProperty("NOQUESTIONNAIRES");
786 * Save Output settings
788 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
789 Boolean.toString(blcjv.isSelected()));
790 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
791 Boolean.toString(clustaljv.isSelected()));
792 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
793 Boolean.toString(fastajv.isSelected()));
794 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
795 Boolean.toString(msfjv.isSelected()));
796 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
797 Boolean.toString(pfamjv.isSelected()));
798 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
799 Boolean.toString(pileupjv.isSelected()));
800 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
801 Boolean.toString(pirjv.isSelected()));
802 Cache.applicationProperties.setProperty("PIR_MODELLER",
803 Boolean.toString(modellerOutput.isSelected()));
804 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
805 Boolean.toString(embbedBioJSON.isSelected()));
806 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
808 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
809 Boolean.toString(autoIdWidth.isSelected()));
810 userIdWidth_actionPerformed();
811 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
812 userIdWidth.getText());
815 * Save Editing settings
817 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
818 Boolean.toString(autoCalculateConsCheck.isSelected()));
819 Cache.applicationProperties.setProperty("SORT_BY_TREE",
820 Boolean.toString(sortByTree.isSelected()));
821 Cache.applicationProperties.setProperty("PAD_GAPS",
822 Boolean.toString(padGaps.isSelected()));
824 wsPrefs.updateAndRefreshWsMenuConfig(false);
827 * Save Backups settings
829 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
830 Boolean.toString(enableBackupFiles.isSelected()));
831 int preset = getComboIntStringKey(backupfilesPresetsCombo);
832 Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET",
833 Integer.toString(preset));
835 if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
837 BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
838 BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
839 BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
840 Cache.applicationProperties.setProperty(
841 BackupFilesPresetEntry.CUSTOMCONFIG, customBFPE.toString());
844 BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
846 Cache.applicationProperties.setProperty(
847 BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
849 Cache.saveProperties();
850 Desktop.instance.doConfigureStructurePrefs();
853 frame.setClosed(true);
854 } catch (Exception ex)
859 public void setProxyFromSettings()
861 String proxyType = Cache.getDefault("USE_PROXY",
862 Cache.PROXYTYPE_SYSTEM);
863 if (proxyType.equals(Cache.PROXYTYPE_NONE))
865 if (!previousProxyType.equals(proxyType))
866 Cache.log.info("Setting no proxy settings");
867 Cache.setProxyProperties(null, null, null, null, null, null, null,
870 else if (proxyType.equals(Cache.PROXYTYPE_CUSTOM))
872 if (!previousProxyType.equals(proxyType))
873 Cache.log.info("Setting custom proxy settings");
874 boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
875 Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
876 Cache.getDefault("PROXY_PORT", null),
877 Cache.getDefault("PROXY_SERVER_HTTPS", null),
878 Cache.getDefault("PROXY_PORT_HTTPS", null),
879 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
881 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_PASSWORD", "")
884 else // systemProxy should be selected and is sensible default anyway
886 if (!previousProxyType.equals(proxyType))
887 Cache.log.info("Setting system proxy settings");
888 Cache.resetProxyProperties();
893 * Do any necessary validation before saving settings. Return focus to the
894 * first tab which fails validation.
898 private boolean validateSettings()
900 if (!validateStructure())
902 structureTab.requestFocusInWindow();
909 protected boolean validateStructure()
911 return validateChimeraPath();
919 public void startupFileTextfield_mouseClicked()
921 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
922 JalviewFileChooser chooser = JalviewFileChooser
923 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
924 chooser.setFileView(new JalviewFileView());
925 chooser.setDialogTitle(
926 MessageManager.getString("label.select_startup_file"));
928 int value = chooser.showOpenDialog(this);
930 if (value == JalviewFileChooser.APPROVE_OPTION)
932 FileFormatI format = chooser.getSelectedFormat();
935 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
939 .setText(chooser.getSelectedFile().getAbsolutePath());
950 public void cancel_actionPerformed(ActionEvent e)
954 wsPrefs.updateWsMenuConfig(true);
955 wsPrefs.refreshWs_actionPerformed(e);
956 frame.setClosed(true);
957 } catch (Exception ex)
969 public void annotations_actionPerformed(ActionEvent e)
971 conservation.setEnabled(annotations.isSelected());
972 quality.setEnabled(annotations.isSelected());
973 identity.setEnabled(annotations.isSelected());
974 showOccupancy.setEnabled(annotations.isSelected());
975 showGroupConsensus.setEnabled(annotations.isSelected());
976 showGroupConservation.setEnabled(annotations.isSelected());
977 showConsensHistogram.setEnabled(annotations.isSelected()
978 && (identity.isSelected() || showGroupConsensus.isSelected()));
979 showConsensLogo.setEnabled(annotations.isSelected()
980 && (identity.isSelected() || showGroupConsensus.isSelected()));
984 public void newLink_actionPerformed(ActionEvent e)
986 GSequenceLink link = new GSequenceLink();
987 boolean valid = false;
990 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
991 MessageManager.getString("label.new_sequence_url_link"),
992 JvOptionPane.OK_CANCEL_OPTION, -1,
993 null) == JvOptionPane.OK_OPTION)
995 if (link.checkValid())
997 if (((UrlLinkTableModel) linkUrlTable.getModel())
998 .isUniqueName(link.getName()))
1000 ((UrlLinkTableModel) linkUrlTable.getModel())
1001 .insertRow(link.getName(), link.getURL());
1006 link.notifyDuplicate();
1019 public void editLink_actionPerformed(ActionEvent e)
1021 GSequenceLink link = new GSequenceLink();
1023 int index = linkUrlTable.getSelectedRow();
1026 // button no longer enabled if row is not selected
1027 Cache.log.debug("Edit with no row selected in linkUrlTable");
1031 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1033 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1035 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1036 link.setName(oldName);
1037 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1039 boolean valid = false;
1042 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1043 MessageManager.getString("label.edit_sequence_url_link"),
1044 JvOptionPane.OK_CANCEL_OPTION, -1,
1045 null) == JvOptionPane.OK_OPTION)
1047 if (link.checkValid())
1049 if ((oldName.equals(link.getName()))
1050 || (((UrlLinkTableModel) linkUrlTable.getModel())
1051 .isUniqueName(link.getName())))
1053 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1054 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1059 link.notifyDuplicate();
1072 public void deleteLink_actionPerformed(ActionEvent e)
1074 int index = linkUrlTable.getSelectedRow();
1075 int modelIndex = -1;
1078 // button no longer enabled if row is not selected
1079 Cache.log.debug("Delete with no row selected in linkUrlTable");
1084 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1087 // make sure we use the model index to delete, and not the table index
1088 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1092 public void defaultBrowser_mouseClicked(MouseEvent e)
1094 JFileChooser chooser = new JFileChooser(".");
1095 chooser.setDialogTitle(
1096 MessageManager.getString("label.select_default_browser"));
1098 int value = chooser.showOpenDialog(this);
1100 if (value == JFileChooser.APPROVE_OPTION)
1102 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1111 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1115 protected void showunconserved_actionPerformed(ActionEvent e)
1117 // TODO Auto-generated method stub
1118 super.showunconserved_actionPerformed(e);
1121 public static List<String> getGroupURLLinks()
1123 return groupURLLinks;
1127 public void minColour_actionPerformed(JPanel panel)
1129 Color col = JColorChooser.showDialog(this,
1130 MessageManager.getString("label.select_colour_minimum_value"),
1131 minColour.getBackground());
1134 panel.setBackground(col);
1140 public void maxColour_actionPerformed(JPanel panel)
1142 Color col = JColorChooser.showDialog(this,
1143 MessageManager.getString("label.select_colour_maximum_value"),
1144 maxColour.getBackground());
1147 panel.setBackground(col);
1153 public void gapColour_actionPerformed(JPanel gap)
1155 if (!useLegacyGap.isSelected())
1157 Color col = JColorChooser.showDialog(this,
1158 MessageManager.getString("label.select_gap_colour"),
1159 gapColour.getBackground());
1162 gap.setBackground(col);
1169 public void hiddenColour_actionPerformed(JPanel hidden)
1171 Color col = JColorChooser.showDialog(this,
1172 MessageManager.getString("label.select_hidden_colour"),
1173 hiddenColour.getBackground());
1176 hidden.setBackground(col);
1182 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1184 boolean enabled = useLegacyGap.isSelected();
1187 gapColour.setBackground(
1188 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1192 gapColour.setBackground(
1193 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1195 gapColour.setEnabled(!enabled);
1196 gapLabel.setEnabled(!enabled);
1200 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1202 useLegacyGap.setSelected(false);
1203 useLegacyGaps_actionPerformed(null);
1204 showHiddenAtStart.setSelected(false);
1205 hiddenColour.setBackground(
1206 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1210 protected void userIdWidth_actionPerformed()
1214 String val = userIdWidth.getText().trim();
1215 if (val.length() > 0)
1217 Integer iw = Integer.parseInt(val);
1218 if (iw.intValue() < 12)
1220 throw new NumberFormatException();
1222 userIdWidth.setText(iw.toString());
1224 } catch (NumberFormatException x)
1226 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1228 .getString("warn.user_defined_width_requirements"),
1229 MessageManager.getString("label.invalid_id_column_width"),
1230 JvOptionPane.WARNING_MESSAGE);
1231 userIdWidth.setText("");
1236 protected void autoIdWidth_actionPerformed()
1238 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1239 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1243 * Returns true if chimera path is to a valid executable, else show an error
1246 private boolean validateChimeraPath()
1248 if (chimeraPath.getText().trim().length() > 0)
1250 File f = new File(chimeraPath.getText());
1251 if (!f.canExecute())
1253 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1254 MessageManager.getString("label.invalid_chimera_path"),
1255 MessageManager.getString("label.invalid_name"),
1256 JvOptionPane.ERROR_MESSAGE);
1264 * If Chimera is selected, check it can be found on default or user-specified
1265 * path, if not show a warning/help dialog.
1268 protected void structureViewer_actionPerformed(String selectedItem)
1270 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1274 boolean found = false;
1277 * Try user-specified and standard paths for Chimera executable.
1279 List<String> paths = StructureManager.getChimeraPaths();
1280 paths.add(0, chimeraPath.getText());
1281 for (String path : paths)
1283 if (new File(path.trim()).canExecute())
1291 String[] options = { "OK", "Help" };
1292 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1293 JvSwingUtils.wrapTooltip(true,
1294 MessageManager.getString("label.chimera_missing")),
1295 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1296 null, options, options[0]);
1297 if (showHelp == JvOptionPane.NO_OPTION)
1301 Help.showHelpWindow(HelpId.StructureViewer);
1302 } catch (HelpSetException e)
1304 e.printStackTrace();
1310 public class OptionsParam
1312 private String name;
1314 private String code;
1316 public OptionsParam(String name, String code)
1322 public String getName()
1327 public void setName(String name)
1332 public String getCode()
1337 public void setCode(String code)
1343 public String toString()
1349 public boolean equals(Object that)
1351 if (!(that instanceof OptionsParam))
1355 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1359 public int hashCode()
1361 return name.hashCode() + code.hashCode();
1365 private class UrlListSelectionHandler implements ListSelectionListener
1369 public void valueChanged(ListSelectionEvent e)
1371 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1373 int index = lsm.getMinSelectionIndex();
1376 // no selection, so disable delete/edit buttons
1377 editLink.setEnabled(false);
1378 deleteLink.setEnabled(false);
1381 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1383 // enable/disable edit and delete link buttons
1384 if (((UrlLinkTableModel) linkUrlTable.getModel())
1385 .isRowDeletable(modelIndex))
1387 deleteLink.setEnabled(true);
1391 deleteLink.setEnabled(false);
1394 if (((UrlLinkTableModel) linkUrlTable.getModel())
1395 .isRowEditable(modelIndex))
1397 editLink.setEnabled(true);
1401 editLink.setEnabled(false);