JAL-1432 updated copyright notices
[jalview.git] / src / jalview / gui / Preferences.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.gui;
20
21 import java.util.*;
22
23 import java.awt.*;
24 import java.awt.event.*;
25
26 import javax.swing.*;
27
28 import jalview.bin.*;
29 import jalview.io.*;
30 import jalview.jbgui.*;
31 import jalview.schemes.*;
32
33 /**
34  * DOCUMENT ME!
35  * 
36  * @author $author$
37  * @version $Revision$
38  */
39 public class Preferences extends GPreferences
40 {
41
42   /**
43    * Holds name and link separated with | character. Sequence ID must be
44    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
45    */
46   public static Vector sequenceURLLinks;
47
48   /**
49    * Holds name and link separated with | character. Sequence IDS and Sequences
50    * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
51    * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
52    * for first and second token specified after a pipe character at end |,|.
53    * (TODO: proper escape for using | to separate ids or sequences
54    */
55
56   public static Vector groupURLLinks;
57   static
58   {
59     String string = Cache
60             .getDefault(
61                     "SEQUENCE_LINKS",
62                     "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
63     sequenceURLLinks = new Vector();
64
65     try
66     {
67       StringTokenizer st = new StringTokenizer(string, "|");
68       while (st.hasMoreElements())
69       {
70         String name = st.nextToken();
71         String url = st.nextToken();
72         // check for '|' within a regex
73         int rxstart = url.indexOf("$SEQUENCE_ID$");
74         while (rxstart == -1 && url.indexOf("/=$") == -1)
75         {
76           url = url + "|" + st.nextToken();
77         }
78         sequenceURLLinks.addElement(name + "|" + url);
79       }
80     } catch (Exception ex)
81     {
82       System.out.println(ex + "\nError parsing sequence links");
83     }
84     {
85       // upgrade old SRS link
86       int srsPos = sequenceURLLinks
87               .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
88       if (srsPos > -1)
89       {
90         sequenceURLLinks.setElementAt(
91                 "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$",
92                 srsPos);
93       }
94     }
95
96     /**
97      * TODO: reformulate groupURL encoding so two or more can be stored in the
98      * .properties file as '|' separated strings
99      */
100
101     groupURLLinks = new Vector();
102     // groupURLLinks.addElement("UNIPROT|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewIDs$DATASETID$&input=$SEQUENCEIDS$&inputType=0|,");
103     // groupURLLinks.addElement("Seqs|EnVision2|http://www.ebi.ac.uk/enfin-srv/envision2/pages/linkin.jsf?tool=Jalview&workflow=Default&datasetName=JalviewSeqs$DATASETID$&input=$SEQUENCES=/([A-Za-z]+)+/=$&inputType=1|,");
104
105   }
106
107   Vector nameLinks, urlLinks;
108
109   JInternalFrame frame;
110
111   DasSourceBrowser dasSource;
112
113   private WsPreferences wsPrefs;
114
115   /**
116    * Creates a new Preferences object.
117    */
118   public Preferences()
119   {
120
121     frame = new JInternalFrame();
122     frame.setContentPane(this);
123     dasSource = new DasSourceBrowser();
124     dasPanel.add(dasSource, BorderLayout.CENTER);
125     wsPrefs = new WsPreferences();
126     wsPanel.add(wsPrefs, BorderLayout.CENTER);
127     int width = 500, height = 420;
128     if (new jalview.util.Platform().isAMac())
129     {
130       width = 570;
131       height = 460;
132     }
133
134     Desktop.addInternalFrame(frame, "Preferences", width, height);
135     frame.setMinimumSize(new Dimension(width, height));
136
137     seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
138     rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
139     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
140     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
141
142     conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
143     quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
144     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
145     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
146     showUnconserved
147             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
148     showNpTooltip.setSelected(Cache
149             .getDefault("SHOW_NPFEATS_TOOLTIP", true));
150     showDbRefTooltip.setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP",
151             true));
152     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
153     for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++)
154     {
155       colour.addItem(ColourSchemeProperty.getColourName(i));
156     }
157
158     String string = Cache.getDefault("DEFAULT_COLOUR", "None");
159
160     colour.setSelectedItem(string);
161
162     /**
163      * default min-max colours for annotation shading
164      */
165     minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
166             Color.orange));
167     maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
168             Color.red));
169
170     String[] fonts = java.awt.GraphicsEnvironment
171             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
172
173     for (int i = 0; i < fonts.length; i++)
174     {
175       fontNameCB.addItem(fonts[i]);
176     }
177
178     for (int i = 1; i < 31; i++)
179     {
180       fontSizeCB.addItem(i + "");
181     }
182
183     fontStyleCB.addItem("plain");
184     fontStyleCB.addItem("bold");
185     fontStyleCB.addItem("italic");
186
187     fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
188     fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
189     fontStyleCB.setSelectedItem(Cache.getDefault("FONT_STYLE", Font.PLAIN
190             + ""));
191
192     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
193
194     idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
195
196     wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
197
198     gapSymbolCB.addItem("-");
199     gapSymbolCB.addItem(".");
200
201     gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
202
203     startupCheckbox
204             .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
205     startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
206             Cache.getDefault("www.jalview.org", "http://www.jalview.org")
207                     + "/examples/exampleFile_2_3.jar"));
208
209     sortby.addItem("No sort");
210     sortby.addItem("Id");
211     sortby.addItem("Pairwise Identity");
212     sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
213
214     epsRendering.addItem("Prompt each time");
215     epsRendering.addItem("Lineart");
216     epsRendering.addItem("Text");
217     epsRendering.setSelectedItem(Cache.getDefault("EPS_RENDERING",
218             "Prompt each time"));
219     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
220     userIdWidth.setEnabled(autoIdWidth.isSelected());
221     userIdWidthlabel.setEnabled(autoIdWidth.isSelected());
222     Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
223     userIdWidth.setText(wi == null ? "" : wi.toString());
224     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
225     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
226     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
227     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
228     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
229     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
230     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
231
232     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
233
234     autoCalculateConsCheck.setSelected(Cache.getDefault(
235             "AUTO_CALC_CONSENSUS", true));
236     showGroupConsensus.setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS",
237             false));
238     showGroupConservation.setSelected(Cache.getDefault(
239             "SHOW_GROUP_CONSERVATION", false));
240     showConsensHistogram.setSelected(Cache.getDefault(
241             "SHOW_CONSENSUS_HISTOGRAM", true));
242     showConsensLogo.setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO",
243             false));
244
245     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
246
247     /***************************************************************************
248      * Set up Connections
249      */
250     nameLinks = new Vector();
251     urlLinks = new Vector();
252     for (int i = 0; i < sequenceURLLinks.size(); i++)
253     {
254       String link = sequenceURLLinks.elementAt(i).toString();
255       nameLinks.addElement(link.substring(0, link.indexOf("|")));
256       urlLinks.addElement(link.substring(link.indexOf("|") + 1));
257     }
258
259     updateLinkData();
260
261     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
262     proxyServerTB.setEnabled(useProxy.isSelected());
263     proxyPortTB.setEnabled(useProxy.isSelected());
264     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
265     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
266
267     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
268
269     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
270     questionnaire
271             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null); // note
272                                                                          // antisense
273                                                                          // here
274     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true)); // default
275                                                                        // is
276                                                                        // true
277     annotations_actionPerformed(null); // update the display of the annotation
278                                        // settings
279     try
280     {
281       jbInit();
282     } catch (Exception ex)
283     {
284       ex.printStackTrace();
285     }
286
287   }
288
289   /**
290    * DOCUMENT ME!
291    * 
292    * @param e
293    *          DOCUMENT ME!
294    */
295   public void ok_actionPerformed(ActionEvent e)
296   {
297
298     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
299             Boolean.toString(seqLimit.isSelected()));
300     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
301             Boolean.toString(rightAlign.isSelected()));
302     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
303             Boolean.toString(fullScreen.isSelected()));
304     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
305             Boolean.toString(openoverv.isSelected()));
306     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
307             Boolean.toString(annotations.isSelected()));
308     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
309             Boolean.toString(conservation.isSelected()));
310     Cache.applicationProperties.setProperty("SHOW_QUALITY",
311             Boolean.toString(quality.isSelected()));
312     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
313             Boolean.toString(identity.isSelected()));
314
315     Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour
316             .getSelectedItem().toString());
317     Cache.applicationProperties.setProperty("GAP_SYMBOL", gapSymbolCB
318             .getSelectedItem().toString());
319
320     Cache.applicationProperties.setProperty("FONT_NAME", fontNameCB
321             .getSelectedItem().toString());
322     Cache.applicationProperties.setProperty("FONT_STYLE", fontStyleCB
323             .getSelectedItem().toString());
324     Cache.applicationProperties.setProperty("FONT_SIZE", fontSizeCB
325             .getSelectedItem().toString());
326
327     Cache.applicationProperties.setProperty("ID_ITALICS",
328             Boolean.toString(idItalics.isSelected()));
329     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
330             Boolean.toString(showUnconserved.isSelected()));
331     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
332             Boolean.toString(showGroupConsensus.isSelected()));
333     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
334             Boolean.toString(showGroupConservation.isSelected()));
335     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
336             Boolean.toString(showConsensHistogram.isSelected()));
337     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
338             Boolean.toString(showConsensLogo.isSelected()));
339     Cache.applicationProperties.setProperty("ANTI_ALIAS",
340             Boolean.toString(smoothFont.isSelected()));
341     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
342             Boolean.toString(showNpTooltip.isSelected()));
343     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
344             Boolean.toString(showDbRefTooltip.isSelected()));
345
346     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
347             Boolean.toString(wrap.isSelected()));
348
349     Cache.applicationProperties.setProperty("STARTUP_FILE",
350             startupFileTextfield.getText());
351     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
352             Boolean.toString(startupCheckbox.isSelected()));
353
354     Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby
355             .getSelectedItem().toString());
356
357     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
358             minColour.getBackground());
359     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
360             maxColour.getBackground());
361
362     if (epsRendering.getSelectedItem().equals("Prompt each time"))
363     {
364       Cache.applicationProperties.remove("EPS_RENDERING");
365     }
366     else
367     {
368       Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering
369               .getSelectedItem().toString());
370     }
371
372     if (defaultBrowser.getText().trim().length() < 1)
373     {
374       Cache.applicationProperties.remove("DEFAULT_BROWSER");
375     }
376     else
377     {
378       Cache.applicationProperties.setProperty("DEFAULT_BROWSER",
379               defaultBrowser.getText());
380     }
381
382     jalview.util.BrowserLauncher.resetBrowser();
383
384     if (nameLinks.size() > 0)
385     {
386       StringBuffer links = new StringBuffer();
387       sequenceURLLinks = new Vector();
388       for (int i = 0; i < nameLinks.size(); i++)
389       {
390         sequenceURLLinks.addElement(nameLinks.elementAt(i) + "|"
391                 + urlLinks.elementAt(i));
392         links.append(sequenceURLLinks.elementAt(i).toString());
393         links.append("|");
394       }
395       // remove last "|"
396       links.setLength(links.length() - 1);
397       Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
398               links.toString());
399     }
400     else
401     {
402       Cache.applicationProperties.remove("SEQUENCE_LINKS");
403     }
404
405     Cache.applicationProperties.setProperty("USE_PROXY",
406             Boolean.toString(useProxy.isSelected()));
407
408     if (proxyServerTB.getText().trim().length() < 1)
409     {
410       Cache.applicationProperties.remove("PROXY_SERVER");
411     }
412     else
413     {
414       Cache.applicationProperties.setProperty("PROXY_SERVER",
415               proxyServerTB.getText());
416     }
417
418     if (proxyPortTB.getText().trim().length() < 1)
419     {
420       Cache.applicationProperties.remove("PROXY_PORT");
421     }
422     else
423     {
424       Cache.applicationProperties.setProperty("PROXY_PORT",
425               proxyPortTB.getText());
426     }
427
428     if (useProxy.isSelected())
429     {
430       System.setProperty("http.proxyHost", proxyServerTB.getText());
431       System.setProperty("http.proxyPort", proxyPortTB.getText());
432     }
433     else
434     {
435       System.setProperty("http.proxyHost", "");
436       System.setProperty("http.proxyPort", "");
437     }
438     Cache.setProperty("VERSION_CHECK",
439             Boolean.toString(versioncheck.isSelected()));
440     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
441     {
442       // default is false - we only set this if the user has actively agreed
443       Cache.setProperty("USAGESTATS",
444               Boolean.toString(usagestats.isSelected()));
445     }
446     if (!questionnaire.isSelected())
447     {
448       Cache.setProperty("NOQUESTIONNAIRES", "true");
449     }
450     else
451     {
452       // special - made easy to edit a property file to disable questionnaires
453       // by just adding the given line
454       Cache.removeProperty("NOQUESTIONNAIRES");
455     }
456     Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
457             Boolean.toString(blcjv.isSelected()));
458     Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
459             Boolean.toString(clustaljv.isSelected()));
460     Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
461             Boolean.toString(fastajv.isSelected()));
462     Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
463             Boolean.toString(msfjv.isSelected()));
464     Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
465             Boolean.toString(pfamjv.isSelected()));
466     Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
467             Boolean.toString(pileupjv.isSelected()));
468     Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
469             Boolean.toString(pirjv.isSelected()));
470     Cache.applicationProperties.setProperty("PIR_MODELLER",
471             Boolean.toString(modellerOutput.isSelected()));
472     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
473
474     Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
475             Boolean.toString(autoIdWidth.isSelected()));
476     userIdWidth_actionPerformed();
477     Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
478             userIdWidth.getText());
479
480     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
481             Boolean.toString(autoCalculateConsCheck.isSelected()));
482     Cache.applicationProperties.setProperty("SORT_BY_TREE",
483             Boolean.toString(sortByTree.isSelected()));
484     Cache.applicationProperties.setProperty("PAD_GAPS",
485             Boolean.toString(padGaps.isSelected()));
486
487     dasSource.saveProperties(Cache.applicationProperties);
488     wsPrefs.updateAndRefreshWsMenuConfig(false);
489     Cache.saveProperties();
490     try
491     {
492       frame.setClosed(true);
493     } catch (Exception ex)
494     {
495     }
496   }
497
498   /**
499    * DOCUMENT ME!
500    */
501   public void startupFileTextfield_mouseClicked()
502   {
503     JalviewFileChooser chooser = new JalviewFileChooser(
504             jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
505             new String[]
506             { "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc", "jar" },
507             new String[]
508             { "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview" },
509             jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
510     chooser.setFileView(new JalviewFileView());
511     chooser.setDialogTitle("Select startup file");
512
513     int value = chooser.showOpenDialog(this);
514
515     if (value == JalviewFileChooser.APPROVE_OPTION)
516     {
517       jalview.bin.Cache.applicationProperties.setProperty(
518               "DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());
519       startupFileTextfield.setText(chooser.getSelectedFile()
520               .getAbsolutePath());
521     }
522   }
523
524   /**
525    * DOCUMENT ME!
526    * 
527    * @param e
528    *          DOCUMENT ME!
529    */
530   public void cancel_actionPerformed(ActionEvent e)
531   {
532     try
533     {
534       wsPrefs.updateWsMenuConfig(true);
535       wsPrefs.refreshWs_actionPerformed(e);
536       frame.setClosed(true);
537     } catch (Exception ex)
538     {
539     }
540   }
541
542   /**
543    * DOCUMENT ME!
544    * 
545    * @param e
546    *          DOCUMENT ME!
547    */
548   public void annotations_actionPerformed(ActionEvent e)
549   {
550     conservation.setEnabled(annotations.isSelected());
551     quality.setEnabled(annotations.isSelected());
552     identity.setEnabled(annotations.isSelected());
553     showGroupConsensus.setEnabled(annotations.isSelected());
554     showGroupConservation.setEnabled(annotations.isSelected());
555     showConsensHistogram.setEnabled(annotations.isSelected()
556             && (identity.isSelected() || showGroupConsensus.isSelected()));
557     showConsensLogo.setEnabled(annotations.isSelected()
558             && (identity.isSelected() || showGroupConsensus.isSelected()));
559   }
560
561   public void newLink_actionPerformed(ActionEvent e)
562   {
563
564     GSequenceLink link = new GSequenceLink();
565     boolean valid = false;
566     while (!valid)
567     {
568       if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
569               "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
570               null) == JOptionPane.OK_OPTION)
571       {
572         if (link.checkValid())
573         {
574           nameLinks.addElement(link.getName());
575           urlLinks.addElement(link.getURL());
576           updateLinkData();
577           valid = true;
578         }
579       }
580       else
581       {
582         break;
583       }
584     }
585   }
586
587   public void editLink_actionPerformed(ActionEvent e)
588   {
589     GSequenceLink link = new GSequenceLink();
590
591     int index = linkNameList.getSelectedIndex();
592     if (index == -1)
593     {
594       JOptionPane.showInternalMessageDialog(Desktop.desktop,
595               "No link selected!", "No link selected",
596               JOptionPane.WARNING_MESSAGE);
597       return;
598     }
599
600     link.setName(nameLinks.elementAt(index).toString());
601     link.setURL(urlLinks.elementAt(index).toString());
602
603     boolean valid = false;
604     while (!valid)
605     {
606
607       if (JOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
608               "New sequence URL link", JOptionPane.OK_CANCEL_OPTION, -1,
609               null) == JOptionPane.OK_OPTION)
610       {
611         if (link.checkValid())
612         {
613           nameLinks.setElementAt(link.getName(), index);
614           urlLinks.setElementAt(link.getURL(), index);
615           updateLinkData();
616           valid = true;
617         }
618       }
619
620       else
621       {
622         break;
623       }
624     }
625   }
626
627   public void deleteLink_actionPerformed(ActionEvent e)
628   {
629     int index = linkNameList.getSelectedIndex();
630     if (index == -1)
631     {
632       JOptionPane.showInternalMessageDialog(Desktop.desktop,
633               "No link selected!", "No link selected",
634               JOptionPane.WARNING_MESSAGE);
635       return;
636     }
637     nameLinks.removeElementAt(index);
638     urlLinks.removeElementAt(index);
639     updateLinkData();
640   }
641
642   void updateLinkData()
643   {
644     linkNameList.setListData(nameLinks);
645     linkURLList.setListData(urlLinks);
646   }
647
648   public void defaultBrowser_mouseClicked(MouseEvent e)
649   {
650     JFileChooser chooser = new JFileChooser(".");
651     chooser.setDialogTitle("Select default web browser");
652
653     int value = chooser.showOpenDialog(this);
654
655     if (value == JFileChooser.APPROVE_OPTION)
656     {
657       defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
658     }
659
660   }
661
662   /*
663    * (non-Javadoc)
664    * 
665    * @see
666    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
667    * .ActionEvent)
668    */
669   protected void showunconserved_actionPerformed(ActionEvent e)
670   {
671     // TODO Auto-generated method stub
672     super.showunconserved_actionPerformed(e);
673   }
674
675   private void jbInit() throws Exception
676   {
677   }
678
679   public static Collection getGroupURLLinks()
680   {
681     return groupURLLinks;
682   }
683
684   public void minColour_actionPerformed()
685   {
686     Color col = JColorChooser.showDialog(this,
687             "Select Colour for Minimum Value", minColour.getBackground());
688     if (col != null)
689     {
690       minColour.setBackground(col);
691     }
692     minColour.repaint();
693   }
694
695   public void maxColour_actionPerformed()
696   {
697     Color col = JColorChooser.showDialog(this,
698             "Select Colour for Maximum Value", maxColour.getBackground());
699     if (col != null)
700     {
701       maxColour.setBackground(col);
702     }
703     maxColour.repaint();
704   }
705
706   @Override
707   protected void userIdWidth_actionPerformed()
708   {
709     try
710     {
711       String val = userIdWidth.getText().trim();
712       if (val.length() > 0)
713       {
714         Integer iw = Integer.parseInt(val);
715         if (iw.intValue() < 12)
716         {
717           throw new NumberFormatException();
718         }
719         userIdWidth.setText(iw.toString());
720       }
721     } catch (NumberFormatException x)
722     {
723       JOptionPane
724               .showInternalMessageDialog(
725                       Desktop.desktop,
726                       "The user defined width for the\nannotation and sequence ID columns\nin exported figures must be\nat least 12 pixels wide.",
727                       "Invalid ID Column width",
728                       JOptionPane.WARNING_MESSAGE);
729       userIdWidth.setText("");
730     }
731   }
732
733   @Override
734   protected void autoIdWidth_actionPerformed()
735   {
736     userIdWidth.setEnabled(!autoIdWidth.isSelected());
737     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
738   }
739
740 }