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?tool=Jalview&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?tool=Jalview&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.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
125 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
126 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
127 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
128 showUnconserved.setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
130 for (int i = 0; i < 13; i++)
132 colour.addItem(ColourSchemeProperty.getColourName(i));
135 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
137 colour.setSelectedItem(string);
139 String[] fonts = java.awt.GraphicsEnvironment
140 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
142 for (int i = 0; i < fonts.length; i++)
144 fontNameCB.addItem(fonts[i]);
147 for (int i = 1; i < 31; i++)
149 fontSizeCB.addItem(i + "");
152 fontStyleCB.addItem("plain");
153 fontStyleCB.addItem("bold");
154 fontStyleCB.addItem("italic");
156 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
157 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
158 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
161 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
163 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
165 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
167 gapSymbolCB.addItem("-");
168 gapSymbolCB.addItem(".");
170 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
173 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
174 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
175 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
177 sortby.addItem("No sort");
178 sortby.addItem("Id");
179 sortby.addItem("Pairwise Identity");
180 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
182 epsRendering.addItem("Prompt each time");
183 epsRendering.addItem("Lineart");
184 epsRendering.addItem("Text");
185 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
186 "Prompt each time"));
188 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
189 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
190 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
191 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
192 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
193 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
194 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
196 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
198 autoCalculateConsCheck.setSelected(Cache.getDefault(
199 "AUTO_CALC_CONSENSUS", true));
200 showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",false));
201 showGroupConservation.setSelected(Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
202 showConsensHistogram.setSelected(Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",true));
203 showConsensProfile.setSelected(Cache.getDefault("SHOW_CONSENSUS_PROFILE",false));
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
232 annotations_actionPerformed(null); // update the display of the annotation settings
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("SHOW_GROUP_CONSENSUS",Boolean.toString(showGroupConsensus.isSelected()));
285 Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",Boolean.toString(showGroupConservation.isSelected()));
286 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",Boolean.toString(showConsensHistogram.isSelected()));
287 Cache.applicationProperties.setProperty("SHOW_CONSENSUS_PROFILE",Boolean.toString(showConsensProfile.isSelected()));
288 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
289 .toString(smoothFont.isSelected()));
291 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
292 .toString(wrap.isSelected()));
294 Cache.applicationProperties.setProperty("STARTUP_FILE",
295 startupFileTextfield.getText());
296 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
297 .toString(startupCheckbox.isSelected()));
299 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
300 .getSelectedItem().toString());
302 if (epsRendering.getSelectedItem().equals("Prompt each time"))
304 Cache.applicationProperties.remove("EPS_RENDERING");
308 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
309 .getSelectedItem().toString());
312 if (defaultBrowser.getText().trim().length() < 1)
314 Cache.applicationProperties.remove("DEFAULT_BROWSER");
318 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
319 defaultBrowser.getText());
322 jalview.util.BrowserLauncher.resetBrowser();
324 if (nameLinks.size() > 0)
326 StringBuffer links = new StringBuffer();
327 sequenceURLLinks = new Vector();
328 for (int i = 0; i < nameLinks.size(); i++)
330 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
331 + urlLinks.elementAt(i));
332 links.append(sequenceURLLinks.elementAt(i).toString());
336 links.setLength(links.length() - 1);
337 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
342 Cache.applicationProperties.remove("SEQUENCE_LINKS");
345 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
346 .toString(useProxy.isSelected()));
348 if (proxyServerTB.getText().trim().length() < 1)
350 Cache.applicationProperties.remove("PROXY_SERVER");
354 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
358 if (proxyPortTB.getText().trim().length() < 1)
360 Cache.applicationProperties.remove("PROXY_PORT");
364 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
368 if (useProxy.isSelected())
370 System.setProperty("http.proxyHost", proxyServerTB.getText());
371 System.setProperty("http.proxyPort", proxyPortTB.getText());
375 System.setProperty("http.proxyHost", "");
376 System.setProperty("http.proxyPort", "");
378 Cache.setProperty("VERSION_CHECK", Boolean
379 .toString(versioncheck.isSelected()));
380 if (Cache.getProperty("USAGESTATS")!=null || usagestats.isSelected()) {
381 // default is false - we only set this if the user has actively agreed
382 Cache.setProperty("USAGESTATS",Boolean
383 .toString(usagestats.isSelected()));
385 if (!questionnaire.isSelected())
387 Cache.setProperty("NOQUESTIONNAIRES", "true");
389 // special - made easy to edit a property file to disable questionnaires by just adding the given line
390 Cache.removeProperty("NOQUESTIONNAIRES");
392 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
393 .toString(blcjv.isSelected()));
394 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
395 .toString(clustaljv.isSelected()));
396 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
397 .toString(fastajv.isSelected()));
398 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
399 .toString(msfjv.isSelected()));
400 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
401 .toString(pfamjv.isSelected()));
402 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
403 .toString(pileupjv.isSelected()));
404 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
405 .toString(pirjv.isSelected()));
406 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
407 .toString(modellerOutput.isSelected()));
408 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
410 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
411 .toString(autoCalculateConsCheck.isSelected()));
412 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
413 .toString(padGaps.isSelected()));
415 dasSource.saveProperties(Cache.applicationProperties);
417 Cache.saveProperties();
420 frame.setClosed(true);
421 } catch (Exception ex)
429 public void startupFileTextfield_mouseClicked()
431 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
432 .getProperty("LAST_DIRECTORY"), new String[]
433 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
435 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
436 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
437 chooser.setFileView(new JalviewFileView());
438 chooser.setDialogTitle("Select startup file");
440 int value = chooser.showOpenDialog(this);
442 if (value == JalviewFileChooser.APPROVE_OPTION)
444 jalview.bin.Cache.applicationProperties.setProperty(
445 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
446 startupFileTextfield.setText(chooser.getSelectedFile()
457 public void cancel_actionPerformed(ActionEvent e)
461 frame.setClosed(true);
462 } catch (Exception ex)
473 public void annotations_actionPerformed(ActionEvent e)
475 conservation.setEnabled(annotations.isSelected());
476 quality.setEnabled(annotations.isSelected());
477 identity.setEnabled(annotations.isSelected());
478 showConsensHistogram.setEnabled(annotations.isSelected());
479 showConsensProfile.setEnabled(annotations.isSelected());
480 showGroupConsensus.setEnabled(annotations.isSelected());
481 showGroupConservation.setEnabled(annotations.isSelected());
484 public void newLink_actionPerformed(ActionEvent e)
487 GSequenceLink link = new GSequenceLink();
488 boolean valid = false;
491 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
492 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
493 null) == JOptionPane.OK_OPTION)
495 if (link.checkValid())
497 nameLinks.addElement(link.getName());
498 urlLinks.addElement(link.getURL());
510 public void editLink_actionPerformed(ActionEvent e)
512 GSequenceLink link = new GSequenceLink();
514 int index = linkNameList.getSelectedIndex();
517 JOptionPane.showInternalMessageDialog(Desktop.desktop,
518 "No link selected!", "No link selected",
519 JOptionPane.WARNING_MESSAGE);
523 link.setName(nameLinks.elementAt(index).toString());
524 link.setURL(urlLinks.elementAt(index).toString());
526 boolean valid = false;
530 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
531 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
532 null) == JOptionPane.OK_OPTION)
534 if (link.checkValid())
536 nameLinks.setElementAt(link.getName(), index);
537 urlLinks.setElementAt(link.getURL(), index);
550 public void deleteLink_actionPerformed(ActionEvent e)
552 int index = linkNameList.getSelectedIndex();
555 JOptionPane.showInternalMessageDialog(Desktop.desktop,
556 "No link selected!", "No link selected",
557 JOptionPane.WARNING_MESSAGE);
560 nameLinks.removeElementAt(index);
561 urlLinks.removeElementAt(index);
565 void updateLinkData()
567 linkNameList.setListData(nameLinks);
568 linkURLList.setListData(urlLinks);
571 public void defaultBrowser_mouseClicked(MouseEvent e)
573 JFileChooser chooser = new JFileChooser(".");
574 chooser.setDialogTitle("Select default web browser");
576 int value = chooser.showOpenDialog(this);
578 if (value == JFileChooser.APPROVE_OPTION)
580 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
585 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
587 protected void showunconserved_actionPerformed(ActionEvent e)
589 // TODO Auto-generated method stub
590 super.showunconserved_actionPerformed(e);
593 private void jbInit() throws Exception