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.JalviewFileChooser;
28 import jalview.io.JalviewFileView;
29 import jalview.jbgui.GPreferences;
30 import jalview.jbgui.GSequenceLink;
31 import jalview.schemes.ColourSchemeProperty;
32 import jalview.urls.UrlLinkTableModel;
33 import jalview.urls.UrlProvider;
34 import jalview.urls.UrlProviderI;
35 import jalview.util.MessageManager;
36 import jalview.util.Platform;
37 import jalview.ws.sifts.SiftsSettings;
39 import java.awt.BorderLayout;
40 import java.awt.Color;
41 import java.awt.Component;
42 import java.awt.Dimension;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.awt.event.MouseEvent;
48 import java.util.ArrayList;
49 import java.util.List;
51 import javax.help.HelpSetException;
52 import javax.swing.JColorChooser;
53 import javax.swing.JFileChooser;
54 import javax.swing.JInternalFrame;
55 import javax.swing.JOptionPane;
56 import javax.swing.JPanel;
57 import javax.swing.ListSelectionModel;
58 import javax.swing.RowFilter;
59 import javax.swing.RowSorter;
60 import javax.swing.SortOrder;
61 import javax.swing.event.DocumentEvent;
62 import javax.swing.event.DocumentListener;
63 import javax.swing.event.ListSelectionEvent;
64 import javax.swing.event.ListSelectionListener;
65 import javax.swing.table.TableCellRenderer;
66 import javax.swing.table.TableColumn;
67 import javax.swing.table.TableModel;
68 import javax.swing.table.TableRowSorter;
70 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
78 public class Preferences extends GPreferences
80 public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
82 public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
84 public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
86 public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
88 public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
90 public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
92 public static final String ADD_SS_ANN = "ADD_SS_ANN";
94 public static final String USE_RNAVIEW = "USE_RNAVIEW";
96 public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
98 public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
100 public static final String CHIMERA_PATH = "CHIMERA_PATH";
102 public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
104 public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
106 private static final int MIN_FONT_SIZE = 1;
108 private static final int MAX_FONT_SIZE = 30;
111 * Holds name and link separated with | character. Sequence ID must be
112 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
114 public static UrlProviderI sequenceUrlLinks;
116 public static UrlLinkTableModel dataModel;
119 * Holds name and link separated with | character. Sequence IDS and Sequences
120 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
121 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
122 * for first and second token specified after a pipe character at end |,|.
123 * (TODO: proper escape for using | to separate ids or sequences
126 public static List<String> groupURLLinks;
129 String string = Cache.getDefault("SEQUENCE_LINKS",
130 UrlProviderI.DEFAULT_STRING);
131 sequenceUrlLinks = new UrlProvider(UrlProviderI.DEFAULT_LABEL, string);
133 List<String> colNames = new ArrayList<String>();
134 // colNames.add("ID");
135 // TODO KM add to properties file
137 colNames.add("In Menu");
138 colNames.add("Default");
139 dataModel = new UrlLinkTableModel(sequenceUrlLinks, colNames, "ID");
142 * TODO: reformulate groupURL encoding so two or more can be stored in the
143 * .properties file as '|' separated strings
146 groupURLLinks = new ArrayList<String>();
149 JInternalFrame frame;
151 DasSourceBrowser dasSource;
153 private WsPreferences wsPrefs;
155 private OptionsParam promptEachTimeOpt = new OptionsParam(
156 MessageManager.getString("label.prompt_each_time"),
159 private OptionsParam lineArtOpt = new OptionsParam(
160 MessageManager.getString("label.lineart"), "Lineart");
162 private OptionsParam textOpt = new OptionsParam(
163 MessageManager.getString("action.text"), "Text");
166 * Creates a new Preferences object.
171 frame = new JInternalFrame();
172 frame.setContentPane(this);
173 dasSource = new DasSourceBrowser();
174 dasTab.add(dasSource, BorderLayout.CENTER);
175 wsPrefs = new WsPreferences();
176 wsTab.add(wsPrefs, BorderLayout.CENTER);
177 int width = 500, height = 450;
178 new jalview.util.Platform();
179 if (Platform.isAMac())
185 Desktop.addInternalFrame(frame,
186 MessageManager.getString("label.preferences"), width, height);
187 frame.setMinimumSize(new Dimension(width, height));
190 * Set Visual tab defaults
192 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
193 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
194 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
195 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
197 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
198 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
199 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
200 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
202 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
203 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
205 showGroupConservation.setSelected(Cache.getDefault(
206 "SHOW_GROUP_CONSERVATION", false));
207 showConsensHistogram.setSelected(Cache.getDefault(
208 "SHOW_CONSENSUS_HISTOGRAM", true));
209 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
211 showNpTooltip.setSelected(Cache
212 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
213 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
216 String[] fonts = java.awt.GraphicsEnvironment
217 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
218 for (int i = 0; i < fonts.length; i++)
220 fontNameCB.addItem(fonts[i]);
223 for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
225 fontSizeCB.addItem(i + "");
228 fontStyleCB.addItem("plain");
229 fontStyleCB.addItem("bold");
230 fontStyleCB.addItem("italic");
232 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
233 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
234 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
237 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
238 scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA,
241 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
243 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
245 gapSymbolCB.addItem("-");
246 gapSymbolCB.addItem(".");
248 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
250 sortby.addItem("No sort");
251 sortby.addItem("Id");
252 sortby.addItem("Pairwise Identity");
253 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
255 sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
257 .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
259 .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
260 SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
261 .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
262 SequenceAnnotationOrder.NONE.name()));
263 sortAnnBy.setSelectedItem(savedSort.toString());
265 sortAutocalc.addItem("Autocalculated first");
266 sortAutocalc.addItem("Autocalculated last");
267 final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
268 sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
269 : sortAutocalc.getItemAt(1));
271 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
272 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
273 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
274 + "/examples/exampleFile_2_3.jar"));
277 * Set Colours tab defaults
279 for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
281 protColour.addItem(ColourSchemeProperty.getColourName(i));
282 nucColour.addItem(ColourSchemeProperty.getColourName(i));
284 String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None");
285 String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
286 protColour.setSelectedItem(newProp != null ? newProp : oldProp);
287 newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
288 nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
289 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
291 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
295 * Set Structure tab defaults.
297 final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
298 structFromPdb.setSelected(structSelected);
299 useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
300 useRnaView.setEnabled(structSelected);
301 addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
302 addSecondaryStructure.setEnabled(structSelected);
303 addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
304 addTempFactor.setEnabled(structSelected);
305 structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY,
306 ViewerType.JMOL.name()));
307 chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
308 chimeraPath.addActionListener(new ActionListener()
311 public void actionPerformed(ActionEvent e)
313 validateChimeraPath();
317 if (Cache.getDefault("MAP_WITH_SIFTS", false))
319 siftsMapping.setSelected(true);
323 nwMapping.setSelected(true);
327 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
330 * Set Connections tab defaults
334 linkUrlTable.setModel(dataModel);
335 final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
336 linkUrlTable.getModel());
337 linkUrlTable.setRowSorter(sorter);
338 List<RowSorter.SortKey> sortKeys = new ArrayList<>();
340 sortKeys.add(new RowSorter.SortKey(3,
341 SortOrder.DESCENDING));
342 sortKeys.add(new RowSorter.SortKey(2, SortOrder.DESCENDING));
343 sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
345 sorter.setSortKeys(sortKeys);
349 ActionListener onReset;
350 onReset = new ActionListener()
353 public void actionPerformed(ActionEvent e)
355 filterTB.setText("");
356 sorter.setRowFilter(RowFilter.regexFilter(""));
360 doReset.addActionListener(onReset);
362 // filter to display only custom urls
363 final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
366 public boolean include(
367 Entry<? extends TableModel, ? extends Object> entry)
369 String id = entry.getStringValue(4);
370 return sequenceUrlLinks.isUserEntry(id);
374 final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
375 linkUrlTable.getModel());
376 customSorter.setRowFilter(customUrlFilter);
378 ActionListener onCustomOnly;
379 onCustomOnly = new ActionListener()
382 public void actionPerformed(ActionEvent e)
384 filterTB.setText("");
385 sorter.setRowFilter(customUrlFilter);
388 userOnly.addActionListener(onCustomOnly);
390 filterTB.getDocument().addDocumentListener(new DocumentListener()
393 public void changedUpdate(DocumentEvent e)
395 sorter.setRowFilter(RowFilter.regexFilter("(?i)"
396 + filterTB.getText()));
400 public void removeUpdate(DocumentEvent e)
402 sorter.setRowFilter(RowFilter.regexFilter("(?i)"
403 + filterTB.getText()));
407 public void insertUpdate(DocumentEvent e)
409 sorter.setRowFilter(RowFilter.regexFilter("(?i)"
410 + filterTB.getText()));
414 // set up list selection functionality
415 linkUrlTable.getSelectionModel().addListSelectionListener(
416 new UrlListSelectionHandler());
418 // set up radio buttons
419 linkUrlTable.getColumn("Default").setCellRenderer(
420 new RadioButtonRenderer());
421 linkUrlTable.getColumn("Default")
422 .setCellEditor(new RadioButtonEditor());
424 // get boolean columns and resize those to min possible
425 for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
427 if (linkUrlTable.getModel().getColumnClass(column)
428 .equals(Boolean.class))
430 TableColumn tableColumn = linkUrlTable.getColumnModel().getColumn(
432 int preferredWidth = tableColumn.getMinWidth();
434 TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
436 Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
437 int cwidth = c.getPreferredSize().width
438 + linkUrlTable.getIntercellSpacing().width;
439 preferredWidth = Math.max(preferredWidth, cwidth);
441 tableColumn.setPreferredWidth(preferredWidth);
445 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
446 useProxy_actionPerformed(); // make sure useProxy is correctly initialised
447 proxyServerTB.setEnabled(useProxy.isSelected());
448 proxyPortTB.setEnabled(useProxy.isSelected());
449 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
450 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
452 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
454 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
455 // note antisense here: default is true
457 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
458 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
461 * Set Output tab defaults
463 epsRendering.addItem(promptEachTimeOpt);
464 epsRendering.addItem(lineArtOpt);
465 epsRendering.addItem(textOpt);
466 String defaultEPS = Cache.getDefault("EPS_RENDERING",
468 if (defaultEPS.equalsIgnoreCase("Text"))
470 epsRendering.setSelectedItem(textOpt);
472 else if (defaultEPS.equalsIgnoreCase("Lineart"))
474 epsRendering.setSelectedItem(lineArtOpt);
478 epsRendering.setSelectedItem(promptEachTimeOpt);
480 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
481 userIdWidth.setEnabled(!autoIdWidth.isSelected());
482 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
483 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
484 userIdWidth.setText(wi == null ? "" : wi.toString());
485 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
486 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
487 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
488 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
489 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
490 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
491 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
492 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
493 embbedBioJSON.setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON",
497 * Set Editing tab defaults
499 autoCalculateConsCheck.setSelected(Cache.getDefault(
500 "AUTO_CALC_CONSENSUS", true));
501 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
502 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
504 annotations_actionPerformed(null); // update the display of the annotation
509 * Save user selections on the Preferences tabs to the Cache and write out to
515 public void ok_actionPerformed(ActionEvent e)
517 if (!validateSettings())
523 * Save Visual settings
525 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
526 Boolean.toString(seqLimit.isSelected()));
527 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
528 Boolean.toString(rightAlign.isSelected()));
529 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
530 Boolean.toString(fullScreen.isSelected()));
531 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
532 Boolean.toString(openoverv.isSelected()));
533 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
534 Boolean.toString(annotations.isSelected()));
535 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
536 Boolean.toString(conservation.isSelected()));
537 Cache.applicationProperties.setProperty("SHOW_QUALITY",
538 Boolean.toString(quality.isSelected()));
539 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
540 Boolean.toString(identity.isSelected()));
542 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
543 .getSelectedItem().toString());
545 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
546 .getSelectedItem().toString());
547 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
548 .getSelectedItem().toString());
549 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
550 .getSelectedItem().toString());
552 Cache.applicationProperties.setProperty("ID_ITALICS",
553 Boolean.toString(idItalics.isSelected()));
554 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
555 Boolean.toString(showUnconserved.isSelected()));
556 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
557 Boolean.toString(showGroupConsensus.isSelected()));
558 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
559 Boolean.toString(showGroupConservation.isSelected()));
560 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
561 Boolean.toString(showConsensHistogram.isSelected()));
562 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
563 Boolean.toString(showConsensLogo.isSelected()));
564 Cache.applicationProperties.setProperty("ANTI_ALIAS",
565 Boolean.toString(smoothFont.isSelected()));
566 Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
567 Boolean.toString(scaleProteinToCdna.isSelected()));
568 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
569 Boolean.toString(showNpTooltip.isSelected()));
570 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
571 Boolean.toString(showDbRefTooltip.isSelected()));
573 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
574 Boolean.toString(wrap.isSelected()));
576 Cache.applicationProperties.setProperty("STARTUP_FILE",
577 startupFileTextfield.getText());
578 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
579 Boolean.toString(startupCheckbox.isSelected()));
581 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
582 .getSelectedItem().toString());
584 // convert description of sort order to enum name for save
585 SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
586 .forDescription(sortAnnBy.getSelectedItem().toString());
587 if (annSortOrder != null)
589 Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
590 annSortOrder.name());
593 final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
594 Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE, Boolean
595 .valueOf(showAutocalcFirst).toString());
598 * Save Colours settings
600 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour
601 .getSelectedItem().toString());
602 Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour
603 .getSelectedItem().toString());
604 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
605 minColour.getBackground());
606 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
607 maxColour.getBackground());
610 * Save Structure settings
612 Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
613 Boolean.toString(addTempFactor.isSelected()));
614 Cache.applicationProperties.setProperty(ADD_SS_ANN,
615 Boolean.toString(addSecondaryStructure.isSelected()));
616 Cache.applicationProperties.setProperty(USE_RNAVIEW,
617 Boolean.toString(useRnaView.isSelected()));
618 Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
619 Boolean.toString(structFromPdb.isSelected()));
620 Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY, structViewer
621 .getSelectedItem().toString());
622 Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
623 Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
624 Boolean.toString(siftsMapping.isSelected()));
625 SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
628 * Save Output settings
630 Cache.applicationProperties.setProperty("EPS_RENDERING",
631 ((OptionsParam) epsRendering.getSelectedItem()).getCode());
634 * Save Connections settings
636 Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
638 jalview.util.BrowserLauncher.resetBrowser();
640 // save user-defined and selected links
641 String links = linkUrlTable.getModel().toString();
644 Cache.applicationProperties.remove("SEQUENCE_LINKS");
648 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
652 Cache.applicationProperties.setProperty("USE_PROXY",
653 Boolean.toString(useProxy.isSelected()));
655 Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
657 Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
659 if (useProxy.isSelected())
661 System.setProperty("http.proxyHost", proxyServerTB.getText());
662 System.setProperty("http.proxyPort", proxyPortTB.getText());
666 System.setProperty("http.proxyHost", "");
667 System.setProperty("http.proxyPort", "");
669 Cache.setProperty("VERSION_CHECK",
670 Boolean.toString(versioncheck.isSelected()));
671 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
673 // default is false - we only set this if the user has actively agreed
674 Cache.setProperty("USAGESTATS",
675 Boolean.toString(usagestats.isSelected()));
677 if (!questionnaire.isSelected())
679 Cache.setProperty("NOQUESTIONNAIRES", "true");
683 // special - made easy to edit a property file to disable questionnaires
684 // by just adding the given line
685 Cache.removeProperty("NOQUESTIONNAIRES");
689 * Save Output settings
691 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
692 Boolean.toString(blcjv.isSelected()));
693 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
694 Boolean.toString(clustaljv.isSelected()));
695 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
696 Boolean.toString(fastajv.isSelected()));
697 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
698 Boolean.toString(msfjv.isSelected()));
699 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
700 Boolean.toString(pfamjv.isSelected()));
701 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
702 Boolean.toString(pileupjv.isSelected()));
703 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
704 Boolean.toString(pirjv.isSelected()));
705 Cache.applicationProperties.setProperty("PIR_MODELLER",
706 Boolean.toString(modellerOutput.isSelected()));
707 Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
708 Boolean.toString(embbedBioJSON.isSelected()));
709 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
711 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
712 Boolean.toString(autoIdWidth.isSelected()));
713 userIdWidth_actionPerformed();
714 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
715 userIdWidth.getText());
718 * Save Editing settings
720 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
721 Boolean.toString(autoCalculateConsCheck.isSelected()));
722 Cache.applicationProperties.setProperty("SORT_BY_TREE",
723 Boolean.toString(sortByTree.isSelected()));
724 Cache.applicationProperties.setProperty("PAD_GAPS",
725 Boolean.toString(padGaps.isSelected()));
727 dasSource.saveProperties(Cache.applicationProperties);
728 wsPrefs.updateAndRefreshWsMenuConfig(false);
729 Cache.saveProperties();
730 Desktop.instance.doConfigureStructurePrefs();
733 frame.setClosed(true);
734 } catch (Exception ex)
740 * Do any necessary validation before saving settings. Return focus to the
741 * first tab which fails validation.
745 private boolean validateSettings()
747 if (!validateStructure())
749 structureTab.requestFocusInWindow();
756 protected boolean validateStructure()
758 return validateChimeraPath();
766 public void startupFileTextfield_mouseClicked()
768 JalviewFileChooser chooser = new JalviewFileChooser(
769 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] {
770 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
771 "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF",
772 "PIR", "BLC", "Jalview" },
773 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
774 chooser.setFileView(new JalviewFileView());
775 chooser.setDialogTitle(MessageManager
776 .getString("label.select_startup_file"));
778 int value = chooser.showOpenDialog(this);
780 if (value == JalviewFileChooser.APPROVE_OPTION)
782 jalview.bin.Cache.applicationProperties.setProperty(
783 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
784 startupFileTextfield.setText(chooser.getSelectedFile()
796 public void cancel_actionPerformed(ActionEvent e)
800 wsPrefs.updateWsMenuConfig(true);
801 wsPrefs.refreshWs_actionPerformed(e);
802 frame.setClosed(true);
803 } catch (Exception ex)
815 public void annotations_actionPerformed(ActionEvent e)
817 conservation.setEnabled(annotations.isSelected());
818 quality.setEnabled(annotations.isSelected());
819 identity.setEnabled(annotations.isSelected());
820 showGroupConsensus.setEnabled(annotations.isSelected());
821 showGroupConservation.setEnabled(annotations.isSelected());
822 showConsensHistogram.setEnabled(annotations.isSelected()
823 && (identity.isSelected() || showGroupConsensus.isSelected()));
824 showConsensLogo.setEnabled(annotations.isSelected()
825 && (identity.isSelected() || showGroupConsensus.isSelected()));
829 public void newLink_actionPerformed(ActionEvent e)
832 GSequenceLink link = new GSequenceLink();
833 boolean valid = false;
836 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
837 MessageManager.getString("label.new_sequence_url_link"),
838 JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
840 if (link.checkValid())
842 ((UrlLinkTableModel) linkUrlTable.getModel()).insertRow(
843 link.getName(), link.getURL());
855 public void editLink_actionPerformed(ActionEvent e)
857 GSequenceLink link = new GSequenceLink();
859 int index = linkUrlTable.getSelectedRow();
862 // no row was selected
863 JOptionPane.showInternalMessageDialog(Desktop.desktop,
864 MessageManager.getString("label.no_link_selected"),
865 MessageManager.getString("label.no_link_selected"),
866 JOptionPane.WARNING_MESSAGE);
870 link.setName(linkUrlTable.getValueAt(index, 0).toString());
871 link.setURL(linkUrlTable.getValueAt(index, 1).toString());
873 boolean valid = false;
877 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
878 MessageManager.getString("label.new_sequence_url_link"),
879 JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
881 if (link.checkValid())
884 linkUrlTable.setValueAt(link.getName(), index, 0);
885 linkUrlTable.setValueAt(link.getURL(), index, 1);
897 public void deleteLink_actionPerformed(ActionEvent e)
899 int index = linkUrlTable.getSelectedRow();
903 // no row is selected
904 JOptionPane.showInternalMessageDialog(Desktop.desktop,
905 MessageManager.getString("label.no_link_selected"),
906 MessageManager.getString("label.no_link_selected"),
907 JOptionPane.WARNING_MESSAGE);
912 modelIndex = linkUrlTable.convertRowIndexToModel(index);
915 // make sure we use the model index to delete, and not the table index
916 ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
921 public void defaultBrowser_mouseClicked(MouseEvent e)
923 JFileChooser chooser = new JFileChooser(".");
924 chooser.setDialogTitle(MessageManager
925 .getString("label.select_default_browser"));
927 int value = chooser.showOpenDialog(this);
929 if (value == JFileChooser.APPROVE_OPTION)
931 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
940 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
944 protected void showunconserved_actionPerformed(ActionEvent e)
946 // TODO Auto-generated method stub
947 super.showunconserved_actionPerformed(e);
950 public static List<String> getGroupURLLinks()
952 return groupURLLinks;
956 public void minColour_actionPerformed(JPanel panel)
958 Color col = JColorChooser.showDialog(this,
959 MessageManager.getString("label.select_colour_minimum_value"),
960 minColour.getBackground());
963 panel.setBackground(col);
969 public void maxColour_actionPerformed(JPanel panel)
971 Color col = JColorChooser.showDialog(this,
972 MessageManager.getString("label.select_colour_maximum_value"),
973 maxColour.getBackground());
976 panel.setBackground(col);
982 protected void userIdWidth_actionPerformed()
986 String val = userIdWidth.getText().trim();
987 if (val.length() > 0)
989 Integer iw = Integer.parseInt(val);
990 if (iw.intValue() < 12)
992 throw new NumberFormatException();
994 userIdWidth.setText(iw.toString());
996 } catch (NumberFormatException x)
998 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
999 .getString("warn.user_defined_width_requirements"),
1000 MessageManager.getString("label.invalid_id_column_width"),
1001 JOptionPane.WARNING_MESSAGE);
1002 userIdWidth.setText("");
1007 protected void autoIdWidth_actionPerformed()
1009 userIdWidth.setEnabled(!autoIdWidth.isSelected());
1010 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1014 * Returns true if chimera path is to a valid executable, else show an error
1017 private boolean validateChimeraPath()
1019 if (chimeraPath.getText().trim().length() > 0)
1021 File f = new File(chimeraPath.getText());
1022 if (!f.canExecute())
1024 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1025 MessageManager.getString("label.invalid_chimera_path"),
1026 MessageManager.getString("label.invalid_name"),
1027 JOptionPane.ERROR_MESSAGE);
1035 * If Chimera is selected, check it can be found on default or user-specified
1036 * path, if not show a warning/help dialog.
1039 protected void structureViewer_actionPerformed(String selectedItem)
1041 if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1045 boolean found = false;
1048 * Try user-specified and standard paths for Chimera executable.
1050 List<String> paths = StructureManager.getChimeraPaths();
1051 paths.add(0, chimeraPath.getText());
1052 for (String path : paths)
1054 if (new File(path.trim()).canExecute())
1062 String[] options = { "OK", "Help" };
1063 int showHelp = JOptionPane.showInternalOptionDialog(
1065 JvSwingUtils.wrapTooltip(true,
1066 MessageManager.getString("label.chimera_missing")),
1067 "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
1068 null, options, options[0]);
1069 if (showHelp == JOptionPane.NO_OPTION)
1073 Help.showHelpWindow(HelpId.StructureViewer);
1074 } catch (HelpSetException e)
1076 e.printStackTrace();
1082 public class OptionsParam
1084 private String name;
1086 private String code;
1088 public OptionsParam(String name, String code)
1094 public String getName()
1099 public void setName(String name)
1104 public String getCode()
1109 public void setCode(String code)
1115 public String toString()
1121 public boolean equals(Object that)
1123 if (!(that instanceof OptionsParam))
1127 return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1131 public int hashCode()
1133 return name.hashCode() + code.hashCode();
1137 private class UrlListSelectionHandler implements ListSelectionListener
1141 public void valueChanged(ListSelectionEvent e)
1143 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1145 int index = lsm.getMinSelectionIndex();
1148 // no selection, so disable delete/edit buttons
1149 editLink.setEnabled(false);
1150 deleteLink.setEnabled(false);
1153 int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1155 // determine if the new selection is a custom url or not
1156 if (!sequenceUrlLinks.isUserEntry((String) linkUrlTable
1158 .getValueAt(modelIndex, 4))) // KM TODO do this better
1160 // entry is not a user-defined url and so should not be edited
1161 // disable edit and delete buttons
1162 deleteLink.setEnabled(false);
1163 editLink.setEnabled(false);
1167 deleteLink.setEnabled(true);
1168 editLink.setEnabled(true);
1171 // BUT it's the default url, don't allow deletion
1172 if ((boolean) linkUrlTable.getValueAt(index, 3))
1174 deleteLink.setEnabled(false);