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