2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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",
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);
150 String[] fonts = java.awt.GraphicsEnvironment
151 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
153 for (int i = 0; i < fonts.length; i++)
155 fontNameCB.addItem(fonts[i]);
158 for (int i = 1; i < 31; i++)
160 fontSizeCB.addItem(i + "");
163 fontStyleCB.addItem("plain");
164 fontStyleCB.addItem("bold");
165 fontStyleCB.addItem("italic");
167 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
168 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
169 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
172 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
174 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
176 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
178 gapSymbolCB.addItem("-");
179 gapSymbolCB.addItem(".");
181 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
184 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
185 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
186 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
188 sortby.addItem("No sort");
189 sortby.addItem("Id");
190 sortby.addItem("Pairwise Identity");
191 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
193 epsRendering.addItem("Prompt each time");
194 epsRendering.addItem("Lineart");
195 epsRendering.addItem("Text");
196 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
197 "Prompt each time"));
199 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
200 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
201 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
202 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
203 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
204 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
205 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
207 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
209 autoCalculateConsCheck.setSelected(Cache.getDefault(
210 "AUTO_CALC_CONSENSUS", true));
211 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
213 showGroupConservation.setSelected(Cache.getDefault(
214 "SHOW_GROUP_CONSERVATION", false));
215 showConsensHistogram.setSelected(Cache.getDefault(
216 "SHOW_CONSENSUS_HISTOGRAM", true));
217 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
220 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
222 /***************************************************************************
225 nameLinks = new Vector();
226 urlLinks = new Vector();
227 for (int i = 0; i < sequenceURLLinks.size(); i++)
229 String link = sequenceURLLinks.elementAt(i).toString();
230 nameLinks.addElement(link.substring(0, link.indexOf("|")));
231 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
236 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
237 proxyServerTB.setEnabled(useProxy.isSelected());
238 proxyPortTB.setEnabled(useProxy.isSelected());
239 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
240 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
242 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
244 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
246 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
249 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
252 annotations_actionPerformed(null); // update the display of the annotation
257 } catch (Exception ex)
259 ex.printStackTrace();
270 public void ok_actionPerformed(ActionEvent e)
273 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
274 .toString(seqLimit.isSelected()));
275 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
276 .toString(rightAlign.isSelected()));
277 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
278 .toString(fullScreen.isSelected()));
279 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
280 .toString(openoverv.isSelected()));
281 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
282 .toString(annotations.isSelected()));
283 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
284 .toString(conservation.isSelected()));
285 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
286 .toString(quality.isSelected()));
287 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
288 .toString(identity.isSelected()));
290 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
291 .getSelectedItem().toString());
292 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
293 .getSelectedItem().toString());
295 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
296 .getSelectedItem().toString());
297 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
298 .getSelectedItem().toString());
299 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
300 .getSelectedItem().toString());
302 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
303 .toString(idItalics.isSelected()));
304 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED", Boolean
305 .toString(showUnconserved.isSelected()));
306 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS", Boolean
307 .toString(showGroupConsensus.isSelected()));
308 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
309 Boolean.toString(showGroupConservation.isSelected()));
310 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
311 Boolean.toString(showConsensHistogram.isSelected()));
312 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO", Boolean
313 .toString(showConsensLogo.isSelected()));
314 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
315 .toString(smoothFont.isSelected()));
316 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP", Boolean
317 .toString(showNpTooltip.isSelected()));
318 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP", Boolean
319 .toString(showDbRefTooltip.isSelected()));
321 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
322 .toString(wrap.isSelected()));
324 Cache.applicationProperties.setProperty("STARTUP_FILE",
325 startupFileTextfield.getText());
326 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
327 .toString(startupCheckbox.isSelected()));
329 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
330 .getSelectedItem().toString());
332 if (epsRendering.getSelectedItem().equals("Prompt each time"))
334 Cache.applicationProperties.remove("EPS_RENDERING");
338 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
339 .getSelectedItem().toString());
342 if (defaultBrowser.getText().trim().length() < 1)
344 Cache.applicationProperties.remove("DEFAULT_BROWSER");
348 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
349 defaultBrowser.getText());
352 jalview.util.BrowserLauncher.resetBrowser();
354 if (nameLinks.size() > 0)
356 StringBuffer links = new StringBuffer();
357 sequenceURLLinks = new Vector();
358 for (int i = 0; i < nameLinks.size(); i++)
360 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
361 + urlLinks.elementAt(i));
362 links.append(sequenceURLLinks.elementAt(i).toString());
366 links.setLength(links.length() - 1);
367 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
372 Cache.applicationProperties.remove("SEQUENCE_LINKS");
375 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
376 .toString(useProxy.isSelected()));
378 if (proxyServerTB.getText().trim().length() < 1)
380 Cache.applicationProperties.remove("PROXY_SERVER");
384 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
388 if (proxyPortTB.getText().trim().length() < 1)
390 Cache.applicationProperties.remove("PROXY_PORT");
394 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
398 if (useProxy.isSelected())
400 System.setProperty("http.proxyHost", proxyServerTB.getText());
401 System.setProperty("http.proxyPort", proxyPortTB.getText());
405 System.setProperty("http.proxyHost", "");
406 System.setProperty("http.proxyPort", "");
408 Cache.setProperty("VERSION_CHECK", Boolean.toString(versioncheck
410 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
412 // default is false - we only set this if the user has actively agreed
413 Cache.setProperty("USAGESTATS", Boolean.toString(usagestats
416 if (!questionnaire.isSelected())
418 Cache.setProperty("NOQUESTIONNAIRES", "true");
422 // special - made easy to edit a property file to disable questionnaires
423 // by just adding the given line
424 Cache.removeProperty("NOQUESTIONNAIRES");
426 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
427 .toString(blcjv.isSelected()));
428 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
429 .toString(clustaljv.isSelected()));
430 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
431 .toString(fastajv.isSelected()));
432 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
433 .toString(msfjv.isSelected()));
434 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
435 .toString(pfamjv.isSelected()));
436 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
437 .toString(pileupjv.isSelected()));
438 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
439 .toString(pirjv.isSelected()));
440 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
441 .toString(modellerOutput.isSelected()));
442 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
444 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
445 .toString(autoCalculateConsCheck.isSelected()));
446 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
447 .toString(padGaps.isSelected()));
449 dasSource.saveProperties(Cache.applicationProperties);
450 wsPrefs.updateWsMenuConfig(false);
451 Cache.saveProperties();
454 frame.setClosed(true);
455 } catch (Exception ex)
463 public void startupFileTextfield_mouseClicked()
465 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
466 .getProperty("LAST_DIRECTORY"), new String[]
467 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
469 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
470 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
471 chooser.setFileView(new JalviewFileView());
472 chooser.setDialogTitle("Select startup file");
474 int value = chooser.showOpenDialog(this);
476 if (value == JalviewFileChooser.APPROVE_OPTION)
478 jalview.bin.Cache.applicationProperties.setProperty(
479 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
480 startupFileTextfield.setText(chooser.getSelectedFile()
491 public void cancel_actionPerformed(ActionEvent e)
495 wsPrefs.updateWsMenuConfig(true);
496 frame.setClosed(true);
497 } catch (Exception ex)
508 public void annotations_actionPerformed(ActionEvent e)
510 conservation.setEnabled(annotations.isSelected());
511 quality.setEnabled(annotations.isSelected());
512 identity.setEnabled(annotations.isSelected());
513 showGroupConsensus.setEnabled(annotations.isSelected());
514 showGroupConservation.setEnabled(annotations.isSelected());
515 showConsensHistogram.setEnabled(annotations.isSelected()
516 && (identity.isSelected() || showGroupConsensus.isSelected()));
517 showConsensLogo.setEnabled(annotations.isSelected()
518 && (identity.isSelected() || showGroupConsensus.isSelected()));
521 public void newLink_actionPerformed(ActionEvent e)
524 GSequenceLink link = new GSequenceLink();
525 boolean valid = false;
528 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
529 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
530 null) == JOptionPane.OK_OPTION)
532 if (link.checkValid())
534 nameLinks.addElement(link.getName());
535 urlLinks.addElement(link.getURL());
547 public void editLink_actionPerformed(ActionEvent e)
549 GSequenceLink link = new GSequenceLink();
551 int index = linkNameList.getSelectedIndex();
554 JOptionPane.showInternalMessageDialog(Desktop.desktop,
555 "No link selected!", "No link selected",
556 JOptionPane.WARNING_MESSAGE);
560 link.setName(nameLinks.elementAt(index).toString());
561 link.setURL(urlLinks.elementAt(index).toString());
563 boolean valid = false;
567 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
568 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
569 null) == JOptionPane.OK_OPTION)
571 if (link.checkValid())
573 nameLinks.setElementAt(link.getName(), index);
574 urlLinks.setElementAt(link.getURL(), index);
587 public void deleteLink_actionPerformed(ActionEvent e)
589 int index = linkNameList.getSelectedIndex();
592 JOptionPane.showInternalMessageDialog(Desktop.desktop,
593 "No link selected!", "No link selected",
594 JOptionPane.WARNING_MESSAGE);
597 nameLinks.removeElementAt(index);
598 urlLinks.removeElementAt(index);
602 void updateLinkData()
604 linkNameList.setListData(nameLinks);
605 linkURLList.setListData(urlLinks);
608 public void defaultBrowser_mouseClicked(MouseEvent e)
610 JFileChooser chooser = new JFileChooser(".");
611 chooser.setDialogTitle("Select default web browser");
613 int value = chooser.showOpenDialog(this);
615 if (value == JFileChooser.APPROVE_OPTION)
617 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
626 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
629 protected void showunconserved_actionPerformed(ActionEvent e)
631 // TODO Auto-generated method stub
632 super.showunconserved_actionPerformed(e);
635 private void jbInit() throws Exception
639 public static Collection getGroupURLLinks()
641 return groupURLLinks;