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.*;
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",
155 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
158 String[] fonts = java.awt.GraphicsEnvironment
159 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
161 for (int i = 0; i < fonts.length; i++)
163 fontNameCB.addItem(fonts[i]);
166 for (int i = 1; i < 31; i++)
168 fontSizeCB.addItem(i + "");
171 fontStyleCB.addItem("plain");
172 fontStyleCB.addItem("bold");
173 fontStyleCB.addItem("italic");
175 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
176 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
177 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
180 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
182 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
184 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
186 gapSymbolCB.addItem("-");
187 gapSymbolCB.addItem(".");
189 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
192 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
193 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
194 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
195 + "/examples/exampleFile_2_3.jar"));
197 sortby.addItem("No sort");
198 sortby.addItem("Id");
199 sortby.addItem("Pairwise Identity");
200 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
202 epsRendering.addItem("Prompt each time");
203 epsRendering.addItem("Lineart");
204 epsRendering.addItem("Text");
205 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
206 "Prompt each time"));
207 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
208 userIdWidth.setEnabled(autoIdWidth.isSelected());
209 userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
210 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
211 userIdWidth.setText(wi == null ? "" : wi.toString());
212 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
213 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
214 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
215 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
216 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
217 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
218 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
220 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
222 autoCalculateConsCheck.setSelected(Cache.getDefault(
223 "AUTO_CALC_CONSENSUS", true));
224 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
226 showGroupConservation.setSelected(Cache.getDefault(
227 "SHOW_GROUP_CONSERVATION", false));
228 showConsensHistogram.setSelected(Cache.getDefault(
229 "SHOW_CONSENSUS_HISTOGRAM", true));
230 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
233 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
235 /***************************************************************************
238 nameLinks = new Vector();
239 urlLinks = new Vector();
240 for (int i = 0; i < sequenceURLLinks.size(); i++)
242 String link = sequenceURLLinks.elementAt(i).toString();
243 nameLinks.addElement(link.substring(0, link.indexOf("|")));
244 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
249 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
250 proxyServerTB.setEnabled(useProxy.isSelected());
251 proxyPortTB.setEnabled(useProxy.isSelected());
252 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
253 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
255 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
257 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
259 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
262 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
265 annotations_actionPerformed(null); // update the display of the annotation
270 } catch (Exception ex)
272 ex.printStackTrace();
283 public void ok_actionPerformed(ActionEvent e)
286 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
287 Boolean.toString(seqLimit.isSelected()));
288 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
289 Boolean.toString(rightAlign.isSelected()));
290 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
291 Boolean.toString(fullScreen.isSelected()));
292 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
293 Boolean.toString(openoverv.isSelected()));
294 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
295 Boolean.toString(annotations.isSelected()));
296 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
297 Boolean.toString(conservation.isSelected()));
298 Cache.applicationProperties.setProperty("SHOW_QUALITY",
299 Boolean.toString(quality.isSelected()));
300 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
301 Boolean.toString(identity.isSelected()));
303 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
304 .getSelectedItem().toString());
305 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
306 .getSelectedItem().toString());
308 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
309 .getSelectedItem().toString());
310 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
311 .getSelectedItem().toString());
312 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
313 .getSelectedItem().toString());
315 Cache.applicationProperties.setProperty("ID_ITALICS",
316 Boolean.toString(idItalics.isSelected()));
317 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
318 Boolean.toString(showUnconserved.isSelected()));
319 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
320 Boolean.toString(showGroupConsensus.isSelected()));
321 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
322 Boolean.toString(showGroupConservation.isSelected()));
323 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
324 Boolean.toString(showConsensHistogram.isSelected()));
325 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
326 Boolean.toString(showConsensLogo.isSelected()));
327 Cache.applicationProperties.setProperty("ANTI_ALIAS",
328 Boolean.toString(smoothFont.isSelected()));
329 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
330 Boolean.toString(showNpTooltip.isSelected()));
331 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
332 Boolean.toString(showDbRefTooltip.isSelected()));
334 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
335 Boolean.toString(wrap.isSelected()));
337 Cache.applicationProperties.setProperty("STARTUP_FILE",
338 startupFileTextfield.getText());
339 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
340 Boolean.toString(startupCheckbox.isSelected()));
342 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
343 .getSelectedItem().toString());
345 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
346 minColour.getBackground());
347 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
348 maxColour.getBackground());
350 if (epsRendering.getSelectedItem().equals("Prompt each time"))
352 Cache.applicationProperties.remove("EPS_RENDERING");
356 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
357 .getSelectedItem().toString());
360 if (defaultBrowser.getText().trim().length() < 1)
362 Cache.applicationProperties.remove("DEFAULT_BROWSER");
366 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
367 defaultBrowser.getText());
370 jalview.util.BrowserLauncher.resetBrowser();
372 if (nameLinks.size() > 0)
374 StringBuffer links = new StringBuffer();
375 sequenceURLLinks = new Vector();
376 for (int i = 0; i < nameLinks.size(); i++)
378 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
379 + urlLinks.elementAt(i));
380 links.append(sequenceURLLinks.elementAt(i).toString());
384 links.setLength(links.length() - 1);
385 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
390 Cache.applicationProperties.remove("SEQUENCE_LINKS");
393 Cache.applicationProperties.setProperty("USE_PROXY",
394 Boolean.toString(useProxy.isSelected()));
396 if (proxyServerTB.getText().trim().length() < 1)
398 Cache.applicationProperties.remove("PROXY_SERVER");
402 Cache.applicationProperties.setProperty("PROXY_SERVER",
403 proxyServerTB.getText());
406 if (proxyPortTB.getText().trim().length() < 1)
408 Cache.applicationProperties.remove("PROXY_PORT");
412 Cache.applicationProperties.setProperty("PROXY_PORT",
413 proxyPortTB.getText());
416 if (useProxy.isSelected())
418 System.setProperty("http.proxyHost", proxyServerTB.getText());
419 System.setProperty("http.proxyPort", proxyPortTB.getText());
423 System.setProperty("http.proxyHost", "");
424 System.setProperty("http.proxyPort", "");
426 Cache.setProperty("VERSION_CHECK",
427 Boolean.toString(versioncheck.isSelected()));
428 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
430 // default is false - we only set this if the user has actively agreed
431 Cache.setProperty("USAGESTATS",
432 Boolean.toString(usagestats.isSelected()));
434 if (!questionnaire.isSelected())
436 Cache.setProperty("NOQUESTIONNAIRES", "true");
440 // special - made easy to edit a property file to disable questionnaires
441 // by just adding the given line
442 Cache.removeProperty("NOQUESTIONNAIRES");
444 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
445 Boolean.toString(blcjv.isSelected()));
446 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
447 Boolean.toString(clustaljv.isSelected()));
448 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
449 Boolean.toString(fastajv.isSelected()));
450 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
451 Boolean.toString(msfjv.isSelected()));
452 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
453 Boolean.toString(pfamjv.isSelected()));
454 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
455 Boolean.toString(pileupjv.isSelected()));
456 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
457 Boolean.toString(pirjv.isSelected()));
458 Cache.applicationProperties.setProperty("PIR_MODELLER",
459 Boolean.toString(modellerOutput.isSelected()));
460 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
462 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
463 Boolean.toString(autoIdWidth.isSelected()));
464 userIdWidth_actionPerformed();
465 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
466 userIdWidth.getText());
468 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
469 Boolean.toString(autoCalculateConsCheck.isSelected()));
470 Cache.applicationProperties.setProperty("SORT_BY_TREE",
471 Boolean.toString(sortByTree.isSelected()));
472 Cache.applicationProperties.setProperty("PAD_GAPS",
473 Boolean.toString(padGaps.isSelected()));
475 dasSource.saveProperties(Cache.applicationProperties);
476 wsPrefs.updateAndRefreshWsMenuConfig(false);
477 Cache.saveProperties();
480 frame.setClosed(true);
481 } catch (Exception ex)
489 public void startupFileTextfield_mouseClicked()
491 JalviewFileChooser chooser = new JalviewFileChooser(
492 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
494 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
496 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
497 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
498 chooser.setFileView(new JalviewFileView());
499 chooser.setDialogTitle("Select startup file");
501 int value = chooser.showOpenDialog(this);
503 if (value == JalviewFileChooser.APPROVE_OPTION)
505 jalview.bin.Cache.applicationProperties.setProperty(
506 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
507 startupFileTextfield.setText(chooser.getSelectedFile()
518 public void cancel_actionPerformed(ActionEvent e)
522 wsPrefs.updateWsMenuConfig(true);
523 wsPrefs.refreshWs_actionPerformed(e);
524 frame.setClosed(true);
525 } catch (Exception ex)
536 public void annotations_actionPerformed(ActionEvent e)
538 conservation.setEnabled(annotations.isSelected());
539 quality.setEnabled(annotations.isSelected());
540 identity.setEnabled(annotations.isSelected());
541 showGroupConsensus.setEnabled(annotations.isSelected());
542 showGroupConservation.setEnabled(annotations.isSelected());
543 showConsensHistogram.setEnabled(annotations.isSelected()
544 && (identity.isSelected() || showGroupConsensus.isSelected()));
545 showConsensLogo.setEnabled(annotations.isSelected()
546 && (identity.isSelected() || showGroupConsensus.isSelected()));
549 public void newLink_actionPerformed(ActionEvent e)
552 GSequenceLink link = new GSequenceLink();
553 boolean valid = false;
556 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
557 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
558 null) == JOptionPane.OK_OPTION)
560 if (link.checkValid())
562 nameLinks.addElement(link.getName());
563 urlLinks.addElement(link.getURL());
575 public void editLink_actionPerformed(ActionEvent e)
577 GSequenceLink link = new GSequenceLink();
579 int index = linkNameList.getSelectedIndex();
582 JOptionPane.showInternalMessageDialog(Desktop.desktop,
583 "No link selected!", "No link selected",
584 JOptionPane.WARNING_MESSAGE);
588 link.setName(nameLinks.elementAt(index).toString());
589 link.setURL(urlLinks.elementAt(index).toString());
591 boolean valid = false;
595 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
596 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
597 null) == JOptionPane.OK_OPTION)
599 if (link.checkValid())
601 nameLinks.setElementAt(link.getName(), index);
602 urlLinks.setElementAt(link.getURL(), index);
615 public void deleteLink_actionPerformed(ActionEvent e)
617 int index = linkNameList.getSelectedIndex();
620 JOptionPane.showInternalMessageDialog(Desktop.desktop,
621 "No link selected!", "No link selected",
622 JOptionPane.WARNING_MESSAGE);
625 nameLinks.removeElementAt(index);
626 urlLinks.removeElementAt(index);
630 void updateLinkData()
632 linkNameList.setListData(nameLinks);
633 linkURLList.setListData(urlLinks);
636 public void defaultBrowser_mouseClicked(MouseEvent e)
638 JFileChooser chooser = new JFileChooser(".");
639 chooser.setDialogTitle("Select default web browser");
641 int value = chooser.showOpenDialog(this);
643 if (value == JFileChooser.APPROVE_OPTION)
645 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
654 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
657 protected void showunconserved_actionPerformed(ActionEvent e)
659 // TODO Auto-generated method stub
660 super.showunconserved_actionPerformed(e);
663 private void jbInit() throws Exception
667 public static Collection getGroupURLLinks()
669 return groupURLLinks;
672 public void minColour_actionPerformed()
674 Color col = JColorChooser.showDialog(this,
675 "Select Colour for Minimum Value", minColour.getBackground());
678 minColour.setBackground(col);
683 public void maxColour_actionPerformed()
685 Color col = JColorChooser.showDialog(this,
686 "Select Colour for Maximum Value", maxColour.getBackground());
689 maxColour.setBackground(col);
695 protected void userIdWidth_actionPerformed()
699 String val = userIdWidth.getText().trim();
700 if (val.length() > 0)
702 Integer iw = Integer.parseInt(val);
703 if (iw.intValue() < 12)
705 throw new NumberFormatException();
707 userIdWidth.setText(iw.toString());
709 } catch (NumberFormatException x)
712 .showInternalMessageDialog(
714 "The user defined width for the\nannotation and sequence ID columns\nin exported figures must be\nat least 12 pixels wide.",
715 "Invalid ID Column width",
716 JOptionPane.WARNING_MESSAGE);
717 userIdWidth.setText("");
722 protected void autoIdWidth_actionPerformed()
724 userIdWidth.setEnabled(!autoIdWidth.isSelected());
725 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());