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