2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
30 import jalview.jbgui.*;
31 import jalview.schemes.*;
32 import jalview.ws.EnfinEnvision2OneWay;
40 public class Preferences extends GPreferences
44 * Holds name and link separated with | character. Sequence ID must be
45 * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
47 public static Vector sequenceURLLinks;
49 * Holds name and link separated with | character. Sequence IDS and Sequences must be
50 * $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$
51 * and separation character for first and second token specified after a pipe character at end |,|.
52 * (TODO: proper escape for using | to separate ids or sequences
55 public static Vector groupURLLinks;
61 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
62 sequenceURLLinks = new Vector();
66 StringTokenizer st = new StringTokenizer(string, "|");
67 while (st.hasMoreElements())
69 String name = st.nextToken();
70 String url = st.nextToken();
71 // check for '|' within a regex
72 int rxstart = url.indexOf("$SEQUENCE_ID$");
73 while (rxstart == -1 && url.indexOf("/=$") == -1)
75 url = url + "|" + st.nextToken();
77 sequenceURLLinks.addElement(name + "|" + url);
79 } catch (Exception ex)
81 System.out.println(ex + "\nError parsing sequence links");
84 * TODO: reformulate groupURL encoding so two or more can be stored in the .properties file as '|' separated strings
87 groupURLLinks = new Vector();
88 //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|,");
89 //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|,");
93 Vector nameLinks, urlLinks;
97 DasSourceBrowser dasSource;
100 * Creates a new Preferences object.
105 frame = new JInternalFrame();
106 frame.setContentPane(this);
107 dasSource = new DasSourceBrowser();
108 dasPanel.add(dasSource, BorderLayout.CENTER);
110 int width = 500, height = 420;
111 if (new jalview.util.Platform().isAMac())
117 Desktop.addInternalFrame(frame, "Preferences", width, height);
118 frame.setMinimumSize(new Dimension(width, height));
120 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
121 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
122 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
123 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
125 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
126 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
127 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
128 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
129 showUnconserved.setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
131 for (int i = 0; i < 13; i++)
133 colour.addItem(ColourSchemeProperty.getColourName(i));
136 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
138 colour.setSelectedItem(string);
140 String[] fonts = java.awt.GraphicsEnvironment
141 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
143 for (int i = 0; i < fonts.length; i++)
145 fontNameCB.addItem(fonts[i]);
148 for (int i = 1; i < 31; i++)
150 fontSizeCB.addItem(i + "");
153 fontStyleCB.addItem("plain");
154 fontStyleCB.addItem("bold");
155 fontStyleCB.addItem("italic");
157 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
158 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
159 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
162 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
164 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
166 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
168 gapSymbolCB.addItem("-");
169 gapSymbolCB.addItem(".");
171 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
174 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
175 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
176 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
178 sortby.addItem("No sort");
179 sortby.addItem("Id");
180 sortby.addItem("Pairwise Identity");
181 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
183 epsRendering.addItem("Prompt each time");
184 epsRendering.addItem("Lineart");
185 epsRendering.addItem("Text");
186 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
187 "Prompt each time"));
189 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
190 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
191 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
192 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
193 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
194 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
195 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
197 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
199 autoCalculateConsCheck.setSelected(Cache.getDefault(
200 "AUTO_CALC_CONSENSUS", true));
201 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",false));
202 showGroupConservation.setSelected(Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
203 showConsensHistogram.setSelected(Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",true));
204 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",false));
206 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
208 /***************************************************************************
211 nameLinks = new Vector();
212 urlLinks = new Vector();
213 for (int i = 0; i < sequenceURLLinks.size(); i++)
215 String link = sequenceURLLinks.elementAt(i).toString();
216 nameLinks.addElement(link.substring(0, link.indexOf("|")));
217 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
222 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
223 proxyServerTB.setEnabled(useProxy.isSelected());
224 proxyPortTB.setEnabled(useProxy.isSelected());
225 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
226 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
228 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
230 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
231 questionnaire.setSelected(Cache.getProperty("NOQUESTIONNAIRES")==null); // note antisense here
232 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default is true
233 annotations_actionPerformed(null); // update the display of the annotation settings
237 } catch (Exception ex)
239 ex.printStackTrace();
250 public void ok_actionPerformed(ActionEvent e)
253 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
254 .toString(seqLimit.isSelected()));
255 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
256 .toString(rightAlign.isSelected()));
257 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
258 .toString(fullScreen.isSelected()));
259 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
260 .toString(openoverv.isSelected()));
261 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
262 .toString(annotations.isSelected()));
263 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
264 .toString(conservation.isSelected()));
265 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
266 .toString(quality.isSelected()));
267 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
268 .toString(identity.isSelected()));
270 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
271 .getSelectedItem().toString());
272 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
273 .getSelectedItem().toString());
275 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
276 .getSelectedItem().toString());
277 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
278 .getSelectedItem().toString());
279 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
280 .getSelectedItem().toString());
282 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
283 .toString(idItalics.isSelected()));
284 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",Boolean.toString(showUnconserved.isSelected()));
285 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",Boolean.toString(showGroupConsensus.isSelected()));
286 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",Boolean.toString(showGroupConservation.isSelected()));
287 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",Boolean.toString(showConsensHistogram.isSelected()));
288 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",Boolean.toString(showConsensLogo.isSelected()));
289 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
290 .toString(smoothFont.isSelected()));
292 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
293 .toString(wrap.isSelected()));
295 Cache.applicationProperties.setProperty("STARTUP_FILE",
296 startupFileTextfield.getText());
297 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
298 .toString(startupCheckbox.isSelected()));
300 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
301 .getSelectedItem().toString());
303 if (epsRendering.getSelectedItem().equals("Prompt each time"))
305 Cache.applicationProperties.remove("EPS_RENDERING");
309 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
310 .getSelectedItem().toString());
313 if (defaultBrowser.getText().trim().length() < 1)
315 Cache.applicationProperties.remove("DEFAULT_BROWSER");
319 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
320 defaultBrowser.getText());
323 jalview.util.BrowserLauncher.resetBrowser();
325 if (nameLinks.size() > 0)
327 StringBuffer links = new StringBuffer();
328 sequenceURLLinks = new Vector();
329 for (int i = 0; i < nameLinks.size(); i++)
331 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
332 + urlLinks.elementAt(i));
333 links.append(sequenceURLLinks.elementAt(i).toString());
337 links.setLength(links.length() - 1);
338 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
343 Cache.applicationProperties.remove("SEQUENCE_LINKS");
346 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
347 .toString(useProxy.isSelected()));
349 if (proxyServerTB.getText().trim().length() < 1)
351 Cache.applicationProperties.remove("PROXY_SERVER");
355 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
359 if (proxyPortTB.getText().trim().length() < 1)
361 Cache.applicationProperties.remove("PROXY_PORT");
365 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
369 if (useProxy.isSelected())
371 System.setProperty("http.proxyHost", proxyServerTB.getText());
372 System.setProperty("http.proxyPort", proxyPortTB.getText());
376 System.setProperty("http.proxyHost", "");
377 System.setProperty("http.proxyPort", "");
379 Cache.setProperty("VERSION_CHECK", Boolean
380 .toString(versioncheck.isSelected()));
381 if (Cache.getProperty("USAGESTATS")!=null || usagestats.isSelected()) {
382 // default is false - we only set this if the user has actively agreed
383 Cache.setProperty("USAGESTATS",Boolean
384 .toString(usagestats.isSelected()));
386 if (!questionnaire.isSelected())
388 Cache.setProperty("NOQUESTIONNAIRES", "true");
390 // special - made easy to edit a property file to disable questionnaires by just adding the given line
391 Cache.removeProperty("NOQUESTIONNAIRES");
393 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
394 .toString(blcjv.isSelected()));
395 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
396 .toString(clustaljv.isSelected()));
397 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
398 .toString(fastajv.isSelected()));
399 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
400 .toString(msfjv.isSelected()));
401 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
402 .toString(pfamjv.isSelected()));
403 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
404 .toString(pileupjv.isSelected()));
405 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
406 .toString(pirjv.isSelected()));
407 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
408 .toString(modellerOutput.isSelected()));
409 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
411 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
412 .toString(autoCalculateConsCheck.isSelected()));
413 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
414 .toString(padGaps.isSelected()));
416 dasSource.saveProperties(Cache.applicationProperties);
418 Cache.saveProperties();
421 frame.setClosed(true);
422 } catch (Exception ex)
430 public void startupFileTextfield_mouseClicked()
432 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
433 .getProperty("LAST_DIRECTORY"), new String[]
434 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
436 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
437 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
438 chooser.setFileView(new JalviewFileView());
439 chooser.setDialogTitle("Select startup file");
441 int value = chooser.showOpenDialog(this);
443 if (value == JalviewFileChooser.APPROVE_OPTION)
445 jalview.bin.Cache.applicationProperties.setProperty(
446 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
447 startupFileTextfield.setText(chooser.getSelectedFile()
458 public void cancel_actionPerformed(ActionEvent e)
462 frame.setClosed(true);
463 } catch (Exception ex)
474 public void annotations_actionPerformed(ActionEvent e)
476 conservation.setEnabled(annotations.isSelected());
477 quality.setEnabled(annotations.isSelected());
478 identity.setEnabled(annotations.isSelected());
479 showGroupConsensus.setEnabled(annotations.isSelected());
480 showGroupConservation.setEnabled(annotations.isSelected());
481 showConsensHistogram.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected()));
482 showConsensLogo.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected()));
485 public void newLink_actionPerformed(ActionEvent e)
488 GSequenceLink link = new GSequenceLink();
489 boolean valid = false;
492 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
493 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
494 null) == JOptionPane.OK_OPTION)
496 if (link.checkValid())
498 nameLinks.addElement(link.getName());
499 urlLinks.addElement(link.getURL());
511 public void editLink_actionPerformed(ActionEvent e)
513 GSequenceLink link = new GSequenceLink();
515 int index = linkNameList.getSelectedIndex();
518 JOptionPane.showInternalMessageDialog(Desktop.desktop,
519 "No link selected!", "No link selected",
520 JOptionPane.WARNING_MESSAGE);
524 link.setName(nameLinks.elementAt(index).toString());
525 link.setURL(urlLinks.elementAt(index).toString());
527 boolean valid = false;
531 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
532 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
533 null) == JOptionPane.OK_OPTION)
535 if (link.checkValid())
537 nameLinks.setElementAt(link.getName(), index);
538 urlLinks.setElementAt(link.getURL(), index);
551 public void deleteLink_actionPerformed(ActionEvent e)
553 int index = linkNameList.getSelectedIndex();
556 JOptionPane.showInternalMessageDialog(Desktop.desktop,
557 "No link selected!", "No link selected",
558 JOptionPane.WARNING_MESSAGE);
561 nameLinks.removeElementAt(index);
562 urlLinks.removeElementAt(index);
566 void updateLinkData()
568 linkNameList.setListData(nameLinks);
569 linkURLList.setListData(urlLinks);
572 public void defaultBrowser_mouseClicked(MouseEvent e)
574 JFileChooser chooser = new JFileChooser(".");
575 chooser.setDialogTitle("Select default web browser");
577 int value = chooser.showOpenDialog(this);
579 if (value == JFileChooser.APPROVE_OPTION)
581 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
586 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
588 protected void showunconserved_actionPerformed(ActionEvent e)
590 // TODO Auto-generated method stub
591 super.showunconserved_actionPerformed(e);
594 private void jbInit() throws Exception
598 public static Collection getGroupURLLinks()
600 return groupURLLinks;