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.FileFormatI;
28 import jalview.io.JalviewFileChooser;
29 import jalview.io.JalviewFileView;
30 import jalview.jbgui.GPreferences;
31 import jalview.jbgui.GSequenceLink;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ColourSchemes;
34 import jalview.schemes.ResidueColourScheme;
35 import jalview.urls.UrlLinkTableModel;
36 import jalview.urls.api.UrlProviderFactoryI;
37 import jalview.urls.api.UrlProviderI;
38 import jalview.urls.desktop.DesktopUrlProviderFactory;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
41 import jalview.util.UrlConstants;
42 import jalview.ws.sifts.SiftsSettings;
44 import java.awt.BorderLayout;
45 import java.awt.Color;
46 import java.awt.Component;
47 import java.awt.Dimension;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.MouseEvent;
53 import java.util.ArrayList;
54 import java.util.List;
56 import javax.help.HelpSetException;
57 import javax.swing.JFileChooser;
58 import javax.swing.JInternalFrame;
59 import javax.swing.JPanel;
60 import javax.swing.ListSelectionModel;
61 import javax.swing.RowFilter;
62 import javax.swing.RowSorter;
63 import javax.swing.SortOrder;
64 import javax.swing.event.DocumentEvent;
65 import javax.swing.event.DocumentListener;
66 import javax.swing.event.ListSelectionEvent;
67 import javax.swing.event.ListSelectionListener;
68 import javax.swing.table.TableCellRenderer;
69 import javax.swing.table.TableColumn;
70 import javax.swing.table.TableModel;
71 import javax.swing.table.TableRowSorter;
73 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
81 public class Preferences extends GPreferences
83 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
85 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
87 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
89 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
91 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
93 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
95 public static final String ADD_SS_ANN = "ADD_SS_ANN";
97 public static final String USE_RNAVIEW = "USE_RNAVIEW";
99 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
101 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
103 public static final String CHIMERA_PATH = "CHIMERA_PATH";
105 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
107 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
109 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
111 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
113 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
115 public static final String GAP_COLOUR = "GAP_COLOUR";
117 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
119 private static final int MIN_FONT_SIZE = 1;
121 private static final int MAX_FONT_SIZE = 30;
124 * Holds name and link separated with | character. Sequence ID must be
125 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
127 public static UrlProviderI sequenceUrlLinks;
129 public static UrlLinkTableModel dataModel;
132 * Holds name and link separated with | character. Sequence IDS and Sequences
133 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
134 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
135 * for first and second token specified after a pipe character at end |,|.
136 * (TODO: proper escape for using | to separate ids or sequences
139 public static List<String> groupURLLinks;
142 // get links selected to be in the menu (SEQUENCE_LINKS)
143 // and links entered by the user but not selected (STORED_LINKS)
144 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
145 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
146 String defaultUrl = Cache.getDefault("DEFAULT_URL",
147 UrlConstants.DEFAULT_LABEL);
149 // if both links lists are empty, add the DEFAULT_URL link
150 // otherwise we assume the default link is in one of the lists
151 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
153 inMenuString = UrlConstants.DEFAULT_STRING;
155 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
156 inMenuString, notInMenuString);
157 sequenceUrlLinks = factory.createUrlProvider();
158 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
161 * TODO: reformulate groupURL encoding so two or more can be stored in the
162 * .properties file as '|' separated strings
165 groupURLLinks = new ArrayList<>();
168 JInternalFrame frame;
170 private WsPreferences wsPrefs;
172 private OptionsParam promptEachTimeOpt = new OptionsParam(
173 MessageManager.getString("label.prompt_each_time"),
176 private OptionsParam lineArtOpt = new OptionsParam(
177 MessageManager.getString("label.lineart"), "Lineart");
179 private OptionsParam textOpt = new OptionsParam(
180 MessageManager.getString("action.text"), "Text");
183 * Creates a new Preferences object.
188 frame = new JInternalFrame();
189 frame.setContentPane(this);
190 wsPrefs = new WsPreferences();
191 wsTab.add(wsPrefs, BorderLayout.CENTER);
192 int width = 500, height = 450;
193 new jalview.util.Platform();
194 if (Platform.isAMac())
200 Desktop.addInternalFrame(frame,
201 MessageManager.getString("label.preferences"), width, height);
202 frame.setMinimumSize(new Dimension(width, height));
205 * Set Visual tab defaults
207 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
208 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
209 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
210 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
212 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
213 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
214 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
215 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
217 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
218 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
220 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
221 showGroupConservation.setSelected(
222 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
223 showConsensHistogram.setSelected(
224 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
226 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
228 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
230 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
232 String[] fonts = java.awt.GraphicsEnvironment
233 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
234 for (int i = 0; i < fonts.length; i++)
236 fontNameCB.addItem(fonts[i]);
239 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
241 fontSizeCB.addItem(i + "");
244 fontStyleCB.addItem("plain");
245 fontStyleCB.addItem("bold");
246 fontStyleCB.addItem("italic");
248 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
249 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
250 fontStyleCB.setSelectedItem(
251 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
253 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
255 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
257 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
259 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
261 gapSymbolCB.addItem("-");
262 gapSymbolCB.addItem(".");
264 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
266 sortby.addItem("No sort");
267 sortby.addItem("Id");
268 sortby.addItem("Pairwise Identity");
269 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
271 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
273 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
275 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
276 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
277 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
278 SequenceAnnotationOrder.NONE.name()));
279 sortAnnBy.setSelectedItem(savedSort.toString());
281 sortAutocalc.addItem("Autocalculated first");
282 sortAutocalc.addItem("Autocalculated last");
283 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
284 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
285 : sortAutocalc.getItemAt(1));
287 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
288 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
289 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
290 + "/examples/exampleFile_2_3.jar"));
293 * Set Colours tab defaults
295 protColour.addItem(ResidueColourScheme.NONE);
296 nucColour.addItem(ResidueColourScheme.NONE);
297 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
299 String name = cs.getSchemeName();
300 protColour.addItem(name);
301 nucColour.addItem(name);
303 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
304 ResidueColourScheme.NONE);
305 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
306 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
307 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
308 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
309 minColour.setBackground(
310 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
311 maxColour.setBackground(
312 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
315 * Set overview panel defaults
317 gapColour.setBackground(
318 Cache.getDefaultColour(GAP_COLOUR,
319 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
320 hiddenColour.setBackground(
321 Cache.getDefaultColour(HIDDEN_COLOUR,
322 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
323 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
324 gapLabel.setEnabled(!useLegacyGap.isSelected());
325 gapColour.setEnabled(!useLegacyGap.isSelected());
327 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
330 * Set Structure tab defaults.
332 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
333 structFromPdb.setSelected(structSelected);
334 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
335 useRnaView.setEnabled(structSelected);
336 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
337 addSecondaryStructure.setEnabled(structSelected);
338 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
339 addTempFactor.setEnabled(structSelected);
340 structViewer.setSelectedItem(
341 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
342 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
343 chimeraPath.addActionListener(new ActionListener()
346 public void actionPerformed(ActionEvent e)
348 validateChimeraPath();
352 if (Cache.getDefault("MAP_WITH_SIFTS", false))
354 siftsMapping.setSelected(true);
358 nwMapping.setSelected(true);
362 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
365 * Set Connections tab defaults
369 linkUrlTable.setModel(dataModel);
370 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
371 linkUrlTable.getModel());
372 linkUrlTable.setRowSorter(sorter);
373 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
375 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
376 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
377 SortOrder.DESCENDING));
378 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
379 SortOrder.DESCENDING));
381 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
383 sorter.setSortKeys(sortKeys);
384 // BH 2018 setSortKeys will do the sort
388 ActionListener onReset;
389 onReset = new ActionListener()
392 public void actionPerformed(ActionEvent e)
394 filterTB.setText("");
395 sorter.setRowFilter(RowFilter.regexFilter(""));
399 doReset.addActionListener(onReset);
401 // filter to display only custom urls
402 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
405 public boolean include(
406 Entry<? extends TableModel, ? extends Object> entry)
408 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
412 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
413 linkUrlTable.getModel());
414 customSorter.setRowFilter(customUrlFilter);
416 ActionListener onCustomOnly;
417 onCustomOnly = new ActionListener()
420 public void actionPerformed(ActionEvent e)
422 filterTB.setText("");
423 sorter.setRowFilter(customUrlFilter);
426 userOnly.addActionListener(onCustomOnly);
428 filterTB.getDocument().addDocumentListener(new DocumentListener()
430 String caseInsensitiveFlag = "(?i)";
433 public void changedUpdate(DocumentEvent e)
435 sorter.setRowFilter(RowFilter
436 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
440 public void removeUpdate(DocumentEvent e)
442 sorter.setRowFilter(RowFilter
443 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
447 public void insertUpdate(DocumentEvent e)
449 sorter.setRowFilter(RowFilter
450 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
454 // set up list selection functionality
455 linkUrlTable.getSelectionModel()
456 .addListSelectionListener(new UrlListSelectionHandler());
458 // set up radio buttons
459 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
461 String onClickName = linkUrlTable.getColumnName(onClickCol);
462 linkUrlTable.getColumn(onClickName)
463 .setCellRenderer(new RadioButtonRenderer());
464 linkUrlTable.getColumn(onClickName)
465 .setCellEditor(new RadioButtonEditor());
467 // get boolean columns and resize those to min possible
468 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
470 if (linkUrlTable.getModel().getColumnClass(column)
471 .equals(Boolean.class))
473 TableColumn tableColumn = linkUrlTable.getColumnModel()
475 int preferredWidth = tableColumn.getMinWidth();
477 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
479 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
480 int cwidth = c.getPreferredSize().width
481 + linkUrlTable.getIntercellSpacing().width;
482 preferredWidth = Math.max(preferredWidth, cwidth);
484 tableColumn.setPreferredWidth(preferredWidth);
488 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
489 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
490 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
491 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
493 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
495 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
496 // note antisense here: default is true
498 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
499 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
502 * Set Output tab defaults
504 epsRendering.addItem(promptEachTimeOpt);
505 epsRendering.addItem(lineArtOpt);
506 epsRendering.addItem(textOpt);
507 String defaultEPS = Cache.getDefault("EPS_RENDERING",
509 if (defaultEPS.equalsIgnoreCase("Text"))
511 epsRendering.setSelectedItem(textOpt);
513 else if (defaultEPS.equalsIgnoreCase("Lineart"))
515 epsRendering.setSelectedItem(lineArtOpt);
519 epsRendering.setSelectedItem(promptEachTimeOpt);
521 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
522 userIdWidth.setEnabled(!autoIdWidth.isSelected());
523 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
524 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
525 userIdWidth.setText(wi == null ? "" : wi.toString());
526 // TODO: refactor to use common enum via FormatAdapter and allow extension
527 // for new flat file formats
528 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
529 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
530 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
531 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
532 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
533 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
534 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
535 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
537 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
540 * Set Editing tab defaults
542 autoCalculateConsCheck
543 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
544 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
545 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
547 annotations_actionPerformed(null); // update the display of the annotation
552 * Save user selections on the Preferences tabs to the Cache and write out to
558 public void ok_actionPerformed(ActionEvent e)
560 if (!validateSettings())
566 * Save Visual settings
568 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
569 Boolean.toString(seqLimit.isSelected()));
570 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
571 Boolean.toString(rightAlign.isSelected()));
572 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
573 Boolean.toString(fullScreen.isSelected()));
574 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
575 Boolean.toString(openoverv.isSelected()));
576 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
577 Boolean.toString(annotations.isSelected()));
578 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
579 Boolean.toString(conservation.isSelected()));
580 Cache.applicationProperties.setProperty("SHOW_QUALITY",
581 Boolean.toString(quality.isSelected()));
582 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
583 Boolean.toString(identity.isSelected()));
585 Cache.applicationProperties.setProperty("GAP_SYMBOL",
586 gapSymbolCB.getSelectedItem().toString());
588 Cache.applicationProperties.setProperty("FONT_NAME",
589 fontNameCB.getSelectedItem().toString());
590 Cache.applicationProperties.setProperty("FONT_STYLE",
591 fontStyleCB.getSelectedItem().toString());
592 Cache.applicationProperties.setProperty("FONT_SIZE",
593 fontSizeCB.getSelectedItem().toString());
595 Cache.applicationProperties.setProperty("ID_ITALICS",
596 Boolean.toString(idItalics.isSelected()));
597 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
598 Boolean.toString(showUnconserved.isSelected()));
599 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
600 Boolean.toString(showOccupancy.isSelected()));
601 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
602 Boolean.toString(showGroupConsensus.isSelected()));
603 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
604 Boolean.toString(showGroupConservation.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
606 Boolean.toString(showConsensHistogram.isSelected()));
607 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
608 Boolean.toString(showConsensLogo.isSelected()));
609 Cache.applicationProperties.setProperty("ANTI_ALIAS",
610 Boolean.toString(smoothFont.isSelected()));
611 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
612 Boolean.toString(scaleProteinToCdna.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
614 Boolean.toString(showNpTooltip.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
616 Boolean.toString(showDbRefTooltip.isSelected()));
618 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
619 Boolean.toString(wrap.isSelected()));
621 Cache.applicationProperties.setProperty("STARTUP_FILE",
622 startupFileTextfield.getText());
623 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
624 Boolean.toString(startupCheckbox.isSelected()));
626 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
627 sortby.getSelectedItem().toString());
629 // convert description of sort order to enum name for save
630 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
631 .forDescription(sortAnnBy.getSelectedItem().toString());
632 if (annSortOrder != null)
634 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
635 annSortOrder.name());
638 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
639 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
640 Boolean.valueOf(showAutocalcFirst).toString());
643 * Save Colours settings
645 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
646 protColour.getSelectedItem().toString());
647 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
648 nucColour.getSelectedItem().toString());
649 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
650 minColour.getBackground());
651 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
652 maxColour.getBackground());
655 * Save Overview settings
657 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
658 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
659 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
660 Boolean.toString(useLegacyGap.isSelected()));
661 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
662 Boolean.toString(showHiddenAtStart.isSelected()));
665 * Save Structure settings
667 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
668 Boolean.toString(addTempFactor.isSelected()));
669 Cache.applicationProperties.setProperty(ADD_SS_ANN,
670 Boolean.toString(addSecondaryStructure.isSelected()));
671 Cache.applicationProperties.setProperty(USE_RNAVIEW,
672 Boolean.toString(useRnaView.isSelected()));
673 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
674 Boolean.toString(structFromPdb.isSelected()));
675 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
676 structViewer.getSelectedItem().toString());
677 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
678 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
679 Boolean.toString(siftsMapping.isSelected()));
680 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
683 * Save Output settings
685 Cache.applicationProperties.setProperty("EPS_RENDERING",
686 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
689 * Save Connections settings
691 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
693 jalview.util.BrowserLauncher.resetBrowser();
695 // save user-defined and selected links
696 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
697 if (menuLinks.isEmpty())
699 Cache.applicationProperties.remove("SEQUENCE_LINKS");
703 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
704 menuLinks.toString());
707 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
708 if (nonMenuLinks.isEmpty())
710 Cache.applicationProperties.remove("STORED_LINKS");
714 Cache.applicationProperties.setProperty("STORED_LINKS",
715 nonMenuLinks.toString());
718 Cache.applicationProperties.setProperty("DEFAULT_URL",
719 sequenceUrlLinks.getPrimaryUrlId());
721 Cache.applicationProperties.setProperty("USE_PROXY",
722 Boolean.toString(useProxy.isSelected()));
724 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
726 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
728 if (useProxy.isSelected())
730 System.setProperty("http.proxyHost", proxyServerTB.getText());
731 System.setProperty("http.proxyPort", proxyPortTB.getText());
735 System.setProperty("http.proxyHost", "");
736 System.setProperty("http.proxyPort", "");
738 Cache.setProperty("VERSION_CHECK",
739 Boolean.toString(versioncheck.isSelected()));
740 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
742 // default is false - we only set this if the user has actively agreed
743 Cache.setProperty("USAGESTATS",
744 Boolean.toString(usagestats.isSelected()));
746 if (!questionnaire.isSelected())
748 Cache.setProperty("NOQUESTIONNAIRES", "true");
752 // special - made easy to edit a property file to disable questionnaires
753 // by just adding the given line
754 Cache.removeProperty("NOQUESTIONNAIRES");
758 * Save Output settings
760 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
761 Boolean.toString(blcjv.isSelected()));
762 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
763 Boolean.toString(clustaljv.isSelected()));
764 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
765 Boolean.toString(fastajv.isSelected()));
766 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
767 Boolean.toString(msfjv.isSelected()));
768 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
769 Boolean.toString(pfamjv.isSelected()));
770 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
771 Boolean.toString(pileupjv.isSelected()));
772 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
773 Boolean.toString(pirjv.isSelected()));
774 Cache.applicationProperties.setProperty("PIR_MODELLER",
775 Boolean.toString(modellerOutput.isSelected()));
776 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
777 Boolean.toString(embbedBioJSON.isSelected()));
778 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
780 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
781 Boolean.toString(autoIdWidth.isSelected()));
782 userIdWidth_actionPerformed();
783 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
784 userIdWidth.getText());
787 * Save Editing settings
789 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
790 Boolean.toString(autoCalculateConsCheck.isSelected()));
791 Cache.applicationProperties.setProperty("SORT_BY_TREE",
792 Boolean.toString(sortByTree.isSelected()));
793 Cache.applicationProperties.setProperty("PAD_GAPS",
794 Boolean.toString(padGaps.isSelected()));
796 wsPrefs.updateAndRefreshWsMenuConfig(false);
797 Cache.saveProperties();
798 Desktop.instance.doConfigureStructurePrefs();
801 frame.setClosed(true);
802 } catch (Exception ex)
808 * Do any necessary validation before saving settings. Return focus to the
809 * first tab which fails validation.
813 private boolean validateSettings()
815 if (!validateStructure())
817 structureTab.requestFocusInWindow();
824 protected boolean validateStructure()
826 return validateChimeraPath();
834 public void startupFileTextfield_mouseClicked()
836 // TODO: JAL-3048 not needed for Jalview-JS
837 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
838 JalviewFileChooser chooser = JalviewFileChooser
839 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
840 chooser.setFileView(new JalviewFileView());
841 chooser.setDialogTitle(
842 MessageManager.getString("label.select_startup_file"));
844 int value = chooser.showOpenDialog(this);
846 if (value == JalviewFileChooser.APPROVE_OPTION)
848 FileFormatI format = chooser.getSelectedFormat();
851 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
855 .setText(chooser.getSelectedFile().getAbsolutePath());
866 public void cancel_actionPerformed(ActionEvent e)
870 wsPrefs.updateWsMenuConfig(true);
871 wsPrefs.refreshWs_actionPerformed(e);
872 frame.setClosed(true);
873 } catch (Exception ex)
885 public void annotations_actionPerformed(ActionEvent e)
887 conservation.setEnabled(annotations.isSelected());
888 quality.setEnabled(annotations.isSelected());
889 identity.setEnabled(annotations.isSelected());
890 showOccupancy.setEnabled(annotations.isSelected());
891 showGroupConsensus.setEnabled(annotations.isSelected());
892 showGroupConservation.setEnabled(annotations.isSelected());
893 showConsensHistogram.setEnabled(annotations.isSelected()
894 && (identity.isSelected() || showGroupConsensus.isSelected()));
895 showConsensLogo.setEnabled(annotations.isSelected()
896 && (identity.isSelected() || showGroupConsensus.isSelected()));
900 public void newLink_actionPerformed(ActionEvent e)
902 GSequenceLink link = new GSequenceLink();
903 boolean valid = false;
906 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
907 MessageManager.getString("label.new_sequence_url_link"),
908 JvOptionPane.OK_CANCEL_OPTION, -1,
909 null) == JvOptionPane.OK_OPTION)
911 if (link.checkValid())
913 if (((UrlLinkTableModel) linkUrlTable.getModel())
914 .isUniqueName(link.getName()))
916 ((UrlLinkTableModel) linkUrlTable.getModel())
917 .insertRow(link.getName(), link.getURL());
922 link.notifyDuplicate();
935 public void editLink_actionPerformed(ActionEvent e)
937 GSequenceLink link = new GSequenceLink();
939 int index = linkUrlTable.getSelectedRow();
942 // button no longer enabled if row is not selected
943 Cache.log.debug("Edit with no row selected in linkUrlTable");
947 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
949 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
951 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
952 link.setName(oldName);
953 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
955 boolean valid = false;
958 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
959 MessageManager.getString("label.edit_sequence_url_link"),
960 JvOptionPane.OK_CANCEL_OPTION, -1,
961 null) == JvOptionPane.OK_OPTION)
963 if (link.checkValid())
965 if ((oldName.equals(link.getName()))
966 || (((UrlLinkTableModel) linkUrlTable.getModel())
967 .isUniqueName(link.getName())))
969 linkUrlTable.setValueAt(link.getName(), index, nameCol);
970 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
975 link.notifyDuplicate();
988 public void deleteLink_actionPerformed(ActionEvent e)
990 int index = linkUrlTable.getSelectedRow();
994 // button no longer enabled if row is not selected
995 Cache.log.debug("Delete with no row selected in linkUrlTable");
1000 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1003 // make sure we use the model index to delete, and not the table index
1004 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1008 public void defaultBrowser_mouseClicked(MouseEvent e)
1010 // TODO: JAL-3048 not needed for j2s
1015 JFileChooser chooser = new JFileChooser(".");
1016 chooser.setDialogTitle(
1017 MessageManager.getString("label.select_default_browser"));
1019 int value = chooser.showOpenDialog(this);
1021 if (value == JFileChooser.APPROVE_OPTION)
1023 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1032 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1036 protected void showunconserved_actionPerformed(ActionEvent e)
1038 // TODO Auto-generated method stub
1039 super.showunconserved_actionPerformed(e);
1042 public static List<String> getGroupURLLinks()
1044 return groupURLLinks;
1048 public void minColour_actionPerformed(JPanel panel)
1050 JalviewColourChooser.showColourChooser(this,
1051 MessageManager.getString("label.select_colour_minimum_value"),
1056 public void maxColour_actionPerformed(JPanel panel)
1058 JalviewColourChooser.showColourChooser(this,
1059 MessageManager.getString("label.select_colour_maximum_value"),
1064 public void gapColour_actionPerformed(JPanel gap)
1066 if (!useLegacyGap.isSelected())
1068 JalviewColourChooser.showColourChooser(this,
1069 MessageManager.getString("label.select_gap_colour"),
1075 public void hiddenColour_actionPerformed(JPanel hidden)
1077 JalviewColourChooser.showColourChooser(this,
1078 MessageManager.getString("label.select_hidden_colour"),
1083 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1085 boolean enabled = useLegacyGap.isSelected();
1088 gapColour.setBackground(
1089 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1093 gapColour.setBackground(
1094 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1096 gapColour.setEnabled(!enabled);
1097 gapLabel.setEnabled(!enabled);
1101 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1103 useLegacyGap.setSelected(false);
1104 useLegacyGaps_actionPerformed(null);
1105 showHiddenAtStart.setSelected(true);
1106 hiddenColour.setBackground(
1107 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1111 protected void userIdWidth_actionPerformed()
1115 String val = userIdWidth.getText().trim();
1116 if (val.length() > 0)
1118 Integer iw = Integer.parseInt(val);
1119 if (iw.intValue() < 12)
1121 throw new NumberFormatException();
1123 userIdWidth.setText(iw.toString());
1125 } catch (NumberFormatException x)
1127 userIdWidth.setText("");
1128 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1130 .getString("warn.user_defined_width_requirements"),
1131 MessageManager.getString("label.invalid_id_column_width"),
1132 JvOptionPane.WARNING_MESSAGE);
1137 protected void autoIdWidth_actionPerformed()
1139 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1140 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1144 * Returns true if chimera path is to a valid executable, else show an error
1147 private boolean validateChimeraPath()
1149 if (chimeraPath.getText().trim().length() > 0)
1151 File f = new File(chimeraPath.getText());
1152 if (!f.canExecute())
1154 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1155 MessageManager.getString("label.invalid_chimera_path"),
1156 MessageManager.getString("label.invalid_name"),
1157 JvOptionPane.ERROR_MESSAGE);
1165 * If Chimera is selected, check it can be found on default or user-specified
1166 * path, if not show a warning/help dialog.
1169 protected void structureViewer_actionPerformed(String selectedItem)
1171 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1175 boolean found = false;
1178 * Try user-specified and standard paths for Chimera executable.
1180 List<String> paths = StructureManager.getChimeraPaths();
1181 paths.add(0, chimeraPath.getText());
1182 for (String path : paths)
1184 if (new File(path.trim()).canExecute())
1192 String[] options = { "OK", "Help" };
1193 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1194 JvSwingUtils.wrapTooltip(true,
1195 MessageManager.getString("label.chimera_missing")),
1196 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1197 null, options, options[0]);
1198 if (showHelp == JvOptionPane.NO_OPTION)
1202 Help.showHelpWindow(HelpId.StructureViewer);
1203 } catch (HelpSetException e)
1205 e.printStackTrace();
1211 public class OptionsParam
1213 private String name;
1215 private String code;
1217 public OptionsParam(String name, String code)
1223 public String getName()
1228 public void setName(String name)
1233 public String getCode()
1238 public void setCode(String code)
1244 public String toString()
1250 public boolean equals(Object that)
1252 if (!(that instanceof OptionsParam))
1256 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1260 public int hashCode()
1262 return name.hashCode() + code.hashCode();
1266 private class UrlListSelectionHandler implements ListSelectionListener
1270 public void valueChanged(ListSelectionEvent e)
1272 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1274 int index = lsm.getMinSelectionIndex();
1277 // no selection, so disable delete/edit buttons
1278 editLink.setEnabled(false);
1279 deleteLink.setEnabled(false);
1282 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1284 // enable/disable edit and delete link buttons
1285 if (((UrlLinkTableModel) linkUrlTable.getModel())
1286 .isRowDeletable(modelIndex))
1288 deleteLink.setEnabled(true);
1292 deleteLink.setEnabled(false);
1295 if (((UrlLinkTableModel) linkUrlTable.getModel())
1296 .isRowEditable(modelIndex))
1298 editLink.setEnabled(true);
1302 editLink.setEnabled(false);