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