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.bin.Jalview;
26 import jalview.gui.Help.HelpId;
27 import jalview.gui.StructureViewer.ViewerType;
28 import jalview.io.FileFormatI;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.jbgui.GPreferences;
32 import jalview.jbgui.GSequenceLink;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ColourSchemes;
35 import jalview.schemes.ResidueColourScheme;
36 import jalview.urls.UrlLinkTableModel;
37 import jalview.urls.api.UrlProviderFactoryI;
38 import jalview.urls.api.UrlProviderI;
39 import jalview.urls.desktop.DesktopUrlProviderFactory;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.util.UrlConstants;
43 import jalview.ws.sifts.SiftsSettings;
45 import java.awt.BorderLayout;
46 import java.awt.Color;
47 import java.awt.Component;
48 import java.awt.Dimension;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.MouseEvent;
54 import java.util.ArrayList;
55 import java.util.List;
57 import javax.help.HelpSetException;
58 import javax.swing.JComboBox;
59 import javax.swing.JFileChooser;
60 import javax.swing.JInternalFrame;
61 import javax.swing.JPanel;
62 import javax.swing.ListSelectionModel;
63 import javax.swing.RowFilter;
64 import javax.swing.RowSorter;
65 import javax.swing.SortOrder;
66 import javax.swing.event.DocumentEvent;
67 import javax.swing.event.DocumentListener;
68 import javax.swing.event.ListSelectionEvent;
69 import javax.swing.event.ListSelectionListener;
70 import javax.swing.table.TableCellRenderer;
71 import javax.swing.table.TableColumn;
72 import javax.swing.table.TableModel;
73 import javax.swing.table.TableRowSorter;
75 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
83 public class Preferences extends GPreferences
85 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
87 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
89 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
91 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
93 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
95 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
97 public static final String ADD_SS_ANN = "ADD_SS_ANN";
99 public static final String USE_RNAVIEW = "USE_RNAVIEW";
101 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
103 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
105 public static final String CHIMERA_PATH = "CHIMERA_PATH";
107 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
109 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
111 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
113 public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
115 public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
117 public static final String GAP_COLOUR = "GAP_COLOUR";
119 public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
121 private static final int MIN_FONT_SIZE = 1;
123 private static final int MAX_FONT_SIZE = 30;
126 * Holds name and link separated with | character. Sequence ID must be
127 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
129 public static UrlProviderI sequenceUrlLinks;
131 public static UrlLinkTableModel dataModel;
134 * Holds name and link separated with | character. Sequence IDS and Sequences
135 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
136 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
137 * for first and second token specified after a pipe character at end |,|.
138 * (TODO: proper escape for using | to separate ids or sequences
141 public static List<String> groupURLLinks;
144 // get links selected to be in the menu (SEQUENCE_LINKS)
145 // and links entered by the user but not selected (STORED_LINKS)
146 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
147 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
148 String defaultUrl = Cache.getDefault("DEFAULT_URL",
149 UrlConstants.DEFAULT_LABEL);
151 // if both links lists are empty, add the DEFAULT_URL link
152 // otherwise we assume the default link is in one of the lists
153 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
155 inMenuString = UrlConstants.DEFAULT_STRING;
157 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
158 inMenuString, notInMenuString);
159 sequenceUrlLinks = factory.createUrlProvider();
160 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
163 * TODO: reformulate groupURL encoding so two or more can be stored in the
164 * .properties file as '|' separated strings
167 groupURLLinks = new ArrayList<>();
170 JInternalFrame frame;
172 private WsPreferences wsPrefs;
174 private OptionsParam promptEachTimeOpt = new OptionsParam(
175 MessageManager.getString("label.prompt_each_time"),
178 private OptionsParam lineArtOpt = new OptionsParam(
179 MessageManager.getString("label.lineart"), "Lineart");
181 private OptionsParam textOpt = new OptionsParam(
182 MessageManager.getString("action.text"), "Text");
185 * Creates a new Preferences object.
190 frame = new JInternalFrame();
191 frame.setContentPane(this);
194 wsPrefs = new WsPreferences();
195 wsTab.add(wsPrefs, BorderLayout.CENTER);
197 int width = 500, height = 450;
198 if (Platform.isAMacAndNotJS())
204 Desktop.addInternalFrame(frame,
205 MessageManager.getString("label.preferences"), width, height);
206 frame.setMinimumSize(new Dimension(width, height));
209 * Set Visual tab defaults
211 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
212 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
213 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
214 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
216 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
217 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
218 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
219 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
221 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
222 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
224 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
225 showGroupConservation.setSelected(
226 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
227 showConsensHistogram.setSelected(
228 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
230 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
232 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
234 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
236 String[] fonts = java.awt.GraphicsEnvironment
237 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
238 for (int i = 0; i < fonts.length; i++)
240 fontNameCB.addItem(fonts[i]);
243 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
245 fontSizeCB.addItem(i + "");
248 fontStyleCB.addItem("plain");
249 fontStyleCB.addItem("bold");
250 fontStyleCB.addItem("italic");
252 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
253 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
254 fontStyleCB.setSelectedItem(
255 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
257 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
259 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
261 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
263 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
265 gapSymbolCB.addItem("-");
266 gapSymbolCB.addItem(".");
268 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
270 sortby.addItem("No sort");
271 sortby.addItem("Id");
272 sortby.addItem("Pairwise Identity");
273 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
275 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
277 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
279 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
280 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
281 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
282 SequenceAnnotationOrder.NONE.name()));
283 sortAnnBy.setSelectedItem(savedSort.toString());
285 sortAutocalc.addItem("Autocalculated first");
286 sortAutocalc.addItem("Autocalculated last");
287 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
288 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
289 : sortAutocalc.getItemAt(1));
291 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
292 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
293 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
294 + "/examples/exampleFile_2_3.jar"));
297 * Set Colours tab defaults
299 protColour.addItem(ResidueColourScheme.NONE);
300 nucColour.addItem(ResidueColourScheme.NONE);
301 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
303 String name = cs.getSchemeName();
304 protColour.addItem(name);
305 nucColour.addItem(name);
307 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
308 ResidueColourScheme.NONE);
309 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
310 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
311 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
312 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
313 minColour.setBackground(
314 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
315 maxColour.setBackground(
316 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
319 * Set overview panel defaults
321 gapColour.setBackground(
322 Cache.getDefaultColour(GAP_COLOUR,
323 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
324 hiddenColour.setBackground(
325 Cache.getDefaultColour(HIDDEN_COLOUR,
326 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
327 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
328 gapLabel.setEnabled(!useLegacyGap.isSelected());
329 gapColour.setEnabled(!useLegacyGap.isSelected());
331 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
334 * Set Structure tab defaults.
336 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
337 structFromPdb.setSelected(structSelected);
338 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
339 useRnaView.setEnabled(structSelected);
340 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
341 addSecondaryStructure.setEnabled(structSelected);
342 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
343 addTempFactor.setEnabled(structSelected);
344 structViewer.setSelectedItem(
345 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
346 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
347 chimeraPath.addActionListener(new ActionListener()
350 public void actionPerformed(ActionEvent e)
352 validateChimeraPath();
356 if (Cache.getDefault("MAP_WITH_SIFTS", false))
358 siftsMapping.setSelected(true);
362 nwMapping.setSelected(true);
366 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
369 * Set Connections tab defaults
373 linkUrlTable.setModel(dataModel);
374 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
375 linkUrlTable.getModel());
376 linkUrlTable.setRowSorter(sorter);
377 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
379 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
380 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
381 SortOrder.DESCENDING));
382 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
383 SortOrder.DESCENDING));
385 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
387 sorter.setSortKeys(sortKeys);
388 // BH 2018 setSortKeys will do the sort
392 ActionListener onReset;
393 onReset = new ActionListener()
396 public void actionPerformed(ActionEvent e)
398 filterTB.setText("");
399 sorter.setRowFilter(RowFilter.regexFilter(""));
403 doReset.addActionListener(onReset);
405 // filter to display only custom urls
406 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
409 public boolean include(
410 Entry<? extends TableModel, ? extends Object> entry)
412 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
416 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
417 linkUrlTable.getModel());
418 customSorter.setRowFilter(customUrlFilter);
420 ActionListener onCustomOnly;
421 onCustomOnly = new ActionListener()
424 public void actionPerformed(ActionEvent e)
426 filterTB.setText("");
427 sorter.setRowFilter(customUrlFilter);
430 userOnly.addActionListener(onCustomOnly);
432 filterTB.getDocument().addDocumentListener(new DocumentListener()
434 String caseInsensitiveFlag = "(?i)";
437 public void changedUpdate(DocumentEvent e)
439 sorter.setRowFilter(RowFilter
440 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
444 public void removeUpdate(DocumentEvent e)
446 sorter.setRowFilter(RowFilter
447 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
451 public void insertUpdate(DocumentEvent e)
453 sorter.setRowFilter(RowFilter
454 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
458 // set up list selection functionality
459 linkUrlTable.getSelectionModel()
460 .addListSelectionListener(new UrlListSelectionHandler());
462 // set up radio buttons
463 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
465 String onClickName = linkUrlTable.getColumnName(onClickCol);
466 linkUrlTable.getColumn(onClickName)
467 .setCellRenderer(new RadioButtonRenderer());
468 linkUrlTable.getColumn(onClickName)
469 .setCellEditor(new RadioButtonEditor());
471 // get boolean columns and resize those to min possible
472 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
474 if (linkUrlTable.getModel().getColumnClass(column)
475 .equals(Boolean.class))
477 TableColumn tableColumn = linkUrlTable.getColumnModel()
479 int preferredWidth = tableColumn.getMinWidth();
481 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
483 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
484 int cwidth = c.getPreferredSize().width
485 + linkUrlTable.getIntercellSpacing().width;
486 preferredWidth = Math.max(preferredWidth, cwidth);
488 tableColumn.setPreferredWidth(preferredWidth);
492 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
493 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
494 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
495 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
497 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
499 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
500 // note antisense here: default is true
502 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
503 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
506 * Set Output tab defaults
508 setupOutputCombo(epsRendering, "EPS_RENDERING");
509 setupOutputCombo(htmlRendering, "HTML_RENDERING");
510 setupOutputCombo(svgRendering, "SVG_RENDERING");
511 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
512 userIdWidth.setEnabled(!autoIdWidth.isSelected());
513 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
514 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
515 userIdWidth.setText(wi == null ? "" : wi.toString());
516 // TODO: refactor to use common enum via FormatAdapter and allow extension
517 // for new flat file formats
518 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
519 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
520 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
521 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
522 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
523 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
524 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
525 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
527 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
530 * Set Editing tab defaults
532 autoCalculateConsCheck
533 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
534 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
535 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
537 annotations_actionPerformed(null); // update the display of the annotation
542 * A helper method that sets the items and initial selection in a character
543 * rendering option list (Prompt each time/Lineart/Text)
548 protected void setupOutputCombo(JComboBox<Object> comboBox,
551 comboBox.addItem(promptEachTimeOpt);
552 comboBox.addItem(lineArtOpt);
553 comboBox.addItem(textOpt);
556 * JalviewJS doesn't support Lineart so force it to Text
558 String defaultOption = Jalview.isJS() ? "Text"
559 : Cache.getDefault(propertyKey, "Prompt each time");
560 if (defaultOption.equalsIgnoreCase("Text"))
562 comboBox.setSelectedItem(textOpt);
564 else if (defaultOption.equalsIgnoreCase("Lineart"))
566 comboBox.setSelectedItem(lineArtOpt);
570 comboBox.setSelectedItem(promptEachTimeOpt);
575 * Save user selections on the Preferences tabs to the Cache and write out to
581 public void ok_actionPerformed(ActionEvent e)
583 if (!validateSettings())
589 * Save Visual settings
591 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
592 Boolean.toString(seqLimit.isSelected()));
593 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
594 Boolean.toString(rightAlign.isSelected()));
595 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
596 Boolean.toString(fullScreen.isSelected()));
597 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
598 Boolean.toString(openoverv.isSelected()));
599 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
600 Boolean.toString(annotations.isSelected()));
601 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
602 Boolean.toString(conservation.isSelected()));
603 Cache.applicationProperties.setProperty("SHOW_QUALITY",
604 Boolean.toString(quality.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
606 Boolean.toString(identity.isSelected()));
608 Cache.applicationProperties.setProperty("GAP_SYMBOL",
609 gapSymbolCB.getSelectedItem().toString());
611 Cache.applicationProperties.setProperty("FONT_NAME",
612 fontNameCB.getSelectedItem().toString());
613 Cache.applicationProperties.setProperty("FONT_STYLE",
614 fontStyleCB.getSelectedItem().toString());
615 Cache.applicationProperties.setProperty("FONT_SIZE",
616 fontSizeCB.getSelectedItem().toString());
618 Cache.applicationProperties.setProperty("ID_ITALICS",
619 Boolean.toString(idItalics.isSelected()));
620 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
621 Boolean.toString(showUnconserved.isSelected()));
622 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
623 Boolean.toString(showOccupancy.isSelected()));
624 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
625 Boolean.toString(showGroupConsensus.isSelected()));
626 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
627 Boolean.toString(showGroupConservation.isSelected()));
628 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
629 Boolean.toString(showConsensHistogram.isSelected()));
630 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
631 Boolean.toString(showConsensLogo.isSelected()));
632 Cache.applicationProperties.setProperty("ANTI_ALIAS",
633 Boolean.toString(smoothFont.isSelected()));
634 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
635 Boolean.toString(scaleProteinToCdna.isSelected()));
636 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
637 Boolean.toString(showNpTooltip.isSelected()));
638 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
639 Boolean.toString(showDbRefTooltip.isSelected()));
641 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
642 Boolean.toString(wrap.isSelected()));
644 Cache.applicationProperties.setProperty("STARTUP_FILE",
645 startupFileTextfield.getText());
646 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
647 Boolean.toString(startupCheckbox.isSelected()));
649 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
650 sortby.getSelectedItem().toString());
652 // convert description of sort order to enum name for save
653 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
654 .forDescription(sortAnnBy.getSelectedItem().toString());
655 if (annSortOrder != null)
657 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
658 annSortOrder.name());
661 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
662 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
663 Boolean.valueOf(showAutocalcFirst).toString());
666 * Save Colours settings
668 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
669 protColour.getSelectedItem().toString());
670 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
671 nucColour.getSelectedItem().toString());
672 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
673 minColour.getBackground());
674 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
675 maxColour.getBackground());
678 * Save Overview settings
680 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
681 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
682 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
683 Boolean.toString(useLegacyGap.isSelected()));
684 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
685 Boolean.toString(showHiddenAtStart.isSelected()));
688 * Save Structure settings
690 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
691 Boolean.toString(addTempFactor.isSelected()));
692 Cache.applicationProperties.setProperty(ADD_SS_ANN,
693 Boolean.toString(addSecondaryStructure.isSelected()));
694 Cache.applicationProperties.setProperty(USE_RNAVIEW,
695 Boolean.toString(useRnaView.isSelected()));
696 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
697 Boolean.toString(structFromPdb.isSelected()));
698 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
699 structViewer.getSelectedItem().toString());
700 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
701 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
702 Boolean.toString(siftsMapping.isSelected()));
703 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
706 * Save Output settings
708 Cache.applicationProperties.setProperty("EPS_RENDERING",
709 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
710 Cache.applicationProperties.setProperty("HTML_RENDERING",
711 ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
712 Cache.applicationProperties.setProperty("SVG_RENDERING",
713 ((OptionsParam) svgRendering.getSelectedItem()).getCode());
716 * Save Connections settings
718 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
720 jalview.util.BrowserLauncher.resetBrowser();
722 // save user-defined and selected links
723 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
724 if (menuLinks.isEmpty())
726 Cache.applicationProperties.remove("SEQUENCE_LINKS");
730 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
731 menuLinks.toString());
734 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
735 if (nonMenuLinks.isEmpty())
737 Cache.applicationProperties.remove("STORED_LINKS");
741 Cache.applicationProperties.setProperty("STORED_LINKS",
742 nonMenuLinks.toString());
745 Cache.applicationProperties.setProperty("DEFAULT_URL",
746 sequenceUrlLinks.getPrimaryUrlId());
748 Cache.applicationProperties.setProperty("USE_PROXY",
749 Boolean.toString(useProxy.isSelected()));
751 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
753 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
755 if (useProxy.isSelected())
757 System.setProperty("http.proxyHost", proxyServerTB.getText());
758 System.setProperty("http.proxyPort", proxyPortTB.getText());
762 System.setProperty("http.proxyHost", "");
763 System.setProperty("http.proxyPort", "");
765 Cache.setProperty("VERSION_CHECK",
766 Boolean.toString(versioncheck.isSelected()));
767 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
769 // default is false - we only set this if the user has actively agreed
770 Cache.setProperty("USAGESTATS",
771 Boolean.toString(usagestats.isSelected()));
773 if (!questionnaire.isSelected())
775 Cache.setProperty("NOQUESTIONNAIRES", "true");
779 // special - made easy to edit a property file to disable questionnaires
780 // by just adding the given line
781 Cache.removeProperty("NOQUESTIONNAIRES");
785 * Save Output settings
787 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
788 Boolean.toString(blcjv.isSelected()));
789 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
790 Boolean.toString(clustaljv.isSelected()));
791 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
792 Boolean.toString(fastajv.isSelected()));
793 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
794 Boolean.toString(msfjv.isSelected()));
795 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
796 Boolean.toString(pfamjv.isSelected()));
797 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
798 Boolean.toString(pileupjv.isSelected()));
799 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
800 Boolean.toString(pirjv.isSelected()));
801 Cache.applicationProperties.setProperty("PIR_MODELLER",
802 Boolean.toString(modellerOutput.isSelected()));
803 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
804 Boolean.toString(embbedBioJSON.isSelected()));
805 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
807 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
808 Boolean.toString(autoIdWidth.isSelected()));
809 userIdWidth_actionPerformed();
810 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
811 userIdWidth.getText());
814 * Save Editing settings
816 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
817 Boolean.toString(autoCalculateConsCheck.isSelected()));
818 Cache.applicationProperties.setProperty("SORT_BY_TREE",
819 Boolean.toString(sortByTree.isSelected()));
820 Cache.applicationProperties.setProperty("PAD_GAPS",
821 Boolean.toString(padGaps.isSelected()));
825 wsPrefs.updateAndRefreshWsMenuConfig(false);
827 Cache.saveProperties();
828 Desktop.instance.doConfigureStructurePrefs();
831 frame.setClosed(true);
832 } catch (Exception ex)
838 * Do any necessary validation before saving settings. Return focus to the
839 * first tab which fails validation.
843 private boolean validateSettings()
845 if (!validateStructure())
847 structureTab.requestFocusInWindow();
854 protected boolean validateStructure()
856 return validateChimeraPath();
864 public void startupFileTextfield_mouseClicked()
866 // TODO: JAL-3048 not needed for Jalview-JS
867 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
868 JalviewFileChooser chooser = JalviewFileChooser
869 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
870 chooser.setFileView(new JalviewFileView());
871 chooser.setDialogTitle(
872 MessageManager.getString("label.select_startup_file"));
874 int value = chooser.showOpenDialog(this);
876 if (value == JalviewFileChooser.APPROVE_OPTION)
878 FileFormatI format = chooser.getSelectedFormat();
881 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
885 .setText(chooser.getSelectedFile().getAbsolutePath());
896 public void cancel_actionPerformed(ActionEvent e)
902 wsPrefs.updateWsMenuConfig(true);
903 wsPrefs.refreshWs_actionPerformed(e);
905 frame.setClosed(true);
906 } catch (Exception ex)
918 public void annotations_actionPerformed(ActionEvent e)
920 conservation.setEnabled(annotations.isSelected());
921 quality.setEnabled(annotations.isSelected());
922 identity.setEnabled(annotations.isSelected());
923 showOccupancy.setEnabled(annotations.isSelected());
924 showGroupConsensus.setEnabled(annotations.isSelected());
925 showGroupConservation.setEnabled(annotations.isSelected());
926 showConsensHistogram.setEnabled(annotations.isSelected()
927 && (identity.isSelected() || showGroupConsensus.isSelected()));
928 showConsensLogo.setEnabled(annotations.isSelected()
929 && (identity.isSelected() || showGroupConsensus.isSelected()));
933 public void newLink_actionPerformed(ActionEvent e)
935 GSequenceLink link = new GSequenceLink();
936 boolean valid = false;
939 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
940 MessageManager.getString("label.new_sequence_url_link"),
941 JvOptionPane.OK_CANCEL_OPTION, -1,
942 null) == JvOptionPane.OK_OPTION)
944 if (link.checkValid())
946 if (((UrlLinkTableModel) linkUrlTable.getModel())
947 .isUniqueName(link.getName()))
949 ((UrlLinkTableModel) linkUrlTable.getModel())
950 .insertRow(link.getName(), link.getURL());
955 link.notifyDuplicate();
968 public void editLink_actionPerformed(ActionEvent e)
970 GSequenceLink link = new GSequenceLink();
972 int index = linkUrlTable.getSelectedRow();
975 // button no longer enabled if row is not selected
976 Cache.log.debug("Edit with no row selected in linkUrlTable");
980 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
982 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
984 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
985 link.setName(oldName);
986 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
988 boolean valid = false;
991 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
992 MessageManager.getString("label.edit_sequence_url_link"),
993 JvOptionPane.OK_CANCEL_OPTION, -1,
994 null) == JvOptionPane.OK_OPTION)
996 if (link.checkValid())
998 if ((oldName.equals(link.getName()))
999 || (((UrlLinkTableModel) linkUrlTable.getModel())
1000 .isUniqueName(link.getName())))
1002 linkUrlTable.setValueAt(link.getName(), index, nameCol);
1003 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1008 link.notifyDuplicate();
1021 public void deleteLink_actionPerformed(ActionEvent e)
1023 int index = linkUrlTable.getSelectedRow();
1024 int modelIndex = -1;
1027 // button no longer enabled if row is not selected
1028 Cache.log.debug("Delete with no row selected in linkUrlTable");
1033 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1036 // make sure we use the model index to delete, and not the table index
1037 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1041 public void defaultBrowser_mouseClicked(MouseEvent e)
1043 // TODO: JAL-3048 not needed for j2s
1048 JFileChooser chooser = new JFileChooser(".");
1049 chooser.setDialogTitle(
1050 MessageManager.getString("label.select_default_browser"));
1052 int value = chooser.showOpenDialog(this);
1054 if (value == JFileChooser.APPROVE_OPTION)
1056 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1065 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1069 protected void showunconserved_actionPerformed(ActionEvent e)
1071 // TODO Auto-generated method stub
1072 super.showunconserved_actionPerformed(e);
1075 public static List<String> getGroupURLLinks()
1077 return groupURLLinks;
1081 public void minColour_actionPerformed(JPanel panel)
1083 JalviewColourChooser.showColourChooser(this,
1084 MessageManager.getString("label.select_colour_minimum_value"),
1089 public void maxColour_actionPerformed(JPanel panel)
1091 JalviewColourChooser.showColourChooser(this,
1092 MessageManager.getString("label.select_colour_maximum_value"),
1097 public void gapColour_actionPerformed(JPanel gap)
1099 if (!useLegacyGap.isSelected())
1101 JalviewColourChooser.showColourChooser(this,
1102 MessageManager.getString("label.select_gap_colour"),
1108 public void hiddenColour_actionPerformed(JPanel hidden)
1110 JalviewColourChooser.showColourChooser(this,
1111 MessageManager.getString("label.select_hidden_colour"),
1116 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1118 boolean enabled = useLegacyGap.isSelected();
1121 gapColour.setBackground(
1122 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1126 gapColour.setBackground(
1127 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1129 gapColour.setEnabled(!enabled);
1130 gapLabel.setEnabled(!enabled);
1134 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1136 useLegacyGap.setSelected(false);
1137 useLegacyGaps_actionPerformed(null);
1138 showHiddenAtStart.setSelected(true);
1139 hiddenColour.setBackground(
1140 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1144 protected void userIdWidth_actionPerformed()
1148 String val = userIdWidth.getText().trim();
1149 if (val.length() > 0)
1151 Integer iw = Integer.parseInt(val);
1152 if (iw.intValue() < 12)
1154 throw new NumberFormatException();
1156 userIdWidth.setText(iw.toString());
1158 } catch (NumberFormatException x)
1160 userIdWidth.setText("");
1161 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1163 .getString("warn.user_defined_width_requirements"),
1164 MessageManager.getString("label.invalid_id_column_width"),
1165 JvOptionPane.WARNING_MESSAGE);
1170 protected void autoIdWidth_actionPerformed()
1172 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1173 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1177 * Returns true if chimera path is to a valid executable, else show an error
1180 private boolean validateChimeraPath()
1182 if (chimeraPath.getText().trim().length() > 0)
1184 File f = new File(chimeraPath.getText());
1185 if (!f.canExecute())
1187 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1188 MessageManager.getString("label.invalid_chimera_path"),
1189 MessageManager.getString("label.invalid_name"),
1190 JvOptionPane.ERROR_MESSAGE);
1198 * If Chimera is selected, check it can be found on default or user-specified
1199 * path, if not show a warning/help dialog.
1202 protected void structureViewer_actionPerformed(String selectedItem)
1204 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1208 boolean found = false;
1211 * Try user-specified and standard paths for Chimera executable.
1213 List<String> paths = StructureManager.getChimeraPaths();
1214 paths.add(0, chimeraPath.getText());
1215 for (String path : paths)
1217 if (new File(path.trim()).canExecute())
1225 String[] options = { "OK", "Help" };
1226 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1227 JvSwingUtils.wrapTooltip(true,
1228 MessageManager.getString("label.chimera_missing")),
1229 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1230 null, options, options[0]);
1231 if (showHelp == JvOptionPane.NO_OPTION)
1235 Help.showHelpWindow(HelpId.StructureViewer);
1236 } catch (HelpSetException e)
1238 e.printStackTrace();
1244 public class OptionsParam
1246 private String name;
1248 private String code;
1250 public OptionsParam(String name, String code)
1256 public String getName()
1261 public void setName(String name)
1266 public String getCode()
1271 public void setCode(String code)
1277 public String toString()
1283 public boolean equals(Object that)
1285 if (!(that instanceof OptionsParam))
1289 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1293 public int hashCode()
1295 return name.hashCode() + code.hashCode();
1299 private class UrlListSelectionHandler implements ListSelectionListener
1303 public void valueChanged(ListSelectionEvent e)
1305 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1307 int index = lsm.getMinSelectionIndex();
1310 // no selection, so disable delete/edit buttons
1311 editLink.setEnabled(false);
1312 deleteLink.setEnabled(false);
1315 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1317 // enable/disable edit and delete link buttons
1318 if (((UrlLinkTableModel) linkUrlTable.getModel())
1319 .isRowDeletable(modelIndex))
1321 deleteLink.setEnabled(true);
1325 deleteLink.setEnabled(false);
1328 if (((UrlLinkTableModel) linkUrlTable.getModel())
1329 .isRowEditable(modelIndex))
1331 editLink.setEnabled(true);
1335 editLink.setEnabled(false);