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;
102 * Creates a new Preferences object.
107 frame = new JInternalFrame();
108 frame.setContentPane(this);
109 dasSource = new DasSourceBrowser();
110 dasPanel.add(dasSource, BorderLayout.CENTER);
112 int width = 500, height = 420;
113 if (new jalview.util.Platform().isAMac())
119 Desktop.addInternalFrame(frame, "Preferences", width, height);
120 frame.setMinimumSize(new Dimension(width, height));
122 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
123 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
124 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
125 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
127 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
128 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
129 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
130 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
132 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
133 showNpTooltip.setSelected(Cache
134 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
135 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
138 for (int i = 0; i < 13; i++)
140 colour.addItem(ColourSchemeProperty.getColourName(i));
143 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
145 colour.setSelectedItem(string);
147 String[] fonts = java.awt.GraphicsEnvironment
148 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
150 for (int i = 0; i < fonts.length; i++)
152 fontNameCB.addItem(fonts[i]);
155 for (int i = 1; i < 31; i++)
157 fontSizeCB.addItem(i + "");
160 fontStyleCB.addItem("plain");
161 fontStyleCB.addItem("bold");
162 fontStyleCB.addItem("italic");
164 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
165 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
166 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
169 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
171 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
173 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
175 gapSymbolCB.addItem("-");
176 gapSymbolCB.addItem(".");
178 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
181 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
182 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
183 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
185 sortby.addItem("No sort");
186 sortby.addItem("Id");
187 sortby.addItem("Pairwise Identity");
188 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
190 epsRendering.addItem("Prompt each time");
191 epsRendering.addItem("Lineart");
192 epsRendering.addItem("Text");
193 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
194 "Prompt each time"));
196 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
197 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
198 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
199 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
200 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
201 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
202 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
204 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
206 autoCalculateConsCheck.setSelected(Cache.getDefault(
207 "AUTO_CALC_CONSENSUS", true));
208 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
210 showGroupConservation.setSelected(Cache.getDefault(
211 "SHOW_GROUP_CONSERVATION", false));
212 showConsensHistogram.setSelected(Cache.getDefault(
213 "SHOW_CONSENSUS_HISTOGRAM", true));
214 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
217 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
219 /***************************************************************************
222 nameLinks = new Vector();
223 urlLinks = new Vector();
224 for (int i = 0; i < sequenceURLLinks.size(); i++)
226 String link = sequenceURLLinks.elementAt(i).toString();
227 nameLinks.addElement(link.substring(0, link.indexOf("|")));
228 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
233 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
234 proxyServerTB.setEnabled(useProxy.isSelected());
235 proxyPortTB.setEnabled(useProxy.isSelected());
236 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
237 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
239 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
241 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
243 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
246 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
249 annotations_actionPerformed(null); // update the display of the annotation
254 } catch (Exception ex)
256 ex.printStackTrace();
267 public void ok_actionPerformed(ActionEvent e)
270 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
271 .toString(seqLimit.isSelected()));
272 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
273 .toString(rightAlign.isSelected()));
274 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
275 .toString(fullScreen.isSelected()));
276 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
277 .toString(openoverv.isSelected()));
278 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
279 .toString(annotations.isSelected()));
280 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
281 .toString(conservation.isSelected()));
282 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
283 .toString(quality.isSelected()));
284 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
285 .toString(identity.isSelected()));
287 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
288 .getSelectedItem().toString());
289 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
290 .getSelectedItem().toString());
292 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
293 .getSelectedItem().toString());
294 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
295 .getSelectedItem().toString());
296 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
297 .getSelectedItem().toString());
299 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
300 .toString(idItalics.isSelected()));
301 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED", Boolean
302 .toString(showUnconserved.isSelected()));
303 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS", Boolean
304 .toString(showGroupConsensus.isSelected()));
305 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
306 Boolean.toString(showGroupConservation.isSelected()));
307 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
308 Boolean.toString(showConsensHistogram.isSelected()));
309 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO", Boolean
310 .toString(showConsensLogo.isSelected()));
311 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
312 .toString(smoothFont.isSelected()));
313 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP", Boolean
314 .toString(showNpTooltip.isSelected()));
315 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP", Boolean
316 .toString(showDbRefTooltip.isSelected()));
318 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
319 .toString(wrap.isSelected()));
321 Cache.applicationProperties.setProperty("STARTUP_FILE",
322 startupFileTextfield.getText());
323 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
324 .toString(startupCheckbox.isSelected()));
326 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
327 .getSelectedItem().toString());
329 if (epsRendering.getSelectedItem().equals("Prompt each time"))
331 Cache.applicationProperties.remove("EPS_RENDERING");
335 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
336 .getSelectedItem().toString());
339 if (defaultBrowser.getText().trim().length() < 1)
341 Cache.applicationProperties.remove("DEFAULT_BROWSER");
345 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
346 defaultBrowser.getText());
349 jalview.util.BrowserLauncher.resetBrowser();
351 if (nameLinks.size() > 0)
353 StringBuffer links = new StringBuffer();
354 sequenceURLLinks = new Vector();
355 for (int i = 0; i < nameLinks.size(); i++)
357 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
358 + urlLinks.elementAt(i));
359 links.append(sequenceURLLinks.elementAt(i).toString());
363 links.setLength(links.length() - 1);
364 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
369 Cache.applicationProperties.remove("SEQUENCE_LINKS");
372 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
373 .toString(useProxy.isSelected()));
375 if (proxyServerTB.getText().trim().length() < 1)
377 Cache.applicationProperties.remove("PROXY_SERVER");
381 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
385 if (proxyPortTB.getText().trim().length() < 1)
387 Cache.applicationProperties.remove("PROXY_PORT");
391 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
395 if (useProxy.isSelected())
397 System.setProperty("http.proxyHost", proxyServerTB.getText());
398 System.setProperty("http.proxyPort", proxyPortTB.getText());
402 System.setProperty("http.proxyHost", "");
403 System.setProperty("http.proxyPort", "");
405 Cache.setProperty("VERSION_CHECK", Boolean.toString(versioncheck
407 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
409 // default is false - we only set this if the user has actively agreed
410 Cache.setProperty("USAGESTATS", Boolean.toString(usagestats
413 if (!questionnaire.isSelected())
415 Cache.setProperty("NOQUESTIONNAIRES", "true");
419 // special - made easy to edit a property file to disable questionnaires
420 // by just adding the given line
421 Cache.removeProperty("NOQUESTIONNAIRES");
423 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
424 .toString(blcjv.isSelected()));
425 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
426 .toString(clustaljv.isSelected()));
427 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
428 .toString(fastajv.isSelected()));
429 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
430 .toString(msfjv.isSelected()));
431 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
432 .toString(pfamjv.isSelected()));
433 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
434 .toString(pileupjv.isSelected()));
435 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
436 .toString(pirjv.isSelected()));
437 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
438 .toString(modellerOutput.isSelected()));
439 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
441 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
442 .toString(autoCalculateConsCheck.isSelected()));
443 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
444 .toString(padGaps.isSelected()));
446 dasSource.saveProperties(Cache.applicationProperties);
448 Cache.saveProperties();
451 frame.setClosed(true);
452 } catch (Exception ex)
460 public void startupFileTextfield_mouseClicked()
462 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
463 .getProperty("LAST_DIRECTORY"), new String[]
464 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
466 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
467 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
468 chooser.setFileView(new JalviewFileView());
469 chooser.setDialogTitle("Select startup file");
471 int value = chooser.showOpenDialog(this);
473 if (value == JalviewFileChooser.APPROVE_OPTION)
475 jalview.bin.Cache.applicationProperties.setProperty(
476 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
477 startupFileTextfield.setText(chooser.getSelectedFile()
488 public void cancel_actionPerformed(ActionEvent e)
492 frame.setClosed(true);
493 } catch (Exception ex)
504 public void annotations_actionPerformed(ActionEvent e)
506 conservation.setEnabled(annotations.isSelected());
507 quality.setEnabled(annotations.isSelected());
508 identity.setEnabled(annotations.isSelected());
509 showGroupConsensus.setEnabled(annotations.isSelected());
510 showGroupConservation.setEnabled(annotations.isSelected());
511 showConsensHistogram.setEnabled(annotations.isSelected()
512 && (identity.isSelected() || showGroupConsensus.isSelected()));
513 showConsensLogo.setEnabled(annotations.isSelected()
514 && (identity.isSelected() || showGroupConsensus.isSelected()));
517 public void newLink_actionPerformed(ActionEvent e)
520 GSequenceLink link = new GSequenceLink();
521 boolean valid = false;
524 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
525 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
526 null) == JOptionPane.OK_OPTION)
528 if (link.checkValid())
530 nameLinks.addElement(link.getName());
531 urlLinks.addElement(link.getURL());
543 public void editLink_actionPerformed(ActionEvent e)
545 GSequenceLink link = new GSequenceLink();
547 int index = linkNameList.getSelectedIndex();
550 JOptionPane.showInternalMessageDialog(Desktop.desktop,
551 "No link selected!", "No link selected",
552 JOptionPane.WARNING_MESSAGE);
556 link.setName(nameLinks.elementAt(index).toString());
557 link.setURL(urlLinks.elementAt(index).toString());
559 boolean valid = false;
563 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
564 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
565 null) == JOptionPane.OK_OPTION)
567 if (link.checkValid())
569 nameLinks.setElementAt(link.getName(), index);
570 urlLinks.setElementAt(link.getURL(), index);
583 public void deleteLink_actionPerformed(ActionEvent e)
585 int index = linkNameList.getSelectedIndex();
588 JOptionPane.showInternalMessageDialog(Desktop.desktop,
589 "No link selected!", "No link selected",
590 JOptionPane.WARNING_MESSAGE);
593 nameLinks.removeElementAt(index);
594 urlLinks.removeElementAt(index);
598 void updateLinkData()
600 linkNameList.setListData(nameLinks);
601 linkURLList.setListData(urlLinks);
604 public void defaultBrowser_mouseClicked(MouseEvent e)
606 JFileChooser chooser = new JFileChooser(".");
607 chooser.setDialogTitle("Select default web browser");
609 int value = chooser.showOpenDialog(this);
611 if (value == JFileChooser.APPROVE_OPTION)
613 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
622 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
625 protected void showunconserved_actionPerformed(ActionEvent e)
627 // TODO Auto-generated method stub
628 super.showunconserved_actionPerformed(e);
631 private void jbInit() throws Exception
635 public static Collection getGroupURLLinks()
637 return groupURLLinks;