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 // TODO: make sequence Group URL links more efficiently generated so popup menu does not take so long.
89 // 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|,");
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.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
126 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
127 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
129 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
130 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
131 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
132 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
133 showUnconserved.setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
135 for (int i = 0; i < 13; i++)
137 colour.addItem(ColourSchemeProperty.getColourName(i));
140 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
142 colour.setSelectedItem(string);
144 String[] fonts = java.awt.GraphicsEnvironment
145 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
147 for (int i = 0; i < fonts.length; i++)
149 fontNameCB.addItem(fonts[i]);
152 for (int i = 1; i < 31; i++)
154 fontSizeCB.addItem(i + "");
157 fontStyleCB.addItem("plain");
158 fontStyleCB.addItem("bold");
159 fontStyleCB.addItem("italic");
161 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
162 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
163 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
166 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
168 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
170 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
172 gapSymbolCB.addItem("-");
173 gapSymbolCB.addItem(".");
175 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
178 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
179 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
180 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
182 sortby.addItem("No sort");
183 sortby.addItem("Id");
184 sortby.addItem("Pairwise Identity");
185 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
187 epsRendering.addItem("Prompt each time");
188 epsRendering.addItem("Lineart");
189 epsRendering.addItem("Text");
190 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
191 "Prompt each time"));
193 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
194 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
195 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
196 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
197 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
198 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
199 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
201 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
203 autoCalculateConsCheck.setSelected(Cache.getDefault(
204 "AUTO_CALC_CONSENSUS", true));
205 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
207 /***************************************************************************
210 nameLinks = new Vector();
211 urlLinks = new Vector();
212 for (int i = 0; i < sequenceURLLinks.size(); i++)
214 String link = sequenceURLLinks.elementAt(i).toString();
215 nameLinks.addElement(link.substring(0, link.indexOf("|")));
216 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
221 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
222 proxyServerTB.setEnabled(useProxy.isSelected());
223 proxyPortTB.setEnabled(useProxy.isSelected());
224 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
225 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
227 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
229 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
230 questionnaire.setSelected(Cache.getProperty("NOQUESTIONNAIRES")==null); // note antisense here
231 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default is true
236 } catch (Exception ex)
238 ex.printStackTrace();
249 public void ok_actionPerformed(ActionEvent e)
252 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
253 .toString(seqLimit.isSelected()));
254 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
255 .toString(rightAlign.isSelected()));
256 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
257 .toString(fullScreen.isSelected()));
258 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
259 .toString(openoverv.isSelected()));
260 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
261 .toString(annotations.isSelected()));
262 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
263 .toString(conservation.isSelected()));
264 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
265 .toString(quality.isSelected()));
266 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
267 .toString(identity.isSelected()));
269 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
270 .getSelectedItem().toString());
271 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
272 .getSelectedItem().toString());
274 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
275 .getSelectedItem().toString());
276 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
277 .getSelectedItem().toString());
278 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
279 .getSelectedItem().toString());
281 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
282 .toString(idItalics.isSelected()));
283 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",Boolean.toString(showUnconserved.isSelected()));
284 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
285 .toString(smoothFont.isSelected()));
287 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
288 .toString(wrap.isSelected()));
290 Cache.applicationProperties.setProperty("STARTUP_FILE",
291 startupFileTextfield.getText());
292 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
293 .toString(startupCheckbox.isSelected()));
295 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
296 .getSelectedItem().toString());
298 if (epsRendering.getSelectedItem().equals("Prompt each time"))
300 Cache.applicationProperties.remove("EPS_RENDERING");
304 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
305 .getSelectedItem().toString());
308 if (defaultBrowser.getText().trim().length() < 1)
310 Cache.applicationProperties.remove("DEFAULT_BROWSER");
314 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
315 defaultBrowser.getText());
318 jalview.util.BrowserLauncher.resetBrowser();
320 if (nameLinks.size() > 0)
322 StringBuffer links = new StringBuffer();
323 sequenceURLLinks = new Vector();
324 for (int i = 0; i < nameLinks.size(); i++)
326 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
327 + urlLinks.elementAt(i));
328 links.append(sequenceURLLinks.elementAt(i).toString());
332 links.setLength(links.length() - 1);
333 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
338 Cache.applicationProperties.remove("SEQUENCE_LINKS");
341 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
342 .toString(useProxy.isSelected()));
344 if (proxyServerTB.getText().trim().length() < 1)
346 Cache.applicationProperties.remove("PROXY_SERVER");
350 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
354 if (proxyPortTB.getText().trim().length() < 1)
356 Cache.applicationProperties.remove("PROXY_PORT");
360 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
364 if (useProxy.isSelected())
366 System.setProperty("http.proxyHost", proxyServerTB.getText());
367 System.setProperty("http.proxyPort", proxyPortTB.getText());
371 System.setProperty("http.proxyHost", "");
372 System.setProperty("http.proxyPort", "");
374 Cache.setProperty("VERSION_CHECK", Boolean
375 .toString(versioncheck.isSelected()));
376 if (Cache.getProperty("USAGESTATS")!=null || usagestats.isSelected()) {
377 // default is false - we only set this if the user has actively agreed
378 Cache.setProperty("USAGESTATS",Boolean
379 .toString(usagestats.isSelected()));
381 if (!questionnaire.isSelected())
383 Cache.setProperty("NOQUESTIONNAIRES", "true");
385 // special - made easy to edit a property file to disable questionnaires by just adding the given line
386 Cache.removeProperty("NOQUESTIONNAIRES");
388 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
389 .toString(blcjv.isSelected()));
390 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
391 .toString(clustaljv.isSelected()));
392 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
393 .toString(fastajv.isSelected()));
394 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
395 .toString(msfjv.isSelected()));
396 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
397 .toString(pfamjv.isSelected()));
398 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
399 .toString(pileupjv.isSelected()));
400 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
401 .toString(pirjv.isSelected()));
402 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
403 .toString(modellerOutput.isSelected()));
404 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
406 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
407 .toString(autoCalculateConsCheck.isSelected()));
408 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
409 .toString(padGaps.isSelected()));
411 dasSource.saveProperties(Cache.applicationProperties);
413 Cache.saveProperties();
416 frame.setClosed(true);
417 } catch (Exception ex)
425 public void startupFileTextfield_mouseClicked()
427 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
428 .getProperty("LAST_DIRECTORY"), new String[]
429 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
431 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
432 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
433 chooser.setFileView(new JalviewFileView());
434 chooser.setDialogTitle("Select startup file");
436 int value = chooser.showOpenDialog(this);
438 if (value == JalviewFileChooser.APPROVE_OPTION)
440 jalview.bin.Cache.applicationProperties.setProperty(
441 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
442 startupFileTextfield.setText(chooser.getSelectedFile()
453 public void cancel_actionPerformed(ActionEvent e)
457 frame.setClosed(true);
458 } catch (Exception ex)
469 public void annotations_actionPerformed(ActionEvent e)
471 conservation.setEnabled(annotations.isSelected());
472 quality.setEnabled(annotations.isSelected());
473 identity.setEnabled(annotations.isSelected());
476 public void newLink_actionPerformed(ActionEvent e)
479 GSequenceLink link = new GSequenceLink();
480 boolean valid = false;
483 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
484 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
485 null) == JOptionPane.OK_OPTION)
487 if (link.checkValid())
489 nameLinks.addElement(link.getName());
490 urlLinks.addElement(link.getURL());
502 public void editLink_actionPerformed(ActionEvent e)
504 GSequenceLink link = new GSequenceLink();
506 int index = linkNameList.getSelectedIndex();
509 JOptionPane.showInternalMessageDialog(Desktop.desktop,
510 "No link selected!", "No link selected",
511 JOptionPane.WARNING_MESSAGE);
515 link.setName(nameLinks.elementAt(index).toString());
516 link.setURL(urlLinks.elementAt(index).toString());
518 boolean valid = false;
522 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
523 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
524 null) == JOptionPane.OK_OPTION)
526 if (link.checkValid())
528 nameLinks.setElementAt(link.getName(), index);
529 urlLinks.setElementAt(link.getURL(), index);
542 public void deleteLink_actionPerformed(ActionEvent e)
544 int index = linkNameList.getSelectedIndex();
547 JOptionPane.showInternalMessageDialog(Desktop.desktop,
548 "No link selected!", "No link selected",
549 JOptionPane.WARNING_MESSAGE);
552 nameLinks.removeElementAt(index);
553 urlLinks.removeElementAt(index);
557 void updateLinkData()
559 linkNameList.setListData(nameLinks);
560 linkURLList.setListData(urlLinks);
563 public void defaultBrowser_mouseClicked(MouseEvent e)
565 JFileChooser chooser = new JFileChooser(".");
566 chooser.setDialogTitle("Select default web browser");
568 int value = chooser.showOpenDialog(this);
570 if (value == JFileChooser.APPROVE_OPTION)
572 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
577 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
579 protected void showunconserved_actionPerformed(ActionEvent e)
581 // TODO Auto-generated method stub
582 super.showunconserved_actionPerformed(e);
585 private void jbInit() throws Exception