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.BackupFilesPresetEntry;
29 import jalview.io.FileFormatI;
30 import jalview.io.JalviewFileChooser;
31 import jalview.io.JalviewFileView;
32 import jalview.jbgui.GPreferences;
33 import jalview.jbgui.GSequenceLink;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.ColourSchemes;
36 import jalview.schemes.ResidueColourScheme;
37 import jalview.urls.UrlLinkTableModel;
38 import jalview.urls.api.UrlProviderFactoryI;
39 import jalview.urls.api.UrlProviderI;
40 import jalview.urls.desktop.DesktopUrlProviderFactory;
41 import jalview.util.MessageManager;
42 import jalview.util.Platform;
43 import jalview.util.UrlConstants;
44 import jalview.ws.sifts.SiftsSettings;
46 import java.awt.BorderLayout;
47 import java.awt.Color;
48 import java.awt.Component;
49 import java.awt.Dimension;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ActionListener;
53 import java.awt.event.MouseEvent;
55 import java.util.ArrayList;
56 import java.util.List;
58 import javax.help.HelpSetException;
59 import javax.swing.JColorChooser;
60 import javax.swing.JFileChooser;
61 import javax.swing.JInternalFrame;
62 import javax.swing.JPanel;
63 import javax.swing.ListSelectionModel;
64 import javax.swing.RowFilter;
65 import javax.swing.RowSorter;
66 import javax.swing.SortOrder;
67 import javax.swing.event.DocumentEvent;
68 import javax.swing.event.DocumentListener;
69 import javax.swing.event.ListSelectionEvent;
70 import javax.swing.event.ListSelectionListener;
71 import javax.swing.table.TableCellRenderer;
72 import javax.swing.table.TableColumn;
73 import javax.swing.table.TableModel;
74 import javax.swing.table.TableRowSorter;
76 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
84 public class Preferences extends GPreferences
86 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
88 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
90 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
92 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
94 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
96 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
98 public static final String ADD_SS_ANN = "ADD_SS_ANN";
100 public static final String USE_RNAVIEW = "USE_RNAVIEW";
102 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
104 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
106 public static final String CHIMERA_PATH = "CHIMERA_PATH";
108 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
110 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
112 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
114 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
116 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
118 public static final String GAP_COLOUR = "GAP_COLOUR";
120 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
122 private static final int MIN_FONT_SIZE = 1;
124 private static final int MAX_FONT_SIZE = 30;
127 * Holds name and link separated with | character. Sequence ID must be
128 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
130 public static UrlProviderI sequenceUrlLinks;
132 public static UrlLinkTableModel dataModel;
135 * Holds name and link separated with | character. Sequence IDS and Sequences
136 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
137 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
138 * for first and second token specified after a pipe character at end |,|.
139 * (TODO: proper escape for using | to separate ids or sequences
142 public static List<String> groupURLLinks;
145 // get links selected to be in the menu (SEQUENCE_LINKS)
146 // and links entered by the user but not selected (STORED_LINKS)
147 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
148 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
149 String defaultUrl = Cache.getDefault("DEFAULT_URL",
150 UrlConstants.DEFAULT_LABEL);
152 // if both links lists are empty, add the DEFAULT_URL link
153 // otherwise we assume the default link is in one of the lists
154 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
156 inMenuString = UrlConstants.DEFAULT_STRING;
158 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
159 inMenuString, notInMenuString);
160 sequenceUrlLinks = factory.createUrlProvider();
161 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
164 * TODO: reformulate groupURL encoding so two or more can be stored in the
165 * .properties file as '|' separated strings
168 groupURLLinks = new ArrayList<>();
171 JInternalFrame frame;
173 private WsPreferences wsPrefs;
175 private OptionsParam promptEachTimeOpt = new OptionsParam(
176 MessageManager.getString("label.prompt_each_time"),
179 private OptionsParam lineArtOpt = new OptionsParam(
180 MessageManager.getString("label.lineart"), "Lineart");
182 private OptionsParam textOpt = new OptionsParam(
183 MessageManager.getString("action.text"), "Text");
186 * Creates a new Preferences object.
191 frame = new JInternalFrame();
192 frame.setContentPane(this);
193 wsPrefs = new WsPreferences();
194 wsTab.add(wsPrefs, BorderLayout.CENTER);
195 int width = 500, height = 450;
196 new jalview.util.Platform();
197 if (Platform.isAMac())
203 Desktop.addInternalFrame(frame,
204 MessageManager.getString("label.preferences"), width, height);
205 frame.setMinimumSize(new Dimension(width, height));
208 * Set Visual tab defaults
210 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
211 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
212 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
213 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
215 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
216 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
217 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
218 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
220 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
221 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
223 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
224 showGroupConservation.setSelected(
225 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
226 showConsensHistogram.setSelected(
227 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
229 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
231 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
233 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
235 String[] fonts = java.awt.GraphicsEnvironment
236 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
237 for (int i = 0; i < fonts.length; i++)
239 fontNameCB.addItem(fonts[i]);
242 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
244 fontSizeCB.addItem(i + "");
247 fontStyleCB.addItem("plain");
248 fontStyleCB.addItem("bold");
249 fontStyleCB.addItem("italic");
251 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
252 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
253 fontStyleCB.setSelectedItem(
254 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
256 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
258 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
260 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
262 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
264 gapSymbolCB.addItem("-");
265 gapSymbolCB.addItem(".");
267 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
269 sortby.addItem("No sort");
270 sortby.addItem("Id");
271 sortby.addItem("Pairwise Identity");
272 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
274 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
276 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
278 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
279 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
280 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
281 SequenceAnnotationOrder.NONE.name()));
282 sortAnnBy.setSelectedItem(savedSort.toString());
284 sortAutocalc.addItem("Autocalculated first");
285 sortAutocalc.addItem("Autocalculated last");
286 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
287 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
288 : sortAutocalc.getItemAt(1));
290 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
291 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
292 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
293 + "/examples/exampleFile_2_3.jar"));
296 * Set Colours tab defaults
298 protColour.addItem(ResidueColourScheme.NONE);
299 nucColour.addItem(ResidueColourScheme.NONE);
300 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
302 String name = cs.getSchemeName();
303 protColour.addItem(name);
304 nucColour.addItem(name);
306 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
307 ResidueColourScheme.NONE);
308 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
309 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
310 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
311 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
312 minColour.setBackground(
313 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
314 maxColour.setBackground(
315 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
318 * Set overview panel defaults
320 gapColour.setBackground(
321 Cache.getDefaultColour(GAP_COLOUR,
322 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
323 hiddenColour.setBackground(
324 Cache.getDefaultColour(HIDDEN_COLOUR,
325 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
326 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
327 gapLabel.setEnabled(!useLegacyGap.isSelected());
328 gapColour.setEnabled(!useLegacyGap.isSelected());
330 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
333 * Set Structure tab defaults.
335 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
336 structFromPdb.setSelected(structSelected);
337 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
338 useRnaView.setEnabled(structSelected);
339 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
340 addSecondaryStructure.setEnabled(structSelected);
341 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
342 addTempFactor.setEnabled(structSelected);
343 structViewer.setSelectedItem(
344 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
345 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
346 chimeraPath.addActionListener(new ActionListener()
349 public void actionPerformed(ActionEvent e)
351 validateChimeraPath();
355 if (Cache.getDefault("MAP_WITH_SIFTS", false))
357 siftsMapping.setSelected(true);
361 nwMapping.setSelected(true);
365 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
368 * Set Connections tab defaults
372 linkUrlTable.setModel(dataModel);
373 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
374 linkUrlTable.getModel());
375 linkUrlTable.setRowSorter(sorter);
376 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
378 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
379 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
380 SortOrder.DESCENDING));
381 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
382 SortOrder.DESCENDING));
384 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
386 sorter.setSortKeys(sortKeys);
390 ActionListener onReset;
391 onReset = new ActionListener()
394 public void actionPerformed(ActionEvent e)
396 filterTB.setText("");
397 sorter.setRowFilter(RowFilter.regexFilter(""));
401 doReset.addActionListener(onReset);
403 // filter to display only custom urls
404 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
407 public boolean include(
408 Entry<? extends TableModel, ? extends Object> entry)
410 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
414 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
415 linkUrlTable.getModel());
416 customSorter.setRowFilter(customUrlFilter);
418 ActionListener onCustomOnly;
419 onCustomOnly = new ActionListener()
422 public void actionPerformed(ActionEvent e)
424 filterTB.setText("");
425 sorter.setRowFilter(customUrlFilter);
428 userOnly.addActionListener(onCustomOnly);
430 filterTB.getDocument().addDocumentListener(new DocumentListener()
432 String caseInsensitiveFlag = "(?i)";
435 public void changedUpdate(DocumentEvent e)
437 sorter.setRowFilter(RowFilter
438 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
442 public void removeUpdate(DocumentEvent e)
444 sorter.setRowFilter(RowFilter
445 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
449 public void insertUpdate(DocumentEvent e)
451 sorter.setRowFilter(RowFilter
452 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
456 // set up list selection functionality
457 linkUrlTable.getSelectionModel()
458 .addListSelectionListener(new UrlListSelectionHandler());
460 // set up radio buttons
461 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
463 String onClickName = linkUrlTable.getColumnName(onClickCol);
464 linkUrlTable.getColumn(onClickName)
465 .setCellRenderer(new RadioButtonRenderer());
466 linkUrlTable.getColumn(onClickName)
467 .setCellEditor(new RadioButtonEditor());
469 // get boolean columns and resize those to min possible
470 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
472 if (linkUrlTable.getModel().getColumnClass(column)
473 .equals(Boolean.class))
475 TableColumn tableColumn = linkUrlTable.getColumnModel()
477 int preferredWidth = tableColumn.getMinWidth();
479 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
481 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
482 int cwidth = c.getPreferredSize().width
483 + linkUrlTable.getIntercellSpacing().width;
484 preferredWidth = Math.max(preferredWidth, cwidth);
486 tableColumn.setPreferredWidth(preferredWidth);
490 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
491 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
492 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
493 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
495 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
497 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
498 // note antisense here: default is true
500 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
501 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
504 * Set Output tab defaults
506 epsRendering.addItem(promptEachTimeOpt);
507 epsRendering.addItem(lineArtOpt);
508 epsRendering.addItem(textOpt);
509 String defaultEPS = Cache.getDefault("EPS_RENDERING",
511 if (defaultEPS.equalsIgnoreCase("Text"))
513 epsRendering.setSelectedItem(textOpt);
515 else if (defaultEPS.equalsIgnoreCase("Lineart"))
517 epsRendering.setSelectedItem(lineArtOpt);
521 epsRendering.setSelectedItem(promptEachTimeOpt);
523 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
524 userIdWidth.setEnabled(!autoIdWidth.isSelected());
525 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
526 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
527 userIdWidth.setText(wi == null ? "" : wi.toString());
528 // TODO: refactor to use common enum via FormatAdapter and allow extension
529 // for new flat file formats
530 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
531 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
532 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
533 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
534 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
535 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
536 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
537 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
539 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
542 * Set Editing tab defaults
544 autoCalculateConsCheck
545 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
546 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
547 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
549 annotations_actionPerformed(null); // update the display of the annotation
554 * Set Backups tab defaults
556 loadLastSavedBackupsOptions();
560 * Save user selections on the Preferences tabs to the Cache and write out to
566 public void ok_actionPerformed(ActionEvent e)
568 if (!validateSettings())
574 * Save Visual settings
576 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
577 Boolean.toString(seqLimit.isSelected()));
578 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
579 Boolean.toString(rightAlign.isSelected()));
580 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
581 Boolean.toString(fullScreen.isSelected()));
582 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
583 Boolean.toString(openoverv.isSelected()));
584 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
585 Boolean.toString(annotations.isSelected()));
586 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
587 Boolean.toString(conservation.isSelected()));
588 Cache.applicationProperties.setProperty("SHOW_QUALITY",
589 Boolean.toString(quality.isSelected()));
590 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
591 Boolean.toString(identity.isSelected()));
593 Cache.applicationProperties.setProperty("GAP_SYMBOL",
594 gapSymbolCB.getSelectedItem().toString());
596 Cache.applicationProperties.setProperty("FONT_NAME",
597 fontNameCB.getSelectedItem().toString());
598 Cache.applicationProperties.setProperty("FONT_STYLE",
599 fontStyleCB.getSelectedItem().toString());
600 Cache.applicationProperties.setProperty("FONT_SIZE",
601 fontSizeCB.getSelectedItem().toString());
603 Cache.applicationProperties.setProperty("ID_ITALICS",
604 Boolean.toString(idItalics.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
606 Boolean.toString(showUnconserved.isSelected()));
607 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
608 Boolean.toString(showOccupancy.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
610 Boolean.toString(showGroupConsensus.isSelected()));
611 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
612 Boolean.toString(showGroupConservation.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
614 Boolean.toString(showConsensHistogram.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
616 Boolean.toString(showConsensLogo.isSelected()));
617 Cache.applicationProperties.setProperty("ANTI_ALIAS",
618 Boolean.toString(smoothFont.isSelected()));
619 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
620 Boolean.toString(scaleProteinToCdna.isSelected()));
621 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
622 Boolean.toString(showNpTooltip.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
624 Boolean.toString(showDbRefTooltip.isSelected()));
626 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
627 Boolean.toString(wrap.isSelected()));
629 Cache.applicationProperties.setProperty("STARTUP_FILE",
630 startupFileTextfield.getText());
631 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
632 Boolean.toString(startupCheckbox.isSelected()));
634 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
635 sortby.getSelectedItem().toString());
637 // convert description of sort order to enum name for save
638 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
639 .forDescription(sortAnnBy.getSelectedItem().toString());
640 if (annSortOrder != null)
642 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
643 annSortOrder.name());
646 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
647 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
648 Boolean.valueOf(showAutocalcFirst).toString());
651 * Save Colours settings
653 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
654 protColour.getSelectedItem().toString());
655 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
656 nucColour.getSelectedItem().toString());
657 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
658 minColour.getBackground());
659 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
660 maxColour.getBackground());
663 * Save Overview settings
665 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
666 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
667 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
668 Boolean.toString(useLegacyGap.isSelected()));
669 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
670 Boolean.toString(showHiddenAtStart.isSelected()));
673 * Save Structure settings
675 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
676 Boolean.toString(addTempFactor.isSelected()));
677 Cache.applicationProperties.setProperty(ADD_SS_ANN,
678 Boolean.toString(addSecondaryStructure.isSelected()));
679 Cache.applicationProperties.setProperty(USE_RNAVIEW,
680 Boolean.toString(useRnaView.isSelected()));
681 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
682 Boolean.toString(structFromPdb.isSelected()));
683 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
684 structViewer.getSelectedItem().toString());
685 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
686 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
687 Boolean.toString(siftsMapping.isSelected()));
688 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
691 * Save Output settings
693 Cache.applicationProperties.setProperty("EPS_RENDERING",
694 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
697 * Save Connections settings
699 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
701 jalview.util.BrowserLauncher.resetBrowser();
703 // save user-defined and selected links
704 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
705 if (menuLinks.isEmpty())
707 Cache.applicationProperties.remove("SEQUENCE_LINKS");
711 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
712 menuLinks.toString());
715 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
716 if (nonMenuLinks.isEmpty())
718 Cache.applicationProperties.remove("STORED_LINKS");
722 Cache.applicationProperties.setProperty("STORED_LINKS",
723 nonMenuLinks.toString());
726 Cache.applicationProperties.setProperty("DEFAULT_URL",
727 sequenceUrlLinks.getPrimaryUrlId());
729 Cache.applicationProperties.setProperty("USE_PROXY",
730 Boolean.toString(useProxy.isSelected()));
732 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
734 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
736 if (useProxy.isSelected())
738 System.setProperty("http.proxyHost", proxyServerTB.getText());
739 System.setProperty("http.proxyPort", proxyPortTB.getText());
743 System.setProperty("http.proxyHost", "");
744 System.setProperty("http.proxyPort", "");
746 Cache.setProperty("VERSION_CHECK",
747 Boolean.toString(versioncheck.isSelected()));
748 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
750 // default is false - we only set this if the user has actively agreed
751 Cache.setProperty("USAGESTATS",
752 Boolean.toString(usagestats.isSelected()));
754 if (!questionnaire.isSelected())
756 Cache.setProperty("NOQUESTIONNAIRES", "true");
760 // special - made easy to edit a property file to disable questionnaires
761 // by just adding the given line
762 Cache.removeProperty("NOQUESTIONNAIRES");
766 * Save Output settings
768 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
769 Boolean.toString(blcjv.isSelected()));
770 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
771 Boolean.toString(clustaljv.isSelected()));
772 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
773 Boolean.toString(fastajv.isSelected()));
774 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
775 Boolean.toString(msfjv.isSelected()));
776 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
777 Boolean.toString(pfamjv.isSelected()));
778 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
779 Boolean.toString(pileupjv.isSelected()));
780 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
781 Boolean.toString(pirjv.isSelected()));
782 Cache.applicationProperties.setProperty("PIR_MODELLER",
783 Boolean.toString(modellerOutput.isSelected()));
784 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
785 Boolean.toString(embbedBioJSON.isSelected()));
786 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
788 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
789 Boolean.toString(autoIdWidth.isSelected()));
790 userIdWidth_actionPerformed();
791 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
792 userIdWidth.getText());
795 * Save Editing settings
797 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
798 Boolean.toString(autoCalculateConsCheck.isSelected()));
799 Cache.applicationProperties.setProperty("SORT_BY_TREE",
800 Boolean.toString(sortByTree.isSelected()));
801 Cache.applicationProperties.setProperty("PAD_GAPS",
802 Boolean.toString(padGaps.isSelected()));
804 wsPrefs.updateAndRefreshWsMenuConfig(false);
807 * Save Backups settings
809 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
810 Boolean.toString(enableBackupFiles.isSelected()));
811 int preset = getComboIntStringKey(backupfilesPresetsCombo);
812 Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
814 if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
816 BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
817 BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
818 BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
819 Cache.applicationProperties
820 .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
821 customBFPE.toString());
824 BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
826 Cache.applicationProperties.setProperty(
827 BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
829 Cache.saveProperties();
830 Desktop.instance.doConfigureStructurePrefs();
833 frame.setClosed(true);
834 } catch (Exception ex)
840 * Do any necessary validation before saving settings. Return focus to the
841 * first tab which fails validation.
845 private boolean validateSettings()
847 if (!validateStructure())
849 structureTab.requestFocusInWindow();
856 protected boolean validateStructure()
858 return validateChimeraPath();
866 public void startupFileTextfield_mouseClicked()
868 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
869 JalviewFileChooser chooser = JalviewFileChooser
870 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
871 chooser.setFileView(new JalviewFileView());
872 chooser.setDialogTitle(
873 MessageManager.getString("label.select_startup_file"));
875 int value = chooser.showOpenDialog(this);
877 if (value == JalviewFileChooser.APPROVE_OPTION)
879 FileFormatI format = chooser.getSelectedFormat();
882 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
886 .setText(chooser.getSelectedFile().getAbsolutePath());
897 public void cancel_actionPerformed(ActionEvent e)
901 wsPrefs.updateWsMenuConfig(true);
902 wsPrefs.refreshWs_actionPerformed(e);
903 frame.setClosed(true);
904 } catch (Exception ex)
916 public void annotations_actionPerformed(ActionEvent e)
918 conservation.setEnabled(annotations.isSelected());
919 quality.setEnabled(annotations.isSelected());
920 identity.setEnabled(annotations.isSelected());
921 showOccupancy.setEnabled(annotations.isSelected());
922 showGroupConsensus.setEnabled(annotations.isSelected());
923 showGroupConservation.setEnabled(annotations.isSelected());
924 showConsensHistogram.setEnabled(annotations.isSelected()
925 && (identity.isSelected() || showGroupConsensus.isSelected()));
926 showConsensLogo.setEnabled(annotations.isSelected()
927 && (identity.isSelected() || showGroupConsensus.isSelected()));
931 public void newLink_actionPerformed(ActionEvent e)
933 GSequenceLink link = new GSequenceLink();
934 boolean valid = false;
937 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
938 MessageManager.getString("label.new_sequence_url_link"),
939 JvOptionPane.OK_CANCEL_OPTION, -1,
940 null) == JvOptionPane.OK_OPTION)
942 if (link.checkValid())
944 if (((UrlLinkTableModel) linkUrlTable.getModel())
945 .isUniqueName(link.getName()))
947 ((UrlLinkTableModel) linkUrlTable.getModel())
948 .insertRow(link.getName(), link.getURL());
953 link.notifyDuplicate();
966 public void editLink_actionPerformed(ActionEvent e)
968 GSequenceLink link = new GSequenceLink();
970 int index = linkUrlTable.getSelectedRow();
973 // button no longer enabled if row is not selected
974 Cache.log.debug("Edit with no row selected in linkUrlTable");
978 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
980 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
982 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
983 link.setName(oldName);
984 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
986 boolean valid = false;
989 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
990 MessageManager.getString("label.edit_sequence_url_link"),
991 JvOptionPane.OK_CANCEL_OPTION, -1,
992 null) == JvOptionPane.OK_OPTION)
994 if (link.checkValid())
996 if ((oldName.equals(link.getName()))
997 || (((UrlLinkTableModel) linkUrlTable.getModel())
998 .isUniqueName(link.getName())))
1000 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1001 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1006 link.notifyDuplicate();
1019 public void deleteLink_actionPerformed(ActionEvent e)
1021 int index = linkUrlTable.getSelectedRow();
1022 int modelIndex = -1;
1025 // button no longer enabled if row is not selected
1026 Cache.log.debug("Delete with no row selected in linkUrlTable");
1031 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1034 // make sure we use the model index to delete, and not the table index
1035 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1039 public void defaultBrowser_mouseClicked(MouseEvent e)
1041 JFileChooser chooser = new JFileChooser(".");
1042 chooser.setDialogTitle(
1043 MessageManager.getString("label.select_default_browser"));
1045 int value = chooser.showOpenDialog(this);
1047 if (value == JFileChooser.APPROVE_OPTION)
1049 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1058 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1062 protected void showunconserved_actionPerformed(ActionEvent e)
1064 // TODO Auto-generated method stub
1065 super.showunconserved_actionPerformed(e);
1068 public static List<String> getGroupURLLinks()
1070 return groupURLLinks;
1074 public void minColour_actionPerformed(JPanel panel)
1076 Color col = JColorChooser.showDialog(this,
1077 MessageManager.getString("label.select_colour_minimum_value"),
1078 minColour.getBackground());
1081 panel.setBackground(col);
1087 public void maxColour_actionPerformed(JPanel panel)
1089 Color col = JColorChooser.showDialog(this,
1090 MessageManager.getString("label.select_colour_maximum_value"),
1091 maxColour.getBackground());
1094 panel.setBackground(col);
1100 public void gapColour_actionPerformed(JPanel gap)
1102 if (!useLegacyGap.isSelected())
1104 Color col = JColorChooser.showDialog(this,
1105 MessageManager.getString("label.select_gap_colour"),
1106 gapColour.getBackground());
1109 gap.setBackground(col);
1116 public void hiddenColour_actionPerformed(JPanel hidden)
1118 Color col = JColorChooser.showDialog(this,
1119 MessageManager.getString("label.select_hidden_colour"),
1120 hiddenColour.getBackground());
1123 hidden.setBackground(col);
1129 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1131 boolean enabled = useLegacyGap.isSelected();
1134 gapColour.setBackground(
1135 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1139 gapColour.setBackground(
1140 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1142 gapColour.setEnabled(!enabled);
1143 gapLabel.setEnabled(!enabled);
1147 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1149 useLegacyGap.setSelected(false);
1150 useLegacyGaps_actionPerformed(null);
1151 showHiddenAtStart.setSelected(false);
1152 hiddenColour.setBackground(
1153 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1157 protected void userIdWidth_actionPerformed()
1161 String val = userIdWidth.getText().trim();
1162 if (val.length() > 0)
1164 Integer iw = Integer.parseInt(val);
1165 if (iw.intValue() < 12)
1167 throw new NumberFormatException();
1169 userIdWidth.setText(iw.toString());
1171 } catch (NumberFormatException x)
1173 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1175 .getString("warn.user_defined_width_requirements"),
1176 MessageManager.getString("label.invalid_id_column_width"),
1177 JvOptionPane.WARNING_MESSAGE);
1178 userIdWidth.setText("");
1183 protected void autoIdWidth_actionPerformed()
1185 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1186 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1190 * Returns true if chimera path is to a valid executable, else show an error
1193 private boolean validateChimeraPath()
1195 if (chimeraPath.getText().trim().length() > 0)
1197 File f = new File(chimeraPath.getText());
1198 if (!f.canExecute())
1200 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1201 MessageManager.getString("label.invalid_chimera_path"),
1202 MessageManager.getString("label.invalid_name"),
1203 JvOptionPane.ERROR_MESSAGE);
1211 * If Chimera is selected, check it can be found on default or user-specified
1212 * path, if not show a warning/help dialog.
1215 protected void structureViewer_actionPerformed(String selectedItem)
1217 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1221 boolean found = false;
1224 * Try user-specified and standard paths for Chimera executable.
1226 List<String> paths = StructureManager.getChimeraPaths();
1227 paths.add(0, chimeraPath.getText());
1228 for (String path : paths)
1230 if (new File(path.trim()).canExecute())
1238 String[] options = { "OK", "Help" };
1239 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1240 JvSwingUtils.wrapTooltip(true,
1241 MessageManager.getString("label.chimera_missing")),
1242 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1243 null, options, options[0]);
1244 if (showHelp == JvOptionPane.NO_OPTION)
1248 Help.showHelpWindow(HelpId.StructureViewer);
1249 } catch (HelpSetException e)
1251 e.printStackTrace();
1257 public class OptionsParam
1259 private String name;
1261 private String code;
1263 public OptionsParam(String name, String code)
1269 public String getName()
1274 public void setName(String name)
1279 public String getCode()
1284 public void setCode(String code)
1290 public String toString()
1296 public boolean equals(Object that)
1298 if (!(that instanceof OptionsParam))
1302 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1306 public int hashCode()
1308 return name.hashCode() + code.hashCode();
1312 private class UrlListSelectionHandler implements ListSelectionListener
1316 public void valueChanged(ListSelectionEvent e)
1318 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1320 int index = lsm.getMinSelectionIndex();
1323 // no selection, so disable delete/edit buttons
1324 editLink.setEnabled(false);
1325 deleteLink.setEnabled(false);
1328 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1330 // enable/disable edit and delete link buttons
1331 if (((UrlLinkTableModel) linkUrlTable.getModel())
1332 .isRowDeletable(modelIndex))
1334 deleteLink.setEnabled(true);
1338 deleteLink.setEnabled(false);
1341 if (((UrlLinkTableModel) linkUrlTable.getModel())
1342 .isRowEditable(modelIndex))
1344 editLink.setEnabled(true);
1348 editLink.setEnabled(false);