2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3 * Copyright (C) 2014 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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.event.*;
30 import jalview.jbgui.*;
31 import jalview.schemes.*;
32 import jalview.util.MessageManager;
40 public class Preferences extends GPreferences
44 * Holds name and link separated with | character. Sequence ID must be
45 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
47 public static Vector sequenceURLLinks;
50 * Holds name and link separated with | character. Sequence IDS and Sequences
51 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
52 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
53 * for first and second token specified after a pipe character at end |,|.
54 * (TODO: proper escape for using | to separate ids or sequences
57 public static Vector groupURLLinks;
63 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
64 sequenceURLLinks = new Vector();
68 StringTokenizer st = new StringTokenizer(string, "|");
69 while (st.hasMoreElements())
71 String name = st.nextToken();
72 String url = st.nextToken();
73 // check for '|' within a regex
74 int rxstart = url.indexOf("$SEQUENCE_ID$");
75 while (rxstart == -1 && url.indexOf("/=$") == -1)
77 url = url + "|" + st.nextToken();
79 sequenceURLLinks.addElement(name + "|" + url);
81 } catch (Exception ex)
83 System.out.println(ex + "\nError parsing sequence links");
86 // upgrade old SRS link
87 int srsPos = sequenceURLLinks
88 .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
91 sequenceURLLinks.setElementAt(
92 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
98 * TODO: reformulate groupURL encoding so two or more can be stored in the
99 * .properties file as '|' separated strings
102 groupURLLinks = new Vector();
105 Vector nameLinks, urlLinks;
107 JInternalFrame frame;
109 DasSourceBrowser dasSource;
111 private WsPreferences wsPrefs;
114 * Creates a new Preferences object.
119 frame = new JInternalFrame();
120 frame.setContentPane(this);
121 dasSource = new DasSourceBrowser();
122 dasPanel.add(dasSource, BorderLayout.CENTER);
123 wsPrefs = new WsPreferences();
124 wsPanel.add(wsPrefs, BorderLayout.CENTER);
125 int width = 500, height = 420;
126 if (new jalview.util.Platform().isAMac())
132 Desktop.addInternalFrame(frame, MessageManager.getString("label.preferences"), width, height);
133 frame.setMinimumSize(new Dimension(width, height));
135 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
136 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
137 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
138 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
140 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
141 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
142 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
143 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
145 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
146 showNpTooltip.setSelected(Cache
147 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
148 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
150 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
151 for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
153 colour.addItem(ColourSchemeProperty.getColourName(i));
156 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
158 colour.setSelectedItem(string);
161 * default min-max colours for annotation shading
163 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
165 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
168 String[] fonts = java.awt.GraphicsEnvironment
169 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
171 for (int i = 0; i < fonts.length; i++)
173 fontNameCB.addItem(fonts[i]);
176 for (int i = 1; i < 31; i++)
178 fontSizeCB.addItem(i + "");
181 fontStyleCB.addItem("plain");
182 fontStyleCB.addItem("bold");
183 fontStyleCB.addItem("italic");
185 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
186 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
187 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
190 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
192 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
194 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
196 gapSymbolCB.addItem("-");
197 gapSymbolCB.addItem(".");
199 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
202 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
203 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
204 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
205 + "/examples/exampleFile_2_3.jar"));
207 sortby.addItem("No sort");
208 sortby.addItem("Id");
209 sortby.addItem("Pairwise Identity");
210 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
212 epsRendering.addItem("Prompt each time");
213 epsRendering.addItem("Lineart");
214 epsRendering.addItem("Text");
215 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
216 "Prompt each time"));
217 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
218 userIdWidth.setEnabled(autoIdWidth.isSelected());
219 userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
220 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
221 userIdWidth.setText(wi == null ? "" : wi.toString());
222 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
223 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
224 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
225 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
226 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
227 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
228 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
230 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
232 autoCalculateConsCheck.setSelected(Cache.getDefault(
233 "AUTO_CALC_CONSENSUS", true));
234 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
236 showGroupConservation.setSelected(Cache.getDefault(
237 "SHOW_GROUP_CONSERVATION", false));
238 showConsensHistogram.setSelected(Cache.getDefault(
239 "SHOW_CONSENSUS_HISTOGRAM", true));
240 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
243 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
245 /***************************************************************************
248 nameLinks = new Vector();
249 urlLinks = new Vector();
250 for (int i = 0; i < sequenceURLLinks.size(); i++)
252 String link = sequenceURLLinks.elementAt(i).toString();
253 nameLinks.addElement(link.substring(0, link.indexOf("|")));
254 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
259 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
260 proxyServerTB.setEnabled(useProxy.isSelected());
261 proxyPortTB.setEnabled(useProxy.isSelected());
262 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
263 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
265 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
267 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
269 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
272 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
275 annotations_actionPerformed(null); // update the display of the annotation
280 } catch (Exception ex)
282 ex.printStackTrace();
293 public void ok_actionPerformed(ActionEvent e)
296 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
297 Boolean.toString(seqLimit.isSelected()));
298 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
299 Boolean.toString(rightAlign.isSelected()));
300 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
301 Boolean.toString(fullScreen.isSelected()));
302 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
303 Boolean.toString(openoverv.isSelected()));
304 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
305 Boolean.toString(annotations.isSelected()));
306 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
307 Boolean.toString(conservation.isSelected()));
308 Cache.applicationProperties.setProperty("SHOW_QUALITY",
309 Boolean.toString(quality.isSelected()));
310 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
311 Boolean.toString(identity.isSelected()));
313 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
314 .getSelectedItem().toString());
315 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
316 .getSelectedItem().toString());
318 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
319 .getSelectedItem().toString());
320 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
321 .getSelectedItem().toString());
322 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
323 .getSelectedItem().toString());
325 Cache.applicationProperties.setProperty("ID_ITALICS",
326 Boolean.toString(idItalics.isSelected()));
327 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
328 Boolean.toString(showUnconserved.isSelected()));
329 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
330 Boolean.toString(showGroupConsensus.isSelected()));
331 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
332 Boolean.toString(showGroupConservation.isSelected()));
333 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
334 Boolean.toString(showConsensHistogram.isSelected()));
335 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
336 Boolean.toString(showConsensLogo.isSelected()));
337 Cache.applicationProperties.setProperty("ANTI_ALIAS",
338 Boolean.toString(smoothFont.isSelected()));
339 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
340 Boolean.toString(showNpTooltip.isSelected()));
341 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
342 Boolean.toString(showDbRefTooltip.isSelected()));
344 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
345 Boolean.toString(wrap.isSelected()));
347 Cache.applicationProperties.setProperty("STARTUP_FILE",
348 startupFileTextfield.getText());
349 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
350 Boolean.toString(startupCheckbox.isSelected()));
352 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
353 .getSelectedItem().toString());
355 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
356 minColour.getBackground());
357 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
358 maxColour.getBackground());
360 if (epsRendering.getSelectedItem().equals("Prompt each time"))
362 Cache.applicationProperties.remove("EPS_RENDERING");
366 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
367 .getSelectedItem().toString());
370 if (defaultBrowser.getText().trim().length() < 1)
372 Cache.applicationProperties.remove("DEFAULT_BROWSER");
376 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
377 defaultBrowser.getText());
380 jalview.util.BrowserLauncher.resetBrowser();
382 if (nameLinks.size() > 0)
384 StringBuffer links = new StringBuffer();
385 sequenceURLLinks = new Vector();
386 for (int i = 0; i < nameLinks.size(); i++)
388 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
389 + urlLinks.elementAt(i));
390 links.append(sequenceURLLinks.elementAt(i).toString());
394 links.setLength(links.length() - 1);
395 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
400 Cache.applicationProperties.remove("SEQUENCE_LINKS");
403 Cache.applicationProperties.setProperty("USE_PROXY",
404 Boolean.toString(useProxy.isSelected()));
406 if (proxyServerTB.getText().trim().length() < 1)
408 Cache.applicationProperties.remove("PROXY_SERVER");
412 Cache.applicationProperties.setProperty("PROXY_SERVER",
413 proxyServerTB.getText());
416 if (proxyPortTB.getText().trim().length() < 1)
418 Cache.applicationProperties.remove("PROXY_PORT");
422 Cache.applicationProperties.setProperty("PROXY_PORT",
423 proxyPortTB.getText());
426 if (useProxy.isSelected())
428 System.setProperty("http.proxyHost", proxyServerTB.getText());
429 System.setProperty("http.proxyPort", proxyPortTB.getText());
433 System.setProperty("http.proxyHost", "");
434 System.setProperty("http.proxyPort", "");
436 Cache.setProperty("VERSION_CHECK",
437 Boolean.toString(versioncheck.isSelected()));
438 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
440 // default is false - we only set this if the user has actively agreed
441 Cache.setProperty("USAGESTATS",
442 Boolean.toString(usagestats.isSelected()));
444 if (!questionnaire.isSelected())
446 Cache.setProperty("NOQUESTIONNAIRES", "true");
450 // special - made easy to edit a property file to disable questionnaires
451 // by just adding the given line
452 Cache.removeProperty("NOQUESTIONNAIRES");
454 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
455 Boolean.toString(blcjv.isSelected()));
456 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
457 Boolean.toString(clustaljv.isSelected()));
458 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
459 Boolean.toString(fastajv.isSelected()));
460 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
461 Boolean.toString(msfjv.isSelected()));
462 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
463 Boolean.toString(pfamjv.isSelected()));
464 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
465 Boolean.toString(pileupjv.isSelected()));
466 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
467 Boolean.toString(pirjv.isSelected()));
468 Cache.applicationProperties.setProperty("PIR_MODELLER",
469 Boolean.toString(modellerOutput.isSelected()));
470 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
472 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
473 Boolean.toString(autoIdWidth.isSelected()));
474 userIdWidth_actionPerformed();
475 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
476 userIdWidth.getText());
478 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
479 Boolean.toString(autoCalculateConsCheck.isSelected()));
480 Cache.applicationProperties.setProperty("SORT_BY_TREE",
481 Boolean.toString(sortByTree.isSelected()));
482 Cache.applicationProperties.setProperty("PAD_GAPS",
483 Boolean.toString(padGaps.isSelected()));
485 dasSource.saveProperties(Cache.applicationProperties);
486 wsPrefs.updateAndRefreshWsMenuConfig(false);
487 Cache.saveProperties();
490 frame.setClosed(true);
491 } catch (Exception ex)
499 public void startupFileTextfield_mouseClicked()
501 JalviewFileChooser chooser = new JalviewFileChooser(
502 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
504 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
506 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
507 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
508 chooser.setFileView(new JalviewFileView());
509 chooser.setDialogTitle("Select startup file");
511 int value = chooser.showOpenDialog(this);
513 if (value == JalviewFileChooser.APPROVE_OPTION)
515 jalview.bin.Cache.applicationProperties.setProperty(
516 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
517 startupFileTextfield.setText(chooser.getSelectedFile()
528 public void cancel_actionPerformed(ActionEvent e)
532 wsPrefs.updateWsMenuConfig(true);
533 wsPrefs.refreshWs_actionPerformed(e);
534 frame.setClosed(true);
535 } catch (Exception ex)
546 public void annotations_actionPerformed(ActionEvent e)
548 conservation.setEnabled(annotations.isSelected());
549 quality.setEnabled(annotations.isSelected());
550 identity.setEnabled(annotations.isSelected());
551 showGroupConsensus.setEnabled(annotations.isSelected());
552 showGroupConservation.setEnabled(annotations.isSelected());
553 showConsensHistogram.setEnabled(annotations.isSelected()
554 && (identity.isSelected() || showGroupConsensus.isSelected()));
555 showConsensLogo.setEnabled(annotations.isSelected()
556 && (identity.isSelected() || showGroupConsensus.isSelected()));
559 public void newLink_actionPerformed(ActionEvent e)
562 GSequenceLink link = new GSequenceLink();
563 boolean valid = false;
566 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
567 MessageManager.getString("label.new_sequence_url_link"), JOptionPane.OK_CANCEL_OPTION, -1,
568 null) == JOptionPane.OK_OPTION)
570 if (link.checkValid())
572 nameLinks.addElement(link.getName());
573 urlLinks.addElement(link.getURL());
585 public void editLink_actionPerformed(ActionEvent e)
587 GSequenceLink link = new GSequenceLink();
589 int index = linkNameList.getSelectedIndex();
592 JOptionPane.showInternalMessageDialog(Desktop.desktop,
593 MessageManager.getString("label.no_link_selected"), MessageManager.getString("label.no_link_selected"),
594 JOptionPane.WARNING_MESSAGE);
598 link.setName(nameLinks.elementAt(index).toString());
599 link.setURL(urlLinks.elementAt(index).toString());
601 boolean valid = false;
605 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
606 MessageManager.getString("label.new_sequence_url_link"), JOptionPane.OK_CANCEL_OPTION, -1,
607 null) == JOptionPane.OK_OPTION)
609 if (link.checkValid())
611 nameLinks.setElementAt(link.getName(), index);
612 urlLinks.setElementAt(link.getURL(), index);
625 public void deleteLink_actionPerformed(ActionEvent e)
627 int index = linkNameList.getSelectedIndex();
630 JOptionPane.showInternalMessageDialog(Desktop.desktop,
631 MessageManager.getString("label.no_link_selected"), MessageManager.getString("label.no_link_selected"),
632 JOptionPane.WARNING_MESSAGE);
635 nameLinks.removeElementAt(index);
636 urlLinks.removeElementAt(index);
640 void updateLinkData()
642 linkNameList.setListData(nameLinks);
643 linkURLList.setListData(urlLinks);
646 public void defaultBrowser_mouseClicked(MouseEvent e)
648 JFileChooser chooser = new JFileChooser(".");
649 chooser.setDialogTitle("Select default web browser");
651 int value = chooser.showOpenDialog(this);
653 if (value == JFileChooser.APPROVE_OPTION)
655 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
664 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
667 protected void showunconserved_actionPerformed(ActionEvent e)
669 // TODO Auto-generated method stub
670 super.showunconserved_actionPerformed(e);
673 private void jbInit() throws Exception
677 public static Collection getGroupURLLinks()
679 return groupURLLinks;
682 public void minColour_actionPerformed()
684 Color col = JColorChooser.showDialog(this,
685 "Select Colour for Minimum Value", minColour.getBackground());
688 minColour.setBackground(col);
693 public void maxColour_actionPerformed()
695 Color col = JColorChooser.showDialog(this,
696 "Select Colour for Maximum Value", maxColour.getBackground());
699 maxColour.setBackground(col);
705 protected void userIdWidth_actionPerformed()
709 String val = userIdWidth.getText().trim();
710 if (val.length() > 0)
712 Integer iw = Integer.parseInt(val);
713 if (iw.intValue() < 12)
715 throw new NumberFormatException();
717 userIdWidth.setText(iw.toString());
719 } catch (NumberFormatException x)
722 .showInternalMessageDialog(
724 "The user defined width for the\nannotation and sequence ID columns\nin exported figures must be\nat least 12 pixels wide.",
725 "Invalid ID Column width",
726 JOptionPane.WARNING_MESSAGE);
727 userIdWidth.setText("");
732 protected void autoIdWidth_actionPerformed()
734 userIdWidth.setEnabled(!autoIdWidth.isSelected());
735 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());