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