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