2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
23 import jalview.jbgui.*;
25 import jalview.schemes.*;
28 import java.awt.event.*;
34 import jalview.bin.Cache;
43 public class Preferences extends GPreferences
45 /** Holds name and link separated with | character. Sequence ID must be $SEQUENCE_ID$ */
46 public static Vector sequenceURLLinks;
49 String string = Cache.getDefault("SEQUENCE_LINKS",
50 "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
51 sequenceURLLinks = new Vector();
55 StringTokenizer st = new StringTokenizer(string, "|");
56 while (st.hasMoreElements())
58 sequenceURLLinks.addElement(st.nextToken() + "|" + st.nextToken());
63 System.out.println(ex + "\nError parsing sequence links");
66 Vector nameLinks, urlLinks;
70 DasSourceBrowser dasSource;
74 * Creates a new Preferences object.
79 frame = new JInternalFrame();
80 frame.setContentPane(this);
81 dasSource = new DasSourceBrowser();
82 dasPanel.add(dasSource, BorderLayout.CENTER);
84 int width = 500, height = 420;
85 if(System.getProperty("os.name").startsWith("Mac"))
91 Desktop.addInternalFrame(frame, "Preferences", width, height);
92 frame.setMinimumSize(new Dimension(width, height));
94 seqLimit.setSelected( Cache.getDefault("SHOW_JVSUFFIX", true));
95 fullScreen.setSelected( Cache.getDefault("SHOW_FULLSCREEN", false));
96 annotations.setSelected( Cache.getDefault("SHOW_ANNOTATIONS", true));
98 conservation.setEnabled( Cache.getDefault("SHOW_ANNOTATIONS", true));
99 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
100 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
102 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
103 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
104 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
106 for (int i = 0; i < 13; i++)
108 colour.addItem(ColourSchemeProperty.getColourName(i));
111 String string = Cache.getDefault("DEFAULT_COLOUR", "None");
113 colour.setSelectedItem(string);
115 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
116 .getAvailableFontFamilyNames();
118 for (int i = 0; i < fonts.length; i++)
120 fontNameCB.addItem(fonts[i]);
123 for (int i = 1; i < 31; i++)
125 fontSizeCB.addItem(i + "");
128 fontStyleCB.addItem("plain");
129 fontStyleCB.addItem("bold");
130 fontStyleCB.addItem("italic");
132 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
133 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
134 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN + "") );
136 smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
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.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", "Prompt each time"));
159 blcjv.setSelected( Cache.getDefault("BLC_JVSUFFIX", true) );
160 clustaljv.setSelected( Cache.getDefault("CLUSTAL_JVSUFFIX", true) );
161 fastajv.setSelected( Cache.getDefault("FASTA_JVSUFFIX", true) );
162 msfjv.setSelected( Cache.getDefault("MSF_JVSUFFIX", true) );
163 pfamjv.setSelected( Cache.getDefault("PFAM_JVSUFFIX", true) );
164 pileupjv.setSelected( Cache.getDefault("PILEUP_JVSUFFIX", true) );
165 pirjv.setSelected( Cache.getDefault("PIR_JVSUFFIX", true) );
167 modellerOutput.setSelected( Cache.getDefault("PIR_MODELLER", false));
169 autoCalculateConsCheck.setSelected( Cache.getDefault("AUTO_CALC_CONSENSUS", true));
170 padGaps.setSelected( Cache.getDefault("PAD_GAPS", false));
172 /****************************************************
175 nameLinks = new Vector();
176 urlLinks = new Vector();
177 for(int i=0; i<sequenceURLLinks.size(); i++)
179 String link = sequenceURLLinks.elementAt(i).toString();
180 nameLinks.addElement(link.substring(0, link.indexOf("|")) );
181 urlLinks.addElement(link.substring(link.indexOf("|")+1));
186 useProxy.setSelected( Cache.getDefault("USE_PROXY", false));
187 proxyServerTB.setEnabled(useProxy.isSelected());
188 proxyPortTB.setEnabled(useProxy.isSelected());
189 proxyServerTB.setText( Cache.getDefault("PROXY_SERVER", ""));
190 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
192 defaultBrowser.setText( Cache.getDefault("DEFAULT_BROWSER",""));
199 ex.printStackTrace();
208 * @param e DOCUMENT ME!
210 public void ok_actionPerformed(ActionEvent e)
213 Cache.applicationProperties.setProperty("SHOW_JVSUFFIX", Boolean.toString(seqLimit.isSelected()));
214 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean.toString(fullScreen.isSelected()));
216 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean.toString(annotations.isSelected()));
217 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean.toString(conservation.isSelected()));
218 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean.toString(quality.isSelected()));
219 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean.toString(identity.isSelected()));
221 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour.getSelectedItem().toString());
222 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB.getSelectedItem().toString());
224 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB.getSelectedItem().toString());
225 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB.getSelectedItem().toString());
226 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB.getSelectedItem().toString());
228 Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected()));
230 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", Boolean.toString(wrap.isSelected()));
232 Cache.applicationProperties.setProperty("STARTUP_FILE", startupFileTextfield.getText());
233 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean.toString(startupCheckbox.isSelected()));
235 Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby.getSelectedItem().toString() );
237 if(epsRendering.getSelectedItem().equals("Prompt each time"))
238 Cache.applicationProperties.remove("EPS_RENDERING");
240 Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering.getSelectedItem().toString());
242 if(defaultBrowser.getText().trim().length()<1)
243 Cache.applicationProperties.remove("DEFAULT_BROWSER");
245 Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
246 defaultBrowser.getText());
248 jalview.util.BrowserLauncher.resetBrowser();
250 if(nameLinks.size()>0)
252 StringBuffer links = new StringBuffer();
253 sequenceURLLinks = new Vector();
254 for (int i = 0; i < nameLinks.size(); i++)
256 sequenceURLLinks.addElement(nameLinks.elementAt(i)+"|"+urlLinks.elementAt(i));
257 links.append(sequenceURLLinks.elementAt(i).toString());
261 links.setLength( links.length()-1 );
262 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links.toString());
265 Cache.applicationProperties.remove("SEQUENCE_LINKS");
268 Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected()));
270 if (proxyServerTB.getText().trim().length() < 1)
271 Cache.applicationProperties.remove("PROXY_SERVER");
273 Cache.applicationProperties.setProperty("PROXY_SERVER",
274 proxyServerTB.getText());
276 if (proxyPortTB.getText().trim().length() < 1)
277 Cache.applicationProperties.remove("PROXY_PORT");
279 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB.getText());
281 if(useProxy.isSelected())
283 System.setProperty("http.proxyHost", proxyServerTB.getText());
284 System.setProperty("http.proxyPort", proxyPortTB.getText());
288 System.setProperty("http.proxyHost","");
289 System.setProperty("http.proxyPort","");
293 Cache.applicationProperties.setProperty("BLC_JVSUFFIX", Boolean.toString(blcjv.isSelected()) );
294 Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX", Boolean.toString(clustaljv.isSelected()) );
295 Cache.applicationProperties.setProperty("FASTA_JVSUFFIX", Boolean.toString(fastajv.isSelected()) );
296 Cache.applicationProperties.setProperty("MSF_JVSUFFIX", Boolean.toString(msfjv.isSelected()) );
297 Cache.applicationProperties.setProperty("PFAM_JVSUFFIX", Boolean.toString(pfamjv.isSelected()) );
298 Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX", Boolean.toString(pileupjv.isSelected()) );
299 Cache.applicationProperties.setProperty("PIR_JVSUFFIX", Boolean.toString(pirjv.isSelected()) );
300 Cache.applicationProperties.setProperty("PIR_MODELLER", Boolean.toString(modellerOutput.isSelected()) );
301 jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
303 Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
304 Boolean.toString(autoCalculateConsCheck.isSelected()));
305 Cache.applicationProperties.setProperty("PAD_GAPS",
306 Boolean.toString(padGaps.isSelected()));
308 dasSource.saveProperties(Cache.applicationProperties);
310 Cache.saveProperties();
313 frame.setClosed(true);
323 public void startupFileTextfield_mouseClicked()
325 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
329 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
334 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
335 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
336 chooser.setFileView(new JalviewFileView());
337 chooser.setDialogTitle("Select startup file");
339 int value = chooser.showOpenDialog(this);
341 if (value == JalviewFileChooser.APPROVE_OPTION)
343 jalview.bin.Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
344 chooser.getSelectedFormat());
345 startupFileTextfield.setText(chooser.getSelectedFile()
353 * @param e DOCUMENT ME!
355 public void cancel_actionPerformed(ActionEvent e)
359 frame.setClosed(true);
369 * @param e DOCUMENT ME!
371 public void annotations_actionPerformed(ActionEvent e)
373 conservation.setEnabled(annotations.isSelected());
374 quality.setEnabled(annotations.isSelected());
375 identity.setEnabled(annotations.isSelected());
379 public void newLink_actionPerformed(ActionEvent e) {
381 GSequenceLink link = new GSequenceLink();
382 boolean valid = false;
385 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
386 "New sequence URL link",
387 JOptionPane.OK_CANCEL_OPTION
389 == JOptionPane.OK_OPTION)
391 if (link.checkValid())
393 nameLinks.addElement(link.getName());
394 urlLinks.addElement(link.getURL());
404 public void editLink_actionPerformed(ActionEvent e) {
405 GSequenceLink link = new GSequenceLink();
407 int index = linkNameList.getSelectedIndex();
410 JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"
411 ,"No link selected", JOptionPane.WARNING_MESSAGE);
415 link.setName( nameLinks.elementAt(index).toString() );
416 link.setURL( urlLinks.elementAt(index).toString() );
418 boolean valid = false;
422 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
423 "New sequence URL link",
424 JOptionPane.OK_CANCEL_OPTION
426 == JOptionPane.OK_OPTION)
428 if (link.checkValid())
430 nameLinks.setElementAt(link.getName(), index);
431 urlLinks.setElementAt(link.getURL(), index);
442 public void deleteLink_actionPerformed(ActionEvent e) {
443 int index = linkNameList.getSelectedIndex();
446 JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"
447 ,"No link selected", JOptionPane.WARNING_MESSAGE);
450 nameLinks.removeElementAt(index);
451 urlLinks.removeElementAt(index);
455 void updateLinkData()
457 linkNameList.setListData(nameLinks);
458 linkURLList.setListData(urlLinks);
461 public void defaultBrowser_mouseClicked(MouseEvent e)
463 JFileChooser chooser = new JFileChooser(".");
464 chooser.setDialogTitle("Select default web browser");
466 int value = chooser.showOpenDialog(this);
468 if (value == JFileChooser.APPROVE_OPTION)
470 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
475 private void jbInit()