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 static { sequenceURLLinks.addElement("SRS|http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:$SEQUENCE_ID$]+-vn+2");}
\r
50 Vector nameLinks, urlLinks;
\r
52 JInternalFrame frame;
\r
56 * Creates a new Preferences object.
\r
58 public Preferences()
\r
61 frame = new JInternalFrame();
\r
62 frame.setContentPane(this);
\r
63 Desktop.addInternalFrame(frame, "Preferences", 480, 390);
\r
64 frame.setMinimumSize(new Dimension(480,390));
\r
66 fullID.setSelected( Cache.getDefault("SHOW_FULL_ID", true));
\r
67 fullScreen.setSelected( Cache.getDefault("SHOW_FULLSCREEN", false));
\r
68 annotations.setSelected( Cache.getDefault("SHOW_FULL_ID", true));
\r
69 conservation.setEnabled( Cache.getDefault("SHOW_ANNOTATIONS", true));
\r
71 quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
\r
72 identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true));
\r
74 conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
\r
75 quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
\r
76 identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
\r
78 for (int i = 0; i < 12; i++)
\r
80 colour.addItem(ColourSchemeProperty.getColourName(i));
\r
83 String string = Cache.getProperty("DEFAULT_COLOUR");
\r
87 colour.setSelectedItem(string);
\r
91 colour.setSelectedIndex(11);
\r
94 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
\r
95 .getAvailableFontFamilyNames();
\r
97 for (int i = 0; i < fonts.length; i++)
\r
99 fontNameCB.addItem(fonts[i]);
\r
102 for (int i = 1; i < 31; i++)
\r
104 fontSizeCB.addItem(i + "");
\r
107 fontStyleCB.addItem("plain");
\r
108 fontStyleCB.addItem("bold");
\r
109 fontStyleCB.addItem("italic");
\r
111 fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
\r
112 fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
\r
113 fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN + "") );
\r
115 gapSymbolCB.addItem("-");
\r
116 gapSymbolCB.addItem(".");
\r
118 gapSymbolCB.setSelectedItem( Cache.getDefault("GAP_SYMBOL", "-"));
\r
120 startupCheckbox.setSelected( Cache.getDefault("SHOW_STARTUP_FILE", true) );
\r
121 startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
\r
122 "http://www.jalview.org/examples/exampleFile.jar"));
\r
124 /****************************************************
\r
125 * Set up Connections
\r
128 string = Cache.getDefault("SEQUENCE_LINKS",
\r
129 "SRS|http://srs.ebi.ac.uk/srs7bin/cgi-bin/wgetz?-e+[uniprot-all:$SEQUENCE_ID$]+-vn+2");
\r
130 sequenceURLLinks = new Vector();
\r
133 StringTokenizer st = new StringTokenizer(string, "|");
\r
134 while (st.hasMoreElements())
\r
136 sequenceURLLinks.addElement(st.nextToken() + "|" + st.nextToken());
\r
138 }catch(Exception ex)
\r
139 {System.out.println(ex+"\nError parsing sequence links");}
\r
141 nameLinks = new Vector();
\r
142 urlLinks = new Vector();
\r
143 for(int i=0; i<sequenceURLLinks.size(); i++)
\r
145 String link = sequenceURLLinks.elementAt(i).toString();
\r
146 nameLinks.addElement(link.substring(0, link.indexOf("|")) );
\r
147 urlLinks.addElement(link.substring(link.indexOf("|")+1));
\r
152 useProxy.setSelected( Cache.getDefault("USE_PROXY", false));
\r
153 proxyServerTB.setEnabled(useProxy.isSelected());
\r
154 proxyPortTB.setEnabled(useProxy.isSelected());
\r
155 proxyServerTB.setText( Cache.getDefault("PROXY_SERVER", ""));
\r
156 proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
\r
158 defaultBrowser.setText( Cache.getDefault("DEFAULT_BROWSER",""));
\r
163 catch (Exception ex)
\r
165 ex.printStackTrace();
\r
174 * @param e DOCUMENT ME!
\r
176 public void ok_actionPerformed(ActionEvent e)
\r
179 Cache.applicationProperties.setProperty("SHOW_FULL_ID", Boolean.toString(fullID.isSelected()));
\r
180 Cache.applicationProperties.setProperty("SHOW_FULLSCREEN", Boolean.toString(fullScreen.isSelected()));
\r
182 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", Boolean.toString(annotations.isSelected()));
\r
183 Cache.applicationProperties.setProperty("SHOW_CONSERVATION", Boolean.toString(conservation.isSelected()));
\r
184 Cache.applicationProperties.setProperty("SHOW_QUALITY", Boolean.toString(quality.isSelected()));
\r
185 Cache.applicationProperties.setProperty("SHOW_IDENTITY", Boolean.toString(identity.isSelected()));
\r
187 Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour.getSelectedItem().toString());
\r
188 Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB.getSelectedItem().toString());
\r
190 Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB.getSelectedItem().toString());
\r
191 Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB.getSelectedItem().toString());
\r
192 Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB.getSelectedItem().toString());
\r
194 Cache.applicationProperties.setProperty("STARTUP_FILE", startupFileTextfield.getText());
\r
195 Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE", Boolean.toString(startupCheckbox.isSelected()));
\r
197 Cache.applicationProperties.setProperty("DEFAULT_BROWSER", defaultBrowser.getText());
\r
199 if(nameLinks.size()>0)
\r
201 StringBuffer links = new StringBuffer();
\r
202 sequenceURLLinks = new Vector();
\r
203 for (int i = 0; i < nameLinks.size(); i++)
\r
205 sequenceURLLinks.addElement(nameLinks.elementAt(i)+"|"+urlLinks.elementAt(i));
\r
206 links.append(sequenceURLLinks.elementAt(i).toString());
\r
210 links.setLength( links.length()-1 );
\r
211 Cache.applicationProperties.setProperty("SEQUENCE_LINKS", links.toString());
\r
214 Cache.applicationProperties.setProperty("USE_PROXY", Boolean.toString(useProxy.isSelected()));
\r
215 Cache.applicationProperties.setProperty("PROXY_SERVER",proxyServerTB.getText());
\r
216 Cache.applicationProperties.setProperty("PROXY_PORT", proxyPortTB.getText());
\r
218 if(useProxy.isSelected())
\r
220 System.setProperty("http.proxyHost", proxyServerTB.getText());
\r
221 System.setProperty("http.proxyPort", proxyPortTB.getText());
\r
226 Cache.saveProperties();
\r
229 frame.setClosed(true);
\r
231 catch (Exception ex)
\r
239 public void startupFileTextfield_mouseClicked()
\r
241 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(
\r
245 "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
\r
250 "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"
\r
251 }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
\r
252 chooser.setFileView(new JalviewFileView());
\r
253 chooser.setDialogTitle("Select startup file");
\r
255 int value = chooser.showOpenDialog(this);
\r
257 if (value == JalviewFileChooser.APPROVE_OPTION)
\r
259 jalview.bin.Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
\r
260 chooser.getSelectedFormat());
\r
261 startupFileTextfield.setText(chooser.getSelectedFile()
\r
262 .getAbsolutePath());
\r
269 * @param e DOCUMENT ME!
\r
271 public void cancel_actionPerformed(ActionEvent e)
\r
275 frame.setClosed(true);
\r
277 catch (Exception ex)
\r
285 * @param e DOCUMENT ME!
\r
287 public void annotations_actionPerformed(ActionEvent e)
\r
289 conservation.setEnabled(annotations.isSelected());
\r
290 quality.setEnabled(annotations.isSelected());
\r
291 identity.setEnabled(annotations.isSelected());
\r
295 public void newLink_actionPerformed(ActionEvent e) {
\r
297 GSequenceLink link = new GSequenceLink();
\r
298 boolean valid = false;
\r
301 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
\r
302 "New sequence URL link",
\r
303 JOptionPane.OK_CANCEL_OPTION
\r
305 == JOptionPane.OK_OPTION)
\r
307 if (link.checkValid())
\r
309 nameLinks.addElement(link.getName());
\r
310 urlLinks.addElement(link.getURL());
\r
320 public void editLink_actionPerformed(ActionEvent e) {
\r
321 GSequenceLink link = new GSequenceLink();
\r
323 int index = linkNameList.getSelectedIndex();
\r
326 JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"
\r
327 ,"No link selected", JOptionPane.WARNING_MESSAGE);
\r
331 link.setName( nameLinks.elementAt(index).toString() );
\r
332 link.setURL( urlLinks.elementAt(index).toString() );
\r
334 boolean valid = false;
\r
338 if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
\r
339 "New sequence URL link",
\r
340 JOptionPane.OK_CANCEL_OPTION
\r
342 == JOptionPane.OK_OPTION)
\r
344 if (link.checkValid())
\r
346 nameLinks.setElementAt(link.getName(), index);
\r
347 urlLinks.setElementAt(link.getURL(), index);
\r
358 public void deleteLink_actionPerformed(ActionEvent e) {
\r
359 int index = linkNameList.getSelectedIndex();
\r
362 JOptionPane.showInternalMessageDialog(Desktop.desktop, "No link selected!"
\r
363 ,"No link selected", JOptionPane.WARNING_MESSAGE);
\r
366 nameLinks.removeElementAt(index);
\r
367 urlLinks.removeElementAt(index);
\r
371 void updateLinkData()
\r
373 linkNameList.setListData(nameLinks);
\r
374 linkURLList.setListData(urlLinks);
\r
377 public void defaultBrowser_mouseClicked(MouseEvent e)
\r
379 JFileChooser chooser = new JFileChooser(".");
\r
380 chooser.setDialogTitle("Select default web browser");
\r
382 int value = chooser.showOpenDialog(this);
\r
384 if (value == JFileChooser.APPROVE_OPTION)
\r
386 defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
\r
391 private void jbInit()
\r