2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.bin.*;
\r
23 import jalview.io.*;
\r
25 import jalview.jbgui.*;
\r
27 import jalview.schemes.*;
\r
30 import java.awt.event.*;
\r
32 import javax.swing.*;
\r
36 import jalview.bin.Cache;
\r
43 * @version $Revision$
\r
45 public class Preferences extends GPreferences
\r
47 /** Holds name and link separated with | character. Sequence ID must be $SEQUENCE_ID$ */
\r
48 public static Vector sequenceURLLinks = new Vector();
\r
49 Vector nameLinks, urlLinks;
\r
51 JInternalFrame frame;
\r
55 * Creates a new Preferences object.
\r
57 public Preferences()
\r
60 frame = new JInternalFrame();
\r
61 frame.setContentPane(this);
\r
62 Desktop.addInternalFrame(frame, "Preferences", 480, 390);
\r
63 frame.setMinimumSize(new Dimension(480,390));
\r
65 fullID.setSelected( Cache.getDefault("SHOW_FULL_ID", true));
\r
66 fullScreen.setSelected( Cache.getDefault("SHOW_FULLSCREEN", false));
\r
67 annotations.setSelected( Cache.getDefault("SHOW_FULL_ID", true));
\r
68 conservation.setEnabled( Cache.getDefault("SHOW_ANNOTATIONS", true));
\r
70 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
\r
71 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
\r
73 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
\r
74 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
\r
75 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
\r
77 for (int i = 0; i < 12; i++)
\r
79 colour.addItem(ColourSchemeProperty.getColourName(i));
\r
82 String string = Cache.getProperty("DEFAULT_COLOUR");
\r
86 colour.setSelectedItem(string);
\r
90 colour.setSelectedIndex(11);
\r
93 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
\r
94 .getAvailableFontFamilyNames();
\r
96 for (int i = 0; i < fonts.length; i++)
\r
98 fontNameCB.addItem(fonts[i]);
\r
101 for (int i = 1; i < 31; i++)
\r
103 fontSizeCB.addItem(i + "");
\r
106 fontStyleCB.addItem("plain");
\r
107 fontStyleCB.addItem("bold");
\r
108 fontStyleCB.addItem("italic");
\r
110 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
\r
111 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
\r
112 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN + "") );
\r
114 gapSymbolCB.addItem("-");
\r
115 gapSymbolCB.addItem(".");
\r
117 gapSymbolCB.setSelectedItem( Cache.getDefault("GAP_SYMBOL", "-"));
\r
119 startupCheckbox.setSelected( Cache.getDefault("SHOW_STARTUP_FILE", true) );
\r
120 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
\r
121 "http://www.jalview.org/examples/exampleFile.jar"));
\r
123 /****************************************************
\r
124 * Set up Connections
\r
127 string = Cache.getDefault("SEQUENCE_LINKS",
\r
128 "SRS|http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:$SEQUENCE_ID$]+-vn+2");
\r
129 sequenceURLLinks = new Vector();
\r
132 StringTokenizer st = new StringTokenizer(string, "|");
\r
133 while (st.hasMoreElements())
\r
135 sequenceURLLinks.addElement(st.nextToken() + "|" + st.nextToken());
\r
137 }catch(Exception ex)
\r
138 {System.out.println(ex+"\nError parsing sequence links");}
\r
140 nameLinks = new Vector();
\r
141 urlLinks = new Vector();
\r
142 for(int i=0; i<sequenceURLLinks.size(); i++)
\r
144 String link = sequenceURLLinks.elementAt(i).toString();
\r
145 nameLinks.addElement(link.substring(0, link.indexOf("|")) );
\r
146 urlLinks.addElement(link.substring(link.indexOf("|")+1));
\r
151 useProxy.setSelected( Cache.getDefault("USE_PROXY", false));
\r
152 proxyServerTB.setEnabled(useProxy.isSelected());
\r
153 proxyPortTB.setEnabled(useProxy.isSelected());
\r
154 proxyServerTB.setText( Cache.getDefault("PROXY_SERVER", ""));
\r
155 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
\r
157 defaultBrowser.setText( Cache.getDefault("DEFAULT_BROWSER",""));
\r
162 catch (Exception ex)
\r
164 ex.printStackTrace();
\r
173 * @param e DOCUMENT ME!
\r
175 public void ok_actionPerformed(ActionEvent e)
\r
178 Cache.applicationProperties.setProperty("SHOW_FULL_ID", Boolean.toString(fullID.isSelected()));
\r
179 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean.toString(fullScreen.isSelected()));
\r
181 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean.toString(annotations.isSelected()));
\r
182 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean.toString(conservation.isSelected()));
\r
183 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean.toString(quality.isSelected()));
\r
184 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean.toString(identity.isSelected()));
\r
186 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour.getSelectedItem().toString());
\r
187 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB.getSelectedItem().toString());
\r
189 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB.getSelectedItem().toString());
\r
190 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB.getSelectedItem().toString());
\r
191 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB.getSelectedItem().toString());
\r
193 Cache.applicationProperties.setProperty("STARTUP_FILE", startupFileTextfield.getText());
\r
194 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean.toString(startupCheckbox.isSelected()));
\r
196 Cache.applicationProperties.setProperty("DEFAULT_BROWSER", defaultBrowser.getText());
\r
198 if(nameLinks.size()>0)
\r
200 StringBuffer links = new StringBuffer();
\r
201 sequenceURLLinks = new Vector();
\r
202 for (int i = 0; i < nameLinks.size(); i++)
\r
204 sequenceURLLinks.addElement(nameLinks.elementAt(i)+"|"+urlLinks.elementAt(i));
\r
205 links.append(sequenceURLLinks.elementAt(i).toString());
\r
209 links.setLength( links.length()-1 );
\r
210 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links.toString());
\r
213 Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected()));
\r
214 Cache.applicationProperties.setProperty("PROXY_SERVER",proxyServerTB.getText());
\r
215 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB.getText());
\r
217 if(useProxy.isSelected())
\r
219 System.setProperty("http.proxyHost", proxyServerTB.getText());
\r
220 System.setProperty("http.proxyPort", proxyPortTB.getText());
\r
225 Cache.saveProperties();
\r
228 frame.setClosed(true);
\r
230 catch (Exception ex)
\r
238 public void startupFileTextfield_mouseClicked()
\r
240 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
244 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
\r
249 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
\r
250 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
\r
251 chooser.setFileView(new JalviewFileView());
\r
252 chooser.setDialogTitle("Select startup file");
\r
254 int value = chooser.showOpenDialog(this);
\r
256 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
258 jalview.bin.Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
\r
259 chooser.getSelectedFormat());
\r
260 startupFileTextfield.setText(chooser.getSelectedFile()
\r
261 .getAbsolutePath());
\r
268 * @param e DOCUMENT ME!
\r
270 public void cancel_actionPerformed(ActionEvent e)
\r
274 frame.setClosed(true);
\r
276 catch (Exception ex)
\r
284 * @param e DOCUMENT ME!
\r
286 public void annotations_actionPerformed(ActionEvent e)
\r
288 conservation.setEnabled(annotations.isSelected());
\r
289 quality.setEnabled(annotations.isSelected());
\r
290 identity.setEnabled(annotations.isSelected());
\r
294 public void newLink_actionPerformed(ActionEvent e) {
\r
296 GSequenceLink link = new GSequenceLink();
\r
297 boolean valid = false;
\r
300 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
\r
301 "New sequence URL link",
\r
302 JOptionPane.OK_CANCEL_OPTION
\r
304 == JOptionPane.OK_OPTION)
\r
306 if (link.checkValid())
\r
308 nameLinks.addElement(link.getName());
\r
309 urlLinks.addElement(link.getURL());
\r
319 public void editLink_actionPerformed(ActionEvent e) {
\r
320 GSequenceLink link = new GSequenceLink();
\r
322 int index = linkNameList.getSelectedIndex();
\r
325 JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"
\r
326 ,"No link selected", JOptionPane.WARNING_MESSAGE);
\r
330 link.setName( nameLinks.elementAt(index).toString() );
\r
331 link.setURL( urlLinks.elementAt(index).toString() );
\r
333 boolean valid = false;
\r
337 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
\r
338 "New sequence URL link",
\r
339 JOptionPane.OK_CANCEL_OPTION
\r
341 == JOptionPane.OK_OPTION)
\r
343 if (link.checkValid())
\r
345 nameLinks.setElementAt(link.getName(), index);
\r
346 urlLinks.setElementAt(link.getURL(), index);
\r
357 public void deleteLink_actionPerformed(ActionEvent e) {
\r
358 int index = linkNameList.getSelectedIndex();
\r
361 JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"
\r
362 ,"No link selected", JOptionPane.WARNING_MESSAGE);
\r
365 nameLinks.removeElementAt(index);
\r
366 urlLinks.removeElementAt(index);
\r
370 void updateLinkData()
\r
372 linkNameList.setListData(nameLinks);
\r
373 linkURLList.setListData(urlLinks);
\r
376 public void defaultBrowser_mouseClicked(MouseEvent e)
\r
378 JFileChooser chooser = new JFileChooser(".");
\r
379 chooser.setDialogTitle("Select default web browser");
\r
381 int value = chooser.showOpenDialog(this);
\r
383 if (value == JFileChooser.APPROVE_OPTION)
\r
385 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
\r
390 private void jbInit()
\r