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;
124 public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
126 public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
128 public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
132 * Holds name and link separated with | character. Sequence ID must be
133 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
135 public static UrlProviderI sequenceUrlLinks;
137 public static UrlLinkTableModel dataModel;
140 * Holds name and link separated with | character. Sequence IDS and Sequences
141 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
142 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
143 * for first and second token specified after a pipe character at end |,|.
144 * (TODO: proper escape for using | to separate ids or sequences
147 public static List<String> groupURLLinks;
150 // get links selected to be in the menu (SEQUENCE_LINKS)
151 // and links entered by the user but not selected (STORED_LINKS)
152 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
153 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
154 String defaultUrl = Cache.getDefault("DEFAULT_URL",
155 UrlConstants.DEFAULT_LABEL);
157 // if both links lists are empty, add the DEFAULT_URL link
158 // otherwise we assume the default link is in one of the lists
159 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
161 inMenuString = UrlConstants.DEFAULT_STRING;
163 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
164 inMenuString, notInMenuString);
165 sequenceUrlLinks = factory.createUrlProvider();
166 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
169 * TODO: reformulate groupURL encoding so two or more can be stored in the
170 * .properties file as '|' separated strings
173 groupURLLinks = new ArrayList<>();
176 JInternalFrame frame;
178 DasSourceBrowser dasSource;
180 private WsPreferences wsPrefs;
182 private OptionsParam promptEachTimeOpt = new OptionsParam(
183 MessageManager.getString("label.prompt_each_time"),
186 private OptionsParam lineArtOpt = new OptionsParam(
187 MessageManager.getString("label.lineart"), "Lineart");
189 private OptionsParam textOpt = new OptionsParam(
190 MessageManager.getString("action.text"), "Text");
193 * Creates a new Preferences object.
198 frame = new JInternalFrame();
199 frame.setContentPane(this);
200 dasSource = new DasSourceBrowser();
201 dasTab.add(dasSource, BorderLayout.CENTER);
202 wsPrefs = new WsPreferences();
203 wsTab.add(wsPrefs, BorderLayout.CENTER);
204 int width = 500, height = 450;
205 new jalview.util.Platform();
206 if (Platform.isAMac())
212 Desktop.addInternalFrame(frame,
213 MessageManager.getString("label.preferences"), width, height);
214 frame.setMinimumSize(new Dimension(width, height));
217 * Set Visual tab defaults
219 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
220 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
221 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
222 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
224 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
225 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
226 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
227 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
229 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
230 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
232 .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
233 showGroupConservation.setSelected(
234 Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
235 showConsensHistogram.setSelected(
236 Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
238 .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
240 .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
242 .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
244 String[] fonts = java.awt.GraphicsEnvironment
245 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
246 for (int i = 0; i < fonts.length; i++)
248 fontNameCB.addItem(fonts[i]);
251 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
253 fontSizeCB.addItem(i + "");
256 fontStyleCB.addItem("plain");
257 fontStyleCB.addItem("bold");
258 fontStyleCB.addItem("italic");
260 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
261 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
262 fontStyleCB.setSelectedItem(
263 Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
265 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
267 .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
269 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
271 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
273 gapSymbolCB.addItem("-");
274 gapSymbolCB.addItem(".");
276 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
278 sortby.addItem("No sort");
279 sortby.addItem("Id");
280 sortby.addItem("Pairwise Identity");
281 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
283 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
285 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
287 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
288 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
289 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
290 SequenceAnnotationOrder.NONE.name()));
291 sortAnnBy.setSelectedItem(savedSort.toString());
293 sortAutocalc.addItem("Autocalculated first");
294 sortAutocalc.addItem("Autocalculated last");
295 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
296 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
297 : sortAutocalc.getItemAt(1));
299 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
300 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
301 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
302 + "/examples/exampleFile_2_3.jar"));
305 * Set Colours tab defaults
307 protColour.addItem(ResidueColourScheme.NONE);
308 nucColour.addItem(ResidueColourScheme.NONE);
309 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
311 String name = cs.getSchemeName();
312 protColour.addItem(name);
313 nucColour.addItem(name);
315 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
316 ResidueColourScheme.NONE);
317 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
318 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
319 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
320 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
321 minColour.setBackground(
322 Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
323 maxColour.setBackground(
324 Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
327 * Set overview panel defaults
329 gapColour.setBackground(
330 Cache.getDefaultColour(GAP_COLOUR, OVERVIEW_DEFAULT_GAP));
331 hiddenColour.setBackground(
332 Cache.getDefaultColour(HIDDEN_COLOUR,
333 OVERVIEW_DEFAULT_HIDDEN));
334 useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
335 gapLabel.setEnabled(!useLegacyGap.isSelected());
336 gapColour.setEnabled(!useLegacyGap.isSelected());
338 .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
341 * Set Structure tab defaults.
343 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
344 structFromPdb.setSelected(structSelected);
345 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
346 useRnaView.setEnabled(structSelected);
347 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
348 addSecondaryStructure.setEnabled(structSelected);
349 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
350 addTempFactor.setEnabled(structSelected);
351 structViewer.setSelectedItem(
352 Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
353 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
354 chimeraPath.addActionListener(new ActionListener()
357 public void actionPerformed(ActionEvent e)
359 validateChimeraPath();
363 if (Cache.getDefault("MAP_WITH_SIFTS", false))
365 siftsMapping.setSelected(true);
369 nwMapping.setSelected(true);
373 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
376 * Set Connections tab defaults
380 linkUrlTable.setModel(dataModel);
381 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
382 linkUrlTable.getModel());
383 linkUrlTable.setRowSorter(sorter);
384 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
386 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
387 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
388 SortOrder.DESCENDING));
389 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
390 SortOrder.DESCENDING));
392 new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
394 sorter.setSortKeys(sortKeys);
398 ActionListener onReset;
399 onReset = new ActionListener()
402 public void actionPerformed(ActionEvent e)
404 filterTB.setText("");
405 sorter.setRowFilter(RowFilter.regexFilter(""));
409 doReset.addActionListener(onReset);
411 // filter to display only custom urls
412 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
415 public boolean include(
416 Entry<? extends TableModel, ? extends Object> entry)
418 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
422 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
423 linkUrlTable.getModel());
424 customSorter.setRowFilter(customUrlFilter);
426 ActionListener onCustomOnly;
427 onCustomOnly = new ActionListener()
430 public void actionPerformed(ActionEvent e)
432 filterTB.setText("");
433 sorter.setRowFilter(customUrlFilter);
436 userOnly.addActionListener(onCustomOnly);
438 filterTB.getDocument().addDocumentListener(new DocumentListener()
440 String caseInsensitiveFlag = "(?i)";
443 public void changedUpdate(DocumentEvent e)
445 sorter.setRowFilter(RowFilter
446 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
450 public void removeUpdate(DocumentEvent e)
452 sorter.setRowFilter(RowFilter
453 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
457 public void insertUpdate(DocumentEvent e)
459 sorter.setRowFilter(RowFilter
460 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
464 // set up list selection functionality
465 linkUrlTable.getSelectionModel()
466 .addListSelectionListener(new UrlListSelectionHandler());
468 // set up radio buttons
469 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
471 String onClickName = linkUrlTable.getColumnName(onClickCol);
472 linkUrlTable.getColumn(onClickName)
473 .setCellRenderer(new RadioButtonRenderer());
474 linkUrlTable.getColumn(onClickName)
475 .setCellEditor(new RadioButtonEditor());
477 // get boolean columns and resize those to min possible
478 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
480 if (linkUrlTable.getModel().getColumnClass(column)
481 .equals(Boolean.class))
483 TableColumn tableColumn = linkUrlTable.getColumnModel()
485 int preferredWidth = tableColumn.getMinWidth();
487 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
489 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
490 int cwidth = c.getPreferredSize().width
491 + linkUrlTable.getIntercellSpacing().width;
492 preferredWidth = Math.max(preferredWidth, cwidth);
494 tableColumn.setPreferredWidth(preferredWidth);
498 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
499 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
500 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
501 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
503 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
505 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
506 // note antisense here: default is true
508 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
509 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
512 * Set Output tab defaults
514 epsRendering.addItem(promptEachTimeOpt);
515 epsRendering.addItem(lineArtOpt);
516 epsRendering.addItem(textOpt);
517 String defaultEPS = Cache.getDefault("EPS_RENDERING",
519 if (defaultEPS.equalsIgnoreCase("Text"))
521 epsRendering.setSelectedItem(textOpt);
523 else if (defaultEPS.equalsIgnoreCase("Lineart"))
525 epsRendering.setSelectedItem(lineArtOpt);
529 epsRendering.setSelectedItem(promptEachTimeOpt);
531 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
532 userIdWidth.setEnabled(!autoIdWidth.isSelected());
533 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
534 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
535 userIdWidth.setText(wi == null ? "" : wi.toString());
536 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
537 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
538 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
539 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
540 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
541 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
542 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
543 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
545 .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
548 * Set Editing tab defaults
550 autoCalculateConsCheck
551 .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
552 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
553 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
555 annotations_actionPerformed(null); // update the display of the annotation
560 * Save user selections on the Preferences tabs to the Cache and write out to
566 public void ok_actionPerformed(ActionEvent e)
568 if (!validateSettings())
574 * Save Visual settings
576 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
577 Boolean.toString(seqLimit.isSelected()));
578 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
579 Boolean.toString(rightAlign.isSelected()));
580 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
581 Boolean.toString(fullScreen.isSelected()));
582 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
583 Boolean.toString(openoverv.isSelected()));
584 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
585 Boolean.toString(annotations.isSelected()));
586 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
587 Boolean.toString(conservation.isSelected()));
588 Cache.applicationProperties.setProperty("SHOW_QUALITY",
589 Boolean.toString(quality.isSelected()));
590 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
591 Boolean.toString(identity.isSelected()));
593 Cache.applicationProperties.setProperty("GAP_SYMBOL",
594 gapSymbolCB.getSelectedItem().toString());
596 Cache.applicationProperties.setProperty("FONT_NAME",
597 fontNameCB.getSelectedItem().toString());
598 Cache.applicationProperties.setProperty("FONT_STYLE",
599 fontStyleCB.getSelectedItem().toString());
600 Cache.applicationProperties.setProperty("FONT_SIZE",
601 fontSizeCB.getSelectedItem().toString());
603 Cache.applicationProperties.setProperty("ID_ITALICS",
604 Boolean.toString(idItalics.isSelected()));
605 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
606 Boolean.toString(showUnconserved.isSelected()));
607 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
608 Boolean.toString(showOccupancy.isSelected()));
609 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
610 Boolean.toString(showGroupConsensus.isSelected()));
611 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
612 Boolean.toString(showGroupConservation.isSelected()));
613 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
614 Boolean.toString(showConsensHistogram.isSelected()));
615 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
616 Boolean.toString(showConsensLogo.isSelected()));
617 Cache.applicationProperties.setProperty("ANTI_ALIAS",
618 Boolean.toString(smoothFont.isSelected()));
619 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
620 Boolean.toString(scaleProteinToCdna.isSelected()));
621 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
622 Boolean.toString(showNpTooltip.isSelected()));
623 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
624 Boolean.toString(showDbRefTooltip.isSelected()));
626 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
627 Boolean.toString(wrap.isSelected()));
629 Cache.applicationProperties.setProperty("STARTUP_FILE",
630 startupFileTextfield.getText());
631 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
632 Boolean.toString(startupCheckbox.isSelected()));
634 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
635 sortby.getSelectedItem().toString());
637 // convert description of sort order to enum name for save
638 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
639 .forDescription(sortAnnBy.getSelectedItem().toString());
640 if (annSortOrder != null)
642 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
643 annSortOrder.name());
646 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
647 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
648 Boolean.valueOf(showAutocalcFirst).toString());
651 * Save Colours settings
653 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
654 protColour.getSelectedItem().toString());
655 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
656 nucColour.getSelectedItem().toString());
657 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
658 minColour.getBackground());
659 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
660 maxColour.getBackground());
663 * Save Overview settings
665 Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
666 Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
667 Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
668 Boolean.toString(useLegacyGap.isSelected()));
669 Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
670 Boolean.toString(showHiddenAtStart.isSelected()));
673 * Save Structure settings
675 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
676 Boolean.toString(addTempFactor.isSelected()));
677 Cache.applicationProperties.setProperty(ADD_SS_ANN,
678 Boolean.toString(addSecondaryStructure.isSelected()));
679 Cache.applicationProperties.setProperty(USE_RNAVIEW,
680 Boolean.toString(useRnaView.isSelected()));
681 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
682 Boolean.toString(structFromPdb.isSelected()));
683 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
684 structViewer.getSelectedItem().toString());
685 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
686 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
687 Boolean.toString(siftsMapping.isSelected()));
688 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
691 * Save Output settings
693 Cache.applicationProperties.setProperty("EPS_RENDERING",
694 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
697 * Save Connections settings
699 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
701 jalview.util.BrowserLauncher.resetBrowser();
703 // save user-defined and selected links
704 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
705 if (menuLinks.isEmpty())
707 Cache.applicationProperties.remove("SEQUENCE_LINKS");
711 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
712 menuLinks.toString());
715 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
716 if (nonMenuLinks.isEmpty())
718 Cache.applicationProperties.remove("STORED_LINKS");
722 Cache.applicationProperties.setProperty("STORED_LINKS",
723 nonMenuLinks.toString());
726 Cache.applicationProperties.setProperty("DEFAULT_URL",
727 sequenceUrlLinks.getPrimaryUrlId());
729 Cache.applicationProperties.setProperty("USE_PROXY",
730 Boolean.toString(useProxy.isSelected()));
732 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
734 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
736 if (useProxy.isSelected())
738 System.setProperty("http.proxyHost", proxyServerTB.getText());
739 System.setProperty("http.proxyPort", proxyPortTB.getText());
743 System.setProperty("http.proxyHost", "");
744 System.setProperty("http.proxyPort", "");
746 Cache.setProperty("VERSION_CHECK",
747 Boolean.toString(versioncheck.isSelected()));
748 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
750 // default is false - we only set this if the user has actively agreed
751 Cache.setProperty("USAGESTATS",
752 Boolean.toString(usagestats.isSelected()));
754 if (!questionnaire.isSelected())
756 Cache.setProperty("NOQUESTIONNAIRES", "true");
760 // special - made easy to edit a property file to disable questionnaires
761 // by just adding the given line
762 Cache.removeProperty("NOQUESTIONNAIRES");
766 * Save Output settings
768 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
769 Boolean.toString(blcjv.isSelected()));
770 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
771 Boolean.toString(clustaljv.isSelected()));
772 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
773 Boolean.toString(fastajv.isSelected()));
774 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
775 Boolean.toString(msfjv.isSelected()));
776 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
777 Boolean.toString(pfamjv.isSelected()));
778 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
779 Boolean.toString(pileupjv.isSelected()));
780 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
781 Boolean.toString(pirjv.isSelected()));
782 Cache.applicationProperties.setProperty("PIR_MODELLER",
783 Boolean.toString(modellerOutput.isSelected()));
784 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
785 Boolean.toString(embbedBioJSON.isSelected()));
786 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
788 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
789 Boolean.toString(autoIdWidth.isSelected()));
790 userIdWidth_actionPerformed();
791 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
792 userIdWidth.getText());
795 * Save Editing settings
797 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
798 Boolean.toString(autoCalculateConsCheck.isSelected()));
799 Cache.applicationProperties.setProperty("SORT_BY_TREE",
800 Boolean.toString(sortByTree.isSelected()));
801 Cache.applicationProperties.setProperty("PAD_GAPS",
802 Boolean.toString(padGaps.isSelected()));
804 dasSource.saveProperties(Cache.applicationProperties);
805 wsPrefs.updateAndRefreshWsMenuConfig(false);
806 Cache.saveProperties();
807 Desktop.instance.doConfigureStructurePrefs();
810 frame.setClosed(true);
811 } catch (Exception ex)
817 * Do any necessary validation before saving settings. Return focus to the
818 * first tab which fails validation.
822 private boolean validateSettings()
824 if (!validateStructure())
826 structureTab.requestFocusInWindow();
833 protected boolean validateStructure()
835 return validateChimeraPath();
843 public void startupFileTextfield_mouseClicked()
845 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
846 JalviewFileChooser chooser = JalviewFileChooser
847 .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
848 chooser.setFileView(new JalviewFileView());
849 chooser.setDialogTitle(
850 MessageManager.getString("label.select_startup_file"));
852 int value = chooser.showOpenDialog(this);
854 if (value == JalviewFileChooser.APPROVE_OPTION)
856 FileFormatI format = chooser.getSelectedFormat();
859 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
863 .setText(chooser.getSelectedFile().getAbsolutePath());
874 public void cancel_actionPerformed(ActionEvent e)
878 wsPrefs.updateWsMenuConfig(true);
879 wsPrefs.refreshWs_actionPerformed(e);
880 frame.setClosed(true);
881 } catch (Exception ex)
893 public void annotations_actionPerformed(ActionEvent e)
895 conservation.setEnabled(annotations.isSelected());
896 quality.setEnabled(annotations.isSelected());
897 identity.setEnabled(annotations.isSelected());
898 showOccupancy.setEnabled(annotations.isSelected());
899 showGroupConsensus.setEnabled(annotations.isSelected());
900 showGroupConservation.setEnabled(annotations.isSelected());
901 showConsensHistogram.setEnabled(annotations.isSelected()
902 && (identity.isSelected() || showGroupConsensus.isSelected()));
903 showConsensLogo.setEnabled(annotations.isSelected()
904 && (identity.isSelected() || showGroupConsensus.isSelected()));
908 public void newLink_actionPerformed(ActionEvent e)
910 GSequenceLink link = new GSequenceLink();
911 boolean valid = false;
914 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
915 MessageManager.getString("label.new_sequence_url_link"),
916 JvOptionPane.OK_CANCEL_OPTION, -1,
917 null) == JvOptionPane.OK_OPTION)
919 if (link.checkValid())
921 if (((UrlLinkTableModel) linkUrlTable.getModel())
922 .isUniqueName(link.getName()))
924 ((UrlLinkTableModel) linkUrlTable.getModel())
925 .insertRow(link.getName(), link.getURL());
930 link.notifyDuplicate();
943 public void editLink_actionPerformed(ActionEvent e)
945 GSequenceLink link = new GSequenceLink();
947 int index = linkUrlTable.getSelectedRow();
950 // button no longer enabled if row is not selected
951 Cache.log.debug("Edit with no row selected in linkUrlTable");
955 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
957 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
959 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
960 link.setName(oldName);
961 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
963 boolean valid = false;
966 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
967 MessageManager.getString("label.edit_sequence_url_link"),
968 JvOptionPane.OK_CANCEL_OPTION, -1,
969 null) == JvOptionPane.OK_OPTION)
971 if (link.checkValid())
973 if ((oldName.equals(link.getName()))
974 || (((UrlLinkTableModel) linkUrlTable.getModel())
975 .isUniqueName(link.getName())))
977 linkUrlTable.setValueAt(link.getName(), index, nameCol);
978 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
983 link.notifyDuplicate();
996 public void deleteLink_actionPerformed(ActionEvent e)
998 int index = linkUrlTable.getSelectedRow();
1002 // button no longer enabled if row is not selected
1003 Cache.log.debug("Delete with no row selected in linkUrlTable");
1008 modelIndex = linkUrlTable.convertRowIndexToModel(index);
1011 // make sure we use the model index to delete, and not the table index
1012 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1016 public void defaultBrowser_mouseClicked(MouseEvent e)
1018 JFileChooser chooser = new JFileChooser(".");
1019 chooser.setDialogTitle(
1020 MessageManager.getString("label.select_default_browser"));
1022 int value = chooser.showOpenDialog(this);
1024 if (value == JFileChooser.APPROVE_OPTION)
1026 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1035 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1039 protected void showunconserved_actionPerformed(ActionEvent e)
1041 // TODO Auto-generated method stub
1042 super.showunconserved_actionPerformed(e);
1045 public static List<String> getGroupURLLinks()
1047 return groupURLLinks;
1051 public void minColour_actionPerformed(JPanel panel)
1053 Color col = JColorChooser.showDialog(this,
1054 MessageManager.getString("label.select_colour_minimum_value"),
1055 minColour.getBackground());
1058 panel.setBackground(col);
1064 public void maxColour_actionPerformed(JPanel panel)
1066 Color col = JColorChooser.showDialog(this,
1067 MessageManager.getString("label.select_colour_maximum_value"),
1068 maxColour.getBackground());
1071 panel.setBackground(col);
1077 public void gapColour_actionPerformed(JPanel gap)
1079 if (!useLegacyGap.isSelected())
1081 Color col = JColorChooser.showDialog(this,
1082 MessageManager.getString("label.select_gap_colour"),
1083 gapColour.getBackground());
1086 gap.setBackground(col);
1093 public void hiddenColour_actionPerformed(JPanel hidden)
1095 Color col = JColorChooser.showDialog(this,
1096 MessageManager.getString("label.select_hidden_colour"),
1097 hiddenColour.getBackground());
1100 hidden.setBackground(col);
1106 protected void useLegacyGaps_actionPerformed(ActionEvent e)
1108 boolean enabled = useLegacyGap.isSelected();
1111 gapColour.setBackground(OVERVIEW_DEFAULT_LEGACY_GAP);
1115 gapColour.setBackground(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(OVERVIEW_DEFAULT_HIDDEN);
1131 protected void userIdWidth_actionPerformed()
1135 String val = userIdWidth.getText().trim();
1136 if (val.length() > 0)
1138 Integer iw = Integer.parseInt(val);
1139 if (iw.intValue() < 12)
1141 throw new NumberFormatException();
1143 userIdWidth.setText(iw.toString());
1145 } catch (NumberFormatException x)
1147 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1149 .getString("warn.user_defined_width_requirements"),
1150 MessageManager.getString("label.invalid_id_column_width"),
1151 JvOptionPane.WARNING_MESSAGE);
1152 userIdWidth.setText("");
1157 protected void autoIdWidth_actionPerformed()
1159 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1160 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1164 * Returns true if chimera path is to a valid executable, else show an error
1167 private boolean validateChimeraPath()
1169 if (chimeraPath.getText().trim().length() > 0)
1171 File f = new File(chimeraPath.getText());
1172 if (!f.canExecute())
1174 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1175 MessageManager.getString("label.invalid_chimera_path"),
1176 MessageManager.getString("label.invalid_name"),
1177 JvOptionPane.ERROR_MESSAGE);
1185 * If Chimera is selected, check it can be found on default or user-specified
1186 * path, if not show a warning/help dialog.
1189 protected void structureViewer_actionPerformed(String selectedItem)
1191 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1195 boolean found = false;
1198 * Try user-specified and standard paths for Chimera executable.
1200 List<String> paths = StructureManager.getChimeraPaths();
1201 paths.add(0, chimeraPath.getText());
1202 for (String path : paths)
1204 if (new File(path.trim()).canExecute())
1212 String[] options = { "OK", "Help" };
1213 int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1214 JvSwingUtils.wrapTooltip(true,
1215 MessageManager.getString("label.chimera_missing")),
1216 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1217 null, options, options[0]);
1218 if (showHelp == JvOptionPane.NO_OPTION)
1222 Help.showHelpWindow(HelpId.StructureViewer);
1223 } catch (HelpSetException e)
1225 e.printStackTrace();
1231 public class OptionsParam
1233 private String name;
1235 private String code;
1237 public OptionsParam(String name, String code)
1243 public String getName()
1248 public void setName(String name)
1253 public String getCode()
1258 public void setCode(String code)
1264 public String toString()
1270 public boolean equals(Object that)
1272 if (!(that instanceof OptionsParam))
1276 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1280 public int hashCode()
1282 return name.hashCode() + code.hashCode();
1286 private class UrlListSelectionHandler implements ListSelectionListener
1290 public void valueChanged(ListSelectionEvent e)
1292 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1294 int index = lsm.getMinSelectionIndex();
1297 // no selection, so disable delete/edit buttons
1298 editLink.setEnabled(false);
1299 deleteLink.setEnabled(false);
1302 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1304 // enable/disable edit and delete link buttons
1305 if (((UrlLinkTableModel) linkUrlTable.getModel())
1306 .isRowDeletable(modelIndex))
1308 deleteLink.setEnabled(true);
1312 deleteLink.setEnabled(false);
1315 if (((UrlLinkTableModel) linkUrlTable.getModel())
1316 .isRowEditable(modelIndex))
1318 editLink.setEnabled(true);
1322 editLink.setEnabled(false);