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.*;
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;
48 * Holds name and link separated with | character. Sequence IDS and Sequences must be
49 * $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$
50 * and separation character for first and second token specified after a pipe character at end |,|.
51 * (TODO: proper escape for using | to separate ids or sequences
54 public static Vector groupURLLinks;
60 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
61 sequenceURLLinks = new Vector();
65 StringTokenizer st = new StringTokenizer(string, "|");
66 while (st.hasMoreElements())
68 String name = st.nextToken();
69 String url = st.nextToken();
70 // check for '|' within a regex
71 int rxstart = url.indexOf("$SEQUENCE_ID$");
72 while (rxstart == -1 && url.indexOf("/=$") == -1)
74 url = url + "|" + st.nextToken();
76 sequenceURLLinks.addElement(name + "|" + url);
78 } catch (Exception ex)
80 System.out.println(ex + "\nError parsing sequence links");
83 * TODO: reformulate groupURL encoding so two or more can be stored in the .properties file as '|' separated strings
86 groupURLLinks = new Vector();
87 groupURLLinks.addElement("UNIPROT|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewIDs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,");
88 groupURLLinks.addElement("Seqs|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,");
92 Vector nameLinks, urlLinks;
96 DasSourceBrowser dasSource;
99 * Creates a new Preferences object.
104 frame = new JInternalFrame();
105 frame.setContentPane(this);
106 dasSource = new DasSourceBrowser();
107 dasPanel.add(dasSource, BorderLayout.CENTER);
109 int width = 500, height = 420;
110 if (new jalview.util.Platform().isAMac())
116 Desktop.addInternalFrame(frame, "Preferences", width, height);
117 frame.setMinimumSize(new Dimension(width, height));
119 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
120 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
121 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
122 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
124 conservation.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
125 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
126 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
128 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
129 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
130 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
131 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
132 showUnconserved.setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
134 for (int i = 0; i < 13; i++)
136 colour.addItem(ColourSchemeProperty.getColourName(i));
139 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
141 colour.setSelectedItem(string);
143 String[] fonts = java.awt.GraphicsEnvironment
144 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
146 for (int i = 0; i < fonts.length; i++)
148 fontNameCB.addItem(fonts[i]);
151 for (int i = 1; i < 31; i++)
153 fontSizeCB.addItem(i + "");
156 fontStyleCB.addItem("plain");
157 fontStyleCB.addItem("bold");
158 fontStyleCB.addItem("italic");
160 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
161 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
162 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
165 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
167 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
169 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
171 gapSymbolCB.addItem("-");
172 gapSymbolCB.addItem(".");
174 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
177 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
178 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
179 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
181 sortby.addItem("No sort");
182 sortby.addItem("Id");
183 sortby.addItem("Pairwise Identity");
184 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
186 epsRendering.addItem("Prompt each time");
187 epsRendering.addItem("Lineart");
188 epsRendering.addItem("Text");
189 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
190 "Prompt each time"));
192 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
193 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
194 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
195 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
196 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
197 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
198 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
200 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
202 autoCalculateConsCheck.setSelected(Cache.getDefault(
203 "AUTO_CALC_CONSENSUS", true));
204 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
206 /***************************************************************************
209 nameLinks = new Vector();
210 urlLinks = new Vector();
211 for (int i = 0; i < sequenceURLLinks.size(); i++)
213 String link = sequenceURLLinks.elementAt(i).toString();
214 nameLinks.addElement(link.substring(0, link.indexOf("|")));
215 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
220 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
221 proxyServerTB.setEnabled(useProxy.isSelected());
222 proxyPortTB.setEnabled(useProxy.isSelected());
223 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
224 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
226 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
228 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
229 questionnaire.setSelected(Cache.getProperty("NOQUESTIONNAIRES")==null); // note antisense here
230 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default is true
235 } catch (Exception ex)
237 ex.printStackTrace();
248 public void ok_actionPerformed(ActionEvent e)
251 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
252 .toString(seqLimit.isSelected()));
253 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
254 .toString(rightAlign.isSelected()));
255 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
256 .toString(fullScreen.isSelected()));
257 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
258 .toString(openoverv.isSelected()));
259 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
260 .toString(annotations.isSelected()));
261 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
262 .toString(conservation.isSelected()));
263 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
264 .toString(quality.isSelected()));
265 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
266 .toString(identity.isSelected()));
268 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
269 .getSelectedItem().toString());
270 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
271 .getSelectedItem().toString());
273 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
274 .getSelectedItem().toString());
275 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
276 .getSelectedItem().toString());
277 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
278 .getSelectedItem().toString());
280 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
281 .toString(idItalics.isSelected()));
282 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",Boolean.toString(showUnconserved.isSelected()));
283 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
284 .toString(smoothFont.isSelected()));
286 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
287 .toString(wrap.isSelected()));
289 Cache.applicationProperties.setProperty("STARTUP_FILE",
290 startupFileTextfield.getText());
291 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
292 .toString(startupCheckbox.isSelected()));
294 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
295 .getSelectedItem().toString());
297 if (epsRendering.getSelectedItem().equals("Prompt each time"))
299 Cache.applicationProperties.remove("EPS_RENDERING");
303 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
304 .getSelectedItem().toString());
307 if (defaultBrowser.getText().trim().length() < 1)
309 Cache.applicationProperties.remove("DEFAULT_BROWSER");
313 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
314 defaultBrowser.getText());
317 jalview.util.BrowserLauncher.resetBrowser();
319 if (nameLinks.size() > 0)
321 StringBuffer links = new StringBuffer();
322 sequenceURLLinks = new Vector();
323 for (int i = 0; i < nameLinks.size(); i++)
325 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
326 + urlLinks.elementAt(i));
327 links.append(sequenceURLLinks.elementAt(i).toString());
331 links.setLength(links.length() - 1);
332 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
337 Cache.applicationProperties.remove("SEQUENCE_LINKS");
340 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
341 .toString(useProxy.isSelected()));
343 if (proxyServerTB.getText().trim().length() < 1)
345 Cache.applicationProperties.remove("PROXY_SERVER");
349 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
353 if (proxyPortTB.getText().trim().length() < 1)
355 Cache.applicationProperties.remove("PROXY_PORT");
359 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
363 if (useProxy.isSelected())
365 System.setProperty("http.proxyHost", proxyServerTB.getText());
366 System.setProperty("http.proxyPort", proxyPortTB.getText());
370 System.setProperty("http.proxyHost", "");
371 System.setProperty("http.proxyPort", "");
373 Cache.setProperty("VERSION_CHECK", Boolean
374 .toString(versioncheck.isSelected()));
375 if (Cache.getProperty("USAGESTATS")!=null || usagestats.isSelected()) {
376 // default is false - we only set this if the user has actively agreed
377 Cache.setProperty("USAGESTATS",Boolean
378 .toString(usagestats.isSelected()));
380 if (!questionnaire.isSelected())
382 Cache.setProperty("NOQUESTIONNAIRES", "true");
384 // special - made easy to edit a property file to disable questionnaires by just adding the given line
385 Cache.removeProperty("NOQUESTIONNAIRES");
387 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
388 .toString(blcjv.isSelected()));
389 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
390 .toString(clustaljv.isSelected()));
391 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
392 .toString(fastajv.isSelected()));
393 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
394 .toString(msfjv.isSelected()));
395 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
396 .toString(pfamjv.isSelected()));
397 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
398 .toString(pileupjv.isSelected()));
399 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
400 .toString(pirjv.isSelected()));
401 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
402 .toString(modellerOutput.isSelected()));
403 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
405 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
406 .toString(autoCalculateConsCheck.isSelected()));
407 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
408 .toString(padGaps.isSelected()));
410 dasSource.saveProperties(Cache.applicationProperties);
412 Cache.saveProperties();
415 frame.setClosed(true);
416 } catch (Exception ex)
424 public void startupFileTextfield_mouseClicked()
426 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
427 .getProperty("LAST_DIRECTORY"), new String[]
428 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
430 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
431 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
432 chooser.setFileView(new JalviewFileView());
433 chooser.setDialogTitle("Select startup file");
435 int value = chooser.showOpenDialog(this);
437 if (value == JalviewFileChooser.APPROVE_OPTION)
439 jalview.bin.Cache.applicationProperties.setProperty(
440 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
441 startupFileTextfield.setText(chooser.getSelectedFile()
452 public void cancel_actionPerformed(ActionEvent e)
456 frame.setClosed(true);
457 } catch (Exception ex)
468 public void annotations_actionPerformed(ActionEvent e)
470 conservation.setEnabled(annotations.isSelected());
471 quality.setEnabled(annotations.isSelected());
472 identity.setEnabled(annotations.isSelected());
475 public void newLink_actionPerformed(ActionEvent e)
478 GSequenceLink link = new GSequenceLink();
479 boolean valid = false;
482 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
483 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
484 null) == JOptionPane.OK_OPTION)
486 if (link.checkValid())
488 nameLinks.addElement(link.getName());
489 urlLinks.addElement(link.getURL());
501 public void editLink_actionPerformed(ActionEvent e)
503 GSequenceLink link = new GSequenceLink();
505 int index = linkNameList.getSelectedIndex();
508 JOptionPane.showInternalMessageDialog(Desktop.desktop,
509 "No link selected!", "No link selected",
510 JOptionPane.WARNING_MESSAGE);
514 link.setName(nameLinks.elementAt(index).toString());
515 link.setURL(urlLinks.elementAt(index).toString());
517 boolean valid = false;
521 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
522 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
523 null) == JOptionPane.OK_OPTION)
525 if (link.checkValid())
527 nameLinks.setElementAt(link.getName(), index);
528 urlLinks.setElementAt(link.getURL(), index);
541 public void deleteLink_actionPerformed(ActionEvent e)
543 int index = linkNameList.getSelectedIndex();
546 JOptionPane.showInternalMessageDialog(Desktop.desktop,
547 "No link selected!", "No link selected",
548 JOptionPane.WARNING_MESSAGE);
551 nameLinks.removeElementAt(index);
552 urlLinks.removeElementAt(index);
556 void updateLinkData()
558 linkNameList.setListData(nameLinks);
559 linkURLList.setListData(urlLinks);
562 public void defaultBrowser_mouseClicked(MouseEvent e)
564 JFileChooser chooser = new JFileChooser(".");
565 chooser.setDialogTitle("Select default web browser");
567 int value = chooser.showOpenDialog(this);
569 if (value == JFileChooser.APPROVE_OPTION)
571 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
576 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
578 protected void showunconserved_actionPerformed(ActionEvent e)
580 // TODO Auto-generated method stub
581 super.showunconserved_actionPerformed(e);
584 private void jbInit() throws Exception