JAL-2629 refactoring of Hmmer preferences
[jalview.git] / src / jalview / gui / Preferences.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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.gui.Help.HelpId;
26 import jalview.gui.StructureViewer.ViewerType;
27 import jalview.hmmer.HmmerCommand;
28 import jalview.io.FileFormatI;
29 import jalview.io.JalviewFileChooser;
30 import jalview.io.JalviewFileView;
31 import jalview.jbgui.GPreferences;
32 import jalview.jbgui.GSequenceLink;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ColourSchemes;
35 import jalview.schemes.ResidueColourScheme;
36 import jalview.urls.UrlLinkTableModel;
37 import jalview.urls.api.UrlProviderFactoryI;
38 import jalview.urls.api.UrlProviderI;
39 import jalview.urls.desktop.DesktopUrlProviderFactory;
40 import jalview.util.MessageManager;
41 import jalview.util.Platform;
42 import jalview.util.UrlConstants;
43 import jalview.ws.sifts.SiftsSettings;
44
45 import java.awt.BorderLayout;
46 import java.awt.Color;
47 import java.awt.Component;
48 import java.awt.Dimension;
49 import java.awt.Font;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.FocusAdapter;
53 import java.awt.event.FocusEvent;
54 import java.awt.event.MouseEvent;
55 import java.io.File;
56 import java.util.ArrayList;
57 import java.util.List;
58
59 import javax.help.HelpSetException;
60 import javax.swing.JColorChooser;
61 import javax.swing.JFileChooser;
62 import javax.swing.JInternalFrame;
63 import javax.swing.JPanel;
64 import javax.swing.ListSelectionModel;
65 import javax.swing.RowFilter;
66 import javax.swing.RowSorter;
67 import javax.swing.SortOrder;
68 import javax.swing.event.DocumentEvent;
69 import javax.swing.event.DocumentListener;
70 import javax.swing.event.ListSelectionEvent;
71 import javax.swing.event.ListSelectionListener;
72 import javax.swing.table.TableCellRenderer;
73 import javax.swing.table.TableColumn;
74 import javax.swing.table.TableModel;
75 import javax.swing.table.TableRowSorter;
76
77 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
78
79 /**
80  * DOCUMENT ME!
81  * 
82  * @author $author$
83  * @version $Revision$
84  */
85 public class Preferences extends GPreferences
86 {
87   public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
88
89   public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
90
91   public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
92
93   public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
94
95   public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
96
97   public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
98
99   public static final String ADD_SS_ANN = "ADD_SS_ANN";
100
101   public static final String USE_RNAVIEW = "USE_RNAVIEW";
102
103   public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
104
105   public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
106
107   public static final String CHIMERA_PATH = "CHIMERA_PATH";
108   
109   public static final String HMMER_PATH = "HMMER_PATH";
110
111   public static final String HMMSEARCH_DB_PATHS = "HMMSEARCH_DB_PATHS";
112
113   public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS";
114
115   public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
116
117   public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
118
119   public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
120
121   private static final int MIN_FONT_SIZE = 1;
122
123   private static final int MAX_FONT_SIZE = 30;
124
125   /**
126    * Holds name and link separated with | character. Sequence ID must be
127    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
128    */
129   public static UrlProviderI sequenceUrlLinks;
130
131   public static UrlLinkTableModel dataModel;
132
133   /**
134    * Holds name and link separated with | character. Sequence IDS and Sequences
135    * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and
136    * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character
137    * for first and second token specified after a pipe character at end |,|.
138    * (TODO: proper escape for using | to separate ids or sequences
139    */
140
141   public static List<String> groupURLLinks;
142   static
143   {
144     // get links selected to be in the menu (SEQUENCE_LINKS)
145     // and links entered by the user but not selected (STORED_LINKS)
146     String inMenuString = Cache.getDefault("SEQUENCE_LINKS", "");
147     String notInMenuString = Cache.getDefault("STORED_LINKS", "");
148     String defaultUrl = Cache.getDefault("DEFAULT_URL",
149             UrlConstants.DEFAULT_LABEL);
150
151     // if both links lists are empty, add the DEFAULT_URL link
152     // otherwise we assume the default link is in one of the lists
153     if (inMenuString.isEmpty() && notInMenuString.isEmpty())
154     {
155       inMenuString = UrlConstants.DEFAULT_STRING;
156     }
157     UrlProviderFactoryI factory = new DesktopUrlProviderFactory(defaultUrl,
158             inMenuString, notInMenuString);
159     sequenceUrlLinks = factory.createUrlProvider();
160     dataModel = new UrlLinkTableModel(sequenceUrlLinks);
161
162     /**
163      * TODO: reformulate groupURL encoding so two or more can be stored in the
164      * .properties file as '|' separated strings
165      */
166
167     groupURLLinks = new ArrayList<>();
168   }
169
170   JInternalFrame frame;
171
172   DasSourceBrowser dasSource;
173
174   private WsPreferences wsPrefs;
175
176   private OptionsParam promptEachTimeOpt = new OptionsParam(
177           MessageManager.getString("label.prompt_each_time"),
178           "Prompt each time");
179
180   private OptionsParam lineArtOpt = new OptionsParam(
181           MessageManager.getString("label.lineart"), "Lineart");
182
183   private OptionsParam textOpt = new OptionsParam(
184           MessageManager.getString("action.text"), "Text");
185
186   /**
187    * Creates a new Preferences object.
188    */
189   public Preferences()
190   {
191     super();
192     frame = new JInternalFrame();
193     frame.setContentPane(this);
194     dasSource = new DasSourceBrowser();
195     dasTab.add(dasSource, BorderLayout.CENTER);
196     wsPrefs = new WsPreferences();
197     wsTab.add(wsPrefs, BorderLayout.CENTER);
198     int width = 500, height = 450;
199     new jalview.util.Platform();
200     if (Platform.isAMac())
201     {
202       width = 570;
203       height = 480;
204     }
205
206     Desktop.addInternalFrame(frame,
207             MessageManager.getString("label.preferences"), width, height);
208     frame.setMinimumSize(new Dimension(width, height));
209
210     /*
211      * Set HMMER tab defaults
212      */
213     hmmrTrimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
214     if (Cache.getDefault("USE_UNIPROT", false))
215     {
216       hmmerBackgroundUniprot.setSelected(true);
217     }
218     else
219     {
220       hmmerBackgroundAlignment.setSelected(true);
221     }
222     hmmerSequenceCount
223             .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
224     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
225     hmmerPath.addActionListener(new ActionListener()
226     {
227       @Override
228       public void actionPerformed(ActionEvent e)
229       {
230         validateHMMERPath(true);
231       }
232     });
233     hmmerPath.addFocusListener(new FocusAdapter()
234     {
235       @Override
236       public void focusLost(FocusEvent e)
237       {
238         validateHMMERPath(true);
239       }
240     });
241
242     /*
243      * Set Visual tab defaults
244      */
245     seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true));
246     rightAlign.setSelected(Cache.getDefault("RIGHT_ALIGN_IDS", false));
247     fullScreen.setSelected(Cache.getDefault("SHOW_FULLSCREEN", false));
248     annotations.setSelected(Cache.getDefault("SHOW_ANNOTATIONS", true));
249
250     conservation.setSelected(Cache.getDefault("SHOW_CONSERVATION", true));
251     quality.setSelected(Cache.getDefault("SHOW_QUALITY", true));
252     identity.setSelected(Cache.getDefault("SHOW_IDENTITY", true));
253     openoverv.setSelected(Cache.getDefault("SHOW_OVERVIEW", false));
254     showUnconserved
255             .setSelected(Cache.getDefault("SHOW_UNCONSERVED", false));
256     showOccupancy.setSelected(Cache.getDefault(SHOW_OCCUPANCY, false));
257     showGroupConsensus
258             .setSelected(Cache.getDefault("SHOW_GROUP_CONSENSUS", false));
259     showGroupConservation.setSelected(
260             Cache.getDefault("SHOW_GROUP_CONSERVATION", false));
261     showConsensHistogram.setSelected(
262             Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true));
263     showConsensLogo
264             .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false));
265     showInformationHistogram.setSelected(
266             Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true));
267     showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false));
268     showNpTooltip
269             .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true));
270     showDbRefTooltip
271             .setSelected(Cache.getDefault("SHOW_DBREFS_TOOLTIP", true));
272
273     String[] fonts = java.awt.GraphicsEnvironment
274             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
275     for (int i = 0; i < fonts.length; i++)
276     {
277       fontNameCB.addItem(fonts[i]);
278     }
279
280     for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++)
281     {
282       fontSizeCB.addItem(i + "");
283     }
284
285     fontStyleCB.addItem("plain");
286     fontStyleCB.addItem("bold");
287     fontStyleCB.addItem("italic");
288
289     fontNameCB.setSelectedItem(Cache.getDefault("FONT_NAME", "SansSerif"));
290     fontSizeCB.setSelectedItem(Cache.getDefault("FONT_SIZE", "10"));
291     fontStyleCB.setSelectedItem(
292             Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
293
294     smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
295     scaleProteinToCdna
296             .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
297
298     idItalics.setSelected(Cache.getDefault("ID_ITALICS", true));
299
300     wrap.setSelected(Cache.getDefault("WRAP_ALIGNMENT", false));
301
302     gapSymbolCB.addItem("-");
303     gapSymbolCB.addItem(".");
304
305     gapSymbolCB.setSelectedItem(Cache.getDefault("GAP_SYMBOL", "-"));
306
307     sortby.addItem("No sort");
308     sortby.addItem("Id");
309     sortby.addItem("Pairwise Identity");
310     sortby.setSelectedItem(Cache.getDefault("SORT_ALIGNMENT", "No sort"));
311
312     sortAnnBy.addItem(SequenceAnnotationOrder.NONE.toString());
313     sortAnnBy
314             .addItem(SequenceAnnotationOrder.SEQUENCE_AND_LABEL.toString());
315     sortAnnBy
316             .addItem(SequenceAnnotationOrder.LABEL_AND_SEQUENCE.toString());
317     SequenceAnnotationOrder savedSort = SequenceAnnotationOrder
318             .valueOf(Cache.getDefault(SORT_ANNOTATIONS,
319                     SequenceAnnotationOrder.NONE.name()));
320     sortAnnBy.setSelectedItem(savedSort.toString());
321
322     sortAutocalc.addItem("Autocalculated first");
323     sortAutocalc.addItem("Autocalculated last");
324     final boolean showAbove = Cache.getDefault(SHOW_AUTOCALC_ABOVE, true);
325     sortAutocalc.setSelectedItem(showAbove ? sortAutocalc.getItemAt(0)
326             : sortAutocalc.getItemAt(1));
327     startupCheckbox
328             .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true));
329     startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE",
330             Cache.getDefault("www.jalview.org", "http://www.jalview.org")
331                     + "/examples/exampleFile_2_3.jar"));
332
333     /*
334      * Set Colours tab defaults
335      */
336     protColour.addItem(ResidueColourScheme.NONE);
337     nucColour.addItem(ResidueColourScheme.NONE);
338     for (ColourSchemeI cs : ColourSchemes.getInstance().getColourSchemes())
339     {
340       String name = cs.getSchemeName();
341       protColour.addItem(name);
342       nucColour.addItem(name);
343     }
344     String oldProp = Cache.getDefault(DEFAULT_COLOUR,
345             ResidueColourScheme.NONE);
346     String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null);
347     protColour.setSelectedItem(newProp != null ? newProp : oldProp);
348     newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null);
349     nucColour.setSelectedItem(newProp != null ? newProp : oldProp);
350     minColour.setBackground(
351             Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
352     maxColour.setBackground(
353             Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
354
355     /*
356      * Set Structure tab defaults.
357      */
358     final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false);
359     structFromPdb.setSelected(structSelected);
360     useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false));
361     useRnaView.setEnabled(structSelected);
362     addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false));
363     addSecondaryStructure.setEnabled(structSelected);
364     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false));
365     addTempFactor.setEnabled(structSelected);
366     structViewer.setSelectedItem(
367             Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name()));
368     chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, ""));
369     chimeraPath.addActionListener(new ActionListener()
370     {
371       @Override
372       public void actionPerformed(ActionEvent e)
373       {
374         validateChimeraPath();
375       }
376     });
377
378     if (Cache.getDefault("MAP_WITH_SIFTS", false))
379     {
380       siftsMapping.setSelected(true);
381     }
382     else
383     {
384       nwMapping.setSelected(true);
385     }
386
387     SiftsSettings
388             .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
389
390     /*
391      * Set Connections tab defaults
392      */
393
394     // set up sorting
395     linkUrlTable.setModel(dataModel);
396     final TableRowSorter<TableModel> sorter = new TableRowSorter<>(
397             linkUrlTable.getModel());
398     linkUrlTable.setRowSorter(sorter);
399     List<RowSorter.SortKey> sortKeys = new ArrayList<>();
400
401     UrlLinkTableModel m = (UrlLinkTableModel) linkUrlTable.getModel();
402     sortKeys.add(new RowSorter.SortKey(m.getPrimaryColumn(),
403             SortOrder.DESCENDING));
404     sortKeys.add(new RowSorter.SortKey(m.getSelectedColumn(),
405             SortOrder.DESCENDING));
406     sortKeys.add(
407             new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
408
409     sorter.setSortKeys(sortKeys);
410     sorter.sort();
411
412     // set up filtering
413     ActionListener onReset;
414     onReset = new ActionListener()
415     {
416       @Override
417       public void actionPerformed(ActionEvent e)
418       {
419         filterTB.setText("");
420         sorter.setRowFilter(RowFilter.regexFilter(""));
421       }
422
423     };
424     doReset.addActionListener(onReset);
425
426     // filter to display only custom urls
427     final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
428     {
429       @Override
430       public boolean include(
431               Entry<? extends TableModel, ? extends Object> entry)
432       {
433         return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
434       }
435     };
436
437     final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
438             linkUrlTable.getModel());
439     customSorter.setRowFilter(customUrlFilter);
440
441     ActionListener onCustomOnly;
442     onCustomOnly = new ActionListener()
443     {
444       @Override
445       public void actionPerformed(ActionEvent e)
446       {
447         filterTB.setText("");
448         sorter.setRowFilter(customUrlFilter);
449       }
450     };
451     userOnly.addActionListener(onCustomOnly);
452
453     filterTB.getDocument().addDocumentListener(new DocumentListener()
454     {
455       String caseInsensitiveFlag = "(?i)";
456
457       @Override
458       public void changedUpdate(DocumentEvent e)
459       {
460         sorter.setRowFilter(RowFilter
461                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
462       }
463
464       @Override
465       public void removeUpdate(DocumentEvent e)
466       {
467         sorter.setRowFilter(RowFilter
468                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
469       }
470
471       @Override
472       public void insertUpdate(DocumentEvent e)
473       {
474         sorter.setRowFilter(RowFilter
475                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
476       }
477     });
478
479     // set up list selection functionality
480     linkUrlTable.getSelectionModel()
481             .addListSelectionListener(new UrlListSelectionHandler());
482
483     // set up radio buttons
484     int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
485             .getPrimaryColumn();
486     String onClickName = linkUrlTable.getColumnName(onClickCol);
487     linkUrlTable.getColumn(onClickName)
488             .setCellRenderer(new RadioButtonRenderer());
489     linkUrlTable.getColumn(onClickName)
490             .setCellEditor(new RadioButtonEditor());
491
492     // get boolean columns and resize those to min possible
493     for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
494     {
495       if (linkUrlTable.getModel().getColumnClass(column)
496               .equals(Boolean.class))
497       {
498         TableColumn tableColumn = linkUrlTable.getColumnModel()
499                 .getColumn(column);
500         int preferredWidth = tableColumn.getMinWidth();
501
502         TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
503                 column);
504         Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
505         int cwidth = c.getPreferredSize().width
506                 + linkUrlTable.getIntercellSpacing().width;
507         preferredWidth = Math.max(preferredWidth, cwidth);
508
509         tableColumn.setPreferredWidth(preferredWidth);
510       }
511     }
512
513     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
514     useProxy_actionPerformed(); // make sure useProxy is correctly initialised
515     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
516     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
517
518     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
519
520     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
521     // note antisense here: default is true
522     questionnaire
523             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
524     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
525
526     /*
527      * Set Output tab defaults
528      */
529     epsRendering.addItem(promptEachTimeOpt);
530     epsRendering.addItem(lineArtOpt);
531     epsRendering.addItem(textOpt);
532     String defaultEPS = Cache.getDefault("EPS_RENDERING",
533             "Prompt each time");
534     if (defaultEPS.equalsIgnoreCase("Text"))
535     {
536       epsRendering.setSelectedItem(textOpt);
537     }
538     else if (defaultEPS.equalsIgnoreCase("Lineart"))
539     {
540       epsRendering.setSelectedItem(lineArtOpt);
541     }
542     else
543     {
544       epsRendering.setSelectedItem(promptEachTimeOpt);
545     }
546     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
547     userIdWidth.setEnabled(!autoIdWidth.isSelected());
548     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
549     Integer wi = Cache.getIntegerProperty("FIGURE_USERIDWIDTH");
550     userIdWidth.setText(wi == null ? "" : wi.toString());
551     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
552     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
553     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
554     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
555     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
556     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
557     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
558     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
559     embbedBioJSON
560             .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
561
562     /*
563      * Set Editing tab defaults
564      */
565     autoCalculateConsCheck
566             .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
567     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
568     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
569
570     annotations_actionPerformed(null); // update the display of the annotation
571                                        // settings
572   }
573
574   /**
575    * Save user selections on the Preferences tabs to the Cache and write out to
576    * file.
577    * 
578    * @param e
579    */
580   @Override
581   public void ok_actionPerformed(ActionEvent e)
582   {
583     if (!validateSettings())
584     {
585       return;
586     }
587
588     /*
589      * Save Visual settings
590      */
591     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
592             Boolean.toString(seqLimit.isSelected()));
593     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
594             Boolean.toString(rightAlign.isSelected()));
595     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
596             Boolean.toString(fullScreen.isSelected()));
597     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
598             Boolean.toString(openoverv.isSelected()));
599     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
600             Boolean.toString(annotations.isSelected()));
601     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
602             Boolean.toString(conservation.isSelected()));
603     Cache.applicationProperties.setProperty("SHOW_QUALITY",
604             Boolean.toString(quality.isSelected()));
605     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
606             Boolean.toString(identity.isSelected()));
607
608     Cache.applicationProperties.setProperty("GAP_SYMBOL",
609             gapSymbolCB.getSelectedItem().toString());
610
611     Cache.applicationProperties.setProperty("FONT_NAME",
612             fontNameCB.getSelectedItem().toString());
613     Cache.applicationProperties.setProperty("FONT_STYLE",
614             fontStyleCB.getSelectedItem().toString());
615     Cache.applicationProperties.setProperty("FONT_SIZE",
616             fontSizeCB.getSelectedItem().toString());
617
618     Cache.applicationProperties.setProperty("ID_ITALICS",
619             Boolean.toString(idItalics.isSelected()));
620     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
621             Boolean.toString(showUnconserved.isSelected()));
622     Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
623             Boolean.toString(showOccupancy.isSelected()));
624     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
625             Boolean.toString(showGroupConsensus.isSelected()));
626     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
627             Boolean.toString(showGroupConservation.isSelected()));
628     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
629             Boolean.toString(showConsensHistogram.isSelected()));
630     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
631             Boolean.toString(showConsensLogo.isSelected()));
632     Cache.applicationProperties.setProperty("SHOW_INFORMATION_HISTOGRAM",
633             Boolean.toString(showConsensHistogram.isSelected()));
634     Cache.applicationProperties.setProperty("SHOW_HMM_LOGO",
635             Boolean.toString(showHMMLogo.isSelected()));
636     Cache.applicationProperties.setProperty("ANTI_ALIAS",
637             Boolean.toString(smoothFont.isSelected()));
638     Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
639             Boolean.toString(scaleProteinToCdna.isSelected()));
640     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
641             Boolean.toString(showNpTooltip.isSelected()));
642     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
643             Boolean.toString(showDbRefTooltip.isSelected()));
644
645     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
646             Boolean.toString(wrap.isSelected()));
647
648     Cache.applicationProperties.setProperty("STARTUP_FILE",
649             startupFileTextfield.getText());
650     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
651             Boolean.toString(startupCheckbox.isSelected()));
652
653     Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
654             sortby.getSelectedItem().toString());
655
656     // convert description of sort order to enum name for save
657     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
658             .forDescription(sortAnnBy.getSelectedItem().toString());
659     if (annSortOrder != null)
660     {
661       Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
662               annSortOrder.name());
663     }
664
665     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
666     Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
667             Boolean.valueOf(showAutocalcFirst).toString());
668
669     /*
670      * Save Colours settings
671      */
672     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
673             protColour.getSelectedItem().toString());
674     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
675             nucColour.getSelectedItem().toString());
676     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
677             minColour.getBackground());
678     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
679             maxColour.getBackground());
680
681     /*
682      * Save HMMER settings
683      */
684     Cache.applicationProperties.setProperty("TRIM_TERMINI",
685             Boolean.toString(hmmrTrimTermini.isSelected()));
686     Cache.applicationProperties.setProperty("USE_UNIPROT",
687             Boolean.toString(hmmerBackgroundUniprot.isSelected()));
688     Cache.applicationProperties.setProperty("SEQUENCES_TO_KEEP",
689             hmmerSequenceCount.getText());
690     Cache.applicationProperties.setProperty(HMMER_PATH,
691             hmmerPath.getText());
692     AlignFrame[] frames = Desktop.getAlignFrames();
693     if (frames != null && frames.length > 0)
694     {
695       for (AlignFrame f : frames)
696       {
697         f.updateHMMERStatus();
698       }
699     }
700     
701     hmmrTrimTermini.setSelected(Cache.getDefault("TRIM_TERMINI", false));
702     if (Cache.getDefault("USE_UNIPROT", false))
703     {
704       hmmerBackgroundUniprot.setSelected(true);
705     }
706     else
707     {
708       hmmerBackgroundAlignment.setSelected(true);
709     }
710     hmmerSequenceCount
711             .setText(Cache.getProperty("SEQUENCES_TO_KEEP"));
712     hmmerPath.setText(Cache.getProperty(HMMER_PATH));
713
714     /*
715      * Save Structure settings
716      */
717     Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
718             Boolean.toString(addTempFactor.isSelected()));
719     Cache.applicationProperties.setProperty(ADD_SS_ANN,
720             Boolean.toString(addSecondaryStructure.isSelected()));
721     Cache.applicationProperties.setProperty(USE_RNAVIEW,
722             Boolean.toString(useRnaView.isSelected()));
723     Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
724             Boolean.toString(structFromPdb.isSelected()));
725     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
726             structViewer.getSelectedItem().toString());
727     Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
728     Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
729             Boolean.toString(siftsMapping.isSelected()));
730     SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
731
732     /*
733      * Save Output settings
734      */
735     Cache.applicationProperties.setProperty("EPS_RENDERING",
736             ((OptionsParam) epsRendering.getSelectedItem()).getCode());
737
738     /*
739      * Save Connections settings
740      */
741     Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
742
743     jalview.util.BrowserLauncher.resetBrowser();
744
745     // save user-defined and selected links
746     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
747     if (menuLinks.isEmpty())
748     {
749       Cache.applicationProperties.remove("SEQUENCE_LINKS");
750     }
751     else
752     {
753       Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
754               menuLinks.toString());
755     }
756
757     String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
758     if (nonMenuLinks.isEmpty())
759     {
760       Cache.applicationProperties.remove("STORED_LINKS");
761     }
762     else
763     {
764       Cache.applicationProperties.setProperty("STORED_LINKS",
765               nonMenuLinks.toString());
766     }
767
768     Cache.applicationProperties.setProperty("DEFAULT_URL",
769             sequenceUrlLinks.getPrimaryUrlId());
770
771     Cache.applicationProperties.setProperty("USE_PROXY",
772             Boolean.toString(useProxy.isSelected()));
773
774     Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
775
776     Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
777
778     if (useProxy.isSelected())
779     {
780       System.setProperty("http.proxyHost", proxyServerTB.getText());
781       System.setProperty("http.proxyPort", proxyPortTB.getText());
782     }
783     else
784     {
785       System.setProperty("http.proxyHost", "");
786       System.setProperty("http.proxyPort", "");
787     }
788     Cache.setProperty("VERSION_CHECK",
789             Boolean.toString(versioncheck.isSelected()));
790     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
791     {
792       // default is false - we only set this if the user has actively agreed
793       Cache.setProperty("USAGESTATS",
794               Boolean.toString(usagestats.isSelected()));
795     }
796     if (!questionnaire.isSelected())
797     {
798       Cache.setProperty("NOQUESTIONNAIRES", "true");
799     }
800     else
801     {
802       // special - made easy to edit a property file to disable questionnaires
803       // by just adding the given line
804       Cache.removeProperty("NOQUESTIONNAIRES");
805     }
806
807     /*
808      * Save Output settings
809      */
810     Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
811             Boolean.toString(blcjv.isSelected()));
812     Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
813             Boolean.toString(clustaljv.isSelected()));
814     Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
815             Boolean.toString(fastajv.isSelected()));
816     Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
817             Boolean.toString(msfjv.isSelected()));
818     Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
819             Boolean.toString(pfamjv.isSelected()));
820     Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
821             Boolean.toString(pileupjv.isSelected()));
822     Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
823             Boolean.toString(pirjv.isSelected()));
824     Cache.applicationProperties.setProperty("PIR_MODELLER",
825             Boolean.toString(modellerOutput.isSelected()));
826     Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
827             Boolean.toString(embbedBioJSON.isSelected()));
828     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
829
830     Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
831             Boolean.toString(autoIdWidth.isSelected()));
832     userIdWidth_actionPerformed();
833     Cache.applicationProperties.setProperty("FIGURE_USERIDWIDTH",
834             userIdWidth.getText());
835
836     /*
837      * Save Editing settings
838      */
839     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
840             Boolean.toString(autoCalculateConsCheck.isSelected()));
841     Cache.applicationProperties.setProperty("SORT_BY_TREE",
842             Boolean.toString(sortByTree.isSelected()));
843     Cache.applicationProperties.setProperty("PAD_GAPS",
844             Boolean.toString(padGaps.isSelected()));
845
846     dasSource.saveProperties(Cache.applicationProperties);
847     wsPrefs.updateAndRefreshWsMenuConfig(false);
848     Cache.saveProperties();
849     Desktop.instance.doConfigureStructurePrefs();
850     try
851     {
852       frame.setClosed(true);
853     } catch (Exception ex)
854     {
855     }
856   }
857
858   /**
859    * Do any necessary validation before saving settings. Return focus to the
860    * first tab which fails validation.
861    * 
862    * @return
863    */
864   private boolean validateSettings()
865   {
866     if (!validateStructure())
867     {
868       structureTab.requestFocusInWindow();
869       return false;
870     }
871     return true;
872   }
873
874   @Override
875   protected boolean validateStructure()
876   {
877     return validateChimeraPath();
878
879   }
880
881   /**
882    * DOCUMENT ME!
883    */
884   @Override
885   public void startupFileTextfield_mouseClicked()
886   {
887     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
888     JalviewFileChooser chooser = JalviewFileChooser
889             .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
890     chooser.setFileView(new JalviewFileView());
891     chooser.setDialogTitle(
892             MessageManager.getString("label.select_startup_file"));
893
894     int value = chooser.showOpenDialog(this);
895
896     if (value == JalviewFileChooser.APPROVE_OPTION)
897     {
898       FileFormatI format = chooser.getSelectedFormat();
899       if (format != null)
900       {
901         Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
902                 format.getName());
903       }
904       startupFileTextfield
905               .setText(chooser.getSelectedFile().getAbsolutePath());
906     }
907   }
908
909   /**
910    * DOCUMENT ME!
911    * 
912    * @param e
913    *          DOCUMENT ME!
914    */
915   @Override
916   public void cancel_actionPerformed(ActionEvent e)
917   {
918     try
919     {
920       wsPrefs.updateWsMenuConfig(true);
921       wsPrefs.refreshWs_actionPerformed(e);
922       frame.setClosed(true);
923     } catch (Exception ex)
924     {
925     }
926   }
927
928   /**
929    * DOCUMENT ME!
930    * 
931    * @param e
932    *          DOCUMENT ME!
933    */
934   @Override
935   public void annotations_actionPerformed(ActionEvent e)
936   {
937     conservation.setEnabled(annotations.isSelected());
938     quality.setEnabled(annotations.isSelected());
939     identity.setEnabled(annotations.isSelected());
940     showOccupancy.setEnabled(annotations.isSelected());
941     showGroupConsensus.setEnabled(annotations.isSelected());
942     showGroupConservation.setEnabled(annotations.isSelected());
943     showConsensHistogram.setEnabled(annotations.isSelected()
944             && (identity.isSelected() || showGroupConsensus.isSelected()));
945     showConsensLogo.setEnabled(annotations.isSelected()
946             && (identity.isSelected() || showGroupConsensus.isSelected()));
947     showInformationHistogram.setEnabled(annotations.isSelected());
948     showHMMLogo.setEnabled(annotations.isSelected());
949   }
950
951   @Override
952   public void newLink_actionPerformed(ActionEvent e)
953   {
954     GSequenceLink link = new GSequenceLink();
955     boolean valid = false;
956     while (!valid)
957     {
958       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
959               MessageManager.getString("label.new_sequence_url_link"),
960               JvOptionPane.OK_CANCEL_OPTION, -1,
961               null) == JvOptionPane.OK_OPTION)
962       {
963         if (link.checkValid())
964         {
965           if (((UrlLinkTableModel) linkUrlTable.getModel())
966                   .isUniqueName(link.getName()))
967           {
968             ((UrlLinkTableModel) linkUrlTable.getModel())
969                     .insertRow(link.getName(), link.getURL());
970             valid = true;
971           }
972           else
973           {
974             link.notifyDuplicate();
975             continue;
976           }
977         }
978       }
979       else
980       {
981         break;
982       }
983     }
984   }
985
986   @Override
987   public void editLink_actionPerformed(ActionEvent e)
988   {
989     GSequenceLink link = new GSequenceLink();
990
991     int index = linkUrlTable.getSelectedRow();
992     if (index == -1)
993     {
994       // button no longer enabled if row is not selected
995       Cache.log.debug("Edit with no row selected in linkUrlTable");
996       return;
997     }
998
999     int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1000             .getNameColumn();
1001     int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
1002             .getUrlColumn();
1003     String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
1004     link.setName(oldName);
1005     link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
1006
1007     boolean valid = false;
1008     while (!valid)
1009     {
1010       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
1011               MessageManager.getString("label.edit_sequence_url_link"),
1012               JvOptionPane.OK_CANCEL_OPTION, -1,
1013               null) == JvOptionPane.OK_OPTION)
1014       {
1015         if (link.checkValid())
1016         {
1017           if ((oldName.equals(link.getName()))
1018                   || (((UrlLinkTableModel) linkUrlTable.getModel())
1019                           .isUniqueName(link.getName())))
1020           {
1021             linkUrlTable.setValueAt(link.getName(), index, nameCol);
1022             linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1023             valid = true;
1024           }
1025           else
1026           {
1027             link.notifyDuplicate();
1028             continue;
1029           }
1030         }
1031       }
1032       else
1033       {
1034         break;
1035       }
1036     }
1037   }
1038
1039   @Override
1040   public void deleteLink_actionPerformed(ActionEvent e)
1041   {
1042     int index = linkUrlTable.getSelectedRow();
1043     int modelIndex = -1;
1044     if (index == -1)
1045     {
1046       // button no longer enabled if row is not selected
1047       Cache.log.debug("Delete with no row selected in linkUrlTable");
1048       return;
1049     }
1050     else
1051     {
1052       modelIndex = linkUrlTable.convertRowIndexToModel(index);
1053     }
1054
1055     // make sure we use the model index to delete, and not the table index
1056     ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1057   }
1058
1059   @Override
1060   public void defaultBrowser_mouseClicked(MouseEvent e)
1061   {
1062     JFileChooser chooser = new JFileChooser(".");
1063     chooser.setDialogTitle(
1064             MessageManager.getString("label.select_default_browser"));
1065
1066     int value = chooser.showOpenDialog(this);
1067
1068     if (value == JFileChooser.APPROVE_OPTION)
1069     {
1070       defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1071     }
1072
1073   }
1074
1075   /*
1076    * (non-Javadoc)
1077    * 
1078    * @see
1079    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1080    * .ActionEvent)
1081    */
1082   @Override
1083   protected void showunconserved_actionPerformed(ActionEvent e)
1084   {
1085     // TODO Auto-generated method stub
1086     super.showunconserved_actionPerformed(e);
1087   }
1088
1089   public static List<String> getGroupURLLinks()
1090   {
1091     return groupURLLinks;
1092   }
1093
1094   @Override
1095   public void minColour_actionPerformed(JPanel panel)
1096   {
1097     Color col = JColorChooser.showDialog(this,
1098             MessageManager.getString("label.select_colour_minimum_value"),
1099             minColour.getBackground());
1100     if (col != null)
1101     {
1102       panel.setBackground(col);
1103     }
1104     panel.repaint();
1105   }
1106
1107   @Override
1108   public void maxColour_actionPerformed(JPanel panel)
1109   {
1110     Color col = JColorChooser.showDialog(this,
1111             MessageManager.getString("label.select_colour_maximum_value"),
1112             maxColour.getBackground());
1113     if (col != null)
1114     {
1115       panel.setBackground(col);
1116     }
1117     panel.repaint();
1118   }
1119
1120   @Override
1121   protected void userIdWidth_actionPerformed()
1122   {
1123     try
1124     {
1125       String val = userIdWidth.getText().trim();
1126       if (val.length() > 0)
1127       {
1128         Integer iw = Integer.parseInt(val);
1129         if (iw.intValue() < 12)
1130         {
1131           throw new NumberFormatException();
1132         }
1133         userIdWidth.setText(iw.toString());
1134       }
1135     } catch (NumberFormatException x)
1136     {
1137       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1138               MessageManager
1139                       .getString("warn.user_defined_width_requirements"),
1140               MessageManager.getString("label.invalid_id_column_width"),
1141               JvOptionPane.WARNING_MESSAGE);
1142       userIdWidth.setText("");
1143     }
1144   }
1145
1146   @Override
1147   protected void autoIdWidth_actionPerformed()
1148   {
1149     userIdWidth.setEnabled(!autoIdWidth.isSelected());
1150     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1151   }
1152
1153   /**
1154    * Returns true if chimera path is to a valid executable, else show an error
1155    * dialog.
1156    */
1157   private boolean validateChimeraPath()
1158   {
1159     if (chimeraPath.getText().trim().length() > 0)
1160     {
1161       File f = new File(chimeraPath.getText());
1162       if (!f.canExecute())
1163       {
1164         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1165                 MessageManager.getString("label.invalid_chimera_path"),
1166                 MessageManager.getString("label.invalid_name"),
1167                 JvOptionPane.ERROR_MESSAGE);
1168         return false;
1169       }
1170     }
1171     return true;
1172   }
1173   
1174   /**
1175    * Returns true if hmmer path is to a folder that contains an executable
1176    * hmmbuild or hmmbuild.exe, else false (optionally after showing a warning
1177    * dialog)
1178    */
1179   @Override
1180   protected boolean validateHMMERPath(boolean showWarning)
1181   {
1182     String folder = hmmerPath.getText().trim();
1183
1184     if (HmmerCommand.getExecutable(HmmerCommand.HMMBUILD, folder) != null)
1185     {
1186       return true;
1187     }
1188     if (showWarning && folder.length() > 0)
1189     {
1190       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1191               MessageManager.getString("label.hmmbuild_not_found"),
1192               MessageManager.getString("label.invalid_folder"),
1193               JvOptionPane.ERROR_MESSAGE);
1194     }
1195     return false;
1196   }
1197
1198   /**
1199    * Checks if a file can be executed
1200    * 
1201    * @param path
1202    *          the path to the file
1203    * @return
1204    */
1205   public boolean canExecute(String path)
1206   {
1207     File file = new File(path);
1208     if (!file.canExecute())
1209     {
1210       file = new File(path + ".exe");
1211       {
1212         if (!file.canExecute())
1213         {
1214           return false;
1215         }
1216       }
1217     }
1218     return true;
1219   }
1220
1221   /**
1222    * If Chimera is selected, check it can be found on default or user-specified
1223    * path, if not show a warning/help dialog.
1224    */
1225   @Override
1226   protected void structureViewer_actionPerformed(String selectedItem)
1227   {
1228     if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1229     {
1230       return;
1231     }
1232     boolean found = false;
1233
1234     /*
1235      * Try user-specified and standard paths for Chimera executable.
1236      */
1237     List<String> paths = StructureManager.getChimeraPaths();
1238     paths.add(0, chimeraPath.getText());
1239     for (String path : paths)
1240     {
1241       if (new File(path.trim()).canExecute())
1242       {
1243         found = true;
1244         break;
1245       }
1246     }
1247     if (!found)
1248     {
1249       String[] options = { "OK", "Help" };
1250       int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1251               JvSwingUtils.wrapTooltip(true,
1252                       MessageManager.getString("label.chimera_missing")),
1253               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1254               null, options, options[0]);
1255       if (showHelp == JvOptionPane.NO_OPTION)
1256       {
1257         try
1258         {
1259           Help.showHelpWindow(HelpId.StructureViewer);
1260         } catch (HelpSetException e)
1261         {
1262           e.printStackTrace();
1263         }
1264       }
1265     }
1266   }
1267
1268   public class OptionsParam
1269   {
1270     private String name;
1271
1272     private String code;
1273
1274     public OptionsParam(String name, String code)
1275     {
1276       this.name = name;
1277       this.code = code;
1278     }
1279
1280     public String getName()
1281     {
1282       return name;
1283     }
1284
1285     public void setName(String name)
1286     {
1287       this.name = name;
1288     }
1289
1290     public String getCode()
1291     {
1292       return code;
1293     }
1294
1295     public void setCode(String code)
1296     {
1297       this.code = code;
1298     }
1299
1300     @Override
1301     public String toString()
1302     {
1303       return name;
1304     }
1305
1306     @Override
1307     public boolean equals(Object that)
1308     {
1309       if (!(that instanceof OptionsParam))
1310       {
1311         return false;
1312       }
1313       return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1314     }
1315
1316     @Override
1317     public int hashCode()
1318     {
1319       return name.hashCode() + code.hashCode();
1320     }
1321   }
1322
1323   private class UrlListSelectionHandler implements ListSelectionListener
1324   {
1325
1326     @Override
1327     public void valueChanged(ListSelectionEvent e)
1328     {
1329       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1330
1331       int index = lsm.getMinSelectionIndex();
1332       if (index == -1)
1333       {
1334         // no selection, so disable delete/edit buttons
1335         editLink.setEnabled(false);
1336         deleteLink.setEnabled(false);
1337         return;
1338       }
1339       int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1340
1341       // enable/disable edit and delete link buttons
1342       if (((UrlLinkTableModel) linkUrlTable.getModel())
1343               .isRowDeletable(modelIndex))
1344       {
1345         deleteLink.setEnabled(true);
1346       }
1347       else
1348       {
1349         deleteLink.setEnabled(false);
1350       }
1351
1352       if (((UrlLinkTableModel) linkUrlTable.getModel())
1353               .isRowEditable(modelIndex))
1354       {
1355         editLink.setEnabled(true);
1356       }
1357       else
1358       {
1359         editLink.setEnabled(false);
1360       }
1361     }
1362   }
1363 }