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.JColorChooser;
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 wsPrefs = new WsPreferences();
192 wsTab.add(wsPrefs, BorderLayout.CENTER);
193 int width = 500, height = 450;
194 new jalview.util.Platform();
195 if (Platform.isAMac())
201 Desktop.addInternalFrame(frame,
202 MessageManager.getString("label.preferences"), width, height);
203 frame.setMinimumSize(new Dimension(width, height));
206 * Set Visual tab defaults
208 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
209 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
210 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
211 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
213 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
214 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
215 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
216 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
218 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
219 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
221 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
222 showGroupConservation.setSelected(
223 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
224 showConsensHistogram.setSelected(
225 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
227 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
229 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
231 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
233 String[] fonts = java.awt.GraphicsEnvironment
234 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
235 for (int i = 0; i < fonts.length; i++)
237 fontNameCB.addItem(fonts[i]);
240 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
242 fontSizeCB.addItem(i + "");
245 fontStyleCB.addItem("plain");
246 fontStyleCB.addItem("bold");
247 fontStyleCB.addItem("italic");
249 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
250 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
251 fontStyleCB.setSelectedItem(
252 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
254 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
256 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
258 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
260 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
262 gapSymbolCB.addItem("-");
263 gapSymbolCB.addItem(".");
265 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
267 sortby.addItem("No sort");
268 sortby.addItem("Id");
269 sortby.addItem("Pairwise Identity");
270 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
272 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
274 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
276 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
277 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
278 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
279 SequenceAnnotationOrder.NONE.name()));
280 sortAnnBy.setSelectedItem(savedSort.toString());
282 sortAutocalc.addItem("Autocalculated first");
283 sortAutocalc.addItem("Autocalculated last");
284 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
285 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
286 : sortAutocalc.getItemAt(1));
288 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
289 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
290 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
291 + "/examples/exampleFile_2_3.jar"));
294 * Set Colours tab defaults
296 protColour.addItem(ResidueColourScheme.NONE);
297 nucColour.addItem(ResidueColourScheme.NONE);
298 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
300 String name = cs.getSchemeName();
301 protColour.addItem(name);
302 nucColour.addItem(name);
304 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
305 ResidueColourScheme.NONE);
306 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
307 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
308 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
309 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
310 minColour.setBackground(
311 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
312 maxColour.setBackground(
313 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
316 * Set overview panel defaults
318 gapColour.setBackground(
319 Cache.getDefaultColour(GAP_COLOUR,
320 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
321 hiddenColour.setBackground(
322 Cache.getDefaultColour(HIDDEN_COLOUR,
323 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
324 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
325 gapLabel.setEnabled(!useLegacyGap.isSelected());
326 gapColour.setEnabled(!useLegacyGap.isSelected());
328 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
331 * Set Structure tab defaults.
333 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
334 structFromPdb.setSelected(structSelected);
335 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
336 useRnaView.setEnabled(structSelected);
337 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
338 addSecondaryStructure.setEnabled(structSelected);
339 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
340 addTempFactor.setEnabled(structSelected);
341 structViewer.setSelectedItem(
342 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
343 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
344 chimeraPath.addActionListener(new ActionListener()
347 public void actionPerformed(ActionEvent e)
349 validateChimeraPath();
353 if (Cache.getDefault("MAP_WITH_SIFTS", false))
355 siftsMapping.setSelected(true);
359 nwMapping.setSelected(true);
363 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
366 * Set Connections tab defaults
370 linkUrlTable.setModel(dataModel);
371 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
372 linkUrlTable.getModel());
373 linkUrlTable.setRowSorter(sorter);
374 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
376 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
377 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
378 SortOrder.DESCENDING));
379 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
380 SortOrder.DESCENDING));
382 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
384 sorter.setSortKeys(sortKeys);
385 // BH 2018 setSortKeys will do the sort
389 ActionListener onReset;
390 onReset = new ActionListener()
393 public void actionPerformed(ActionEvent e)
395 filterTB.setText("");
396 sorter.setRowFilter(RowFilter.regexFilter(""));
400 doReset.addActionListener(onReset);
402 // filter to display only custom urls
403 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
406 public boolean include(
407 Entry<? extends TableModel, ? extends Object> entry)
409 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
413 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
414 linkUrlTable.getModel());
415 customSorter.setRowFilter(customUrlFilter);
417 ActionListener onCustomOnly;
418 onCustomOnly = new ActionListener()
421 public void actionPerformed(ActionEvent e)
423 filterTB.setText("");
424 sorter.setRowFilter(customUrlFilter);
427 userOnly.addActionListener(onCustomOnly);
429 filterTB.getDocument().addDocumentListener(new DocumentListener()
431 String caseInsensitiveFlag = "(?i)";
434 public void changedUpdate(DocumentEvent e)
436 sorter.setRowFilter(RowFilter
437 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
441 public void removeUpdate(DocumentEvent e)
443 sorter.setRowFilter(RowFilter
444 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
448 public void insertUpdate(DocumentEvent e)
450 sorter.setRowFilter(RowFilter
451 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
455 // set up list selection functionality
456 linkUrlTable.getSelectionModel()
457 .addListSelectionListener(new UrlListSelectionHandler());
459 // set up radio buttons
460 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
462 String onClickName = linkUrlTable.getColumnName(onClickCol);
463 linkUrlTable.getColumn(onClickName)
464 .setCellRenderer(new RadioButtonRenderer());
465 linkUrlTable.getColumn(onClickName)
466 .setCellEditor(new RadioButtonEditor());
468 // get boolean columns and resize those to min possible
469 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
471 if (linkUrlTable.getModel().getColumnClass(column)
472 .equals(Boolean.class))
474 TableColumn tableColumn = linkUrlTable.getColumnModel()
476 int preferredWidth = tableColumn.getMinWidth();
478 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
480 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
481 int cwidth = c.getPreferredSize().width
482 + linkUrlTable.getIntercellSpacing().width;
483 preferredWidth = Math.max(preferredWidth, cwidth);
485 tableColumn.setPreferredWidth(preferredWidth);
489 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
490 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
491 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
492 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
494 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
496 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
497 // note antisense here: default is true
499 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
500 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
503 * Set Output tab defaults
505 epsRendering.addItem(promptEachTimeOpt);
506 epsRendering.addItem(lineArtOpt);
507 epsRendering.addItem(textOpt);
508 String defaultEPS = Cache.getDefault("EPS_RENDERING",
510 if (defaultEPS.equalsIgnoreCase("Text"))
512 epsRendering.setSelectedItem(textOpt);
514 else if (defaultEPS.equalsIgnoreCase("Lineart"))
516 epsRendering.setSelectedItem(lineArtOpt);
520 epsRendering.setSelectedItem(promptEachTimeOpt);
522 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
523 userIdWidth.setEnabled(!autoIdWidth.isSelected());
524 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
525 Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
526 userIdWidth.setText(wi == null ? "" : wi.toString());
527 // TODO: refactor to use common enum via FormatAdapter and allow extension
528 // for new flat file formats
529 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
530 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
531 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
532 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
533 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
534 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
535 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
536 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
538 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
541 * Set Editing tab defaults
543 autoCalculateConsCheck
544 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
545 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
546 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
548 annotations_actionPerformed(null); // update the display of the annotation
553 * Save user selections on the Preferences tabs to the Cache and write out to
559 public void ok_actionPerformed(ActionEvent e)
561 if (!validateSettings())
567 * Save Visual settings
569 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
570 Boolean.toString(seqLimit.isSelected()));
571 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
572 Boolean.toString(rightAlign.isSelected()));
573 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
574 Boolean.toString(fullScreen.isSelected()));
575 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
576 Boolean.toString(openoverv.isSelected()));
577 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
578 Boolean.toString(annotations.isSelected()));
579 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
580 Boolean.toString(conservation.isSelected()));
581 Cache.applicationProperties.setProperty("SHOW_QUALITY",
582 Boolean.toString(quality.isSelected()));
583 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
584 Boolean.toString(identity.isSelected()));
586 Cache.applicationProperties.setProperty("GAP_SYMBOL",
587 gapSymbolCB.getSelectedItem().toString());
589 Cache.applicationProperties.setProperty("FONT_NAME",
590 fontNameCB.getSelectedItem().toString());
591 Cache.applicationProperties.setProperty("FONT_STYLE",
592 fontStyleCB.getSelectedItem().toString());
593 Cache.applicationProperties.setProperty("FONT_SIZE",
594 fontSizeCB.getSelectedItem().toString());
596 Cache.applicationProperties.setProperty("ID_ITALICS",
597 Boolean.toString(idItalics.isSelected()));
598 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
599 Boolean.toString(showUnconserved.isSelected()));
600 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
601 Boolean.toString(showOccupancy.isSelected()));
602 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
603 Boolean.toString(showGroupConsensus.isSelected()));
604 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
605 Boolean.toString(showGroupConservation.isSelected()));
606 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
607 Boolean.toString(showConsensHistogram.isSelected()));
608 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
609 Boolean.toString(showConsensLogo.isSelected()));
610 Cache.applicationProperties.setProperty("ANTI_ALIAS",
611 Boolean.toString(smoothFont.isSelected()));
612 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
613 Boolean.toString(scaleProteinToCdna.isSelected()));
614 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
615 Boolean.toString(showNpTooltip.isSelected()));
616 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
617 Boolean.toString(showDbRefTooltip.isSelected()));
619 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
620 Boolean.toString(wrap.isSelected()));
622 Cache.applicationProperties.setProperty("STARTUP_FILE",
623 startupFileTextfield.getText());
624 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
625 Boolean.toString(startupCheckbox.isSelected()));
627 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
628 sortby.getSelectedItem().toString());
630 // convert description of sort order to enum name for save
631 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
632 .forDescription(sortAnnBy.getSelectedItem().toString());
633 if (annSortOrder != null)
635 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
636 annSortOrder.name());
639 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
640 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
641 Boolean.valueOf(showAutocalcFirst).toString());
644 * Save Colours settings
646 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
647 protColour.getSelectedItem().toString());
648 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
649 nucColour.getSelectedItem().toString());
650 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
651 minColour.getBackground());
652 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
653 maxColour.getBackground());
656 * Save Overview settings
658 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
659 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
660 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
661 Boolean.toString(useLegacyGap.isSelected()));
662 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
663 Boolean.toString(showHiddenAtStart.isSelected()));
666 * Save Structure settings
668 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
669 Boolean.toString(addTempFactor.isSelected()));
670 Cache.applicationProperties.setProperty(ADD_SS_ANN,
671 Boolean.toString(addSecondaryStructure.isSelected()));
672 Cache.applicationProperties.setProperty(USE_RNAVIEW,
673 Boolean.toString(useRnaView.isSelected()));
674 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
675 Boolean.toString(structFromPdb.isSelected()));
676 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
677 structViewer.getSelectedItem().toString());
678 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
679 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
680 Boolean.toString(siftsMapping.isSelected()));
681 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
684 * Save Output settings
686 Cache.applicationProperties.setProperty("EPS_RENDERING",
687 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
690 * Save Connections settings
692 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
694 jalview.util.BrowserLauncher.resetBrowser();
696 // save user-defined and selected links
697 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
698 if (menuLinks.isEmpty())
700 Cache.applicationProperties.remove("SEQUENCE_LINKS");
704 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
705 menuLinks.toString());
708 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
709 if (nonMenuLinks.isEmpty())
711 Cache.applicationProperties.remove("STORED_LINKS");
715 Cache.applicationProperties.setProperty("STORED_LINKS",
716 nonMenuLinks.toString());
719 Cache.applicationProperties.setProperty("DEFAULT_URL",
720 sequenceUrlLinks.getPrimaryUrlId());
722 Cache.applicationProperties.setProperty("USE_PROXY",
723 Boolean.toString(useProxy.isSelected()));
725 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
727 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
729 if (useProxy.isSelected())
731 System.setProperty("http.proxyHost", proxyServerTB.getText());
732 System.setProperty("http.proxyPort", proxyPortTB.getText());
736 System.setProperty("http.proxyHost", "");
737 System.setProperty("http.proxyPort", "");
739 Cache.setProperty("VERSION_CHECK",
740 Boolean.toString(versioncheck.isSelected()));
741 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
743 // default is false - we only set this if the user has actively agreed
744 Cache.setProperty("USAGESTATS",
745 Boolean.toString(usagestats.isSelected()));
747 if (!questionnaire.isSelected())
749 Cache.setProperty("NOQUESTIONNAIRES", "true");
753 // special - made easy to edit a property file to disable questionnaires
754 // by just adding the given line
755 Cache.removeProperty("NOQUESTIONNAIRES");
759 * Save Output settings
761 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
762 Boolean.toString(blcjv.isSelected()));
763 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
764 Boolean.toString(clustaljv.isSelected()));
765 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
766 Boolean.toString(fastajv.isSelected()));
767 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
768 Boolean.toString(msfjv.isSelected()));
769 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
770 Boolean.toString(pfamjv.isSelected()));
771 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
772 Boolean.toString(pileupjv.isSelected()));
773 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
774 Boolean.toString(pirjv.isSelected()));
775 Cache.applicationProperties.setProperty("PIR_MODELLER",
776 Boolean.toString(modellerOutput.isSelected()));
777 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
778 Boolean.toString(embbedBioJSON.isSelected()));
779 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
781 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
782 Boolean.toString(autoIdWidth.isSelected()));
783 userIdWidth_actionPerformed();
784 Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
785 userIdWidth.getText());
788 * Save Editing settings
790 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
791 Boolean.toString(autoCalculateConsCheck.isSelected()));
792 Cache.applicationProperties.setProperty("SORT_BY_TREE",
793 Boolean.toString(sortByTree.isSelected()));
794 Cache.applicationProperties.setProperty("PAD_GAPS",
795 Boolean.toString(padGaps.isSelected()));
797 wsPrefs.updateAndRefreshWsMenuConfig(false);
798 Cache.saveProperties();
799 Desktop.instance.doConfigureStructurePrefs();
802 frame.setClosed(true);
803 } catch (Exception ex)
809 * Do any necessary validation before saving settings. Return focus to the
810 * first tab which fails validation.
814 private boolean validateSettings()
816 if (!validateStructure())
818 structureTab.requestFocusInWindow();
825 protected boolean validateStructure()
827 return validateChimeraPath();
835 public void startupFileTextfield_mouseClicked()
837 // TODO: JAL-3048 not needed for Jalview-JS
838 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
839 JalviewFileChooser chooser = JalviewFileChooser
840 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
841 chooser.setFileView(new JalviewFileView());
842 chooser.setDialogTitle(
843 MessageManager.getString("label.select_startup_file"));
845 int value = chooser.showOpenDialog(this);
847 if (value == JalviewFileChooser.APPROVE_OPTION)
849 FileFormatI format = chooser.getSelectedFormat();
852 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
856 .setText(chooser.getSelectedFile().getAbsolutePath());
867 public void cancel_actionPerformed(ActionEvent e)
871 wsPrefs.updateWsMenuConfig(true);
872 wsPrefs.refreshWs_actionPerformed(e);
873 frame.setClosed(true);
874 } catch (Exception ex)
886 public void annotations_actionPerformed(ActionEvent e)
888 conservation.setEnabled(annotations.isSelected());
889 quality.setEnabled(annotations.isSelected());
890 identity.setEnabled(annotations.isSelected());
891 showOccupancy.setEnabled(annotations.isSelected());
892 showGroupConsensus.setEnabled(annotations.isSelected());
893 showGroupConservation.setEnabled(annotations.isSelected());
894 showConsensHistogram.setEnabled(annotations.isSelected()
895 && (identity.isSelected() || showGroupConsensus.isSelected()));
896 showConsensLogo.setEnabled(annotations.isSelected()
897 && (identity.isSelected() || showGroupConsensus.isSelected()));
901 public void newLink_actionPerformed(ActionEvent e)
903 GSequenceLink link = new GSequenceLink();
904 boolean valid = false;
907 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
908 MessageManager.getString("label.new_sequence_url_link"),
909 JvOptionPane.OK_CANCEL_OPTION, -1,
910 null) == JvOptionPane.OK_OPTION)
912 if (link.checkValid())
914 if (((UrlLinkTableModel) linkUrlTable.getModel())
915 .isUniqueName(link.getName()))
917 ((UrlLinkTableModel) linkUrlTable.getModel())
918 .insertRow(link.getName(), link.getURL());
923 link.notifyDuplicate();
936 public void editLink_actionPerformed(ActionEvent e)
938 GSequenceLink link = new GSequenceLink();
940 int index = linkUrlTable.getSelectedRow();
943 // button no longer enabled if row is not selected
944 Cache.log.debug("Edit with no row selected in linkUrlTable");
948 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
950 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
952 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
953 link.setName(oldName);
954 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
956 boolean valid = false;
959 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
960 MessageManager.getString("label.edit_sequence_url_link"),
961 JvOptionPane.OK_CANCEL_OPTION, -1,
962 null) == JvOptionPane.OK_OPTION)
964 if (link.checkValid())
966 if ((oldName.equals(link.getName()))
967 || (((UrlLinkTableModel) linkUrlTable.getModel())
968 .isUniqueName(link.getName())))
970 linkUrlTable.setValueAt(link.getName(), index, nameCol);
971 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
976 link.notifyDuplicate();
989 public void deleteLink_actionPerformed(ActionEvent e)
991 int index = linkUrlTable.getSelectedRow();
995 // button no longer enabled if row is not selected
996 Cache.log.debug("Delete with no row selected in linkUrlTable");
1001 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1004 // make sure we use the model index to delete, and not the table index
1005 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1009 public void defaultBrowser_mouseClicked(MouseEvent e)
1011 // TODO: JAL-3048 not needed for j2s
1016 JFileChooser chooser = new JFileChooser(".");
1017 chooser.setDialogTitle(
1018 MessageManager.getString("label.select_default_browser"));
1020 int value = chooser.showOpenDialog(this);
1022 if (value == JFileChooser.APPROVE_OPTION)
1024 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1033 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1037 protected void showunconserved_actionPerformed(ActionEvent e)
1039 // TODO Auto-generated method stub
1040 super.showunconserved_actionPerformed(e);
1043 public static List<String> getGroupURLLinks()
1045 return groupURLLinks;
1049 public void minColour_actionPerformed(JPanel panel)
1051 Color col = JColorChooser.showDialog(this,
1052 MessageManager.getString("label.select_colour_minimum_value"),
1053 minColour.getBackground());
1056 panel.setBackground(col);
1062 public void maxColour_actionPerformed(JPanel panel)
1064 Color col = JColorChooser.showDialog(this,
1065 MessageManager.getString("label.select_colour_maximum_value"),
1066 maxColour.getBackground());
1069 panel.setBackground(col);
1075 public void gapColour_actionPerformed(JPanel gap)
1077 if (!useLegacyGap.isSelected())
1079 Color col = JColorChooser.showDialog(this,
1080 MessageManager.getString("label.select_gap_colour"),
1081 gapColour.getBackground());
1084 gap.setBackground(col);
1091 public void hiddenColour_actionPerformed(JPanel hidden)
1093 Color col = JColorChooser.showDialog(this,
1094 MessageManager.getString("label.select_hidden_colour"),
1095 hiddenColour.getBackground());
1098 hidden.setBackground(col);
1104 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1106 boolean enabled = useLegacyGap.isSelected();
1109 gapColour.setBackground(
1110 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1114 gapColour.setBackground(
1115 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1117 gapColour.setEnabled(!enabled);
1118 gapLabel.setEnabled(!enabled);
1122 protected void resetOvDefaults_actionPerformed(ActionEvent e)
1124 useLegacyGap.setSelected(false);
1125 useLegacyGaps_actionPerformed(null);
1126 showHiddenAtStart.setSelected(true);
1127 hiddenColour.setBackground(
1128 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1132 protected void userIdWidth_actionPerformed()
1136 String val = userIdWidth.getText().trim();
1137 if (val.length() > 0)
1139 Integer iw = Integer.parseInt(val);
1140 if (iw.intValue() < 12)
1142 throw new NumberFormatException();
1144 userIdWidth.setText(iw.toString());
1146 } catch (NumberFormatException x)
1148 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1150 .getString("warn.user_defined_width_requirements"),
1151 MessageManager.getString("label.invalid_id_column_width"),
1152 JvOptionPane.WARNING_MESSAGE);
1153 userIdWidth.setText("");
1158 protected void autoIdWidth_actionPerformed()
1160 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1161 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1165 * Returns true if chimera path is to a valid executable, else show an error
1168 private boolean validateChimeraPath()
1170 if (chimeraPath.getText().trim().length() > 0)
1172 File f = new File(chimeraPath.getText());
1173 if (!f.canExecute())
1175 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1176 MessageManager.getString("label.invalid_chimera_path"),
1177 MessageManager.getString("label.invalid_name"),
1178 JvOptionPane.ERROR_MESSAGE);
1186 * If Chimera is selected, check it can be found on default or user-specified
1187 * path, if not show a warning/help dialog.
1190 protected void structureViewer_actionPerformed(String selectedItem)
1192 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1196 boolean found = false;
1199 * Try user-specified and standard paths for Chimera executable.
1201 List<String> paths = StructureManager.getChimeraPaths();
1202 paths.add(0, chimeraPath.getText());
1203 for (String path : paths)
1205 if (new File(path.trim()).canExecute())
1213 String[] options = { "OK", "Help" };
1214 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1215 JvSwingUtils.wrapTooltip(true,
1216 MessageManager.getString("label.chimera_missing")),
1217 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1218 null, options, options[0]);
1219 if (showHelp == JvOptionPane.NO_OPTION)
1223 Help.showHelpWindow(HelpId.StructureViewer);
1224 } catch (HelpSetException e)
1226 e.printStackTrace();
1232 public class OptionsParam
1234 private String name;
1236 private String code;
1238 public OptionsParam(String name, String code)
1244 public String getName()
1249 public void setName(String name)
1254 public String getCode()
1259 public void setCode(String code)
1265 public String toString()
1271 public boolean equals(Object that)
1273 if (!(that instanceof OptionsParam))
1277 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1281 public int hashCode()
1283 return name.hashCode() + code.hashCode();
1287 private class UrlListSelectionHandler implements ListSelectionListener
1291 public void valueChanged(ListSelectionEvent e)
1293 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1295 int index = lsm.getMinSelectionIndex();
1298 // no selection, so disable delete/edit buttons
1299 editLink.setEnabled(false);
1300 deleteLink.setEnabled(false);
1303 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1305 // enable/disable edit and delete link buttons
1306 if (((UrlLinkTableModel) linkUrlTable.getModel())
1307 .isRowDeletable(modelIndex))
1309 deleteLink.setEnabled(true);
1313 deleteLink.setEnabled(false);
1316 if (((UrlLinkTableModel) linkUrlTable.getModel())
1317 .isRowEditable(modelIndex))
1319 editLink.setEnabled(true);
1323 editLink.setEnabled(false);