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));
130 showNpTooltip.setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
131 showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
133 for (int i = 0; i < 13; i++)
135 colour.addItem(ColourSchemeProperty.getColourName(i));
138 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
140 colour.setSelectedItem(string);
142 String[] fonts = java.awt.GraphicsEnvironment
143 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
145 for (int i = 0; i < fonts.length; i++)
147 fontNameCB.addItem(fonts[i]);
150 for (int i = 1; i < 31; i++)
152 fontSizeCB.addItem(i + "");
155 fontStyleCB.addItem("plain");
156 fontStyleCB.addItem("bold");
157 fontStyleCB.addItem("italic");
159 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
160 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
161 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
164 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
166 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
168 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
170 gapSymbolCB.addItem("-");
171 gapSymbolCB.addItem(".");
173 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
176 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
177 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
178 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
180 sortby.addItem("No sort");
181 sortby.addItem("Id");
182 sortby.addItem("Pairwise Identity");
183 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
185 epsRendering.addItem("Prompt each time");
186 epsRendering.addItem("Lineart");
187 epsRendering.addItem("Text");
188 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
189 "Prompt each time"));
191 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
192 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
193 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
194 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
195 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
196 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
197 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
199 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
201 autoCalculateConsCheck.setSelected(Cache.getDefault(
202 "AUTO_CALC_CONSENSUS", true));
203 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",false));
204 showGroupConservation.setSelected(Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
205 showConsensHistogram.setSelected(Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",true));
206 showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",false));
208 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
210 /***************************************************************************
213 nameLinks = new Vector();
214 urlLinks = new Vector();
215 for (int i = 0; i < sequenceURLLinks.size(); i++)
217 String link = sequenceURLLinks.elementAt(i).toString();
218 nameLinks.addElement(link.substring(0, link.indexOf("|")));
219 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
224 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
225 proxyServerTB.setEnabled(useProxy.isSelected());
226 proxyPortTB.setEnabled(useProxy.isSelected());
227 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
228 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
230 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
232 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
233 questionnaire.setSelected(Cache.getProperty("NOQUESTIONNAIRES")==null); // note antisense here
234 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default is true
235 annotations_actionPerformed(null); // update the display of the annotation settings
239 } catch (Exception ex)
241 ex.printStackTrace();
252 public void ok_actionPerformed(ActionEvent e)
255 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
256 .toString(seqLimit.isSelected()));
257 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
258 .toString(rightAlign.isSelected()));
259 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
260 .toString(fullScreen.isSelected()));
261 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
262 .toString(openoverv.isSelected()));
263 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
264 .toString(annotations.isSelected()));
265 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
266 .toString(conservation.isSelected()));
267 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
268 .toString(quality.isSelected()));
269 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
270 .toString(identity.isSelected()));
272 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
273 .getSelectedItem().toString());
274 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
275 .getSelectedItem().toString());
277 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
278 .getSelectedItem().toString());
279 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
280 .getSelectedItem().toString());
281 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
282 .getSelectedItem().toString());
284 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
285 .toString(idItalics.isSelected()));
286 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",Boolean.toString(showUnconserved.isSelected()));
287 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",Boolean.toString(showGroupConsensus.isSelected()));
288 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",Boolean.toString(showGroupConservation.isSelected()));
289 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",Boolean.toString(showConsensHistogram.isSelected()));
290 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",Boolean.toString(showConsensLogo.isSelected()));
291 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
292 .toString(smoothFont.isSelected()));
293 Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP", Boolean.toString(showNpTooltip.isSelected()));
294 Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP", Boolean.toString(showDbRefTooltip.isSelected()));
296 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
297 .toString(wrap.isSelected()));
299 Cache.applicationProperties.setProperty("STARTUP_FILE",
300 startupFileTextfield.getText());
301 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
302 .toString(startupCheckbox.isSelected()));
304 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
305 .getSelectedItem().toString());
307 if (epsRendering.getSelectedItem().equals("Prompt each time"))
309 Cache.applicationProperties.remove("EPS_RENDERING");
313 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
314 .getSelectedItem().toString());
317 if (defaultBrowser.getText().trim().length() < 1)
319 Cache.applicationProperties.remove("DEFAULT_BROWSER");
323 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
324 defaultBrowser.getText());
327 jalview.util.BrowserLauncher.resetBrowser();
329 if (nameLinks.size() > 0)
331 StringBuffer links = new StringBuffer();
332 sequenceURLLinks = new Vector();
333 for (int i = 0; i < nameLinks.size(); i++)
335 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
336 + urlLinks.elementAt(i));
337 links.append(sequenceURLLinks.elementAt(i).toString());
341 links.setLength(links.length() - 1);
342 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
347 Cache.applicationProperties.remove("SEQUENCE_LINKS");
350 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
351 .toString(useProxy.isSelected()));
353 if (proxyServerTB.getText().trim().length() < 1)
355 Cache.applicationProperties.remove("PROXY_SERVER");
359 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
363 if (proxyPortTB.getText().trim().length() < 1)
365 Cache.applicationProperties.remove("PROXY_PORT");
369 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
373 if (useProxy.isSelected())
375 System.setProperty("http.proxyHost", proxyServerTB.getText());
376 System.setProperty("http.proxyPort", proxyPortTB.getText());
380 System.setProperty("http.proxyHost", "");
381 System.setProperty("http.proxyPort", "");
383 Cache.setProperty("VERSION_CHECK", Boolean
384 .toString(versioncheck.isSelected()));
385 if (Cache.getProperty("USAGESTATS")!=null || usagestats.isSelected()) {
386 // default is false - we only set this if the user has actively agreed
387 Cache.setProperty("USAGESTATS",Boolean
388 .toString(usagestats.isSelected()));
390 if (!questionnaire.isSelected())
392 Cache.setProperty("NOQUESTIONNAIRES", "true");
394 // special - made easy to edit a property file to disable questionnaires by just adding the given line
395 Cache.removeProperty("NOQUESTIONNAIRES");
397 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
398 .toString(blcjv.isSelected()));
399 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
400 .toString(clustaljv.isSelected()));
401 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
402 .toString(fastajv.isSelected()));
403 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
404 .toString(msfjv.isSelected()));
405 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
406 .toString(pfamjv.isSelected()));
407 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
408 .toString(pileupjv.isSelected()));
409 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
410 .toString(pirjv.isSelected()));
411 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
412 .toString(modellerOutput.isSelected()));
413 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
415 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
416 .toString(autoCalculateConsCheck.isSelected()));
417 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
418 .toString(padGaps.isSelected()));
420 dasSource.saveProperties(Cache.applicationProperties);
422 Cache.saveProperties();
425 frame.setClosed(true);
426 } catch (Exception ex)
434 public void startupFileTextfield_mouseClicked()
436 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
437 .getProperty("LAST_DIRECTORY"), new String[]
438 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
440 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
441 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
442 chooser.setFileView(new JalviewFileView());
443 chooser.setDialogTitle("Select startup file");
445 int value = chooser.showOpenDialog(this);
447 if (value == JalviewFileChooser.APPROVE_OPTION)
449 jalview.bin.Cache.applicationProperties.setProperty(
450 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
451 startupFileTextfield.setText(chooser.getSelectedFile()
462 public void cancel_actionPerformed(ActionEvent e)
466 frame.setClosed(true);
467 } catch (Exception ex)
478 public void annotations_actionPerformed(ActionEvent e)
480 conservation.setEnabled(annotations.isSelected());
481 quality.setEnabled(annotations.isSelected());
482 identity.setEnabled(annotations.isSelected());
483 showGroupConsensus.setEnabled(annotations.isSelected());
484 showGroupConservation.setEnabled(annotations.isSelected());
485 showConsensHistogram.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected()));
486 showConsensLogo.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected()));
489 public void newLink_actionPerformed(ActionEvent e)
492 GSequenceLink link = new GSequenceLink();
493 boolean valid = false;
496 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
497 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
498 null) == JOptionPane.OK_OPTION)
500 if (link.checkValid())
502 nameLinks.addElement(link.getName());
503 urlLinks.addElement(link.getURL());
515 public void editLink_actionPerformed(ActionEvent e)
517 GSequenceLink link = new GSequenceLink();
519 int index = linkNameList.getSelectedIndex();
522 JOptionPane.showInternalMessageDialog(Desktop.desktop,
523 "No link selected!", "No link selected",
524 JOptionPane.WARNING_MESSAGE);
528 link.setName(nameLinks.elementAt(index).toString());
529 link.setURL(urlLinks.elementAt(index).toString());
531 boolean valid = false;
535 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
536 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
537 null) == JOptionPane.OK_OPTION)
539 if (link.checkValid())
541 nameLinks.setElementAt(link.getName(), index);
542 urlLinks.setElementAt(link.getURL(), index);
555 public void deleteLink_actionPerformed(ActionEvent e)
557 int index = linkNameList.getSelectedIndex();
560 JOptionPane.showInternalMessageDialog(Desktop.desktop,
561 "No link selected!", "No link selected",
562 JOptionPane.WARNING_MESSAGE);
565 nameLinks.removeElementAt(index);
566 urlLinks.removeElementAt(index);
570 void updateLinkData()
572 linkNameList.setListData(nameLinks);
573 linkURLList.setListData(urlLinks);
576 public void defaultBrowser_mouseClicked(MouseEvent e)
578 JFileChooser chooser = new JFileChooser(".");
579 chooser.setDialogTitle("Select default web browser");
581 int value = chooser.showOpenDialog(this);
583 if (value == JFileChooser.APPROVE_OPTION)
585 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
590 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
592 protected void showunconserved_actionPerformed(ActionEvent e)
594 // TODO Auto-generated method stub
595 super.showunconserved_actionPerformed(e);
598 private void jbInit() throws Exception
602 public static Collection getGroupURLLinks()
604 return groupURLLinks;