2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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.*;
31 import jalview.ws.EnfinEnvision2OneWay;
39 public class Preferences extends GPreferences
43 * Holds name and link separated with | character. Sequence ID must be
44 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
46 public static Vector sequenceURLLinks;
49 * Holds name and link separated with | character. Sequence IDS and Sequences
50 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
51 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
52 * for first and second token specified after a pipe character at end |,|.
53 * (TODO: proper escape for using | to separate ids or sequences
56 public static Vector groupURLLinks;
62 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
63 sequenceURLLinks = new Vector();
67 StringTokenizer st = new StringTokenizer(string, "|");
68 while (st.hasMoreElements())
70 String name = st.nextToken();
71 String url = st.nextToken();
72 // check for '|' within a regex
73 int rxstart = url.indexOf("$SEQUENCE_ID$");
74 while (rxstart == -1 && url.indexOf("/=$") == -1)
76 url = url + "|" + st.nextToken();
78 sequenceURLLinks.addElement(name + "|" + url);
80 } catch (Exception ex)
82 System.out.println(ex + "\nError parsing sequence links");
85 * TODO: reformulate groupURL encoding so two or more can be stored in the
86 * .properties file as '|' separated strings
89 groupURLLinks = new Vector();
90 // 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|,");
91 // 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|,");
95 Vector nameLinks, urlLinks;
99 DasSourceBrowser dasSource;
101 private WsPreferences wsPrefs;
104 * Creates a new Preferences object.
109 frame = new JInternalFrame();
110 frame.setContentPane(this);
111 dasSource = new DasSourceBrowser();
112 dasPanel.add(dasSource, BorderLayout.CENTER);
113 wsPrefs = new WsPreferences();
114 wsPanel.add(wsPrefs, BorderLayout.CENTER);
115 int width = 500, height = 420;
116 if (new jalview.util.Platform().isAMac())
122 Desktop.addInternalFrame(frame, "Preferences", width, height);
123 frame.setMinimumSize(new Dimension(width, height));
125 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
126 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
127 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
128 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
130 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
131 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
132 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
133 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
135 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
136 showNpTooltip.setSelected(Cache
137 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
138 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
140 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
141 for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
143 colour.addItem(ColourSchemeProperty.getColourName(i));
146 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
148 colour.setSelectedItem(string);
151 * default min-max colours for annotation shading
153 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
154 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
156 String[] fonts = java.awt.GraphicsEnvironment
157 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
159 for (int i = 0; i < fonts.length; i++)
161 fontNameCB.addItem(fonts[i]);
164 for (int i = 1; i < 31; i++)
166 fontSizeCB.addItem(i + "");
169 fontStyleCB.addItem("plain");
170 fontStyleCB.addItem("bold");
171 fontStyleCB.addItem("italic");
173 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
174 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
175 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
178 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
180 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
182 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
184 gapSymbolCB.addItem("-");
185 gapSymbolCB.addItem(".");
187 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
190 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
191 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
192 Cache.getDefault("www.jalview.org","http://www.jalview.org")+"/examples/exampleFile_2_3.jar"));
194 sortby.addItem("No sort");
195 sortby.addItem("Id");
196 sortby.addItem("Pairwise Identity");
197 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
199 epsRendering.addItem("Prompt each time");
200 epsRendering.addItem("Lineart");
201 epsRendering.addItem("Text");
202 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
203 "Prompt each time"));
205 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
206 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
207 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
208 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
209 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
210 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
211 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
213 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
215 autoCalculateConsCheck.setSelected(Cache.getDefault(
216 "AUTO_CALC_CONSENSUS", true));
217 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
219 showGroupConservation.setSelected(Cache.getDefault(
220 "SHOW_GROUP_CONSERVATION", false));
221 showConsensHistogram.setSelected(Cache.getDefault(
222 "SHOW_CONSENSUS_HISTOGRAM", true));
223 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
226 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
228 /***************************************************************************
231 nameLinks = new Vector();
232 urlLinks = new Vector();
233 for (int i = 0; i < sequenceURLLinks.size(); i++)
235 String link = sequenceURLLinks.elementAt(i).toString();
236 nameLinks.addElement(link.substring(0, link.indexOf("|")));
237 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
242 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
243 proxyServerTB.setEnabled(useProxy.isSelected());
244 proxyPortTB.setEnabled(useProxy.isSelected());
245 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
246 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
248 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
250 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
252 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
255 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
258 annotations_actionPerformed(null); // update the display of the annotation
263 } catch (Exception ex)
265 ex.printStackTrace();
276 public void ok_actionPerformed(ActionEvent e)
279 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
280 Boolean.toString(seqLimit.isSelected()));
281 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
282 Boolean.toString(rightAlign.isSelected()));
283 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
284 Boolean.toString(fullScreen.isSelected()));
285 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
286 Boolean.toString(openoverv.isSelected()));
287 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
288 Boolean.toString(annotations.isSelected()));
289 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
290 Boolean.toString(conservation.isSelected()));
291 Cache.applicationProperties.setProperty("SHOW_QUALITY",
292 Boolean.toString(quality.isSelected()));
293 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
294 Boolean.toString(identity.isSelected()));
296 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
297 .getSelectedItem().toString());
298 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
299 .getSelectedItem().toString());
301 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
302 .getSelectedItem().toString());
303 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
304 .getSelectedItem().toString());
305 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
306 .getSelectedItem().toString());
308 Cache.applicationProperties.setProperty("ID_ITALICS",
309 Boolean.toString(idItalics.isSelected()));
310 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
311 Boolean.toString(showUnconserved.isSelected()));
312 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
313 Boolean.toString(showGroupConsensus.isSelected()));
314 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
315 Boolean.toString(showGroupConservation.isSelected()));
316 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
317 Boolean.toString(showConsensHistogram.isSelected()));
318 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
319 Boolean.toString(showConsensLogo.isSelected()));
320 Cache.applicationProperties.setProperty("ANTI_ALIAS",
321 Boolean.toString(smoothFont.isSelected()));
322 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
323 Boolean.toString(showNpTooltip.isSelected()));
324 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
325 Boolean.toString(showDbRefTooltip.isSelected()));
327 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
328 Boolean.toString(wrap.isSelected()));
330 Cache.applicationProperties.setProperty("STARTUP_FILE",
331 startupFileTextfield.getText());
332 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
333 Boolean.toString(startupCheckbox.isSelected()));
335 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
336 .getSelectedItem().toString());
338 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN", minColour.getBackground());
339 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX", maxColour.getBackground());
341 if (epsRendering.getSelectedItem().equals("Prompt each time"))
343 Cache.applicationProperties.remove("EPS_RENDERING");
347 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
348 .getSelectedItem().toString());
351 if (defaultBrowser.getText().trim().length() < 1)
353 Cache.applicationProperties.remove("DEFAULT_BROWSER");
357 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
358 defaultBrowser.getText());
361 jalview.util.BrowserLauncher.resetBrowser();
363 if (nameLinks.size() > 0)
365 StringBuffer links = new StringBuffer();
366 sequenceURLLinks = new Vector();
367 for (int i = 0; i < nameLinks.size(); i++)
369 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
370 + urlLinks.elementAt(i));
371 links.append(sequenceURLLinks.elementAt(i).toString());
375 links.setLength(links.length() - 1);
376 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
381 Cache.applicationProperties.remove("SEQUENCE_LINKS");
384 Cache.applicationProperties.setProperty("USE_PROXY",
385 Boolean.toString(useProxy.isSelected()));
387 if (proxyServerTB.getText().trim().length() < 1)
389 Cache.applicationProperties.remove("PROXY_SERVER");
393 Cache.applicationProperties.setProperty("PROXY_SERVER",
394 proxyServerTB.getText());
397 if (proxyPortTB.getText().trim().length() < 1)
399 Cache.applicationProperties.remove("PROXY_PORT");
403 Cache.applicationProperties.setProperty("PROXY_PORT",
404 proxyPortTB.getText());
407 if (useProxy.isSelected())
409 System.setProperty("http.proxyHost", proxyServerTB.getText());
410 System.setProperty("http.proxyPort", proxyPortTB.getText());
414 System.setProperty("http.proxyHost", "");
415 System.setProperty("http.proxyPort", "");
417 Cache.setProperty("VERSION_CHECK",
418 Boolean.toString(versioncheck.isSelected()));
419 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
421 // default is false - we only set this if the user has actively agreed
422 Cache.setProperty("USAGESTATS",
423 Boolean.toString(usagestats.isSelected()));
425 if (!questionnaire.isSelected())
427 Cache.setProperty("NOQUESTIONNAIRES", "true");
431 // special - made easy to edit a property file to disable questionnaires
432 // by just adding the given line
433 Cache.removeProperty("NOQUESTIONNAIRES");
435 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
436 Boolean.toString(blcjv.isSelected()));
437 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
438 Boolean.toString(clustaljv.isSelected()));
439 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
440 Boolean.toString(fastajv.isSelected()));
441 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
442 Boolean.toString(msfjv.isSelected()));
443 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
444 Boolean.toString(pfamjv.isSelected()));
445 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
446 Boolean.toString(pileupjv.isSelected()));
447 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
448 Boolean.toString(pirjv.isSelected()));
449 Cache.applicationProperties.setProperty("PIR_MODELLER",
450 Boolean.toString(modellerOutput.isSelected()));
451 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
453 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
454 Boolean.toString(autoCalculateConsCheck.isSelected()));
455 Cache.applicationProperties.setProperty("SORT_BY_TREE",
456 Boolean.toString(sortByTree.isSelected()));
457 Cache.applicationProperties.setProperty("PAD_GAPS",
458 Boolean.toString(padGaps.isSelected()));
460 dasSource.saveProperties(Cache.applicationProperties);
461 wsPrefs.updateAndRefreshWsMenuConfig(false);
462 Cache.saveProperties();
465 frame.setClosed(true);
466 } catch (Exception ex)
474 public void startupFileTextfield_mouseClicked()
476 JalviewFileChooser chooser = new JalviewFileChooser(
477 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
479 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
481 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
482 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
483 chooser.setFileView(new JalviewFileView());
484 chooser.setDialogTitle("Select startup file");
486 int value = chooser.showOpenDialog(this);
488 if (value == JalviewFileChooser.APPROVE_OPTION)
490 jalview.bin.Cache.applicationProperties.setProperty(
491 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
492 startupFileTextfield.setText(chooser.getSelectedFile()
503 public void cancel_actionPerformed(ActionEvent e)
507 wsPrefs.updateWsMenuConfig(true);
508 wsPrefs.refreshWs_actionPerformed(e);
509 frame.setClosed(true);
510 } catch (Exception ex)
521 public void annotations_actionPerformed(ActionEvent e)
523 conservation.setEnabled(annotations.isSelected());
524 quality.setEnabled(annotations.isSelected());
525 identity.setEnabled(annotations.isSelected());
526 showGroupConsensus.setEnabled(annotations.isSelected());
527 showGroupConservation.setEnabled(annotations.isSelected());
528 showConsensHistogram.setEnabled(annotations.isSelected()
529 && (identity.isSelected() || showGroupConsensus.isSelected()));
530 showConsensLogo.setEnabled(annotations.isSelected()
531 && (identity.isSelected() || showGroupConsensus.isSelected()));
534 public void newLink_actionPerformed(ActionEvent e)
537 GSequenceLink link = new GSequenceLink();
538 boolean valid = false;
541 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
542 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
543 null) == JOptionPane.OK_OPTION)
545 if (link.checkValid())
547 nameLinks.addElement(link.getName());
548 urlLinks.addElement(link.getURL());
560 public void editLink_actionPerformed(ActionEvent e)
562 GSequenceLink link = new GSequenceLink();
564 int index = linkNameList.getSelectedIndex();
567 JOptionPane.showInternalMessageDialog(Desktop.desktop,
568 "No link selected!", "No link selected",
569 JOptionPane.WARNING_MESSAGE);
573 link.setName(nameLinks.elementAt(index).toString());
574 link.setURL(urlLinks.elementAt(index).toString());
576 boolean valid = false;
580 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
581 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
582 null) == JOptionPane.OK_OPTION)
584 if (link.checkValid())
586 nameLinks.setElementAt(link.getName(), index);
587 urlLinks.setElementAt(link.getURL(), index);
600 public void deleteLink_actionPerformed(ActionEvent e)
602 int index = linkNameList.getSelectedIndex();
605 JOptionPane.showInternalMessageDialog(Desktop.desktop,
606 "No link selected!", "No link selected",
607 JOptionPane.WARNING_MESSAGE);
610 nameLinks.removeElementAt(index);
611 urlLinks.removeElementAt(index);
615 void updateLinkData()
617 linkNameList.setListData(nameLinks);
618 linkURLList.setListData(urlLinks);
621 public void defaultBrowser_mouseClicked(MouseEvent e)
623 JFileChooser chooser = new JFileChooser(".");
624 chooser.setDialogTitle("Select default web browser");
626 int value = chooser.showOpenDialog(this);
628 if (value == JFileChooser.APPROVE_OPTION)
630 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
639 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
642 protected void showunconserved_actionPerformed(ActionEvent e)
644 // TODO Auto-generated method stub
645 super.showunconserved_actionPerformed(e);
648 private void jbInit() throws Exception
652 public static Collection getGroupURLLinks()
654 return groupURLLinks;
656 public void minColour_actionPerformed()
658 Color col = JColorChooser.showDialog(this,
659 "Select Colour for Minimum Value", minColour.getBackground());
662 minColour.setBackground(col);
667 public void maxColour_actionPerformed()
669 Color col = JColorChooser.showDialog(this,
670 "Select Colour for Maximum Value", maxColour.getBackground());
673 maxColour.setBackground(col);