2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.
26 import java.awt.event.*;
32 import jalview.jbgui.*;
33 import jalview.schemes.*;
34 import jalview.util.MessageManager;
42 public class Preferences extends GPreferences
46 * Holds name and link separated with | character. Sequence ID must be
47 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
49 public static Vector sequenceURLLinks;
52 * Holds name and link separated with | character. Sequence IDS and Sequences
53 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
54 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
55 * for first and second token specified after a pipe character at end |,|.
56 * (TODO: proper escape for using | to separate ids or sequences
59 public static Vector groupURLLinks;
65 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
66 sequenceURLLinks = new Vector();
70 StringTokenizer st = new StringTokenizer(string, "|");
71 while (st.hasMoreElements())
73 String name = st.nextToken();
74 String url = st.nextToken();
75 // check for '|' within a regex
76 int rxstart = url.indexOf("$SEQUENCE_ID$");
77 while (rxstart == -1 && url.indexOf("/=$") == -1)
79 url = url + "|" + st.nextToken();
81 sequenceURLLinks.addElement(name + "|" + url);
83 } catch (Exception ex)
85 System.out.println(ex + "\nError parsing sequence links");
88 // upgrade old SRS link
89 int srsPos = sequenceURLLinks
90 .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
95 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
101 * TODO: reformulate groupURL encoding so two or more can be stored in the
102 * .properties file as '|' separated strings
105 groupURLLinks = new Vector();
108 Vector nameLinks, urlLinks;
110 JInternalFrame frame;
112 DasSourceBrowser dasSource;
114 private WsPreferences wsPrefs;
117 * Creates a new Preferences object.
122 frame = new JInternalFrame();
123 frame.setContentPane(this);
124 dasSource = new DasSourceBrowser();
125 dasPanel.add(dasSource, BorderLayout.CENTER);
126 wsPrefs = new WsPreferences();
127 wsPanel.add(wsPrefs, BorderLayout.CENTER);
128 int width = 500, height = 420;
129 if (new jalview.util.Platform().isAMac())
135 Desktop.addInternalFrame(frame,
136 MessageManager.getString("label.preferences"), width, height);
137 frame.setMinimumSize(new Dimension(width, height));
139 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
140 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
141 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
142 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
144 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
145 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
146 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
147 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
149 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
150 showNpTooltip.setSelected(Cache
151 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
152 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
154 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
155 for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
157 colour.addItem(ColourSchemeProperty.getColourName(i));
160 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
162 colour.setSelectedItem(string);
165 * default min-max colours for annotation shading
167 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
169 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
172 String[] fonts = java.awt.GraphicsEnvironment
173 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
175 for (int i = 0; i < fonts.length; i++)
177 fontNameCB.addItem(fonts[i]);
180 for (int i = 1; i < 31; i++)
182 fontSizeCB.addItem(i + "");
185 fontStyleCB.addItem("plain");
186 fontStyleCB.addItem("bold");
187 fontStyleCB.addItem("italic");
189 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
190 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
191 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
194 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
196 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
198 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
200 gapSymbolCB.addItem("-");
201 gapSymbolCB.addItem(".");
203 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
206 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
207 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
208 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
209 + "/examples/exampleFile_2_3.jar"));
211 sortby.addItem("No sort");
212 sortby.addItem("Id");
213 sortby.addItem("Pairwise Identity");
214 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
216 epsRendering.addItem("Prompt each time");
217 epsRendering.addItem("Lineart");
218 epsRendering.addItem("Text");
219 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
220 "Prompt each time"));
221 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
222 userIdWidth.setEnabled(autoIdWidth.isSelected());
223 userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
224 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
225 userIdWidth.setText(wi == null ? "" : wi.toString());
226 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
227 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
228 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
229 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
230 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
231 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
232 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
234 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
236 autoCalculateConsCheck.setSelected(Cache.getDefault(
237 "AUTO_CALC_CONSENSUS", true));
238 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
240 showGroupConservation.setSelected(Cache.getDefault(
241 "SHOW_GROUP_CONSERVATION", false));
242 showConsensHistogram.setSelected(Cache.getDefault(
243 "SHOW_CONSENSUS_HISTOGRAM", true));
244 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
247 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
249 /***************************************************************************
252 nameLinks = new Vector();
253 urlLinks = new Vector();
254 for (int i = 0; i < sequenceURLLinks.size(); i++)
256 String link = sequenceURLLinks.elementAt(i).toString();
257 nameLinks.addElement(link.substring(0, link.indexOf("|")));
258 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
263 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
264 proxyServerTB.setEnabled(useProxy.isSelected());
265 proxyPortTB.setEnabled(useProxy.isSelected());
266 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
267 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
269 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
271 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
273 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
276 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
279 annotations_actionPerformed(null); // update the display of the annotation
284 } catch (Exception ex)
286 ex.printStackTrace();
297 public void ok_actionPerformed(ActionEvent e)
300 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
301 Boolean.toString(seqLimit.isSelected()));
302 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
303 Boolean.toString(rightAlign.isSelected()));
304 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
305 Boolean.toString(fullScreen.isSelected()));
306 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
307 Boolean.toString(openoverv.isSelected()));
308 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
309 Boolean.toString(annotations.isSelected()));
310 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
311 Boolean.toString(conservation.isSelected()));
312 Cache.applicationProperties.setProperty("SHOW_QUALITY",
313 Boolean.toString(quality.isSelected()));
314 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
315 Boolean.toString(identity.isSelected()));
317 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
318 .getSelectedItem().toString());
319 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
320 .getSelectedItem().toString());
322 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
323 .getSelectedItem().toString());
324 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
325 .getSelectedItem().toString());
326 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
327 .getSelectedItem().toString());
329 Cache.applicationProperties.setProperty("ID_ITALICS",
330 Boolean.toString(idItalics.isSelected()));
331 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
332 Boolean.toString(showUnconserved.isSelected()));
333 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
334 Boolean.toString(showGroupConsensus.isSelected()));
335 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
336 Boolean.toString(showGroupConservation.isSelected()));
337 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
338 Boolean.toString(showConsensHistogram.isSelected()));
339 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
340 Boolean.toString(showConsensLogo.isSelected()));
341 Cache.applicationProperties.setProperty("ANTI_ALIAS",
342 Boolean.toString(smoothFont.isSelected()));
343 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
344 Boolean.toString(showNpTooltip.isSelected()));
345 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
346 Boolean.toString(showDbRefTooltip.isSelected()));
348 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
349 Boolean.toString(wrap.isSelected()));
351 Cache.applicationProperties.setProperty("STARTUP_FILE",
352 startupFileTextfield.getText());
353 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
354 Boolean.toString(startupCheckbox.isSelected()));
356 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
357 .getSelectedItem().toString());
359 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
360 minColour.getBackground());
361 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
362 maxColour.getBackground());
364 if (epsRendering.getSelectedItem().equals("Prompt each time"))
366 Cache.applicationProperties.remove("EPS_RENDERING");
370 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
371 .getSelectedItem().toString());
374 if (defaultBrowser.getText().trim().length() < 1)
376 Cache.applicationProperties.remove("DEFAULT_BROWSER");
380 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
381 defaultBrowser.getText());
384 jalview.util.BrowserLauncher.resetBrowser();
386 if (nameLinks.size() > 0)
388 StringBuffer links = new StringBuffer();
389 sequenceURLLinks = new Vector();
390 for (int i = 0; i < nameLinks.size(); i++)
392 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
393 + urlLinks.elementAt(i));
394 links.append(sequenceURLLinks.elementAt(i).toString());
398 links.setLength(links.length() - 1);
399 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
404 Cache.applicationProperties.remove("SEQUENCE_LINKS");
407 Cache.applicationProperties.setProperty("USE_PROXY",
408 Boolean.toString(useProxy.isSelected()));
410 if (proxyServerTB.getText().trim().length() < 1)
412 Cache.applicationProperties.remove("PROXY_SERVER");
416 Cache.applicationProperties.setProperty("PROXY_SERVER",
417 proxyServerTB.getText());
420 if (proxyPortTB.getText().trim().length() < 1)
422 Cache.applicationProperties.remove("PROXY_PORT");
426 Cache.applicationProperties.setProperty("PROXY_PORT",
427 proxyPortTB.getText());
430 if (useProxy.isSelected())
432 System.setProperty("http.proxyHost", proxyServerTB.getText());
433 System.setProperty("http.proxyPort", proxyPortTB.getText());
437 System.setProperty("http.proxyHost", "");
438 System.setProperty("http.proxyPort", "");
440 Cache.setProperty("VERSION_CHECK",
441 Boolean.toString(versioncheck.isSelected()));
442 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
444 // default is false - we only set this if the user has actively agreed
445 Cache.setProperty("USAGESTATS",
446 Boolean.toString(usagestats.isSelected()));
448 if (!questionnaire.isSelected())
450 Cache.setProperty("NOQUESTIONNAIRES", "true");
454 // special - made easy to edit a property file to disable questionnaires
455 // by just adding the given line
456 Cache.removeProperty("NOQUESTIONNAIRES");
458 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
459 Boolean.toString(blcjv.isSelected()));
460 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
461 Boolean.toString(clustaljv.isSelected()));
462 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
463 Boolean.toString(fastajv.isSelected()));
464 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
465 Boolean.toString(msfjv.isSelected()));
466 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
467 Boolean.toString(pfamjv.isSelected()));
468 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
469 Boolean.toString(pileupjv.isSelected()));
470 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
471 Boolean.toString(pirjv.isSelected()));
472 Cache.applicationProperties.setProperty("PIR_MODELLER",
473 Boolean.toString(modellerOutput.isSelected()));
474 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
476 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
477 Boolean.toString(autoIdWidth.isSelected()));
478 userIdWidth_actionPerformed();
479 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
480 userIdWidth.getText());
482 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
483 Boolean.toString(autoCalculateConsCheck.isSelected()));
484 Cache.applicationProperties.setProperty("SORT_BY_TREE",
485 Boolean.toString(sortByTree.isSelected()));
486 Cache.applicationProperties.setProperty("PAD_GAPS",
487 Boolean.toString(padGaps.isSelected()));
489 dasSource.saveProperties(Cache.applicationProperties);
490 wsPrefs.updateAndRefreshWsMenuConfig(false);
491 Cache.saveProperties();
494 frame.setClosed(true);
495 } catch (Exception ex)
503 public void startupFileTextfield_mouseClicked()
505 JalviewFileChooser chooser = new JalviewFileChooser(
506 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
508 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
510 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
511 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
512 chooser.setFileView(new JalviewFileView());
513 chooser.setDialogTitle("Select startup file");
515 int value = chooser.showOpenDialog(this);
517 if (value == JalviewFileChooser.APPROVE_OPTION)
519 jalview.bin.Cache.applicationProperties.setProperty(
520 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
521 startupFileTextfield.setText(chooser.getSelectedFile()
532 public void cancel_actionPerformed(ActionEvent e)
536 wsPrefs.updateWsMenuConfig(true);
537 wsPrefs.refreshWs_actionPerformed(e);
538 frame.setClosed(true);
539 } catch (Exception ex)
550 public void annotations_actionPerformed(ActionEvent e)
552 conservation.setEnabled(annotations.isSelected());
553 quality.setEnabled(annotations.isSelected());
554 identity.setEnabled(annotations.isSelected());
555 showGroupConsensus.setEnabled(annotations.isSelected());
556 showGroupConservation.setEnabled(annotations.isSelected());
557 showConsensHistogram.setEnabled(annotations.isSelected()
558 && (identity.isSelected() || showGroupConsensus.isSelected()));
559 showConsensLogo.setEnabled(annotations.isSelected()
560 && (identity.isSelected() || showGroupConsensus.isSelected()));
563 public void newLink_actionPerformed(ActionEvent e)
566 GSequenceLink link = new GSequenceLink();
567 boolean valid = false;
570 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
571 MessageManager.getString("label.new_sequence_url_link"),
572 JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
574 if (link.checkValid())
576 nameLinks.addElement(link.getName());
577 urlLinks.addElement(link.getURL());
589 public void editLink_actionPerformed(ActionEvent e)
591 GSequenceLink link = new GSequenceLink();
593 int index = linkNameList.getSelectedIndex();
596 JOptionPane.showInternalMessageDialog(Desktop.desktop,
597 MessageManager.getString("label.no_link_selected"),
598 MessageManager.getString("label.no_link_selected"),
599 JOptionPane.WARNING_MESSAGE);
603 link.setName(nameLinks.elementAt(index).toString());
604 link.setURL(urlLinks.elementAt(index).toString());
606 boolean valid = false;
610 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
611 MessageManager.getString("label.new_sequence_url_link"),
612 JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
614 if (link.checkValid())
616 nameLinks.setElementAt(link.getName(), index);
617 urlLinks.setElementAt(link.getURL(), index);
630 public void deleteLink_actionPerformed(ActionEvent e)
632 int index = linkNameList.getSelectedIndex();
635 JOptionPane.showInternalMessageDialog(Desktop.desktop,
636 MessageManager.getString("label.no_link_selected"),
637 MessageManager.getString("label.no_link_selected"),
638 JOptionPane.WARNING_MESSAGE);
641 nameLinks.removeElementAt(index);
642 urlLinks.removeElementAt(index);
646 void updateLinkData()
648 linkNameList.setListData(nameLinks);
649 linkURLList.setListData(urlLinks);
652 public void defaultBrowser_mouseClicked(MouseEvent e)
654 JFileChooser chooser = new JFileChooser(".");
655 chooser.setDialogTitle("Select default web browser");
657 int value = chooser.showOpenDialog(this);
659 if (value == JFileChooser.APPROVE_OPTION)
661 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
670 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
673 protected void showunconserved_actionPerformed(ActionEvent e)
675 // TODO Auto-generated method stub
676 super.showunconserved_actionPerformed(e);
679 private void jbInit() throws Exception
683 public static Collection getGroupURLLinks()
685 return groupURLLinks;
688 public void minColour_actionPerformed()
690 Color col = JColorChooser.showDialog(this,
691 "Select Colour for Minimum Value", minColour.getBackground());
694 minColour.setBackground(col);
699 public void maxColour_actionPerformed()
701 Color col = JColorChooser.showDialog(this,
702 "Select Colour for Maximum Value", maxColour.getBackground());
705 maxColour.setBackground(col);
711 protected void userIdWidth_actionPerformed()
715 String val = userIdWidth.getText().trim();
716 if (val.length() > 0)
718 Integer iw = Integer.parseInt(val);
719 if (iw.intValue() < 12)
721 throw new NumberFormatException();
723 userIdWidth.setText(iw.toString());
725 } catch (NumberFormatException x)
728 .showInternalMessageDialog(
730 "The user defined width for the\nannotation and sequence ID columns\nin exported figures must be\nat least 12 pixels wide.",
731 "Invalid ID Column width",
732 JOptionPane.WARNING_MESSAGE);
733 userIdWidth.setText("");
738 protected void autoIdWidth_actionPerformed()
740 userIdWidth.setEnabled(!autoIdWidth.isSelected());
741 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());