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