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