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.JComboBox;
58 import javax.swing.JFileChooser;
59 import javax.swing.JInternalFrame;
60 import javax.swing.JPanel;
61 import javax.swing.ListSelectionModel;
62 import javax.swing.RowFilter;
63 import javax.swing.RowSorter;
64 import javax.swing.SortOrder;
65 import javax.swing.event.DocumentEvent;
66 import javax.swing.event.DocumentListener;
67 import javax.swing.event.ListSelectionEvent;
68 import javax.swing.event.ListSelectionListener;
69 import javax.swing.table.TableCellRenderer;
70 import javax.swing.table.TableColumn;
71 import javax.swing.table.TableModel;
72 import javax.swing.table.TableRowSorter;
74 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
82 public class Preferences extends GPreferences
84 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
86 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
88 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
90 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
92 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
94 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
96 public static final String ADD_SS_ANN = "ADD_SS_ANN";
98 public static final String USE_RNAVIEW = "USE_RNAVIEW";
100 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
102 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
104 public static final String CHIMERA_PATH = "CHIMERA_PATH";
106 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
108 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
110 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
112 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
114 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
116 public static final String GAP_COLOUR = "GAP_COLOUR";
118 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
120 private static final int MIN_FONT_SIZE = 1;
122 private static final int MAX_FONT_SIZE = 30;
125 * Holds name and link separated with | character. Sequence ID must be
126 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
128 public static UrlProviderI sequenceUrlLinks;
130 public static UrlLinkTableModel dataModel;
133 * Holds name and link separated with | character. Sequence IDS and Sequences
134 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
135 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
136 * for first and second token specified after a pipe character at end |,|.
137 * (TODO: proper escape for using | to separate ids or sequences
140 public static List<String> groupURLLinks;
143 // get links selected to be in the menu (SEQUENCE_LINKS)
144 // and links entered by the user but not selected (STORED_LINKS)
145 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
146 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
147 String defaultUrl = Cache.getDefault("DEFAULT_URL",
148 UrlConstants.DEFAULT_LABEL);
150 // if both links lists are empty, add the DEFAULT_URL link
151 // otherwise we assume the default link is in one of the lists
152 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
154 inMenuString = UrlConstants.DEFAULT_STRING;
156 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
157 inMenuString, notInMenuString);
158 sequenceUrlLinks = factory.createUrlProvider();
159 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
162 * TODO: reformulate groupURL encoding so two or more can be stored in the
163 * .properties file as '|' separated strings
166 groupURLLinks = new ArrayList<>();
169 JInternalFrame frame;
171 private WsPreferences wsPrefs;
173 private OptionsParam promptEachTimeOpt = new OptionsParam(
174 MessageManager.getString("label.prompt_each_time"),
177 private OptionsParam lineArtOpt = new OptionsParam(
178 MessageManager.getString("label.lineart"), "Lineart");
180 private OptionsParam textOpt = new OptionsParam(
181 MessageManager.getString("action.text"), "Text");
184 * Creates a new Preferences object.
189 frame = new JInternalFrame();
190 frame.setContentPane(this);
191 if (!Platform.isJS())
193 wsPrefs = new WsPreferences();
194 wsTab.add(wsPrefs, BorderLayout.CENTER);
196 int width = 500, height = 450;
197 if (Platform.isAMacAndNotJS())
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, true));
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);
387 // BH 2018 setSortKeys will do the sort
391 ActionListener onReset;
392 onReset = new ActionListener()
395 public void actionPerformed(ActionEvent e)
397 filterTB.setText("");
398 sorter.setRowFilter(RowFilter.regexFilter(""));
402 doReset.addActionListener(onReset);
404 // filter to display only custom urls
405 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
408 public boolean include(
409 Entry<? extends TableModel, ? extends Object> entry)
411 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
415 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
416 linkUrlTable.getModel());
417 customSorter.setRowFilter(customUrlFilter);
419 ActionListener onCustomOnly;
420 onCustomOnly = new ActionListener()
423 public void actionPerformed(ActionEvent e)
425 filterTB.setText("");
426 sorter.setRowFilter(customUrlFilter);
429 userOnly.addActionListener(onCustomOnly);
431 filterTB.getDocument().addDocumentListener(new DocumentListener()
433 String caseInsensitiveFlag = "(?i)";
436 public void changedUpdate(DocumentEvent e)
438 sorter.setRowFilter(RowFilter
439 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
443 public void removeUpdate(DocumentEvent e)
445 sorter.setRowFilter(RowFilter
446 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
450 public void insertUpdate(DocumentEvent e)
452 sorter.setRowFilter(RowFilter
453 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
457 // set up list selection functionality
458 linkUrlTable.getSelectionModel()
459 .addListSelectionListener(new UrlListSelectionHandler());
461 // set up radio buttons
462 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
464 String onClickName = linkUrlTable.getColumnName(onClickCol);
465 linkUrlTable.getColumn(onClickName)
466 .setCellRenderer(new RadioButtonRenderer());
467 linkUrlTable.getColumn(onClickName)
468 .setCellEditor(new RadioButtonEditor());
470 // get boolean columns and resize those to min possible
471 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
473 if (linkUrlTable.getModel().getColumnClass(column)
474 .equals(Boolean.class))
476 TableColumn tableColumn = linkUrlTable.getColumnModel()
478 int preferredWidth = tableColumn.getMinWidth();
480 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
482 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
483 int cwidth = c.getPreferredSize().width
484 + linkUrlTable.getIntercellSpacing().width;
485 preferredWidth = Math.max(preferredWidth, cwidth);
487 tableColumn.setPreferredWidth(preferredWidth);
491 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
492 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
493 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
494 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
496 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
498 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
499 // note antisense here: default is true
501 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
502 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
505 * Set Output tab defaults
507 setupOutputCombo(epsRendering, "EPS_RENDERING");
508 setupOutputCombo(htmlRendering, "HTML_RENDERING");
509 setupOutputCombo(svgRendering, "SVG_RENDERING");
510 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
511 userIdWidth.setEnabled(!autoIdWidth.isSelected());
512 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
513 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
514 userIdWidth.setText(wi == null ? "" : wi.toString());
515 // TODO: refactor to use common enum via FormatAdapter and allow extension
516 // for new flat file formats
517 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
518 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
519 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
520 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
521 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
522 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
523 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
524 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
526 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
529 * Set Editing tab defaults
531 autoCalculateConsCheck
532 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
533 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
534 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
536 annotations_actionPerformed(null); // update the display of the annotation
541 * A helper method that sets the items and initial selection in a character
542 * rendering option list (Prompt each time/Lineart/Text)
547 protected void setupOutputCombo(JComboBox<Object> comboBox,
550 comboBox.addItem(promptEachTimeOpt);
551 comboBox.addItem(lineArtOpt);
552 comboBox.addItem(textOpt);
555 * JalviewJS doesn't support Lineart so force it to Text
557 String defaultOption = Platform.isJS() ? "Text"
558 : Cache.getDefault(propertyKey, "Prompt each time");
559 if (defaultOption.equalsIgnoreCase("Text"))
561 comboBox.setSelectedItem(textOpt);
563 else if (defaultOption.equalsIgnoreCase("Lineart"))
565 comboBox.setSelectedItem(lineArtOpt);
569 comboBox.setSelectedItem(promptEachTimeOpt);
574 * Save user selections on the Preferences tabs to the Cache and write out to
580 public void ok_actionPerformed(ActionEvent e)
582 if (!validateSettings())
588 * Save Visual settings
590 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
591 Boolean.toString(seqLimit.isSelected()));
592 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
593 Boolean.toString(rightAlign.isSelected()));
594 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
595 Boolean.toString(fullScreen.isSelected()));
596 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
597 Boolean.toString(openoverv.isSelected()));
598 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
599 Boolean.toString(annotations.isSelected()));
600 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
601 Boolean.toString(conservation.isSelected()));
602 Cache.applicationProperties.setProperty("SHOW_QUALITY",
603 Boolean.toString(quality.isSelected()));
604 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
605 Boolean.toString(identity.isSelected()));
607 Cache.applicationProperties.setProperty("GAP_SYMBOL",
608 gapSymbolCB.getSelectedItem().toString());
610 Cache.applicationProperties.setProperty("FONT_NAME",
611 fontNameCB.getSelectedItem().toString());
612 Cache.applicationProperties.setProperty("FONT_STYLE",
613 fontStyleCB.getSelectedItem().toString());
614 Cache.applicationProperties.setProperty("FONT_SIZE",
615 fontSizeCB.getSelectedItem().toString());
617 Cache.applicationProperties.setProperty("ID_ITALICS",
618 Boolean.toString(idItalics.isSelected()));
619 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
620 Boolean.toString(showUnconserved.isSelected()));
621 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
622 Boolean.toString(showOccupancy.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
624 Boolean.toString(showGroupConsensus.isSelected()));
625 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
626 Boolean.toString(showGroupConservation.isSelected()));
627 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
628 Boolean.toString(showConsensHistogram.isSelected()));
629 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
630 Boolean.toString(showConsensLogo.isSelected()));
631 Cache.applicationProperties.setProperty("ANTI_ALIAS",
632 Boolean.toString(smoothFont.isSelected()));
633 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
634 Boolean.toString(scaleProteinToCdna.isSelected()));
635 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
636 Boolean.toString(showNpTooltip.isSelected()));
637 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
638 Boolean.toString(showDbRefTooltip.isSelected()));
640 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
641 Boolean.toString(wrap.isSelected()));
643 Cache.applicationProperties.setProperty("STARTUP_FILE",
644 startupFileTextfield.getText());
645 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
646 Boolean.toString(startupCheckbox.isSelected()));
648 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
649 sortby.getSelectedItem().toString());
651 // convert description of sort order to enum name for save
652 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
653 .forDescription(sortAnnBy.getSelectedItem().toString());
654 if (annSortOrder != null)
656 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
657 annSortOrder.name());
660 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
661 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
662 Boolean.valueOf(showAutocalcFirst).toString());
665 * Save Colours settings
667 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
668 protColour.getSelectedItem().toString());
669 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
670 nucColour.getSelectedItem().toString());
671 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
672 minColour.getBackground());
673 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
674 maxColour.getBackground());
677 * Save Overview settings
679 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
680 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
681 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
682 Boolean.toString(useLegacyGap.isSelected()));
683 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
684 Boolean.toString(showHiddenAtStart.isSelected()));
687 * Save Structure settings
689 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
690 Boolean.toString(addTempFactor.isSelected()));
691 Cache.applicationProperties.setProperty(ADD_SS_ANN,
692 Boolean.toString(addSecondaryStructure.isSelected()));
693 Cache.applicationProperties.setProperty(USE_RNAVIEW,
694 Boolean.toString(useRnaView.isSelected()));
695 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
696 Boolean.toString(structFromPdb.isSelected()));
697 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
698 structViewer.getSelectedItem().toString());
699 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
700 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
701 Boolean.toString(siftsMapping.isSelected()));
702 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
705 * Save Output settings
707 Cache.applicationProperties.setProperty("EPS_RENDERING",
708 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
709 Cache.applicationProperties.setProperty("HTML_RENDERING",
710 ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
711 Cache.applicationProperties.setProperty("SVG_RENDERING",
712 ((OptionsParam) svgRendering.getSelectedItem()).getCode());
715 * Save Connections settings
717 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
719 jalview.util.BrowserLauncher.resetBrowser();
721 // save user-defined and selected links
722 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
723 if (menuLinks.isEmpty())
725 Cache.applicationProperties.remove("SEQUENCE_LINKS");
729 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
730 menuLinks.toString());
733 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
734 if (nonMenuLinks.isEmpty())
736 Cache.applicationProperties.remove("STORED_LINKS");
740 Cache.applicationProperties.setProperty("STORED_LINKS",
741 nonMenuLinks.toString());
744 Cache.applicationProperties.setProperty("DEFAULT_URL",
745 sequenceUrlLinks.getPrimaryUrlId());
747 Cache.applicationProperties.setProperty("USE_PROXY",
748 Boolean.toString(useProxy.isSelected()));
750 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
752 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
754 if (useProxy.isSelected())
756 System.setProperty("http.proxyHost", proxyServerTB.getText());
757 System.setProperty("http.proxyPort", proxyPortTB.getText());
761 System.setProperty("http.proxyHost", "");
762 System.setProperty("http.proxyPort", "");
764 Cache.setProperty("VERSION_CHECK",
765 Boolean.toString(versioncheck.isSelected()));
766 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
768 // default is false - we only set this if the user has actively agreed
769 Cache.setProperty("USAGESTATS",
770 Boolean.toString(usagestats.isSelected()));
772 if (!questionnaire.isSelected())
774 Cache.setProperty("NOQUESTIONNAIRES", "true");
778 // special - made easy to edit a property file to disable questionnaires
779 // by just adding the given line
780 Cache.removeProperty("NOQUESTIONNAIRES");
784 * Save Output settings
786 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
787 Boolean.toString(blcjv.isSelected()));
788 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
789 Boolean.toString(clustaljv.isSelected()));
790 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
791 Boolean.toString(fastajv.isSelected()));
792 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
793 Boolean.toString(msfjv.isSelected()));
794 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
795 Boolean.toString(pfamjv.isSelected()));
796 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
797 Boolean.toString(pileupjv.isSelected()));
798 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
799 Boolean.toString(pirjv.isSelected()));
800 Cache.applicationProperties.setProperty("PIR_MODELLER",
801 Boolean.toString(modellerOutput.isSelected()));
802 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
803 Boolean.toString(embbedBioJSON.isSelected()));
804 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
806 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
807 Boolean.toString(autoIdWidth.isSelected()));
808 userIdWidth_actionPerformed();
809 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
810 userIdWidth.getText());
813 * Save Editing settings
815 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
816 Boolean.toString(autoCalculateConsCheck.isSelected()));
817 Cache.applicationProperties.setProperty("SORT_BY_TREE",
818 Boolean.toString(sortByTree.isSelected()));
819 Cache.applicationProperties.setProperty("PAD_GAPS",
820 Boolean.toString(padGaps.isSelected()));
822 if (!Platform.isJS())
824 wsPrefs.updateAndRefreshWsMenuConfig(false);
826 Cache.saveProperties();
827 Desktop.instance.doConfigureStructurePrefs();
830 frame.setClosed(true);
831 } catch (Exception ex)
837 * Do any necessary validation before saving settings. Return focus to the
838 * first tab which fails validation.
842 private boolean validateSettings()
844 if (!validateStructure())
846 structureTab.requestFocusInWindow();
853 protected boolean validateStructure()
855 return validateChimeraPath();
863 public void startupFileTextfield_mouseClicked()
865 // TODO: JAL-3048 not needed for Jalview-JS
866 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
867 JalviewFileChooser chooser = JalviewFileChooser
868 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
869 chooser.setFileView(new JalviewFileView());
870 chooser.setDialogTitle(
871 MessageManager.getString("label.select_startup_file"));
873 int value = chooser.showOpenDialog(this);
875 if (value == JalviewFileChooser.APPROVE_OPTION)
877 FileFormatI format = chooser.getSelectedFormat();
880 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
884 .setText(chooser.getSelectedFile().getAbsolutePath());
895 public void cancel_actionPerformed(ActionEvent e)
899 if (!Platform.isJS())
901 wsPrefs.updateWsMenuConfig(true);
902 wsPrefs.refreshWs_actionPerformed(e);
904 frame.setClosed(true);
905 } catch (Exception ex)
917 public void annotations_actionPerformed(ActionEvent e)
919 conservation.setEnabled(annotations.isSelected());
920 quality.setEnabled(annotations.isSelected());
921 identity.setEnabled(annotations.isSelected());
922 showOccupancy.setEnabled(annotations.isSelected());
923 showGroupConsensus.setEnabled(annotations.isSelected());
924 showGroupConservation.setEnabled(annotations.isSelected());
925 showConsensHistogram.setEnabled(annotations.isSelected()
926 && (identity.isSelected() || showGroupConsensus.isSelected()));
927 showConsensLogo.setEnabled(annotations.isSelected()
928 && (identity.isSelected() || showGroupConsensus.isSelected()));
932 public void newLink_actionPerformed(ActionEvent e)
934 GSequenceLink link = new GSequenceLink();
935 boolean valid = false;
938 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
939 MessageManager.getString("label.new_sequence_url_link"),
940 JvOptionPane.OK_CANCEL_OPTION, -1,
941 null) == JvOptionPane.OK_OPTION)
943 if (link.checkValid())
945 if (((UrlLinkTableModel) linkUrlTable.getModel())
946 .isUniqueName(link.getName()))
948 ((UrlLinkTableModel) linkUrlTable.getModel())
949 .insertRow(link.getName(), link.getURL());
954 link.notifyDuplicate();
967 public void editLink_actionPerformed(ActionEvent e)
969 GSequenceLink link = new GSequenceLink();
971 int index = linkUrlTable.getSelectedRow();
974 // button no longer enabled if row is not selected
975 Cache.log.debug("Edit with no row selected in linkUrlTable");
979 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
981 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
983 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
984 link.setName(oldName);
985 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
987 boolean valid = false;
990 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
991 MessageManager.getString("label.edit_sequence_url_link"),
992 JvOptionPane.OK_CANCEL_OPTION, -1,
993 null) == JvOptionPane.OK_OPTION)
995 if (link.checkValid())
997 if ((oldName.equals(link.getName()))
998 || (((UrlLinkTableModel) linkUrlTable.getModel())
999 .isUniqueName(link.getName())))
1001 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1002 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1007 link.notifyDuplicate();
1020 public void deleteLink_actionPerformed(ActionEvent e)
1022 int index = linkUrlTable.getSelectedRow();
1023 int modelIndex = -1;
1026 // button no longer enabled if row is not selected
1027 Cache.log.debug("Delete with no row selected in linkUrlTable");
1032 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1035 // make sure we use the model index to delete, and not the table index
1036 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1040 public void defaultBrowser_mouseClicked(MouseEvent e)
1042 // TODO: JAL-3048 not needed for j2s
1047 JFileChooser chooser = new JFileChooser(".");
1048 chooser.setDialogTitle(
1049 MessageManager.getString("label.select_default_browser"));
1051 int value = chooser.showOpenDialog(this);
1053 if (value == JFileChooser.APPROVE_OPTION)
1055 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1064 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1068 protected void showunconserved_actionPerformed(ActionEvent e)
1070 // TODO Auto-generated method stub
1071 super.showunconserved_actionPerformed(e);
1074 public static List<String> getGroupURLLinks()
1076 return groupURLLinks;
1080 public void minColour_actionPerformed(JPanel panel)
1082 JalviewColourChooser.showColourChooser(this,
1083 MessageManager.getString("label.select_colour_minimum_value"),
1088 public void maxColour_actionPerformed(JPanel panel)
1090 JalviewColourChooser.showColourChooser(this,
1091 MessageManager.getString("label.select_colour_maximum_value"),
1096 public void gapColour_actionPerformed(JPanel gap)
1098 if (!useLegacyGap.isSelected())
1100 JalviewColourChooser.showColourChooser(this,
1101 MessageManager.getString("label.select_gap_colour"),
1107 public void hiddenColour_actionPerformed(JPanel hidden)
1109 JalviewColourChooser.showColourChooser(this,
1110 MessageManager.getString("label.select_hidden_colour"),
1115 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1117 boolean enabled = useLegacyGap.isSelected();
1120 gapColour.setBackground(
1121 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1125 gapColour.setBackground(
1126 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1128 gapColour.setEnabled(!enabled);
1129 gapLabel.setEnabled(!enabled);
1133 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1135 useLegacyGap.setSelected(false);
1136 useLegacyGaps_actionPerformed(null);
1137 showHiddenAtStart.setSelected(true);
1138 hiddenColour.setBackground(
1139 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1143 protected void userIdWidth_actionPerformed()
1147 String val = userIdWidth.getText().trim();
1148 if (val.length() > 0)
1150 Integer iw = Integer.parseInt(val);
1151 if (iw.intValue() < 12)
1153 throw new NumberFormatException();
1155 userIdWidth.setText(iw.toString());
1157 } catch (NumberFormatException x)
1159 userIdWidth.setText("");
1160 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1162 .getString("warn.user_defined_width_requirements"),
1163 MessageManager.getString("label.invalid_id_column_width"),
1164 JvOptionPane.WARNING_MESSAGE);
1169 protected void autoIdWidth_actionPerformed()
1171 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1172 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1176 * Returns true if chimera path is to a valid executable, else show an error
1179 private boolean validateChimeraPath()
1181 if (chimeraPath.getText().trim().length() > 0)
1183 File f = new File(chimeraPath.getText());
1184 if (!f.canExecute())
1186 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1187 MessageManager.getString("label.invalid_chimera_path"),
1188 MessageManager.getString("label.invalid_name"),
1189 JvOptionPane.ERROR_MESSAGE);
1197 * If Chimera is selected, check it can be found on default or user-specified
1198 * path, if not show a warning/help dialog.
1201 protected void structureViewer_actionPerformed(String selectedItem)
1203 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1207 boolean found = false;
1210 * Try user-specified and standard paths for Chimera executable.
1212 List<String> paths = StructureManager.getChimeraPaths();
1213 paths.add(0, chimeraPath.getText());
1214 for (String path : paths)
1216 if (new File(path.trim()).canExecute())
1224 String[] options = { "OK", "Help" };
1225 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1226 JvSwingUtils.wrapTooltip(true,
1227 MessageManager.getString("label.chimera_missing")),
1228 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1229 null, options, options[0]);
1230 if (showHelp == JvOptionPane.NO_OPTION)
1234 Help.showHelpWindow(HelpId.StructureViewer);
1235 } catch (HelpSetException e)
1237 e.printStackTrace();
1243 public class OptionsParam
1245 private String name;
1247 private String code;
1249 public OptionsParam(String name, String code)
1255 public String getName()
1260 public void setName(String name)
1265 public String getCode()
1270 public void setCode(String code)
1276 public String toString()
1282 public boolean equals(Object that)
1284 if (!(that instanceof OptionsParam))
1288 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1292 public int hashCode()
1294 return name.hashCode() + code.hashCode();
1298 private class UrlListSelectionHandler implements ListSelectionListener
1302 public void valueChanged(ListSelectionEvent e)
1304 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1306 int index = lsm.getMinSelectionIndex();
1309 // no selection, so disable delete/edit buttons
1310 editLink.setEnabled(false);
1311 deleteLink.setEnabled(false);
1314 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1316 // enable/disable edit and delete link buttons
1317 if (((UrlLinkTableModel) linkUrlTable.getModel())
1318 .isRowDeletable(modelIndex))
1320 deleteLink.setEnabled(true);
1324 deleteLink.setEnabled(false);
1327 if (((UrlLinkTableModel) linkUrlTable.getModel())
1328 .isRowEditable(modelIndex))
1330 editLink.setEnabled(true);
1334 editLink.setEnabled(false);