2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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", ""));
214 } catch (Exception ex)
216 ex.printStackTrace();
227 public void ok_actionPerformed(ActionEvent e)
230 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean
231 .toString(seqLimit.isSelected()));
232 Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS", Boolean
233 .toString(rightAlign.isSelected()));
234 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean
235 .toString(fullScreen.isSelected()));
236 Cache.applicationProperties.setProperty("SHOW_OVERVIEW", Boolean
237 .toString(openoverv.isSelected()));
238 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean
239 .toString(annotations.isSelected()));
240 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean
241 .toString(conservation.isSelected()));
242 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean
243 .toString(quality.isSelected()));
244 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean
245 .toString(identity.isSelected()));
247 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
248 .getSelectedItem().toString());
249 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
250 .getSelectedItem().toString());
252 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
253 .getSelectedItem().toString());
254 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
255 .getSelectedItem().toString());
256 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
257 .getSelectedItem().toString());
259 Cache.applicationProperties.setProperty("ID_ITALICS", Boolean
260 .toString(idItalics.isSelected()));
261 Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",Boolean.toString(showUnconserved.isSelected()));
262 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean
263 .toString(smoothFont.isSelected()));
265 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean
266 .toString(wrap.isSelected()));
268 Cache.applicationProperties.setProperty("STARTUP_FILE",
269 startupFileTextfield.getText());
270 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean
271 .toString(startupCheckbox.isSelected()));
273 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
274 .getSelectedItem().toString());
276 if (epsRendering.getSelectedItem().equals("Prompt each time"))
278 Cache.applicationProperties.remove("EPS_RENDERING");
282 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
283 .getSelectedItem().toString());
286 if (defaultBrowser.getText().trim().length() < 1)
288 Cache.applicationProperties.remove("DEFAULT_BROWSER");
292 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
293 defaultBrowser.getText());
296 jalview.util.BrowserLauncher.resetBrowser();
298 if (nameLinks.size() > 0)
300 StringBuffer links = new StringBuffer();
301 sequenceURLLinks = new Vector();
302 for (int i = 0; i < nameLinks.size(); i++)
304 sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
305 + urlLinks.elementAt(i));
306 links.append(sequenceURLLinks.elementAt(i).toString());
310 links.setLength(links.length() - 1);
311 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links
316 Cache.applicationProperties.remove("SEQUENCE_LINKS");
319 Cache.applicationProperties.setProperty("USE_PROXY", Boolean
320 .toString(useProxy.isSelected()));
322 if (proxyServerTB.getText().trim().length() < 1)
324 Cache.applicationProperties.remove("PROXY_SERVER");
328 Cache.applicationProperties.setProperty("PROXY_SERVER", proxyServerTB
332 if (proxyPortTB.getText().trim().length() < 1)
334 Cache.applicationProperties.remove("PROXY_PORT");
338 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB
342 if (useProxy.isSelected())
344 System.setProperty("http.proxyHost", proxyServerTB.getText());
345 System.setProperty("http.proxyPort", proxyPortTB.getText());
349 System.setProperty("http.proxyHost", "");
350 System.setProperty("http.proxyPort", "");
353 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean
354 .toString(blcjv.isSelected()));
355 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean
356 .toString(clustaljv.isSelected()));
357 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean
358 .toString(fastajv.isSelected()));
359 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean
360 .toString(msfjv.isSelected()));
361 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean
362 .toString(pfamjv.isSelected()));
363 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean
364 .toString(pileupjv.isSelected()));
365 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean
366 .toString(pirjv.isSelected()));
367 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean
368 .toString(modellerOutput.isSelected()));
369 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
371 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS", Boolean
372 .toString(autoCalculateConsCheck.isSelected()));
373 Cache.applicationProperties.setProperty("PAD_GAPS", Boolean
374 .toString(padGaps.isSelected()));
376 dasSource.saveProperties(Cache.applicationProperties);
378 Cache.saveProperties();
381 frame.setClosed(true);
382 } catch (Exception ex)
390 public void startupFileTextfield_mouseClicked()
392 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
393 .getProperty("LAST_DIRECTORY"), new String[]
394 { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
396 { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
397 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
398 chooser.setFileView(new JalviewFileView());
399 chooser.setDialogTitle("Select startup file");
401 int value = chooser.showOpenDialog(this);
403 if (value == JalviewFileChooser.APPROVE_OPTION)
405 jalview.bin.Cache.applicationProperties.setProperty(
406 "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
407 startupFileTextfield.setText(chooser.getSelectedFile()
418 public void cancel_actionPerformed(ActionEvent e)
422 frame.setClosed(true);
423 } catch (Exception ex)
434 public void annotations_actionPerformed(ActionEvent e)
436 conservation.setEnabled(annotations.isSelected());
437 quality.setEnabled(annotations.isSelected());
438 identity.setEnabled(annotations.isSelected());
441 public void newLink_actionPerformed(ActionEvent e)
444 GSequenceLink link = new GSequenceLink();
445 boolean valid = false;
448 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
449 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
450 null) == JOptionPane.OK_OPTION)
452 if (link.checkValid())
454 nameLinks.addElement(link.getName());
455 urlLinks.addElement(link.getURL());
467 public void editLink_actionPerformed(ActionEvent e)
469 GSequenceLink link = new GSequenceLink();
471 int index = linkNameList.getSelectedIndex();
474 JOptionPane.showInternalMessageDialog(Desktop.desktop,
475 "No link selected!", "No link selected",
476 JOptionPane.WARNING_MESSAGE);
480 link.setName(nameLinks.elementAt(index).toString());
481 link.setURL(urlLinks.elementAt(index).toString());
483 boolean valid = false;
487 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
488 "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
489 null) == JOptionPane.OK_OPTION)
491 if (link.checkValid())
493 nameLinks.setElementAt(link.getName(), index);
494 urlLinks.setElementAt(link.getURL(), index);
507 public void deleteLink_actionPerformed(ActionEvent e)
509 int index = linkNameList.getSelectedIndex();
512 JOptionPane.showInternalMessageDialog(Desktop.desktop,
513 "No link selected!", "No link selected",
514 JOptionPane.WARNING_MESSAGE);
517 nameLinks.removeElementAt(index);
518 urlLinks.removeElementAt(index);
522 void updateLinkData()
524 linkNameList.setListData(nameLinks);
525 linkURLList.setListData(urlLinks);
528 public void defaultBrowser_mouseClicked(MouseEvent e)
530 JFileChooser chooser = new JFileChooser(".");
531 chooser.setDialogTitle("Select default web browser");
533 int value = chooser.showOpenDialog(this);
535 if (value == JFileChooser.APPROVE_OPTION)
537 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
542 * @see jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event.ActionEvent)
544 protected void showunconserved_actionPerformed(ActionEvent e)
546 // TODO Auto-generated method stub
547 super.showunconserved_actionPerformed(e);
550 private void jbInit() throws Exception