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