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