2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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.*;
29 import jalview.jbgui.*;
30 import jalview.schemes.*;
38 public class Preferences
41 /** Holds name and link separated with | character. Sequence ID must be $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$ */
42 public static Vector sequenceURLLinks;
45 String string = Cache.getDefault("SEQUENCE_LINKS",
46 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
47 sequenceURLLinks = new Vector();
51 StringTokenizer st = new StringTokenizer(string, "|");
52 while (st.hasMoreElements())
54 String name=st.nextToken();
55 String url= st.nextToken();
56 // check for '|' within a regex
57 int rxstart = url.indexOf("$SEQUENCE_ID$");
58 while (rxstart==-1 && url.indexOf("/=$")==-1)
60 url = url + "|" + st.nextToken();
62 sequenceURLLinks.addElement(name + "|" + url);
67 System.out.println(ex + "\nError parsing sequence links");
71 Vector nameLinks, urlLinks;
75 DasSourceBrowser dasSource;
78 * Creates a new Preferences object.
83 frame = new JInternalFrame();
84 frame.setContentPane(this);
85 dasSource = new DasSourceBrowser();
86 dasPanel.add(dasSource, BorderLayout.CENTER);
88 int width = 500, height = 420;
89 if (new jalview.util.Platform().isAMac())
95 Desktop.addInternalFrame(frame, "Preferences", width, height);
96 frame.setMinimumSize(new Dimension(width, height));
98 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
99 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
100 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
101 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
103 conservation.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
104 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
105 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
107 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
108 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
109 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
110 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
112 for (int i = 0; i < 13; i++)
114 colour.addItem(ColourSchemeProperty.getColourName(i));
117 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
119 colour.setSelectedItem(string);
121 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
122 .getAvailableFontFamilyNames();
124 for (int i = 0; i < fonts.length; i++)
126 fontNameCB.addItem(fonts[i]);
129 for (int i = 1; i < 31; i++)
131 fontSizeCB.addItem(i + "");
134 fontStyleCB.addItem("plain");
135 fontStyleCB.addItem("bold");
136 fontStyleCB.addItem("italic");
138 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
139 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
140 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
142 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
144 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
146 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
148 gapSymbolCB.addItem("-");
149 gapSymbolCB.addItem(".");
151 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
153 startupCheckbox.setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
154 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
155 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
157 sortby.addItem("No sort");
158 sortby.addItem("Id");
159 sortby.addItem("Pairwise Identity");
160 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
162 epsRendering.addItem("Prompt each time");
163 epsRendering.addItem("Lineart");
164 epsRendering.addItem("Text");
165 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
166 "Prompt each time"));
168 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
169 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
170 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
171 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
172 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
173 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
174 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
176 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
178 autoCalculateConsCheck.setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
179 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
181 /****************************************************
184 nameLinks = new Vector();
185 urlLinks = new Vector();
186 for (int i = 0; i < sequenceURLLinks.size(); i++)
188 String link = sequenceURLLinks.elementAt(i).toString();
189 nameLinks.addElement(link.substring(0, link.indexOf("|")));
190 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
195 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
196 proxyServerTB.setEnabled(useProxy.isSelected());
197 proxyPortTB.setEnabled(useProxy.isSelected());
198 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
199 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
201 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
208 ex.printStackTrace();
216 * @param e DOCUMENT ME!
218 public void ok_actionPerformed(ActionEvent e)
221 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
222 Boolean.toString(seqLimit.
224 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
225 Boolean.toString(rightAlign.
227 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
228 Boolean.toString(fullScreen.
230 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
231 Boolean.toString(openoverv.
233 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
235 toString(annotations.isSelected()));
236 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
238 toString(conservation.isSelected()));
239 Cache.applicationProperties.setProperty("SHOW_QUALITY",
240 Boolean.toString(quality.isSelected()));
241 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
242 Boolean.toString(identity.
245 Cache.applicationProperties.setProperty("DEFAULT_COLOUR",
246 colour.getSelectedItem().toString());
247 Cache.applicationProperties.setProperty("GAP_SYMBOL",
248 gapSymbolCB.getSelectedItem().
251 Cache.applicationProperties.setProperty("FONT_NAME",
252 fontNameCB.getSelectedItem().
254 Cache.applicationProperties.setProperty("FONT_STYLE",
255 fontStyleCB.getSelectedItem().
257 Cache.applicationProperties.setProperty("FONT_SIZE",
258 fontSizeCB.getSelectedItem().
261 Cache.applicationProperties.setProperty("ID_ITALICS",
262 Boolean.toString(idItalics.
265 Cache.applicationProperties.setProperty("ANTI_ALIAS",
266 Boolean.toString(smoothFont.
269 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
270 Boolean.toString(wrap.isSelected()));
272 Cache.applicationProperties.setProperty("STARTUP_FILE",
273 startupFileTextfield.getText());
274 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
276 toString(startupCheckbox.isSelected()));
278 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
279 sortby.getSelectedItem().toString());
281 if (epsRendering.getSelectedItem().equals("Prompt each time"))
283 Cache.applicationProperties.remove("EPS_RENDERING");
287 Cache.applicationProperties.setProperty("EPS_RENDERING",
288 epsRendering.getSelectedItem().
292 if (defaultBrowser.getText().trim().length() < 1)
294 Cache.applicationProperties.remove("DEFAULT_BROWSER");
298 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
299 defaultBrowser.getText());
302 jalview.util.BrowserLauncher.resetBrowser();
304 if (nameLinks.size() > 0)
306 StringBuffer links = new StringBuffer();
307 sequenceURLLinks = new Vector();
308 for (int i = 0; i < nameLinks.size(); i++)
310 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|" +
311 urlLinks.elementAt(i));
312 links.append(sequenceURLLinks.elementAt(i).toString());
316 links.setLength(links.length() - 1);
317 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links.toString());
321 Cache.applicationProperties.remove("SEQUENCE_LINKS");
324 Cache.applicationProperties.setProperty("USE_PROXY",
325 Boolean.toString(useProxy.
328 if (proxyServerTB.getText().trim().length() < 1)
330 Cache.applicationProperties.remove("PROXY_SERVER");
334 Cache.applicationProperties.setProperty("PROXY_SERVER",
335 proxyServerTB.getText());
338 if (proxyPortTB.getText().trim().length() < 1)
340 Cache.applicationProperties.remove("PROXY_PORT");
344 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB.getText());
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", "");
358 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
359 Boolean.toString(blcjv.isSelected()));
360 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
362 toString(clustaljv.isSelected()));
363 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
364 Boolean.toString(fastajv.isSelected()));
365 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
366 Boolean.toString(msfjv.isSelected()));
367 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
368 Boolean.toString(pfamjv.isSelected()));
369 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
370 Boolean.toString(pileupjv.
372 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
373 Boolean.toString(pirjv.isSelected()));
374 Cache.applicationProperties.setProperty("PIR_MODELLER",
375 Boolean.toString(modellerOutput.
377 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
379 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
381 autoCalculateConsCheck.isSelected()));
382 Cache.applicationProperties.setProperty("PAD_GAPS",
383 Boolean.toString(padGaps.isSelected()));
385 dasSource.saveProperties(Cache.applicationProperties);
387 Cache.saveProperties();
390 frame.setClosed(true);
400 public void startupFileTextfield_mouseClicked()
402 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
407 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
412 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
413 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
414 chooser.setFileView(new JalviewFileView());
415 chooser.setDialogTitle("Select startup file");
417 int value = chooser.showOpenDialog(this);
419 if (value == JalviewFileChooser.APPROVE_OPTION)
421 jalview.bin.Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
422 chooser.getSelectedFormat());
423 startupFileTextfield.setText(chooser.getSelectedFile()
431 * @param e DOCUMENT ME!
433 public void cancel_actionPerformed(ActionEvent e)
437 frame.setClosed(true);
447 * @param e DOCUMENT ME!
449 public void annotations_actionPerformed(ActionEvent e)
451 conservation.setEnabled(annotations.isSelected());
452 quality.setEnabled(annotations.isSelected());
453 identity.setEnabled(annotations.isSelected());
456 public void newLink_actionPerformed(ActionEvent e)
459 GSequenceLink link = new GSequenceLink();
460 boolean valid = false;
463 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
464 "New sequence URL link",
465 JOptionPane.OK_CANCEL_OPTION
467 == JOptionPane.OK_OPTION)
469 if (link.checkValid())
471 nameLinks.addElement(link.getName());
472 urlLinks.addElement(link.getURL());
484 public void editLink_actionPerformed(ActionEvent e)
486 GSequenceLink link = new GSequenceLink();
488 int index = linkNameList.getSelectedIndex();
491 JOptionPane.showInternalMessageDialog(Desktop.desktop,
493 , "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",
507 JOptionPane.OK_CANCEL_OPTION
509 == JOptionPane.OK_OPTION)
511 if (link.checkValid())
513 nameLinks.setElementAt(link.getName(), index);
514 urlLinks.setElementAt(link.getURL(), index);
527 public void deleteLink_actionPerformed(ActionEvent e)
529 int index = linkNameList.getSelectedIndex();
532 JOptionPane.showInternalMessageDialog(Desktop.desktop,
534 , "No link selected",
535 JOptionPane.WARNING_MESSAGE);
538 nameLinks.removeElementAt(index);
539 urlLinks.removeElementAt(index);
543 void updateLinkData()
545 linkNameList.setListData(nameLinks);
546 linkURLList.setListData(urlLinks);
549 public void defaultBrowser_mouseClicked(MouseEvent e)
551 JFileChooser chooser = new JFileChooser(".");
552 chooser.setDialogTitle("Select default web browser");
554 int value = chooser.showOpenDialog(this);
556 if (value == JFileChooser.APPROVE_OPTION)
558 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
563 private void jbInit()