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$ */
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 sequenceURLLinks.addElement(st.nextToken() + "|" + st.nextToken());
59 System.out.println(ex + "\nError parsing sequence links");
63 Vector nameLinks, urlLinks;
67 DasSourceBrowser dasSource;
70 * Creates a new Preferences object.
75 frame = new JInternalFrame();
76 frame.setContentPane(this);
77 dasSource = new DasSourceBrowser();
78 dasPanel.add(dasSource, BorderLayout.CENTER);
80 int width = 500, height = 420;
81 if (new jalview.util.Platform().isAMac())
87 Desktop.addInternalFrame(frame, "Preferences", width, height);
88 frame.setMinimumSize(new Dimension(width, height));
90 seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
91 rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
92 fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
93 annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
95 conservation.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
96 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
97 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
99 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
100 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
101 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
102 openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
104 for (int i = 0; i < 13; i++)
106 colour.addItem(ColourSchemeProperty.getColourName(i));
109 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
111 colour.setSelectedItem(string);
113 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
114 .getAvailableFontFamilyNames();
116 for (int i = 0; i < fonts.length; i++)
118 fontNameCB.addItem(fonts[i]);
121 for (int i = 1; i < 31; i++)
123 fontSizeCB.addItem(i + "");
126 fontStyleCB.addItem("plain");
127 fontStyleCB.addItem("bold");
128 fontStyleCB.addItem("italic");
130 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
131 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
132 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
134 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
136 idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
138 wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
140 gapSymbolCB.addItem("-");
141 gapSymbolCB.addItem(".");
143 gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
145 startupCheckbox.setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
146 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
147 "http://www.jalview.org/examples/exampleFile_2_3.jar"));
149 sortby.addItem("No sort");
150 sortby.addItem("Id");
151 sortby.addItem("Pairwise Identity");
152 sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
154 epsRendering.addItem("Prompt each time");
155 epsRendering.addItem("Lineart");
156 epsRendering.addItem("Text");
157 epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
158 "Prompt each time"));
160 blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
161 clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
162 fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
163 msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
164 pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
165 pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
166 pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
168 modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
170 autoCalculateConsCheck.setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
171 padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
173 /****************************************************
176 nameLinks = new Vector();
177 urlLinks = new Vector();
178 for (int i = 0; i < sequenceURLLinks.size(); i++)
180 String link = sequenceURLLinks.elementAt(i).toString();
181 nameLinks.addElement(link.substring(0, link.indexOf("|")));
182 urlLinks.addElement(link.substring(link.indexOf("|") + 1));
187 useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
188 proxyServerTB.setEnabled(useProxy.isSelected());
189 proxyPortTB.setEnabled(useProxy.isSelected());
190 proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
191 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
193 defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
200 ex.printStackTrace();
208 * @param e DOCUMENT ME!
210 public void ok_actionPerformed(ActionEvent e)
213 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
214 Boolean.toString(seqLimit.
216 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
217 Boolean.toString(rightAlign.
219 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
220 Boolean.toString(fullScreen.
222 Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
223 Boolean.toString(openoverv.
225 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
227 toString(annotations.isSelected()));
228 Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
230 toString(conservation.isSelected()));
231 Cache.applicationProperties.setProperty("SHOW_QUALITY",
232 Boolean.toString(quality.isSelected()));
233 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
234 Boolean.toString(identity.
237 Cache.applicationProperties.setProperty("DEFAULT_COLOUR",
238 colour.getSelectedItem().toString());
239 Cache.applicationProperties.setProperty("GAP_SYMBOL",
240 gapSymbolCB.getSelectedItem().
243 Cache.applicationProperties.setProperty("FONT_NAME",
244 fontNameCB.getSelectedItem().
246 Cache.applicationProperties.setProperty("FONT_STYLE",
247 fontStyleCB.getSelectedItem().
249 Cache.applicationProperties.setProperty("FONT_SIZE",
250 fontSizeCB.getSelectedItem().
253 Cache.applicationProperties.setProperty("ID_ITALICS",
254 Boolean.toString(idItalics.
257 Cache.applicationProperties.setProperty("ANTI_ALIAS",
258 Boolean.toString(smoothFont.
261 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
262 Boolean.toString(wrap.isSelected()));
264 Cache.applicationProperties.setProperty("STARTUP_FILE",
265 startupFileTextfield.getText());
266 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
268 toString(startupCheckbox.isSelected()));
270 Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
271 sortby.getSelectedItem().toString());
273 if (epsRendering.getSelectedItem().equals("Prompt each time"))
275 Cache.applicationProperties.remove("EPS_RENDERING");
279 Cache.applicationProperties.setProperty("EPS_RENDERING",
280 epsRendering.getSelectedItem().
284 if (defaultBrowser.getText().trim().length() < 1)
286 Cache.applicationProperties.remove("DEFAULT_BROWSER");
290 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
291 defaultBrowser.getText());
294 jalview.util.BrowserLauncher.resetBrowser();
296 if (nameLinks.size() > 0)
298 StringBuffer links = new StringBuffer();
299 sequenceURLLinks = new Vector();
300 for (int i = 0; i < nameLinks.size(); i++)
302 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|" +
303 urlLinks.elementAt(i));
304 links.append(sequenceURLLinks.elementAt(i).toString());
308 links.setLength(links.length() - 1);
309 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links.toString());
313 Cache.applicationProperties.remove("SEQUENCE_LINKS");
316 Cache.applicationProperties.setProperty("USE_PROXY",
317 Boolean.toString(useProxy.
320 if (proxyServerTB.getText().trim().length() < 1)
322 Cache.applicationProperties.remove("PROXY_SERVER");
326 Cache.applicationProperties.setProperty("PROXY_SERVER",
327 proxyServerTB.getText());
330 if (proxyPortTB.getText().trim().length() < 1)
332 Cache.applicationProperties.remove("PROXY_PORT");
336 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB.getText());
339 if (useProxy.isSelected())
341 System.setProperty("http.proxyHost", proxyServerTB.getText());
342 System.setProperty("http.proxyPort", proxyPortTB.getText());
346 System.setProperty("http.proxyHost", "");
347 System.setProperty("http.proxyPort", "");
350 Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
351 Boolean.toString(blcjv.isSelected()));
352 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
354 toString(clustaljv.isSelected()));
355 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
356 Boolean.toString(fastajv.isSelected()));
357 Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
358 Boolean.toString(msfjv.isSelected()));
359 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
360 Boolean.toString(pfamjv.isSelected()));
361 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
362 Boolean.toString(pileupjv.
364 Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
365 Boolean.toString(pirjv.isSelected()));
366 Cache.applicationProperties.setProperty("PIR_MODELLER",
367 Boolean.toString(modellerOutput.
369 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
371 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
373 autoCalculateConsCheck.isSelected()));
374 Cache.applicationProperties.setProperty("PAD_GAPS",
375 Boolean.toString(padGaps.isSelected()));
377 dasSource.saveProperties(Cache.applicationProperties);
379 Cache.saveProperties();
382 frame.setClosed(true);
392 public void startupFileTextfield_mouseClicked()
394 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
399 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
404 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
405 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
406 chooser.setFileView(new JalviewFileView());
407 chooser.setDialogTitle("Select startup file");
409 int value = chooser.showOpenDialog(this);
411 if (value == JalviewFileChooser.APPROVE_OPTION)
413 jalview.bin.Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
414 chooser.getSelectedFormat());
415 startupFileTextfield.setText(chooser.getSelectedFile()
423 * @param e DOCUMENT ME!
425 public void cancel_actionPerformed(ActionEvent e)
429 frame.setClosed(true);
439 * @param e DOCUMENT ME!
441 public void annotations_actionPerformed(ActionEvent e)
443 conservation.setEnabled(annotations.isSelected());
444 quality.setEnabled(annotations.isSelected());
445 identity.setEnabled(annotations.isSelected());
448 public void newLink_actionPerformed(ActionEvent e)
451 GSequenceLink link = new GSequenceLink();
452 boolean valid = false;
455 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
456 "New sequence URL link",
457 JOptionPane.OK_CANCEL_OPTION
459 == JOptionPane.OK_OPTION)
461 if (link.checkValid())
463 nameLinks.addElement(link.getName());
464 urlLinks.addElement(link.getURL());
476 public void editLink_actionPerformed(ActionEvent e)
478 GSequenceLink link = new GSequenceLink();
480 int index = linkNameList.getSelectedIndex();
483 JOptionPane.showInternalMessageDialog(Desktop.desktop,
485 , "No link selected",
486 JOptionPane.WARNING_MESSAGE);
490 link.setName(nameLinks.elementAt(index).toString());
491 link.setURL(urlLinks.elementAt(index).toString());
493 boolean valid = false;
497 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
498 "New sequence URL link",
499 JOptionPane.OK_CANCEL_OPTION
501 == JOptionPane.OK_OPTION)
503 if (link.checkValid())
505 nameLinks.setElementAt(link.getName(), index);
506 urlLinks.setElementAt(link.getURL(), index);
519 public void deleteLink_actionPerformed(ActionEvent e)
521 int index = linkNameList.getSelectedIndex();
524 JOptionPane.showInternalMessageDialog(Desktop.desktop,
526 , "No link selected",
527 JOptionPane.WARNING_MESSAGE);
530 nameLinks.removeElementAt(index);
531 urlLinks.removeElementAt(index);
535 void updateLinkData()
537 linkNameList.setListData(nameLinks);
538 linkURLList.setListData(urlLinks);
541 public void defaultBrowser_mouseClicked(MouseEvent e)
543 JFileChooser chooser = new JFileChooser(".");
544 chooser.setDialogTitle("Select default web browser");
546 int value = chooser.showOpenDialog(this);
548 if (value == JFileChooser.APPROVE_OPTION)
550 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
555 private void jbInit()