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;
84 * for merge with Jalview-JS
85 public class Preferences extends GPreferences implements ApplicationSingletonI
87 public class Preferences extends GPreferences
89 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
91 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
93 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
95 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
97 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
99 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
101 public static final String ADD_SS_ANN = "ADD_SS_ANN";
103 public static final String USE_RNAVIEW = "USE_RNAVIEW";
105 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
107 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
109 public static final String CHIMERA_PATH = "CHIMERA_PATH";
111 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
113 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
115 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
117 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
119 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
121 public static final String GAP_COLOUR = "GAP_COLOUR";
123 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
125 private static final int MIN_FONT_SIZE = 1;
127 private static final int MAX_FONT_SIZE = 30;
129 private String previousProxyType;
131 private static Preferences INSTANCE = null; // add "final"
134 * Holds name and link separated with | character. Sequence ID must be
135 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
137 public static UrlProviderI sequenceUrlLinks;
139 public static UrlLinkTableModel dataModel;
142 * Holds name and link separated with | character. Sequence IDS and Sequences
143 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
144 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
145 * for first and second token specified after a pipe character at end |,|.
146 * (TODO: proper escape for using | to separate ids or sequences
149 public static List<String> groupURLLinks;
152 // get links selected to be in the menu (SEQUENCE_LINKS)
153 // and links entered by the user but not selected (STORED_LINKS)
154 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
155 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
156 String defaultUrl = Cache.getDefault("DEFAULT_URL",
157 UrlConstants.DEFAULT_LABEL);
159 // if both links lists are empty, add the DEFAULT_URL link
160 // otherwise we assume the default link is in one of the lists
161 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
163 inMenuString = UrlConstants.DEFAULT_STRING;
165 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
166 inMenuString, notInMenuString);
167 sequenceUrlLinks = factory.createUrlProvider();
168 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
171 * TODO: reformulate groupURL encoding so two or more can be stored in the
172 * .properties file as '|' separated strings
175 groupURLLinks = new ArrayList<>();
178 JInternalFrame frame;
180 private WsPreferences wsPrefs;
182 private OptionsParam promptEachTimeOpt = new OptionsParam(
183 MessageManager.getString("label.prompt_each_time"),
186 private OptionsParam lineArtOpt = new OptionsParam(
187 MessageManager.getString("label.lineart"), "Lineart");
189 private OptionsParam textOpt = new OptionsParam(
190 MessageManager.getString("action.text"), "Text");
192 // get singleton Preferences instance
193 public static Preferences getInstance()
195 if (INSTANCE == null || INSTANCE.frame == null
196 || INSTANCE.frame.isClosed())
198 INSTANCE = new Preferences();
203 * Replace code with the following for Jalvew-JS
204 Preferences INSTANCE = ApplicationSingletonProvider.getInstance(Preferences.class);
205 if (INSTANCE == null || INSTANCE.frame == null
206 || INSTANCE.frame.isClosed())
208 ApplicationSingletonProvider.remove(Preferences.class);
209 INSTANCE = ApplicationSingletonProvider.getInstance(Preferences.class);
215 public static void openPreferences()
217 openPreferences(0, null);
220 public static void openPreferences(int selectTab, String message)
222 Preferences p = getInstance();
223 p.selectTab(selectTab);
224 p.setMessage(message);
226 p.frame.moveToFront();
231 * Creates a new Preferences object.
233 private Preferences()
236 frame = new JInternalFrame();
237 frame.setContentPane(this);
238 wsPrefs = new WsPreferences();
239 wsTab.add(wsPrefs, BorderLayout.CENTER);
240 int width = 500, height = 450;
241 new jalview.util.Platform();
242 if (Platform.isAMac())
248 Desktop.addInternalFrame(frame,
249 MessageManager.getString("label.preferences"), width, height);
250 frame.setMinimumSize(new Dimension(width, height));
253 * Set Visual tab defaults
255 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
256 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
257 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
258 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
260 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
261 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
262 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
263 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
265 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
266 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
268 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
269 showGroupConservation.setSelected(
270 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
271 showConsensHistogram.setSelected(
272 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
274 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
276 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
278 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
280 String[] fonts = java.awt.GraphicsEnvironment
281 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
282 for (int i = 0; i < fonts.length; i++)
284 fontNameCB.addItem(fonts[i]);
287 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
289 fontSizeCB.addItem(i + "");
292 fontStyleCB.addItem("plain");
293 fontStyleCB.addItem("bold");
294 fontStyleCB.addItem("italic");
296 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
297 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
298 fontStyleCB.setSelectedItem(
299 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
301 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", true));
303 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
305 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
307 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
309 gapSymbolCB.addItem("-");
310 gapSymbolCB.addItem(".");
312 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
314 sortby.addItem("No sort");
315 sortby.addItem("Id");
316 sortby.addItem("Pairwise Identity");
317 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
319 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
321 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
323 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
324 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
325 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
326 SequenceAnnotationOrder.NONE.name()));
327 sortAnnBy.setSelectedItem(savedSort.toString());
329 sortAutocalc.addItem("Autocalculated first");
330 sortAutocalc.addItem("Autocalculated last");
331 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
332 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
333 : sortAutocalc.getItemAt(1));
335 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
336 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
337 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
338 + "/examples/exampleFile_2_3.jar"));
341 * Set Colours tab defaults
343 protColour.addItem(ResidueColourScheme.NONE);
344 nucColour.addItem(ResidueColourScheme.NONE);
345 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
347 String name = cs.getSchemeName();
348 protColour.addItem(name);
349 nucColour.addItem(name);
351 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
352 ResidueColourScheme.NONE);
353 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
354 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
355 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
356 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
357 minColour.setBackground(
358 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
359 maxColour.setBackground(
360 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
363 * Set overview panel defaults
365 gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR,
366 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
367 hiddenColour.setBackground(Cache.getDefaultColour(HIDDEN_COLOUR,
368 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
369 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
370 gapLabel.setEnabled(!useLegacyGap.isSelected());
371 gapColour.setEnabled(!useLegacyGap.isSelected());
373 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
376 * Set Structure tab defaults.
378 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
379 structFromPdb.setSelected(structSelected);
380 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
381 useRnaView.setEnabled(structSelected);
382 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
383 addSecondaryStructure.setEnabled(structSelected);
384 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
385 addTempFactor.setEnabled(structSelected);
386 structViewer.setSelectedItem(
387 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
388 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
389 chimeraPath.addActionListener(new ActionListener()
392 public void actionPerformed(ActionEvent e)
394 validateChimeraPath();
398 if (Cache.getDefault("MAP_WITH_SIFTS", false))
400 siftsMapping.setSelected(true);
404 nwMapping.setSelected(true);
408 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
411 * Set Connections tab defaults
415 linkUrlTable.setModel(dataModel);
416 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
417 linkUrlTable.getModel());
418 linkUrlTable.setRowSorter(sorter);
419 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
421 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
422 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
423 SortOrder.DESCENDING));
424 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
425 SortOrder.DESCENDING));
427 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
429 sorter.setSortKeys(sortKeys);
433 ActionListener onReset;
434 onReset = new ActionListener()
437 public void actionPerformed(ActionEvent e)
439 filterTB.setText("");
440 sorter.setRowFilter(RowFilter.regexFilter(""));
444 doReset.addActionListener(onReset);
446 // filter to display only custom urls
447 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
450 public boolean include(
451 Entry<? extends TableModel, ? extends Object> entry)
453 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
457 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
458 linkUrlTable.getModel());
459 customSorter.setRowFilter(customUrlFilter);
461 ActionListener onCustomOnly;
462 onCustomOnly = new ActionListener()
465 public void actionPerformed(ActionEvent e)
467 filterTB.setText("");
468 sorter.setRowFilter(customUrlFilter);
471 userOnly.addActionListener(onCustomOnly);
473 filterTB.getDocument().addDocumentListener(new DocumentListener()
475 String caseInsensitiveFlag = "(?i)";
478 public void changedUpdate(DocumentEvent e)
480 sorter.setRowFilter(RowFilter
481 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
485 public void removeUpdate(DocumentEvent e)
487 sorter.setRowFilter(RowFilter
488 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
492 public void insertUpdate(DocumentEvent e)
494 sorter.setRowFilter(RowFilter
495 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
499 // set up list selection functionality
500 linkUrlTable.getSelectionModel()
501 .addListSelectionListener(new UrlListSelectionHandler());
503 // set up radio buttons
504 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
506 String onClickName = linkUrlTable.getColumnName(onClickCol);
507 linkUrlTable.getColumn(onClickName)
508 .setCellRenderer(new RadioButtonRenderer());
509 linkUrlTable.getColumn(onClickName)
510 .setCellEditor(new RadioButtonEditor());
512 // get boolean columns and resize those to min possible
513 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
515 if (linkUrlTable.getModel().getColumnClass(column)
516 .equals(Boolean.class))
518 TableColumn tableColumn = linkUrlTable.getColumnModel()
520 int preferredWidth = tableColumn.getMinWidth();
522 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
524 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
525 int cwidth = c.getPreferredSize().width
526 + linkUrlTable.getIntercellSpacing().width;
527 preferredWidth = Math.max(preferredWidth, cwidth);
529 tableColumn.setPreferredWidth(preferredWidth);
533 String proxyTypeString = Cache.getDefault("USE_PROXY", "false");
534 previousProxyType = proxyTypeString;
535 switch (proxyTypeString)
537 case Cache.PROXYTYPE_NONE:
538 proxyType.setSelected(noProxy.getModel(), true);
540 case Cache.PROXYTYPE_SYSTEM:
541 proxyType.setSelected(systemProxy.getModel(), true);
543 case Cache.PROXYTYPE_CUSTOM:
544 proxyType.setSelected(customProxy.getModel(), true);
548 "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
551 proxyServerHttpTB.setText(Cache.getDefault("PROXY_SERVER", ""));
552 proxyPortHttpTB.setText(Cache.getDefault("PROXY_PORT", ""));
553 proxyServerHttpsTB.setText(Cache.getDefault("PROXY_SERVER_HTTPS", ""));
554 proxyPortHttpsTB.setText(Cache.getDefault("PROXY_PORT_HTTPS", ""));
555 proxyAuth.setSelected(Cache.getDefault("PROXY_AUTH", false));
557 .setText(Cache.getDefault("PROXY_AUTH_USERNAME", ""));
558 // we are not storing or retrieving proxy password from .jalview_properties
559 proxyAuthPasswordPB.setText(Cache.proxyAuthPassword == null ? ""
560 : new String(Cache.proxyAuthPassword));
561 setCustomProxyEnabled();
563 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
565 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
566 // note antisense here: default is true
568 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
569 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
572 * Set Output tab defaults
574 epsRendering.addItem(promptEachTimeOpt);
575 epsRendering.addItem(lineArtOpt);
576 epsRendering.addItem(textOpt);
577 String defaultEPS = Cache.getDefault("EPS_RENDERING",
579 if (defaultEPS.equalsIgnoreCase("Text"))
581 epsRendering.setSelectedItem(textOpt);
583 else if (defaultEPS.equalsIgnoreCase("Lineart"))
585 epsRendering.setSelectedItem(lineArtOpt);
589 epsRendering.setSelectedItem(promptEachTimeOpt);
591 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
592 userIdWidth.setEnabled(!autoIdWidth.isSelected());
593 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
594 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
595 userIdWidth.setText(wi == null ? "" : wi.toString());
596 // TODO: refactor to use common enum via FormatAdapter and allow extension
597 // for new flat file formats
598 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
599 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
600 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
601 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
602 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
603 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
604 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
605 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
607 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
610 * Set Editing tab defaults
612 autoCalculateConsCheck
613 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
614 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
615 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
617 annotations_actionPerformed(null); // update the display of the annotation
621 * Set Backups tab defaults
623 loadLastSavedBackupsOptions();
627 * Save user selections on the Preferences tabs to the Cache and write out to
633 public void ok_actionPerformed(ActionEvent e)
635 if (!validateSettings())
641 * Set proxy settings first (to be before web services refresh)
646 * Save Visual settings
648 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
649 Boolean.toString(seqLimit.isSelected()));
650 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
651 Boolean.toString(rightAlign.isSelected()));
652 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
653 Boolean.toString(fullScreen.isSelected()));
654 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
655 Boolean.toString(openoverv.isSelected()));
656 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
657 Boolean.toString(annotations.isSelected()));
658 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
659 Boolean.toString(conservation.isSelected()));
660 Cache.applicationProperties.setProperty("SHOW_QUALITY",
661 Boolean.toString(quality.isSelected()));
662 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
663 Boolean.toString(identity.isSelected()));
665 Cache.applicationProperties.setProperty("GAP_SYMBOL",
666 gapSymbolCB.getSelectedItem().toString());
668 Cache.applicationProperties.setProperty("FONT_NAME",
669 fontNameCB.getSelectedItem().toString());
670 Cache.applicationProperties.setProperty("FONT_STYLE",
671 fontStyleCB.getSelectedItem().toString());
672 Cache.applicationProperties.setProperty("FONT_SIZE",
673 fontSizeCB.getSelectedItem().toString());
675 Cache.applicationProperties.setProperty("ID_ITALICS",
676 Boolean.toString(idItalics.isSelected()));
677 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
678 Boolean.toString(showUnconserved.isSelected()));
679 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
680 Boolean.toString(showOccupancy.isSelected()));
681 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
682 Boolean.toString(showGroupConsensus.isSelected()));
683 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
684 Boolean.toString(showGroupConservation.isSelected()));
685 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
686 Boolean.toString(showConsensHistogram.isSelected()));
687 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
688 Boolean.toString(showConsensLogo.isSelected()));
689 Cache.applicationProperties.setProperty("ANTI_ALIAS",
690 Boolean.toString(smoothFont.isSelected()));
691 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
692 Boolean.toString(scaleProteinToCdna.isSelected()));
693 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
694 Boolean.toString(showNpTooltip.isSelected()));
695 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
696 Boolean.toString(showDbRefTooltip.isSelected()));
698 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
699 Boolean.toString(wrap.isSelected()));
701 Cache.applicationProperties.setProperty("STARTUP_FILE",
702 startupFileTextfield.getText());
703 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
704 Boolean.toString(startupCheckbox.isSelected()));
706 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
707 sortby.getSelectedItem().toString());
709 // convert description of sort order to enum name for save
710 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
711 .forDescription(sortAnnBy.getSelectedItem().toString());
712 if (annSortOrder != null)
714 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
715 annSortOrder.name());
718 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
719 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
720 Boolean.valueOf(showAutocalcFirst).toString());
723 * Save Colours settings
725 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
726 protColour.getSelectedItem().toString());
727 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
728 nucColour.getSelectedItem().toString());
729 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
730 minColour.getBackground());
731 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
732 maxColour.getBackground());
735 * Save Overview settings
737 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
738 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
739 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
740 Boolean.toString(useLegacyGap.isSelected()));
741 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
742 Boolean.toString(showHiddenAtStart.isSelected()));
745 * Save Structure settings
747 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
748 Boolean.toString(addTempFactor.isSelected()));
749 Cache.applicationProperties.setProperty(ADD_SS_ANN,
750 Boolean.toString(addSecondaryStructure.isSelected()));
751 Cache.applicationProperties.setProperty(USE_RNAVIEW,
752 Boolean.toString(useRnaView.isSelected()));
753 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
754 Boolean.toString(structFromPdb.isSelected()));
755 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
756 structViewer.getSelectedItem().toString());
757 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
758 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
759 Boolean.toString(siftsMapping.isSelected()));
760 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
763 * Save Output settings
765 Cache.applicationProperties.setProperty("EPS_RENDERING",
766 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
769 * Save Connections settings
771 // Proxy settings set first (to catch web services)
773 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
775 jalview.util.BrowserLauncher.resetBrowser();
777 // save user-defined and selected links
778 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
779 if (menuLinks.isEmpty())
781 Cache.applicationProperties.remove("SEQUENCE_LINKS");
785 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
786 menuLinks.toString());
789 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
790 if (nonMenuLinks.isEmpty())
792 Cache.applicationProperties.remove("STORED_LINKS");
796 Cache.applicationProperties.setProperty("STORED_LINKS",
797 nonMenuLinks.toString());
800 Cache.applicationProperties.setProperty("DEFAULT_URL",
801 sequenceUrlLinks.getPrimaryUrlId());
803 Cache.setProperty("VERSION_CHECK",
804 Boolean.toString(versioncheck.isSelected()));
805 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
807 // default is false - we only set this if the user has actively agreed
808 Cache.setProperty("USAGESTATS",
809 Boolean.toString(usagestats.isSelected()));
811 if (!questionnaire.isSelected())
813 Cache.setProperty("NOQUESTIONNAIRES", "true");
817 // special - made easy to edit a property file to disable questionnaires
818 // by just adding the given line
819 Cache.removeProperty("NOQUESTIONNAIRES");
823 * Save Output settings
825 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
826 Boolean.toString(blcjv.isSelected()));
827 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
828 Boolean.toString(clustaljv.isSelected()));
829 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
830 Boolean.toString(fastajv.isSelected()));
831 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
832 Boolean.toString(msfjv.isSelected()));
833 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
834 Boolean.toString(pfamjv.isSelected()));
835 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
836 Boolean.toString(pileupjv.isSelected()));
837 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
838 Boolean.toString(pirjv.isSelected()));
839 Cache.applicationProperties.setProperty("PIR_MODELLER",
840 Boolean.toString(modellerOutput.isSelected()));
841 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
842 Boolean.toString(embbedBioJSON.isSelected()));
843 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
845 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
846 Boolean.toString(autoIdWidth.isSelected()));
847 userIdWidth_actionPerformed();
848 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
849 userIdWidth.getText());
852 * Save Editing settings
854 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
855 Boolean.toString(autoCalculateConsCheck.isSelected()));
856 Cache.applicationProperties.setProperty("SORT_BY_TREE",
857 Boolean.toString(sortByTree.isSelected()));
858 Cache.applicationProperties.setProperty("PAD_GAPS",
859 Boolean.toString(padGaps.isSelected()));
861 wsPrefs.updateAndRefreshWsMenuConfig(false);
864 * Save Backups settings
866 Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
867 Boolean.toString(enableBackupFiles.isSelected()));
868 int preset = getComboIntStringKey(backupfilesPresetsCombo);
869 Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET",
870 Integer.toString(preset));
872 if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
874 BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
875 BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
876 BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
877 Cache.applicationProperties.setProperty(
878 BackupFilesPresetEntry.CUSTOMCONFIG, customBFPE.toString());
881 BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
883 Cache.applicationProperties.setProperty(
884 BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
886 Cache.saveProperties();
887 Desktop.instance.doConfigureStructurePrefs();
890 frame.setClosed(true);
891 } catch (Exception ex)
896 public void saveProxySettings()
898 String newProxyType = customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
899 : noProxy.isSelected() ? Cache.PROXYTYPE_NONE
900 : Cache.PROXYTYPE_SYSTEM;
901 Cache.applicationProperties.setProperty("USE_PROXY", newProxyType);
902 Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText());
903 Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText());
904 Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText());
905 Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText());
906 Cache.setOrRemove("PROXY_AUTH",
907 Boolean.toString(proxyAuth.isSelected()));
908 Cache.setOrRemove("PROXY_AUTH_USERNAME", proxyAuthUsernameTB.getText());
909 Cache.proxyAuthPassword = proxyAuthPasswordPB.getPassword();
910 Cache.setProxyPropertiesFromPreferences(previousProxyType);
911 if (newProxyType.equals(Cache.PROXYTYPE_CUSTOM)
912 || !newProxyType.equals(previousProxyType))
914 // force a re-lookup of ws if proxytype is custom or has changed
917 previousProxyType = newProxyType;
921 * Do any necessary validation before saving settings. Return focus to the
922 * first tab which fails validation.
926 private boolean validateSettings()
928 if (!validateStructure())
930 structureTab.requestFocusInWindow();
937 protected boolean validateStructure()
939 return validateChimeraPath();
947 public void startupFileTextfield_mouseClicked()
949 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
950 JalviewFileChooser chooser = JalviewFileChooser
951 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
952 chooser.setFileView(new JalviewFileView());
953 chooser.setDialogTitle(
954 MessageManager.getString("label.select_startup_file"));
956 int value = chooser.showOpenDialog(this);
958 if (value == JalviewFileChooser.APPROVE_OPTION)
960 FileFormatI format = chooser.getSelectedFormat();
963 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
967 .setText(chooser.getSelectedFile().getAbsolutePath());
978 public void cancel_actionPerformed(ActionEvent e)
982 wsPrefs.updateWsMenuConfig(true);
983 wsPrefs.refreshWs_actionPerformed(e);
984 frame.setClosed(true);
985 } catch (Exception ex)
997 public void annotations_actionPerformed(ActionEvent e)
999 conservation.setEnabled(annotations.isSelected());
1000 quality.setEnabled(annotations.isSelected());
1001 identity.setEnabled(annotations.isSelected());
1002 showOccupancy.setEnabled(annotations.isSelected());
1003 showGroupConsensus.setEnabled(annotations.isSelected());
1004 showGroupConservation.setEnabled(annotations.isSelected());
1005 showConsensHistogram.setEnabled(annotations.isSelected()
1006 && (identity.isSelected() || showGroupConsensus.isSelected()));
1007 showConsensLogo.setEnabled(annotations.isSelected()
1008 && (identity.isSelected() || showGroupConsensus.isSelected()));
1012 public void newLink_actionPerformed(ActionEvent e)
1014 GSequenceLink link = new GSequenceLink();
1015 boolean valid = false;
1018 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1019 MessageManager.getString("label.new_sequence_url_link"),
1020 JvOptionPane.OK_CANCEL_OPTION, -1,
1021 null) == JvOptionPane.OK_OPTION)
1023 if (link.checkValid())
1025 if (((UrlLinkTableModel) linkUrlTable.getModel())
1026 .isUniqueName(link.getName()))
1028 ((UrlLinkTableModel) linkUrlTable.getModel())
1029 .insertRow(link.getName(), link.getURL());
1034 link.notifyDuplicate();
1047 public void editLink_actionPerformed(ActionEvent e)
1049 GSequenceLink link = new GSequenceLink();
1051 int index = linkUrlTable.getSelectedRow();
1054 // button no longer enabled if row is not selected
1055 Cache.log.debug("Edit with no row selected in linkUrlTable");
1059 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1061 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1063 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1064 link.setName(oldName);
1065 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1067 boolean valid = false;
1070 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1071 MessageManager.getString("label.edit_sequence_url_link"),
1072 JvOptionPane.OK_CANCEL_OPTION, -1,
1073 null) == JvOptionPane.OK_OPTION)
1075 if (link.checkValid())
1077 if ((oldName.equals(link.getName()))
1078 || (((UrlLinkTableModel) linkUrlTable.getModel())
1079 .isUniqueName(link.getName())))
1081 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1082 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1087 link.notifyDuplicate();
1100 public void deleteLink_actionPerformed(ActionEvent e)
1102 int index = linkUrlTable.getSelectedRow();
1103 int modelIndex = -1;
1106 // button no longer enabled if row is not selected
1107 Cache.log.debug("Delete with no row selected in linkUrlTable");
1112 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1115 // make sure we use the model index to delete, and not the table index
1116 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1120 public void defaultBrowser_mouseClicked(MouseEvent e)
1122 JFileChooser chooser = new JFileChooser(".");
1123 chooser.setDialogTitle(
1124 MessageManager.getString("label.select_default_browser"));
1126 int value = chooser.showOpenDialog(this);
1128 if (value == JFileChooser.APPROVE_OPTION)
1130 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1139 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1143 protected void showunconserved_actionPerformed(ActionEvent e)
1145 // TODO Auto-generated method stub
1146 super.showunconserved_actionPerformed(e);
1149 public static List<String> getGroupURLLinks()
1151 return groupURLLinks;
1155 public void minColour_actionPerformed(JPanel panel)
1157 Color col = JColorChooser.showDialog(this,
1158 MessageManager.getString("label.select_colour_minimum_value"),
1159 minColour.getBackground());
1162 panel.setBackground(col);
1168 public void maxColour_actionPerformed(JPanel panel)
1170 Color col = JColorChooser.showDialog(this,
1171 MessageManager.getString("label.select_colour_maximum_value"),
1172 maxColour.getBackground());
1175 panel.setBackground(col);
1181 public void gapColour_actionPerformed(JPanel gap)
1183 if (!useLegacyGap.isSelected())
1185 Color col = JColorChooser.showDialog(this,
1186 MessageManager.getString("label.select_gap_colour"),
1187 gapColour.getBackground());
1190 gap.setBackground(col);
1197 public void hiddenColour_actionPerformed(JPanel hidden)
1199 Color col = JColorChooser.showDialog(this,
1200 MessageManager.getString("label.select_hidden_colour"),
1201 hiddenColour.getBackground());
1204 hidden.setBackground(col);
1210 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1212 boolean enabled = useLegacyGap.isSelected();
1215 gapColour.setBackground(
1216 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1220 gapColour.setBackground(
1221 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1223 gapColour.setEnabled(!enabled);
1224 gapLabel.setEnabled(!enabled);
1228 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1230 useLegacyGap.setSelected(false);
1231 useLegacyGaps_actionPerformed(null);
1232 showHiddenAtStart.setSelected(false);
1233 hiddenColour.setBackground(
1234 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1238 protected void userIdWidth_actionPerformed()
1242 String val = userIdWidth.getText().trim();
1243 if (val.length() > 0)
1245 Integer iw = Integer.parseInt(val);
1246 if (iw.intValue() < 12)
1248 throw new NumberFormatException();
1250 userIdWidth.setText(iw.toString());
1252 } catch (NumberFormatException x)
1254 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1256 .getString("warn.user_defined_width_requirements"),
1257 MessageManager.getString("label.invalid_id_column_width"),
1258 JvOptionPane.WARNING_MESSAGE);
1259 userIdWidth.setText("");
1264 protected void autoIdWidth_actionPerformed()
1266 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1267 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1271 * Returns true if chimera path is to a valid executable, else show an error
1274 private boolean validateChimeraPath()
1276 if (chimeraPath.getText().trim().length() > 0)
1278 File f = new File(chimeraPath.getText());
1279 if (!f.canExecute())
1281 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1282 MessageManager.getString("label.invalid_chimera_path"),
1283 MessageManager.getString("label.invalid_name"),
1284 JvOptionPane.ERROR_MESSAGE);
1292 * If Chimera is selected, check it can be found on default or user-specified
1293 * path, if not show a warning/help dialog.
1296 protected void structureViewer_actionPerformed(String selectedItem)
1298 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1302 boolean found = false;
1305 * Try user-specified and standard paths for Chimera executable.
1307 List<String> paths = StructureManager.getChimeraPaths();
1308 paths.add(0, chimeraPath.getText());
1309 for (String path : paths)
1311 if (new File(path.trim()).canExecute())
1319 String[] options = { "OK", "Help" };
1320 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1321 JvSwingUtils.wrapTooltip(true,
1322 MessageManager.getString("label.chimera_missing")),
1323 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1324 null, options, options[0]);
1325 if (showHelp == JvOptionPane.NO_OPTION)
1329 Help.showHelpWindow(HelpId.StructureViewer);
1330 } catch (HelpSetException e)
1332 e.printStackTrace();
1338 public class OptionsParam
1340 private String name;
1342 private String code;
1344 public OptionsParam(String name, String code)
1350 public String getName()
1355 public void setName(String name)
1360 public String getCode()
1365 public void setCode(String code)
1371 public String toString()
1377 public boolean equals(Object that)
1379 if (!(that instanceof OptionsParam))
1383 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1387 public int hashCode()
1389 return name.hashCode() + code.hashCode();
1393 private class UrlListSelectionHandler implements ListSelectionListener
1397 public void valueChanged(ListSelectionEvent e)
1399 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1401 int index = lsm.getMinSelectionIndex();
1404 // no selection, so disable delete/edit buttons
1405 editLink.setEnabled(false);
1406 deleteLink.setEnabled(false);
1409 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1411 // enable/disable edit and delete link buttons
1412 if (((UrlLinkTableModel) linkUrlTable.getModel())
1413 .isRowDeletable(modelIndex))
1415 deleteLink.setEnabled(true);
1419 deleteLink.setEnabled(false);
1422 if (((UrlLinkTableModel) linkUrlTable.getModel())
1423 .isRowEditable(modelIndex))
1425 editLink.setEnabled(true);
1429 editLink.setEnabled(false);