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 HMMER_PATH = "HMMER_PATH";
108 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
110 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
112 public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
114 private static final int MIN_FONT_SIZE = 1;
116 private static final int MAX_FONT_SIZE = 30;
119 * Holds name and link separated with | character. Sequence ID must be
120 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
122 public static UrlProviderI sequenceUrlLinks;
124 public static UrlLinkTableModel dataModel;
127 * Holds name and link separated with | character. Sequence IDS and Sequences
128 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
129 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
130 * for first and second token specified after a pipe character at end |,|.
131 * (TODO: proper escape for using | to separate ids or sequences
134 public static List<String> groupURLLinks;
137 // get links selected to be in the menu (SEQUENCE_LINKS)
138 // and links entered by the user but not selected (STORED_LINKS)
139 String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
140 String notInMenuString = Cache.getDefault("STORED_LINKS", "");
141 String defaultUrl = Cache.getDefault("DEFAULT_URL",
142 UrlConstants.DEFAULT_LABEL);
144 // if both links lists are empty, add the DEFAULT_URL link
145 // otherwise we assume the default link is in one of the lists
146 if (inMenuString.isEmpty() && notInMenuString.isEmpty())
148 inMenuString = UrlConstants.DEFAULT_STRING;
150 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
151 inMenuString, notInMenuString);
152 sequenceUrlLinks = factory.createUrlProvider();
153 dataModel = new UrlLinkTableModel(sequenceUrlLinks);
156 * TODO: reformulate groupURL encoding so two or more can be stored in the
157 * .properties file as '|' separated strings
160 groupURLLinks = new ArrayList<>();
163 JInternalFrame frame;
165 DasSourceBrowser dasSource;
167 private WsPreferences wsPrefs;
169 private OptionsParam promptEachTimeOpt = new OptionsParam(
170 MessageManager.getString("label.prompt_each_time"),
173 private OptionsParam lineArtOpt = new OptionsParam(
174 MessageManager.getString("label.lineart"), "Lineart");
176 private OptionsParam textOpt = new OptionsParam(
177 MessageManager.getString("action.text"), "Text");
180 * Creates a new Preferences object.
185 frame = new JInternalFrame();
186 frame.setContentPane(this);
187 dasSource = new DasSourceBrowser();
188 dasTab.add(dasSource, BorderLayout.CENTER);
189 wsPrefs = new WsPreferences();
190 wsTab.add(wsPrefs, BorderLayout.CENTER);
191 int width = 500, height = 450;
192 new jalview.util.Platform();
193 if (Platform.isAMac())
199 Desktop.addInternalFrame(frame,
200 MessageManager.getString("label.preferences"), width, height);
201 frame.setMinimumSize(new Dimension(width, height));
204 * Set Visual tab defaults
206 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
207 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
208 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
209 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
211 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
212 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
213 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
214 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
216 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
217 showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
218 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
220 showGroupConservation.setSelected(Cache.getDefault(
221 "SHOW_GROUP_CONSERVATION", false));
222 showConsensHistogram.setSelected(Cache.getDefault(
223 "SHOW_CONSENSUS_HISTOGRAM", true));
224 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
226 showInformationHistogram.setSelected(
227 Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
228 showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
229 showNpTooltip.setSelected(Cache
230 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
231 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
234 String[] fonts = java.awt.GraphicsEnvironment
235 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
236 for (int i = 0; i < fonts.length; i++)
238 fontNameCB.addItem(fonts[i]);
241 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
243 fontSizeCB.addItem(i + "");
246 fontStyleCB.addItem("plain");
247 fontStyleCB.addItem("bold");
248 fontStyleCB.addItem("italic");
250 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
251 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
252 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
255 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
256 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
259 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
261 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
263 gapSymbolCB.addItem("-");
264 gapSymbolCB.addItem(".");
266 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
268 sortby.addItem("No sort");
269 sortby.addItem("Id");
270 sortby.addItem("Pairwise Identity");
271 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
273 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
275 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
277 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
278 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
279 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
280 SequenceAnnotationOrder.NONE.name()));
281 sortAnnBy.setSelectedItem(savedSort.toString());
283 sortAutocalc.addItem("Autocalculated first");
284 sortAutocalc.addItem("Autocalculated last");
285 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
286 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
287 : sortAutocalc.getItemAt(1));
289 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
290 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
291 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
292 + "/examples/exampleFile_2_3.jar"));
295 * Set Colours tab defaults
297 protColour.addItem(ResidueColourScheme.NONE);
298 nucColour.addItem(ResidueColourScheme.NONE);
299 for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
301 String name = cs.getSchemeName();
302 protColour.addItem(name);
303 nucColour.addItem(name);
305 String oldProp = Cache.getDefault(DEFAULT_COLOUR,
306 ResidueColourScheme.NONE);
307 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
308 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
309 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
310 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
311 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
313 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
317 * Set Structure tab defaults.
319 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
320 structFromPdb.setSelected(structSelected);
321 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
322 useRnaView.setEnabled(structSelected);
323 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
324 addSecondaryStructure.setEnabled(structSelected);
325 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
326 addTempFactor.setEnabled(structSelected);
327 structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
328 ViewerType.JMOL.name()));
329 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
330 chimeraPath.addActionListener(new ActionListener()
333 public void actionPerformed(ActionEvent e)
335 validateChimeraPath();
339 if (Cache.getDefault("MAP_WITH_SIFTS", false))
341 siftsMapping.setSelected(true);
345 nwMapping.setSelected(true);
349 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
352 * Set Connections tab defaults
356 linkUrlTable.setModel(dataModel);
357 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
358 linkUrlTable.getModel());
359 linkUrlTable.setRowSorter(sorter);
360 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
362 UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
363 sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
364 SortOrder.DESCENDING));
365 sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
366 SortOrder.DESCENDING));
367 sortKeys.add(new RowSorter.SortKey(m.getNameColumn(),
368 SortOrder.ASCENDING));
370 sorter.setSortKeys(sortKeys);
374 ActionListener onReset;
375 onReset = new ActionListener()
378 public void actionPerformed(ActionEvent e)
380 filterTB.setText("");
381 sorter.setRowFilter(RowFilter.regexFilter(""));
385 doReset.addActionListener(onReset);
387 // filter to display only custom urls
388 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
391 public boolean include(
392 Entry<? extends TableModel, ? extends Object> entry)
394 return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
398 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
399 linkUrlTable.getModel());
400 customSorter.setRowFilter(customUrlFilter);
402 ActionListener onCustomOnly;
403 onCustomOnly = new ActionListener()
406 public void actionPerformed(ActionEvent e)
408 filterTB.setText("");
409 sorter.setRowFilter(customUrlFilter);
412 userOnly.addActionListener(onCustomOnly);
414 filterTB.getDocument().addDocumentListener(new DocumentListener()
416 String caseInsensitiveFlag = "(?i)";
419 public void changedUpdate(DocumentEvent e)
421 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
422 + filterTB.getText()));
426 public void removeUpdate(DocumentEvent e)
428 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
429 + filterTB.getText()));
433 public void insertUpdate(DocumentEvent e)
435 sorter.setRowFilter(RowFilter.regexFilter(caseInsensitiveFlag
436 + filterTB.getText()));
440 // set up list selection functionality
441 linkUrlTable.getSelectionModel().addListSelectionListener(
442 new UrlListSelectionHandler());
444 // set up radio buttons
445 int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
447 String onClickName = linkUrlTable.getColumnName(onClickCol);
448 linkUrlTable.getColumn(onClickName).setCellRenderer(
449 new RadioButtonRenderer());
450 linkUrlTable.getColumn(onClickName)
451 .setCellEditor(new RadioButtonEditor());
453 // get boolean columns and resize those to min possible
454 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
456 if (linkUrlTable.getModel().getColumnClass(column)
457 .equals(Boolean.class))
459 TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
461 int preferredWidth = tableColumn.getMinWidth();
463 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
465 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
466 int cwidth = c.getPreferredSize().width
467 + linkUrlTable.getIntercellSpacing().width;
468 preferredWidth = Math.max(preferredWidth, cwidth);
470 tableColumn.setPreferredWidth(preferredWidth);
474 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
475 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
476 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
477 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
479 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
481 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
482 // note antisense here: default is true
484 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
485 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
488 * Set Output tab defaults
490 epsRendering.addItem(promptEachTimeOpt);
491 epsRendering.addItem(lineArtOpt);
492 epsRendering.addItem(textOpt);
493 String defaultEPS = Cache.getDefault("EPS_RENDERING",
495 if (defaultEPS.equalsIgnoreCase("Text"))
497 epsRendering.setSelectedItem(textOpt);
499 else if (defaultEPS.equalsIgnoreCase("Lineart"))
501 epsRendering.setSelectedItem(lineArtOpt);
505 epsRendering.setSelectedItem(promptEachTimeOpt);
507 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
508 userIdWidth.setEnabled(!autoIdWidth.isSelected());
509 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
510 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
511 userIdWidth.setText(wi == null ? "" : wi.toString());
512 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
513 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
514 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
515 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
516 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
517 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
518 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
519 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
520 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
524 * Set Editing tab defaults
526 autoCalculateConsCheck.setSelected(Cache.getDefault(
527 "AUTO_CALC_CONSENSUS", true));
528 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
529 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
531 annotations_actionPerformed(null); // update the display of the annotation
536 * Save user selections on the Preferences tabs to the Cache and write out to
542 public void ok_actionPerformed(ActionEvent e)
544 if (!validateSettings())
550 * Save Visual settings
552 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
553 Boolean.toString(seqLimit.isSelected()));
554 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
555 Boolean.toString(rightAlign.isSelected()));
556 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
557 Boolean.toString(fullScreen.isSelected()));
558 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
559 Boolean.toString(openoverv.isSelected()));
560 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
561 Boolean.toString(annotations.isSelected()));
562 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
563 Boolean.toString(conservation.isSelected()));
564 Cache.applicationProperties.setProperty("SHOW_QUALITY",
565 Boolean.toString(quality.isSelected()));
566 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
567 Boolean.toString(identity.isSelected()));
569 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
570 .getSelectedItem().toString());
572 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
573 .getSelectedItem().toString());
574 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
575 .getSelectedItem().toString());
576 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
577 .getSelectedItem().toString());
579 Cache.applicationProperties.setProperty("ID_ITALICS",
580 Boolean.toString(idItalics.isSelected()));
581 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
582 Boolean.toString(showUnconserved.isSelected()));
583 Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
584 Boolean.toString(showOccupancy.isSelected()));
585 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
586 Boolean.toString(showGroupConsensus.isSelected()));
587 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
588 Boolean.toString(showGroupConservation.isSelected()));
589 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
590 Boolean.toString(showConsensHistogram.isSelected()));
591 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
592 Boolean.toString(showConsensLogo.isSelected()));
593 Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
594 Boolean.toString(showConsensHistogram.isSelected()));
595 Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
596 Boolean.toString(showHMMLogo.isSelected()));
597 Cache.applicationProperties.setProperty("ANTI_ALIAS",
598 Boolean.toString(smoothFont.isSelected()));
599 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
600 Boolean.toString(scaleProteinToCdna.isSelected()));
601 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
602 Boolean.toString(showNpTooltip.isSelected()));
603 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
604 Boolean.toString(showDbRefTooltip.isSelected()));
606 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
607 Boolean.toString(wrap.isSelected()));
609 Cache.applicationProperties.setProperty("STARTUP_FILE",
610 startupFileTextfield.getText());
611 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
612 Boolean.toString(startupCheckbox.isSelected()));
614 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
615 .getSelectedItem().toString());
617 // convert description of sort order to enum name for save
618 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
619 .forDescription(sortAnnBy.getSelectedItem().toString());
620 if (annSortOrder != null)
622 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
623 annSortOrder.name());
626 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
627 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
628 .valueOf(showAutocalcFirst).toString());
631 * Save Colours settings
633 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
634 .getSelectedItem().toString());
635 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
636 .getSelectedItem().toString());
637 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
638 minColour.getBackground());
639 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
640 maxColour.getBackground());
643 * Save Structure settings
645 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
646 Boolean.toString(addTempFactor.isSelected()));
647 Cache.applicationProperties.setProperty(ADD_SS_ANN,
648 Boolean.toString(addSecondaryStructure.isSelected()));
649 Cache.applicationProperties.setProperty(USE_RNAVIEW,
650 Boolean.toString(useRnaView.isSelected()));
651 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
652 Boolean.toString(structFromPdb.isSelected()));
653 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
654 .getSelectedItem().toString());
655 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
656 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
657 Boolean.toString(siftsMapping.isSelected()));
658 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
661 * Save Output settings
663 Cache.applicationProperties.setProperty("EPS_RENDERING",
664 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
667 * Save Connections settings
669 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
671 jalview.util.BrowserLauncher.resetBrowser();
673 // save user-defined and selected links
674 String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
675 if (menuLinks.isEmpty())
677 Cache.applicationProperties.remove("SEQUENCE_LINKS");
681 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
682 menuLinks.toString());
685 String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
686 if (nonMenuLinks.isEmpty())
688 Cache.applicationProperties.remove("STORED_LINKS");
692 Cache.applicationProperties.setProperty("STORED_LINKS",
693 nonMenuLinks.toString());
696 Cache.applicationProperties.setProperty("DEFAULT_URL",
697 sequenceUrlLinks.getPrimaryUrlId());
699 Cache.applicationProperties.setProperty("USE_PROXY",
700 Boolean.toString(useProxy.isSelected()));
702 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
704 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
706 if (useProxy.isSelected())
708 System.setProperty("http.proxyHost", proxyServerTB.getText());
709 System.setProperty("http.proxyPort", proxyPortTB.getText());
713 System.setProperty("http.proxyHost", "");
714 System.setProperty("http.proxyPort", "");
716 Cache.setProperty("VERSION_CHECK",
717 Boolean.toString(versioncheck.isSelected()));
718 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
720 // default is false - we only set this if the user has actively agreed
721 Cache.setProperty("USAGESTATS",
722 Boolean.toString(usagestats.isSelected()));
724 if (!questionnaire.isSelected())
726 Cache.setProperty("NOQUESTIONNAIRES", "true");
730 // special - made easy to edit a property file to disable questionnaires
731 // by just adding the given line
732 Cache.removeProperty("NOQUESTIONNAIRES");
736 * Save Output settings
738 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
739 Boolean.toString(blcjv.isSelected()));
740 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
741 Boolean.toString(clustaljv.isSelected()));
742 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
743 Boolean.toString(fastajv.isSelected()));
744 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
745 Boolean.toString(msfjv.isSelected()));
746 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
747 Boolean.toString(pfamjv.isSelected()));
748 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
749 Boolean.toString(pileupjv.isSelected()));
750 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
751 Boolean.toString(pirjv.isSelected()));
752 Cache.applicationProperties.setProperty("PIR_MODELLER",
753 Boolean.toString(modellerOutput.isSelected()));
754 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
755 Boolean.toString(embbedBioJSON.isSelected()));
756 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
758 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
759 Boolean.toString(autoIdWidth.isSelected()));
760 userIdWidth_actionPerformed();
761 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
762 userIdWidth.getText());
765 * Save Editing settings
767 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
768 Boolean.toString(autoCalculateConsCheck.isSelected()));
769 Cache.applicationProperties.setProperty("SORT_BY_TREE",
770 Boolean.toString(sortByTree.isSelected()));
771 Cache.applicationProperties.setProperty("PAD_GAPS",
772 Boolean.toString(padGaps.isSelected()));
774 dasSource.saveProperties(Cache.applicationProperties);
775 wsPrefs.updateAndRefreshWsMenuConfig(false);
776 Cache.saveProperties();
777 Desktop.instance.doConfigureStructurePrefs();
780 frame.setClosed(true);
781 } catch (Exception ex)
787 * Do any necessary validation before saving settings. Return focus to the
788 * first tab which fails validation.
792 private boolean validateSettings()
794 if (!validateStructure())
796 structureTab.requestFocusInWindow();
803 protected boolean validateStructure()
805 return validateChimeraPath();
813 public void startupFileTextfield_mouseClicked()
815 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
816 JalviewFileChooser chooser = JalviewFileChooser.forRead(
817 Cache.getProperty("LAST_DIRECTORY"), fileFormat);
818 chooser.setFileView(new JalviewFileView());
819 chooser.setDialogTitle(MessageManager
820 .getString("label.select_startup_file"));
822 int value = chooser.showOpenDialog(this);
824 if (value == JalviewFileChooser.APPROVE_OPTION)
826 FileFormatI format = chooser.getSelectedFormat();
829 Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
832 startupFileTextfield.setText(chooser.getSelectedFile()
844 public void cancel_actionPerformed(ActionEvent e)
848 wsPrefs.updateWsMenuConfig(true);
849 wsPrefs.refreshWs_actionPerformed(e);
850 frame.setClosed(true);
851 } catch (Exception ex)
863 public void annotations_actionPerformed(ActionEvent e)
865 conservation.setEnabled(annotations.isSelected());
866 quality.setEnabled(annotations.isSelected());
867 identity.setEnabled(annotations.isSelected());
868 showOccupancy.setEnabled(annotations.isSelected());
869 showGroupConsensus.setEnabled(annotations.isSelected());
870 showGroupConservation.setEnabled(annotations.isSelected());
871 showConsensHistogram.setEnabled(annotations.isSelected()
872 && (identity.isSelected() || showGroupConsensus.isSelected()));
873 showConsensLogo.setEnabled(annotations.isSelected()
874 && (identity.isSelected() || showGroupConsensus.isSelected()));
875 showInformationHistogram.setEnabled(annotations.isSelected());
876 showHMMLogo.setEnabled(annotations.isSelected());
880 public void newLink_actionPerformed(ActionEvent e)
882 GSequenceLink link = new GSequenceLink();
883 boolean valid = false;
886 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
887 MessageManager.getString("label.new_sequence_url_link"),
888 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
890 if (link.checkValid())
892 if (((UrlLinkTableModel) linkUrlTable.getModel())
893 .isUniqueName(link.getName()))
895 ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
896 link.getName(), link.getURL());
901 link.notifyDuplicate();
914 public void editLink_actionPerformed(ActionEvent e)
916 GSequenceLink link = new GSequenceLink();
918 int index = linkUrlTable.getSelectedRow();
921 // button no longer enabled if row is not selected
922 Cache.log.debug("Edit with no row selected in linkUrlTable");
926 int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
928 int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
930 String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
931 link.setName(oldName);
932 link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
934 boolean valid = false;
937 if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
938 MessageManager.getString("label.edit_sequence_url_link"),
939 JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION)
941 if (link.checkValid())
943 if ((oldName.equals(link.getName()))
944 || (((UrlLinkTableModel) linkUrlTable.getModel())
945 .isUniqueName(link.getName())))
947 linkUrlTable.setValueAt(link.getName(), index, nameCol);
948 linkUrlTable.setValueAt(link.getURL(), index, urlCol);
953 link.notifyDuplicate();
966 public void deleteLink_actionPerformed(ActionEvent e)
968 int index = linkUrlTable.getSelectedRow();
972 // button no longer enabled if row is not selected
973 Cache.log.debug("Delete with no row selected in linkUrlTable");
978 modelIndex = linkUrlTable.convertRowIndexToModel(index);
981 // make sure we use the model index to delete, and not the table index
982 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
987 public void defaultBrowser_mouseClicked(MouseEvent e)
989 JFileChooser chooser = new JFileChooser(".");
990 chooser.setDialogTitle(MessageManager
991 .getString("label.select_default_browser"));
993 int value = chooser.showOpenDialog(this);
995 if (value == JFileChooser.APPROVE_OPTION)
997 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1006 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1010 protected void showunconserved_actionPerformed(ActionEvent e)
1012 // TODO Auto-generated method stub
1013 super.showunconserved_actionPerformed(e);
1016 public static List<String> getGroupURLLinks()
1018 return groupURLLinks;
1022 public void minColour_actionPerformed(JPanel panel)
1024 Color col = JColorChooser.showDialog(this,
1025 MessageManager.getString("label.select_colour_minimum_value"),
1026 minColour.getBackground());
1029 panel.setBackground(col);
1035 public void maxColour_actionPerformed(JPanel panel)
1037 Color col = JColorChooser.showDialog(this,
1038 MessageManager.getString("label.select_colour_maximum_value"),
1039 maxColour.getBackground());
1042 panel.setBackground(col);
1048 protected void userIdWidth_actionPerformed()
1052 String val = userIdWidth.getText().trim();
1053 if (val.length() > 0)
1055 Integer iw = Integer.parseInt(val);
1056 if (iw.intValue() < 12)
1058 throw new NumberFormatException();
1060 userIdWidth.setText(iw.toString());
1062 } catch (NumberFormatException x)
1064 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
1065 .getString("warn.user_defined_width_requirements"),
1066 MessageManager.getString("label.invalid_id_column_width"),
1067 JvOptionPane.WARNING_MESSAGE);
1068 userIdWidth.setText("");
1073 protected void autoIdWidth_actionPerformed()
1075 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1076 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1080 * Returns true if chimera path is to a valid executable, else show an error
1083 private boolean validateChimeraPath()
1085 if (chimeraPath.getText().trim().length() > 0)
1087 File f = new File(chimeraPath.getText());
1088 if (!f.canExecute())
1090 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1091 MessageManager.getString("label.invalid_chimera_path"),
1092 MessageManager.getString("label.invalid_name"),
1093 JvOptionPane.ERROR_MESSAGE);
1101 * Returns true if hmmer path contains the necessary valid executables, else show an error
1104 private boolean validateHMMERPath()
1106 String path = Cache.getProperty("HMMERPATH");
1107 if (path.length() > 0)
1109 File f = new File(path);
1110 if (!f.canExecute())
1112 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1113 MessageManager.getString("label.invalid_hmmer_folder"),
1114 MessageManager.getString("Invalid folder"),
1115 JvOptionPane.ERROR_MESSAGE);
1123 * If Chimera is selected, check it can be found on default or user-specified
1124 * path, if not show a warning/help dialog.
1127 protected void structureViewer_actionPerformed(String selectedItem)
1129 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1133 boolean found = false;
1136 * Try user-specified and standard paths for Chimera executable.
1138 List<String> paths = StructureManager.getChimeraPaths();
1139 paths.add(0, chimeraPath.getText());
1140 for (String path : paths)
1142 if (new File(path.trim()).canExecute())
1150 String[] options = { "OK", "Help" };
1151 int showHelp = JvOptionPane.showInternalOptionDialog(
1153 JvSwingUtils.wrapTooltip(true,
1154 MessageManager.getString("label.chimera_missing")),
1155 "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1156 null, options, options[0]);
1157 if (showHelp == JvOptionPane.NO_OPTION)
1161 Help.showHelpWindow(HelpId.StructureViewer);
1162 } catch (HelpSetException e)
1164 e.printStackTrace();
1170 public class OptionsParam
1172 private String name;
1174 private String code;
1176 public OptionsParam(String name, String code)
1182 public String getName()
1187 public void setName(String name)
1192 public String getCode()
1197 public void setCode(String code)
1203 public String toString()
1209 public boolean equals(Object that)
1211 if (!(that instanceof OptionsParam))
1215 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1219 public int hashCode()
1221 return name.hashCode() + code.hashCode();
1225 private class UrlListSelectionHandler implements ListSelectionListener
1229 public void valueChanged(ListSelectionEvent e)
1231 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1233 int index = lsm.getMinSelectionIndex();
1236 // no selection, so disable delete/edit buttons
1237 editLink.setEnabled(false);
1238 deleteLink.setEnabled(false);
1241 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1243 // enable/disable edit and delete link buttons
1244 if (((UrlLinkTableModel) linkUrlTable.getModel())
1245 .isRowDeletable(modelIndex))
1247 deleteLink.setEnabled(true);
1251 deleteLink.setEnabled(false);
1254 if (((UrlLinkTableModel) linkUrlTable.getModel())
1255 .isRowEditable(modelIndex))
1257 editLink.setEnabled(true);
1261 editLink.setEnabled(false);