2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
23 import java.awt.event.*;
29 import jalview.jbgui.*;
30 import jalview.schemes.*;
38 public class Preferences extends GPreferences
42 * Holds name and link separated with | character. Sequence ID must be
43 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
45 public static Vector sequenceURLLinks;
48 * Holds name and link separated with | character. Sequence IDS and Sequences
49 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
50 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
51 * for first and second token specified after a pipe character at end |,|.
52 * (TODO: proper escape for using | to separate ids or sequences
55 public static Vector groupURLLinks;
61 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
62 sequenceURLLinks = new Vector();
66 StringTokenizer st = new StringTokenizer(string, "|");
67 while (st.hasMoreElements())
69 String name = st.nextToken();
70 String url = st.nextToken();
71 // check for '|' within a regex
72 int rxstart = url.indexOf("$SEQUENCE_ID$");
73 while (rxstart == -1 && url.indexOf("/=$") == -1)
75 url = url + "|" + st.nextToken();
77 sequenceURLLinks.addElement(name + "|" + url);
79 } catch (Exception ex)
81 System.out.println(ex + "\nError parsing sequence links");
84 * TODO: reformulate groupURL encoding so two or more can be stored in the
85 * .properties file as '|' separated strings
88 groupURLLinks = new Vector();
89 // groupURLLinks.addElement("UNIPROT|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewIDs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,");
90 // groupURLLinks.addElement("Seqs|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,");
94 Vector nameLinks, urlLinks;
98 DasSourceBrowser dasSource;
100 private WsPreferences wsPrefs;
103 * Creates a new Preferences object.
108 frame = new JInternalFrame();
109 frame.setContentPane(this);
110 dasSource = new DasSourceBrowser();
111 dasPanel.add(dasSource, BorderLayout.CENTER);
112 wsPrefs = new WsPreferences();
113 wsPanel.add(wsPrefs, BorderLayout.CENTER);
114 int width = 500, height = 420;
115 if (new jalview.util.Platform().isAMac())
121 Desktop.addInternalFrame(frame, "Preferences", width, height);
122 frame.setMinimumSize(new Dimension(width, height));
124 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
125 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
126 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
127 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
129 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
130 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
131 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
132 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
134 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
135 showNpTooltip.setSelected(Cache
136 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
137 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
139 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
140 for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
142 colour.addItem(ColourSchemeProperty.getColourName(i));
145 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
147 colour.setSelectedItem(string);
150 * default min-max colours for annotation shading
152 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
154 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
157 String[] fonts = java.awt.GraphicsEnvironment
158 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
160 for (int i = 0; i < fonts.length; i++)
162 fontNameCB.addItem(fonts[i]);
165 for (int i = 1; i < 31; i++)
167 fontSizeCB.addItem(i + "");
170 fontStyleCB.addItem("plain");
171 fontStyleCB.addItem("bold");
172 fontStyleCB.addItem("italic");
174 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
175 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
176 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
179 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
181 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
183 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
185 gapSymbolCB.addItem("-");
186 gapSymbolCB.addItem(".");
188 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
191 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
192 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
193 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
194 + "/examples/exampleFile_2_3.jar"));
196 sortby.addItem("No sort");
197 sortby.addItem("Id");
198 sortby.addItem("Pairwise Identity");
199 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
201 epsRendering.addItem("Prompt each time");
202 epsRendering.addItem("Lineart");
203 epsRendering.addItem("Text");
204 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
205 "Prompt each time"));
206 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
207 userIdWidth.setEnabled(autoIdWidth.isSelected());
208 userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
209 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
210 userIdWidth.setText(wi == null ? "" : wi.toString());
211 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
212 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
213 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
214 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
215 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
216 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
217 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
219 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
221 autoCalculateConsCheck.setSelected(Cache.getDefault(
222 "AUTO_CALC_CONSENSUS", true));
223 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
225 showGroupConservation.setSelected(Cache.getDefault(
226 "SHOW_GROUP_CONSERVATION", false));
227 showConsensHistogram.setSelected(Cache.getDefault(
228 "SHOW_CONSENSUS_HISTOGRAM", true));
229 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
232 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
234 /***************************************************************************
237 nameLinks = new Vector();
238 urlLinks = new Vector();
239 for (int i = 0; i < sequenceURLLinks.size(); i++)
241 String link = sequenceURLLinks.elementAt(i).toString();
242 nameLinks.addElement(link.substring(0, link.indexOf("|")));
243 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
248 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
249 proxyServerTB.setEnabled(useProxy.isSelected());
250 proxyPortTB.setEnabled(useProxy.isSelected());
251 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
252 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
254 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
256 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
258 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
261 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
264 annotations_actionPerformed(null); // update the display of the annotation
269 } catch (Exception ex)
271 ex.printStackTrace();
282 public void ok_actionPerformed(ActionEvent e)
285 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
286 Boolean.toString(seqLimit.isSelected()));
287 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
288 Boolean.toString(rightAlign.isSelected()));
289 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
290 Boolean.toString(fullScreen.isSelected()));
291 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
292 Boolean.toString(openoverv.isSelected()));
293 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
294 Boolean.toString(annotations.isSelected()));
295 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
296 Boolean.toString(conservation.isSelected()));
297 Cache.applicationProperties.setProperty("SHOW_QUALITY",
298 Boolean.toString(quality.isSelected()));
299 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
300 Boolean.toString(identity.isSelected()));
302 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
303 .getSelectedItem().toString());
304 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
305 .getSelectedItem().toString());
307 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
308 .getSelectedItem().toString());
309 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
310 .getSelectedItem().toString());
311 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
312 .getSelectedItem().toString());
314 Cache.applicationProperties.setProperty("ID_ITALICS",
315 Boolean.toString(idItalics.isSelected()));
316 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
317 Boolean.toString(showUnconserved.isSelected()));
318 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
319 Boolean.toString(showGroupConsensus.isSelected()));
320 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
321 Boolean.toString(showGroupConservation.isSelected()));
322 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
323 Boolean.toString(showConsensHistogram.isSelected()));
324 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
325 Boolean.toString(showConsensLogo.isSelected()));
326 Cache.applicationProperties.setProperty("ANTI_ALIAS",
327 Boolean.toString(smoothFont.isSelected()));
328 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
329 Boolean.toString(showNpTooltip.isSelected()));
330 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
331 Boolean.toString(showDbRefTooltip.isSelected()));
333 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
334 Boolean.toString(wrap.isSelected()));
336 Cache.applicationProperties.setProperty("STARTUP_FILE",
337 startupFileTextfield.getText());
338 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
339 Boolean.toString(startupCheckbox.isSelected()));
341 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
342 .getSelectedItem().toString());
344 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
345 minColour.getBackground());
346 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
347 maxColour.getBackground());
349 if (epsRendering.getSelectedItem().equals("Prompt each time"))
351 Cache.applicationProperties.remove("EPS_RENDERING");
355 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
356 .getSelectedItem().toString());
359 if (defaultBrowser.getText().trim().length() < 1)
361 Cache.applicationProperties.remove("DEFAULT_BROWSER");
365 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
366 defaultBrowser.getText());
369 jalview.util.BrowserLauncher.resetBrowser();
371 if (nameLinks.size() > 0)
373 StringBuffer links = new StringBuffer();
374 sequenceURLLinks = new Vector();
375 for (int i = 0; i < nameLinks.size(); i++)
377 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
378 + urlLinks.elementAt(i));
379 links.append(sequenceURLLinks.elementAt(i).toString());
383 links.setLength(links.length() - 1);
384 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
389 Cache.applicationProperties.remove("SEQUENCE_LINKS");
392 Cache.applicationProperties.setProperty("USE_PROXY",
393 Boolean.toString(useProxy.isSelected()));
395 if (proxyServerTB.getText().trim().length() < 1)
397 Cache.applicationProperties.remove("PROXY_SERVER");
401 Cache.applicationProperties.setProperty("PROXY_SERVER",
402 proxyServerTB.getText());
405 if (proxyPortTB.getText().trim().length() < 1)
407 Cache.applicationProperties.remove("PROXY_PORT");
411 Cache.applicationProperties.setProperty("PROXY_PORT",
412 proxyPortTB.getText());
415 if (useProxy.isSelected())
417 System.setProperty("http.proxyHost", proxyServerTB.getText());
418 System.setProperty("http.proxyPort", proxyPortTB.getText());
422 System.setProperty("http.proxyHost", "");
423 System.setProperty("http.proxyPort", "");
425 Cache.setProperty("VERSION_CHECK",
426 Boolean.toString(versioncheck.isSelected()));
427 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
429 // default is false - we only set this if the user has actively agreed
430 Cache.setProperty("USAGESTATS",
431 Boolean.toString(usagestats.isSelected()));
433 if (!questionnaire.isSelected())
435 Cache.setProperty("NOQUESTIONNAIRES", "true");
439 // special - made easy to edit a property file to disable questionnaires
440 // by just adding the given line
441 Cache.removeProperty("NOQUESTIONNAIRES");
443 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
444 Boolean.toString(blcjv.isSelected()));
445 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
446 Boolean.toString(clustaljv.isSelected()));
447 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
448 Boolean.toString(fastajv.isSelected()));
449 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
450 Boolean.toString(msfjv.isSelected()));
451 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
452 Boolean.toString(pfamjv.isSelected()));
453 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
454 Boolean.toString(pileupjv.isSelected()));
455 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
456 Boolean.toString(pirjv.isSelected()));
457 Cache.applicationProperties.setProperty("PIR_MODELLER",
458 Boolean.toString(modellerOutput.isSelected()));
459 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
461 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
462 Boolean.toString(autoIdWidth.isSelected()));
463 userIdWidth_actionPerformed();
464 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
465 userIdWidth.getText());
467 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
468 Boolean.toString(autoCalculateConsCheck.isSelected()));
469 Cache.applicationProperties.setProperty("SORT_BY_TREE",
470 Boolean.toString(sortByTree.isSelected()));
471 Cache.applicationProperties.setProperty("PAD_GAPS",
472 Boolean.toString(padGaps.isSelected()));
474 dasSource.saveProperties(Cache.applicationProperties);
475 wsPrefs.updateAndRefreshWsMenuConfig(false);
476 Cache.saveProperties();
479 frame.setClosed(true);
480 } catch (Exception ex)
488 public void startupFileTextfield_mouseClicked()
490 JalviewFileChooser chooser = new JalviewFileChooser(
491 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
493 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
495 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
496 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
497 chooser.setFileView(new JalviewFileView());
498 chooser.setDialogTitle("Select startup file");
500 int value = chooser.showOpenDialog(this);
502 if (value == JalviewFileChooser.APPROVE_OPTION)
504 jalview.bin.Cache.applicationProperties.setProperty(
505 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
506 startupFileTextfield.setText(chooser.getSelectedFile()
517 public void cancel_actionPerformed(ActionEvent e)
521 wsPrefs.updateWsMenuConfig(true);
522 wsPrefs.refreshWs_actionPerformed(e);
523 frame.setClosed(true);
524 } catch (Exception ex)
535 public void annotations_actionPerformed(ActionEvent e)
537 conservation.setEnabled(annotations.isSelected());
538 quality.setEnabled(annotations.isSelected());
539 identity.setEnabled(annotations.isSelected());
540 showGroupConsensus.setEnabled(annotations.isSelected());
541 showGroupConservation.setEnabled(annotations.isSelected());
542 showConsensHistogram.setEnabled(annotations.isSelected()
543 && (identity.isSelected() || showGroupConsensus.isSelected()));
544 showConsensLogo.setEnabled(annotations.isSelected()
545 && (identity.isSelected() || showGroupConsensus.isSelected()));
548 public void newLink_actionPerformed(ActionEvent e)
551 GSequenceLink link = new GSequenceLink();
552 boolean valid = false;
555 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
556 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
557 null) == JOptionPane.OK_OPTION)
559 if (link.checkValid())
561 nameLinks.addElement(link.getName());
562 urlLinks.addElement(link.getURL());
574 public void editLink_actionPerformed(ActionEvent e)
576 GSequenceLink link = new GSequenceLink();
578 int index = linkNameList.getSelectedIndex();
581 JOptionPane.showInternalMessageDialog(Desktop.desktop,
582 "No link selected!", "No link selected",
583 JOptionPane.WARNING_MESSAGE);
587 link.setName(nameLinks.elementAt(index).toString());
588 link.setURL(urlLinks.elementAt(index).toString());
590 boolean valid = false;
594 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
595 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
596 null) == JOptionPane.OK_OPTION)
598 if (link.checkValid())
600 nameLinks.setElementAt(link.getName(), index);
601 urlLinks.setElementAt(link.getURL(), index);
614 public void deleteLink_actionPerformed(ActionEvent e)
616 int index = linkNameList.getSelectedIndex();
619 JOptionPane.showInternalMessageDialog(Desktop.desktop,
620 "No link selected!", "No link selected",
621 JOptionPane.WARNING_MESSAGE);
624 nameLinks.removeElementAt(index);
625 urlLinks.removeElementAt(index);
629 void updateLinkData()
631 linkNameList.setListData(nameLinks);
632 linkURLList.setListData(urlLinks);
635 public void defaultBrowser_mouseClicked(MouseEvent e)
637 JFileChooser chooser = new JFileChooser(".");
638 chooser.setDialogTitle("Select default web browser");
640 int value = chooser.showOpenDialog(this);
642 if (value == JFileChooser.APPROVE_OPTION)
644 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
653 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
656 protected void showunconserved_actionPerformed(ActionEvent e)
658 // TODO Auto-generated method stub
659 super.showunconserved_actionPerformed(e);
662 private void jbInit() throws Exception
666 public static Collection getGroupURLLinks()
668 return groupURLLinks;
671 public void minColour_actionPerformed()
673 Color col = JColorChooser.showDialog(this,
674 "Select Colour for Minimum Value", minColour.getBackground());
677 minColour.setBackground(col);
682 public void maxColour_actionPerformed()
684 Color col = JColorChooser.showDialog(this,
685 "Select Colour for Maximum Value", maxColour.getBackground());
688 maxColour.setBackground(col);
694 protected void userIdWidth_actionPerformed()
698 String val = userIdWidth.getText().trim();
699 if (val.length() > 0)
701 Integer iw = Integer.parseInt(val);
702 if (iw.intValue() < 12)
704 throw new NumberFormatException();
706 userIdWidth.setText(iw.toString());
708 } catch (NumberFormatException x)
711 .showInternalMessageDialog(
713 "The user defined width for the\nannotation and sequence ID columns\nin exported figures must be\nat least 12 pixels wide.",
714 "Invalid ID Column width",
715 JOptionPane.WARNING_MESSAGE);
716 userIdWidth.setText("");
721 protected void autoIdWidth_actionPerformed()
723 userIdWidth.setEnabled(!autoIdWidth.isSelected());
724 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());