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