2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
26 import java.awt.event.*;
32 import jalview.jbgui.*;
33 import jalview.schemes.*;
34 import jalview.util.MessageManager;
42 public class Preferences extends GPreferences
46 * Holds name and link separated with | character. Sequence ID must be
47 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
49 public static Vector sequenceURLLinks;
52 * Holds name and link separated with | character. Sequence IDS and Sequences
53 * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
54 * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
55 * for first and second token specified after a pipe character at end |,|.
56 * (TODO: proper escape for using | to separate ids or sequences
59 public static Vector groupURLLinks;
65 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
66 sequenceURLLinks = new Vector();
70 StringTokenizer st = new StringTokenizer(string, "|");
71 while (st.hasMoreElements())
73 String name = st.nextToken();
74 String url = st.nextToken();
75 // check for '|' within a regex
76 int rxstart = url.indexOf("$SEQUENCE_ID$");
77 while (rxstart == -1 && url.indexOf("/=$") == -1)
79 url = url + "|" + st.nextToken();
81 sequenceURLLinks.addElement(name + "|" + url);
83 } catch (Exception ex)
85 System.out.println(ex + "\nError parsing sequence links");
88 // upgrade old SRS link
89 int srsPos = sequenceURLLinks
90 .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
95 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
101 * TODO: reformulate groupURL encoding so two or more can be stored in the
102 * .properties file as '|' separated strings
105 groupURLLinks = new Vector();
108 Vector nameLinks, urlLinks;
110 JInternalFrame frame;
112 DasSourceBrowser dasSource;
114 private WsPreferences wsPrefs;
117 * Creates a new Preferences object.
122 frame = new JInternalFrame();
123 frame.setContentPane(this);
124 dasSource = new DasSourceBrowser();
125 dasPanel.add(dasSource, BorderLayout.CENTER);
126 wsPrefs = new WsPreferences();
127 wsPanel.add(wsPrefs, BorderLayout.CENTER);
128 int width = 500, height = 420;
129 if (new jalview.util.Platform().isAMac())
135 Desktop.addInternalFrame(frame,
136 MessageManager.getString("label.preferences"), width, height);
137 frame.setMinimumSize(new Dimension(width, height));
139 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
140 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
141 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
142 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
144 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
145 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
146 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
147 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
149 .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
150 showNpTooltip.setSelected(Cache
151 .getDefault("SHOW_NPFEATS_TOOLTIP", true));
152 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
154 sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
155 for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
157 colour.addItem(ColourSchemeProperty.getColourName(i));
160 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
162 colour.setSelectedItem(string);
165 * default min-max colours for annotation shading
167 minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
169 maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
172 String[] fonts = java.awt.GraphicsEnvironment
173 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
175 for (int i = 0; i < fonts.length; i++)
177 fontNameCB.addItem(fonts[i]);
180 for (int i = 1; i < 31; i++)
182 fontSizeCB.addItem(i + "");
185 fontStyleCB.addItem("plain");
186 fontStyleCB.addItem("bold");
187 fontStyleCB.addItem("italic");
189 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
190 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
191 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
194 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
196 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
198 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
200 gapSymbolCB.addItem("-");
201 gapSymbolCB.addItem(".");
203 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
206 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
207 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
208 Cache.getDefault("www.jalview.org", "http://www.jalview.org")
209 + "/examples/exampleFile_2_3.jar"));
211 sortby.addItem("No sort");
212 sortby.addItem("Id");
213 sortby.addItem("Pairwise Identity");
214 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
216 epsRendering.addItem(MessageManager.getString("label.prompt_each_time"));
217 epsRendering.addItem(MessageManager.getString("label.lineart"));
218 epsRendering.addItem(MessageManager.getString("action.text"));
219 epsRendering.setSelectedIndex(0);
220 autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
221 userIdWidth.setEnabled(autoIdWidth.isSelected());
222 userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
223 Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
224 userIdWidth.setText(wi == null ? "" : wi.toString());
225 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
226 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
227 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
228 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
229 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
230 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
231 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
233 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
235 autoCalculateConsCheck.setSelected(Cache.getDefault(
236 "AUTO_CALC_CONSENSUS", true));
237 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
239 showGroupConservation.setSelected(Cache.getDefault(
240 "SHOW_GROUP_CONSERVATION", false));
241 showConsensHistogram.setSelected(Cache.getDefault(
242 "SHOW_CONSENSUS_HISTOGRAM", true));
243 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
246 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
248 /***************************************************************************
251 nameLinks = new Vector();
252 urlLinks = new Vector();
253 for (int i = 0; i < sequenceURLLinks.size(); i++)
255 String link = sequenceURLLinks.elementAt(i).toString();
256 nameLinks.addElement(link.substring(0, link.indexOf("|")));
257 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
262 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
263 proxyServerTB.setEnabled(useProxy.isSelected());
264 proxyPortTB.setEnabled(useProxy.isSelected());
265 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
266 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
268 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
270 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
272 .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
275 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
278 annotations_actionPerformed(null); // update the display of the annotation
283 } catch (Exception ex)
285 ex.printStackTrace();
296 public void ok_actionPerformed(ActionEvent e)
299 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
300 Boolean.toString(seqLimit.isSelected()));
301 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
302 Boolean.toString(rightAlign.isSelected()));
303 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
304 Boolean.toString(fullScreen.isSelected()));
305 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
306 Boolean.toString(openoverv.isSelected()));
307 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
308 Boolean.toString(annotations.isSelected()));
309 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
310 Boolean.toString(conservation.isSelected()));
311 Cache.applicationProperties.setProperty("SHOW_QUALITY",
312 Boolean.toString(quality.isSelected()));
313 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
314 Boolean.toString(identity.isSelected()));
316 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
317 .getSelectedItem().toString());
318 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
319 .getSelectedItem().toString());
321 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
322 .getSelectedItem().toString());
323 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
324 .getSelectedItem().toString());
325 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
326 .getSelectedItem().toString());
328 Cache.applicationProperties.setProperty("ID_ITALICS",
329 Boolean.toString(idItalics.isSelected()));
330 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
331 Boolean.toString(showUnconserved.isSelected()));
332 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
333 Boolean.toString(showGroupConsensus.isSelected()));
334 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
335 Boolean.toString(showGroupConservation.isSelected()));
336 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
337 Boolean.toString(showConsensHistogram.isSelected()));
338 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
339 Boolean.toString(showConsensLogo.isSelected()));
340 Cache.applicationProperties.setProperty("ANTI_ALIAS",
341 Boolean.toString(smoothFont.isSelected()));
342 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
343 Boolean.toString(showNpTooltip.isSelected()));
344 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
345 Boolean.toString(showDbRefTooltip.isSelected()));
347 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
348 Boolean.toString(wrap.isSelected()));
350 Cache.applicationProperties.setProperty("STARTUP_FILE",
351 startupFileTextfield.getText());
352 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
353 Boolean.toString(startupCheckbox.isSelected()));
355 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
356 .getSelectedItem().toString());
358 Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
359 minColour.getBackground());
360 Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
361 maxColour.getBackground());
363 if (epsRendering.getSelectedItem().equals("Prompt each time"))
365 Cache.applicationProperties.remove("EPS_RENDERING");
369 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
370 .getSelectedItem().toString());
373 if (defaultBrowser.getText().trim().length() < 1)
375 Cache.applicationProperties.remove("DEFAULT_BROWSER");
379 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
380 defaultBrowser.getText());
383 jalview.util.BrowserLauncher.resetBrowser();
385 if (nameLinks.size() > 0)
387 StringBuffer links = new StringBuffer();
388 sequenceURLLinks = new Vector();
389 for (int i = 0; i < nameLinks.size(); i++)
391 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
392 + urlLinks.elementAt(i));
393 links.append(sequenceURLLinks.elementAt(i).toString());
397 links.setLength(links.length() - 1);
398 Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
403 Cache.applicationProperties.remove("SEQUENCE_LINKS");
406 Cache.applicationProperties.setProperty("USE_PROXY",
407 Boolean.toString(useProxy.isSelected()));
409 if (proxyServerTB.getText().trim().length() < 1)
411 Cache.applicationProperties.remove("PROXY_SERVER");
415 Cache.applicationProperties.setProperty("PROXY_SERVER",
416 proxyServerTB.getText());
419 if (proxyPortTB.getText().trim().length() < 1)
421 Cache.applicationProperties.remove("PROXY_PORT");
425 Cache.applicationProperties.setProperty("PROXY_PORT",
426 proxyPortTB.getText());
429 if (useProxy.isSelected())
431 System.setProperty("http.proxyHost", proxyServerTB.getText());
432 System.setProperty("http.proxyPort", proxyPortTB.getText());
436 System.setProperty("http.proxyHost", "");
437 System.setProperty("http.proxyPort", "");
439 Cache.setProperty("VERSION_CHECK",
440 Boolean.toString(versioncheck.isSelected()));
441 if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
443 // default is false - we only set this if the user has actively agreed
444 Cache.setProperty("USAGESTATS",
445 Boolean.toString(usagestats.isSelected()));
447 if (!questionnaire.isSelected())
449 Cache.setProperty("NOQUESTIONNAIRES", "true");
453 // special - made easy to edit a property file to disable questionnaires
454 // by just adding the given line
455 Cache.removeProperty("NOQUESTIONNAIRES");
457 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
458 Boolean.toString(blcjv.isSelected()));
459 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
460 Boolean.toString(clustaljv.isSelected()));
461 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
462 Boolean.toString(fastajv.isSelected()));
463 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
464 Boolean.toString(msfjv.isSelected()));
465 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
466 Boolean.toString(pfamjv.isSelected()));
467 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
468 Boolean.toString(pileupjv.isSelected()));
469 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
470 Boolean.toString(pirjv.isSelected()));
471 Cache.applicationProperties.setProperty("PIR_MODELLER",
472 Boolean.toString(modellerOutput.isSelected()));
473 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
475 Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
476 Boolean.toString(autoIdWidth.isSelected()));
477 userIdWidth_actionPerformed();
478 Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
479 userIdWidth.getText());
481 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
482 Boolean.toString(autoCalculateConsCheck.isSelected()));
483 Cache.applicationProperties.setProperty("SORT_BY_TREE",
484 Boolean.toString(sortByTree.isSelected()));
485 Cache.applicationProperties.setProperty("PAD_GAPS",
486 Boolean.toString(padGaps.isSelected()));
488 dasSource.saveProperties(Cache.applicationProperties);
489 wsPrefs.updateAndRefreshWsMenuConfig(false);
490 Cache.saveProperties();
493 frame.setClosed(true);
494 } catch (Exception ex)
502 public void startupFileTextfield_mouseClicked()
504 JalviewFileChooser chooser = new JalviewFileChooser(
505 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
507 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
509 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
510 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
511 chooser.setFileView(new JalviewFileView());
512 chooser.setDialogTitle(MessageManager.getString("label.select_startup_file"));
514 int value = chooser.showOpenDialog(this);
516 if (value == JalviewFileChooser.APPROVE_OPTION)
518 jalview.bin.Cache.applicationProperties.setProperty(
519 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
520 startupFileTextfield.setText(chooser.getSelectedFile()
531 public void cancel_actionPerformed(ActionEvent e)
535 wsPrefs.updateWsMenuConfig(true);
536 wsPrefs.refreshWs_actionPerformed(e);
537 frame.setClosed(true);
538 } catch (Exception ex)
549 public void annotations_actionPerformed(ActionEvent e)
551 conservation.setEnabled(annotations.isSelected());
552 quality.setEnabled(annotations.isSelected());
553 identity.setEnabled(annotations.isSelected());
554 showGroupConsensus.setEnabled(annotations.isSelected());
555 showGroupConservation.setEnabled(annotations.isSelected());
556 showConsensHistogram.setEnabled(annotations.isSelected()
557 && (identity.isSelected() || showGroupConsensus.isSelected()));
558 showConsensLogo.setEnabled(annotations.isSelected()
559 && (identity.isSelected() || showGroupConsensus.isSelected()));
562 public void newLink_actionPerformed(ActionEvent e)
565 GSequenceLink link = new GSequenceLink();
566 boolean valid = false;
569 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
570 MessageManager.getString("label.new_sequence_url_link"),
571 JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
573 if (link.checkValid())
575 nameLinks.addElement(link.getName());
576 urlLinks.addElement(link.getURL());
588 public void editLink_actionPerformed(ActionEvent e)
590 GSequenceLink link = new GSequenceLink();
592 int index = linkNameList.getSelectedIndex();
595 JOptionPane.showInternalMessageDialog(Desktop.desktop,
596 MessageManager.getString("label.no_link_selected"),
597 MessageManager.getString("label.no_link_selected"),
598 JOptionPane.WARNING_MESSAGE);
602 link.setName(nameLinks.elementAt(index).toString());
603 link.setURL(urlLinks.elementAt(index).toString());
605 boolean valid = false;
609 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
610 MessageManager.getString("label.new_sequence_url_link"),
611 JOptionPane.OK_CANCEL_OPTION, -1, null) == JOptionPane.OK_OPTION)
613 if (link.checkValid())
615 nameLinks.setElementAt(link.getName(), index);
616 urlLinks.setElementAt(link.getURL(), index);
629 public void deleteLink_actionPerformed(ActionEvent e)
631 int index = linkNameList.getSelectedIndex();
634 JOptionPane.showInternalMessageDialog(Desktop.desktop,
635 MessageManager.getString("label.no_link_selected"),
636 MessageManager.getString("label.no_link_selected"),
637 JOptionPane.WARNING_MESSAGE);
640 nameLinks.removeElementAt(index);
641 urlLinks.removeElementAt(index);
645 void updateLinkData()
647 linkNameList.setListData(nameLinks);
648 linkURLList.setListData(urlLinks);
651 public void defaultBrowser_mouseClicked(MouseEvent e)
653 JFileChooser chooser = new JFileChooser(".");
654 chooser.setDialogTitle(MessageManager.getString("label.select_default_browser"));
656 int value = chooser.showOpenDialog(this);
658 if (value == JFileChooser.APPROVE_OPTION)
660 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
669 * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
672 protected void showunconserved_actionPerformed(ActionEvent e)
674 // TODO Auto-generated method stub
675 super.showunconserved_actionPerformed(e);
678 private void jbInit() throws Exception
682 public static Collection getGroupURLLinks()
684 return groupURLLinks;
687 public void minColour_actionPerformed()
689 Color col = JColorChooser.showDialog(this,
690 MessageManager.getString("label.select_colour_minimum_value"), minColour.getBackground());
693 minColour.setBackground(col);
698 public void maxColour_actionPerformed()
700 Color col = JColorChooser.showDialog(this,
701 MessageManager.getString("label.select_colour_maximum_value"), maxColour.getBackground());
704 maxColour.setBackground(col);
710 protected void userIdWidth_actionPerformed()
714 String val = userIdWidth.getText().trim();
715 if (val.length() > 0)
717 Integer iw = Integer.parseInt(val);
718 if (iw.intValue() < 12)
720 throw new NumberFormatException();
722 userIdWidth.setText(iw.toString());
724 } catch (NumberFormatException x)
727 .showInternalMessageDialog(
729 MessageManager.getString("warn.user_defined_width_requirements"),
730 MessageManager.getString("label.invalid_id_column_width"),
731 JOptionPane.WARNING_MESSAGE);
732 userIdWidth.setText("");
737 protected void autoIdWidth_actionPerformed()
739 userIdWidth.setEnabled(!autoIdWidth.isSelected());
740 userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());