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;
52 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
53 sequenceURLLinks = new Vector();
57 StringTokenizer st = new StringTokenizer(string, "|");
58 while (st.hasMoreElements())
60 String name = st.nextToken();
61 String url = st.nextToken();
62 // check for '|' within a regex
63 int rxstart = url.indexOf("$SEQUENCE_ID$");
64 while (rxstart == -1 && url.indexOf("/=$") == -1)
66 url = url + "|" + st.nextToken();
68 sequenceURLLinks.addElement(name + "|" + url);
70 } catch (Exception ex)
72 System.out.println(ex + "\nError parsing sequence links");
76 Vector nameLinks, urlLinks;
80 DasSourceBrowser dasSource;
83 * Creates a new Preferences object.
88 frame = new JInternalFrame();
89 frame.setContentPane(this);
90 dasSource = new DasSourceBrowser();
91 dasPanel.add(dasSource, BorderLayout.CENTER);
93 int width = 500, height = 420;
94 if (new jalview.util.Platform().isAMac())
100 Desktop.addInternalFrame(frame, "Preferences", width, height);
101 frame.setMinimumSize(new Dimension(width, height));
103 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
104 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
105 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
106 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
108 conservation.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
109 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
110 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
112 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
113 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
114 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
115 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
116 showUnconserved.setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
118 for (int i = 0; i < 13; i++)
120 colour.addItem(ColourSchemeProperty.getColourName(i));
123 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
125 colour.setSelectedItem(string);
127 String[] fonts = java.awt.GraphicsEnvironment
128 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
130 for (int i = 0; i < fonts.length; i++)
132 fontNameCB.addItem(fonts[i]);
135 for (int i = 1; i < 31; i++)
137 fontSizeCB.addItem(i + "");
140 fontStyleCB.addItem("plain");
141 fontStyleCB.addItem("bold");
142 fontStyleCB.addItem("italic");
144 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
145 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
146 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
149 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
151 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
153 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
155 gapSymbolCB.addItem("-");
156 gapSymbolCB.addItem(".");
158 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
161 .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
162 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
163 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
165 sortby.addItem("No sort");
166 sortby.addItem("Id");
167 sortby.addItem("Pairwise Identity");
168 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
170 epsRendering.addItem("Prompt each time");
171 epsRendering.addItem("Lineart");
172 epsRendering.addItem("Text");
173 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
174 "Prompt each time"));
176 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
177 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
178 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
179 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
180 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
181 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
182 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
184 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
186 autoCalculateConsCheck.setSelected(Cache.getDefault(
187 "AUTO_CALC_CONSENSUS", true));
188 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
190 /***************************************************************************
193 nameLinks = new Vector();
194 urlLinks = new Vector();
195 for (int i = 0; i < sequenceURLLinks.size(); i++)
197 String link = sequenceURLLinks.elementAt(i).toString();
198 nameLinks.addElement(link.substring(0, link.indexOf("|")));
199 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
204 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
205 proxyServerTB.setEnabled(useProxy.isSelected());
206 proxyPortTB.setEnabled(useProxy.isSelected());
207 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
208 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
210 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
212 usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
213 questionnaire.setSelected(Cache.getProperty("NOQUESTIONNAIRES")==null); // note antisense here
214 versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default is true
219 } catch (Exception ex)
221 ex.printStackTrace();
232 public void ok_actionPerformed(ActionEvent e)
235 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
236 .toString(seqLimit.isSelected()));
237 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
238 .toString(rightAlign.isSelected()));
239 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
240 .toString(fullScreen.isSelected()));
241 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
242 .toString(openoverv.isSelected()));
243 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
244 .toString(annotations.isSelected()));
245 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
246 .toString(conservation.isSelected()));
247 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
248 .toString(quality.isSelected()));
249 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
250 .toString(identity.isSelected()));
252 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
253 .getSelectedItem().toString());
254 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
255 .getSelectedItem().toString());
257 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
258 .getSelectedItem().toString());
259 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
260 .getSelectedItem().toString());
261 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
262 .getSelectedItem().toString());
264 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
265 .toString(idItalics.isSelected()));
266 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",Boolean.toString(showUnconserved.isSelected()));
267 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
268 .toString(smoothFont.isSelected()));
270 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
271 .toString(wrap.isSelected()));
273 Cache.applicationProperties.setProperty("STARTUP_FILE",
274 startupFileTextfield.getText());
275 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
276 .toString(startupCheckbox.isSelected()));
278 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
279 .getSelectedItem().toString());
281 if (epsRendering.getSelectedItem().equals("Prompt each time"))
283 Cache.applicationProperties.remove("EPS_RENDERING");
287 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
288 .getSelectedItem().toString());
291 if (defaultBrowser.getText().trim().length() < 1)
293 Cache.applicationProperties.remove("DEFAULT_BROWSER");
297 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
298 defaultBrowser.getText());
301 jalview.util.BrowserLauncher.resetBrowser();
303 if (nameLinks.size() > 0)
305 StringBuffer links = new StringBuffer();
306 sequenceURLLinks = new Vector();
307 for (int i = 0; i < nameLinks.size(); i++)
309 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
310 + urlLinks.elementAt(i));
311 links.append(sequenceURLLinks.elementAt(i).toString());
315 links.setLength(links.length() - 1);
316 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
321 Cache.applicationProperties.remove("SEQUENCE_LINKS");
324 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
325 .toString(useProxy.isSelected()));
327 if (proxyServerTB.getText().trim().length() < 1)
329 Cache.applicationProperties.remove("PROXY_SERVER");
333 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
337 if (proxyPortTB.getText().trim().length() < 1)
339 Cache.applicationProperties.remove("PROXY_PORT");
343 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
347 if (useProxy.isSelected())
349 System.setProperty("http.proxyHost", proxyServerTB.getText());
350 System.setProperty("http.proxyPort", proxyPortTB.getText());
354 System.setProperty("http.proxyHost", "");
355 System.setProperty("http.proxyPort", "");
357 Cache.setProperty("VERSION_CHECK", Boolean
358 .toString(versioncheck.isSelected()));
359 if (Cache.getProperty("USAGESTATS")!=null || usagestats.isSelected()) {
360 // default is false - we only set this if the user has actively agreed
361 Cache.setProperty("USAGESTATS",Boolean
362 .toString(usagestats.isSelected()));
364 if (!questionnaire.isSelected())
366 Cache.setProperty("NOQUESTIONNAIRES", "true");
368 // special - made easy to edit a property file to disable questionnaires by just adding the given line
369 Cache.removeProperty("NOQUESTIONNAIRES");
371 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
372 .toString(blcjv.isSelected()));
373 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
374 .toString(clustaljv.isSelected()));
375 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
376 .toString(fastajv.isSelected()));
377 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
378 .toString(msfjv.isSelected()));
379 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
380 .toString(pfamjv.isSelected()));
381 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
382 .toString(pileupjv.isSelected()));
383 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
384 .toString(pirjv.isSelected()));
385 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
386 .toString(modellerOutput.isSelected()));
387 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
389 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
390 .toString(autoCalculateConsCheck.isSelected()));
391 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
392 .toString(padGaps.isSelected()));
394 dasSource.saveProperties(Cache.applicationProperties);
396 Cache.saveProperties();
399 frame.setClosed(true);
400 } catch (Exception ex)
408 public void startupFileTextfield_mouseClicked()
410 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
411 .getProperty("LAST_DIRECTORY"), new String[]
412 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
414 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
415 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
416 chooser.setFileView(new JalviewFileView());
417 chooser.setDialogTitle("Select startup file");
419 int value = chooser.showOpenDialog(this);
421 if (value == JalviewFileChooser.APPROVE_OPTION)
423 jalview.bin.Cache.applicationProperties.setProperty(
424 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
425 startupFileTextfield.setText(chooser.getSelectedFile()
436 public void cancel_actionPerformed(ActionEvent e)
440 frame.setClosed(true);
441 } catch (Exception ex)
452 public void annotations_actionPerformed(ActionEvent e)
454 conservation.setEnabled(annotations.isSelected());
455 quality.setEnabled(annotations.isSelected());
456 identity.setEnabled(annotations.isSelected());
459 public void newLink_actionPerformed(ActionEvent e)
462 GSequenceLink link = new GSequenceLink();
463 boolean valid = false;
466 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
467 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
468 null) == JOptionPane.OK_OPTION)
470 if (link.checkValid())
472 nameLinks.addElement(link.getName());
473 urlLinks.addElement(link.getURL());
485 public void editLink_actionPerformed(ActionEvent e)
487 GSequenceLink link = new GSequenceLink();
489 int index = linkNameList.getSelectedIndex();
492 JOptionPane.showInternalMessageDialog(Desktop.desktop,
493 "No link selected!", "No link selected",
494 JOptionPane.WARNING_MESSAGE);
498 link.setName(nameLinks.elementAt(index).toString());
499 link.setURL(urlLinks.elementAt(index).toString());
501 boolean valid = false;
505 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
506 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
507 null) == JOptionPane.OK_OPTION)
509 if (link.checkValid())
511 nameLinks.setElementAt(link.getName(), index);
512 urlLinks.setElementAt(link.getURL(), index);
525 public void deleteLink_actionPerformed(ActionEvent e)
527 int index = linkNameList.getSelectedIndex();
530 JOptionPane.showInternalMessageDialog(Desktop.desktop,
531 "No link selected!", "No link selected",
532 JOptionPane.WARNING_MESSAGE);
535 nameLinks.removeElementAt(index);
536 urlLinks.removeElementAt(index);
540 void updateLinkData()
542 linkNameList.setListData(nameLinks);
543 linkURLList.setListData(urlLinks);
546 public void defaultBrowser_mouseClicked(MouseEvent e)
548 JFileChooser chooser = new JFileChooser(".");
549 chooser.setDialogTitle("Select default web browser");
551 int value = chooser.showOpenDialog(this);
553 if (value == JFileChooser.APPROVE_OPTION)
555 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
560 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
562 protected void showunconserved_actionPerformed(ActionEvent e)
564 // TODO Auto-generated method stub
565 super.showunconserved_actionPerformed(e);
568 private void jbInit() throws Exception