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