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