35641f81d7f1815baf67fe5666201591a339654a
[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     if (!Platform.isJS())
192     {
193       wsPrefs = new WsPreferences();
194       wsTab.add(wsPrefs, BorderLayout.CENTER);
195     }
196     int width = 500, height = 450;
197     if (Platform.isAMacAndNotJS())
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, true));
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     // BH 2018 setSortKeys will do the sort
388     // sorter.sort();
389
390     // set up filtering
391     ActionListener onReset;
392     onReset = new ActionListener()
393     {
394       @Override
395       public void actionPerformed(ActionEvent e)
396       {
397         filterTB.setText("");
398         sorter.setRowFilter(RowFilter.regexFilter(""));
399       }
400
401     };
402     doReset.addActionListener(onReset);
403
404     // filter to display only custom urls
405     final RowFilter<TableModel, Object> customUrlFilter = new RowFilter<TableModel, Object>()
406     {
407       @Override
408       public boolean include(
409               Entry<? extends TableModel, ? extends Object> entry)
410       {
411         return ((UrlLinkTableModel) entry.getModel()).isUserEntry(entry);
412       }
413     };
414
415     final TableRowSorter<TableModel> customSorter = new TableRowSorter<>(
416             linkUrlTable.getModel());
417     customSorter.setRowFilter(customUrlFilter);
418
419     ActionListener onCustomOnly;
420     onCustomOnly = new ActionListener()
421     {
422       @Override
423       public void actionPerformed(ActionEvent e)
424       {
425         filterTB.setText("");
426         sorter.setRowFilter(customUrlFilter);
427       }
428     };
429     userOnly.addActionListener(onCustomOnly);
430
431     filterTB.getDocument().addDocumentListener(new DocumentListener()
432     {
433       String caseInsensitiveFlag = "(?i)";
434
435       @Override
436       public void changedUpdate(DocumentEvent e)
437       {
438         sorter.setRowFilter(RowFilter
439                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
440       }
441
442       @Override
443       public void removeUpdate(DocumentEvent e)
444       {
445         sorter.setRowFilter(RowFilter
446                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
447       }
448
449       @Override
450       public void insertUpdate(DocumentEvent e)
451       {
452         sorter.setRowFilter(RowFilter
453                 .regexFilter(caseInsensitiveFlag + filterTB.getText()));
454       }
455     });
456
457     // set up list selection functionality
458     linkUrlTable.getSelectionModel()
459             .addListSelectionListener(new UrlListSelectionHandler());
460
461     // set up radio buttons
462     int onClickCol = ((UrlLinkTableModel) linkUrlTable.getModel())
463             .getPrimaryColumn();
464     String onClickName = linkUrlTable.getColumnName(onClickCol);
465     linkUrlTable.getColumn(onClickName)
466             .setCellRenderer(new RadioButtonRenderer());
467     linkUrlTable.getColumn(onClickName)
468             .setCellEditor(new RadioButtonEditor());
469
470     // get boolean columns and resize those to min possible
471     for (int column = 0; column < linkUrlTable.getColumnCount(); column++)
472     {
473       if (linkUrlTable.getModel().getColumnClass(column)
474               .equals(Boolean.class))
475       {
476         TableColumn tableColumn = linkUrlTable.getColumnModel()
477                 .getColumn(column);
478         int preferredWidth = tableColumn.getMinWidth();
479
480         TableCellRenderer cellRenderer = linkUrlTable.getCellRenderer(0,
481                 column);
482         Component c = linkUrlTable.prepareRenderer(cellRenderer, 0, column);
483         int cwidth = c.getPreferredSize().width
484                 + linkUrlTable.getIntercellSpacing().width;
485         preferredWidth = Math.max(preferredWidth, cwidth);
486
487         tableColumn.setPreferredWidth(preferredWidth);
488       }
489     }
490
491     useProxy.setSelected(Cache.getDefault("USE_PROXY", false));
492     useProxy_actionPerformed(); // make sure useProxy is correctly initialised
493     proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", ""));
494     proxyPortTB.setText(Cache.getDefault("PROXY_PORT", ""));
495
496     defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", ""));
497
498     usagestats.setSelected(Cache.getDefault("USAGESTATS", false));
499     // note antisense here: default is true
500     questionnaire
501             .setSelected(Cache.getProperty("NOQUESTIONNAIRES") == null);
502     versioncheck.setSelected(Cache.getDefault("VERSION_CHECK", true));
503
504     /*
505      * Set Output tab defaults
506      */
507     setupOutputCombo(epsRendering, "EPS_RENDERING");
508     setupOutputCombo(htmlRendering, "HTML_RENDERING");
509     setupOutputCombo(svgRendering, "SVG_RENDERING");
510     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
511     userIdWidth.setEnabled(!autoIdWidth.isSelected());
512     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
513     Integer wi = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH");
514     userIdWidth.setText(wi == null ? "" : wi.toString());
515     // TODO: refactor to use common enum via FormatAdapter and allow extension
516     // for new flat file formats
517     blcjv.setSelected(Cache.getDefault("BLC_JVSUFFIX", true));
518     clustaljv.setSelected(Cache.getDefault("CLUSTAL_JVSUFFIX", true));
519     fastajv.setSelected(Cache.getDefault("FASTA_JVSUFFIX", true));
520     msfjv.setSelected(Cache.getDefault("MSF_JVSUFFIX", true));
521     pfamjv.setSelected(Cache.getDefault("PFAM_JVSUFFIX", true));
522     pileupjv.setSelected(Cache.getDefault("PILEUP_JVSUFFIX", true));
523     pirjv.setSelected(Cache.getDefault("PIR_JVSUFFIX", true));
524     modellerOutput.setSelected(Cache.getDefault("PIR_MODELLER", false));
525     embbedBioJSON
526             .setSelected(Cache.getDefault("EXPORT_EMBBED_BIOJSON", true));
527
528     /*
529      * Set Editing tab defaults
530      */
531     autoCalculateConsCheck
532             .setSelected(Cache.getDefault("AUTO_CALC_CONSENSUS", true));
533     padGaps.setSelected(Cache.getDefault("PAD_GAPS", false));
534     sortByTree.setSelected(Cache.getDefault("SORT_BY_TREE", false));
535
536     annotations_actionPerformed(null); // update the display of the annotation
537                                        // settings
538   }
539
540   /**
541    * A helper method that sets the items and initial selection in a character
542    * rendering option list (Prompt each time/Lineart/Text)
543    * 
544    * @param comboBox
545    * @param propertyKey
546    */
547   protected void setupOutputCombo(JComboBox<Object> comboBox,
548           String propertyKey)
549   {
550     comboBox.addItem(promptEachTimeOpt);
551     comboBox.addItem(lineArtOpt);
552     comboBox.addItem(textOpt);
553     
554     /*
555      * JalviewJS doesn't support Lineart so force it to Text
556      */
557     String defaultOption = Platform.isJS() ? "Text"
558             : Cache.getDefault(propertyKey, "Prompt each time");
559     if (defaultOption.equalsIgnoreCase("Text"))
560     {
561       comboBox.setSelectedItem(textOpt);
562     }
563     else if (defaultOption.equalsIgnoreCase("Lineart"))
564     {
565       comboBox.setSelectedItem(lineArtOpt);
566     }
567     else
568     {
569       comboBox.setSelectedItem(promptEachTimeOpt);
570     }
571   }
572
573   /**
574    * Save user selections on the Preferences tabs to the Cache and write out to
575    * file.
576    * 
577    * @param e
578    */
579   @Override
580   public void ok_actionPerformed(ActionEvent e)
581   {
582     if (!validateSettings())
583     {
584       return;
585     }
586
587     /*
588      * Save Visual settings
589      */
590     Cache.applicationProperties.setProperty("SHOW_JVSUFFIX",
591             Boolean.toString(seqLimit.isSelected()));
592     Cache.applicationProperties.setProperty("RIGHT_ALIGN_IDS",
593             Boolean.toString(rightAlign.isSelected()));
594     Cache.applicationProperties.setProperty("SHOW_FULLSCREEN",
595             Boolean.toString(fullScreen.isSelected()));
596     Cache.applicationProperties.setProperty("SHOW_OVERVIEW",
597             Boolean.toString(openoverv.isSelected()));
598     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
599             Boolean.toString(annotations.isSelected()));
600     Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
601             Boolean.toString(conservation.isSelected()));
602     Cache.applicationProperties.setProperty("SHOW_QUALITY",
603             Boolean.toString(quality.isSelected()));
604     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
605             Boolean.toString(identity.isSelected()));
606
607     Cache.applicationProperties.setProperty("GAP_SYMBOL",
608             gapSymbolCB.getSelectedItem().toString());
609
610     Cache.applicationProperties.setProperty("FONT_NAME",
611             fontNameCB.getSelectedItem().toString());
612     Cache.applicationProperties.setProperty("FONT_STYLE",
613             fontStyleCB.getSelectedItem().toString());
614     Cache.applicationProperties.setProperty("FONT_SIZE",
615             fontSizeCB.getSelectedItem().toString());
616
617     Cache.applicationProperties.setProperty("ID_ITALICS",
618             Boolean.toString(idItalics.isSelected()));
619     Cache.applicationProperties.setProperty("SHOW_UNCONSERVED",
620             Boolean.toString(showUnconserved.isSelected()));
621     Cache.applicationProperties.setProperty(SHOW_OCCUPANCY,
622             Boolean.toString(showOccupancy.isSelected()));
623     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSENSUS",
624             Boolean.toString(showGroupConsensus.isSelected()));
625     Cache.applicationProperties.setProperty("SHOW_GROUP_CONSERVATION",
626             Boolean.toString(showGroupConservation.isSelected()));
627     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_HISTOGRAM",
628             Boolean.toString(showConsensHistogram.isSelected()));
629     Cache.applicationProperties.setProperty("SHOW_CONSENSUS_LOGO",
630             Boolean.toString(showConsensLogo.isSelected()));
631     Cache.applicationProperties.setProperty("ANTI_ALIAS",
632             Boolean.toString(smoothFont.isSelected()));
633     Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA,
634             Boolean.toString(scaleProteinToCdna.isSelected()));
635     Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP",
636             Boolean.toString(showNpTooltip.isSelected()));
637     Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP",
638             Boolean.toString(showDbRefTooltip.isSelected()));
639
640     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT",
641             Boolean.toString(wrap.isSelected()));
642
643     Cache.applicationProperties.setProperty("STARTUP_FILE",
644             startupFileTextfield.getText());
645     Cache.applicationProperties.setProperty("SHOW_STARTUP_FILE",
646             Boolean.toString(startupCheckbox.isSelected()));
647
648     Cache.applicationProperties.setProperty("SORT_ALIGNMENT",
649             sortby.getSelectedItem().toString());
650
651     // convert description of sort order to enum name for save
652     SequenceAnnotationOrder annSortOrder = SequenceAnnotationOrder
653             .forDescription(sortAnnBy.getSelectedItem().toString());
654     if (annSortOrder != null)
655     {
656       Cache.applicationProperties.setProperty(SORT_ANNOTATIONS,
657               annSortOrder.name());
658     }
659
660     final boolean showAutocalcFirst = sortAutocalc.getSelectedIndex() == 0;
661     Cache.applicationProperties.setProperty(SHOW_AUTOCALC_ABOVE,
662             Boolean.valueOf(showAutocalcFirst).toString());
663
664     /*
665      * Save Colours settings
666      */
667     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT,
668             protColour.getSelectedItem().toString());
669     Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC,
670             nucColour.getSelectedItem().toString());
671     Cache.setColourProperty("ANNOTATIONCOLOUR_MIN",
672             minColour.getBackground());
673     Cache.setColourProperty("ANNOTATIONCOLOUR_MAX",
674             maxColour.getBackground());
675
676     /*
677      * Save Overview settings
678      */
679     Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
680     Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
681     Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
682             Boolean.toString(useLegacyGap.isSelected()));
683     Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
684             Boolean.toString(showHiddenAtStart.isSelected()));
685
686     /*
687      * Save Structure settings
688      */
689     Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
690             Boolean.toString(addTempFactor.isSelected()));
691     Cache.applicationProperties.setProperty(ADD_SS_ANN,
692             Boolean.toString(addSecondaryStructure.isSelected()));
693     Cache.applicationProperties.setProperty(USE_RNAVIEW,
694             Boolean.toString(useRnaView.isSelected()));
695     Cache.applicationProperties.setProperty(STRUCT_FROM_PDB,
696             Boolean.toString(structFromPdb.isSelected()));
697     Cache.applicationProperties.setProperty(STRUCTURE_DISPLAY,
698             structViewer.getSelectedItem().toString());
699     Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText());
700     Cache.applicationProperties.setProperty("MAP_WITH_SIFTS",
701             Boolean.toString(siftsMapping.isSelected()));
702     SiftsSettings.setMapWithSifts(siftsMapping.isSelected());
703
704     /*
705      * Save Output settings
706      */
707     Cache.applicationProperties.setProperty("EPS_RENDERING",
708             ((OptionsParam) epsRendering.getSelectedItem()).getCode());
709     Cache.applicationProperties.setProperty("HTML_RENDERING",
710             ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
711     Cache.applicationProperties.setProperty("SVG_RENDERING",
712             ((OptionsParam) svgRendering.getSelectedItem()).getCode());
713
714     /*
715      * Save Connections settings
716      */
717     Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText());
718
719     jalview.util.BrowserLauncher.resetBrowser();
720
721     // save user-defined and selected links
722     String menuLinks = sequenceUrlLinks.writeUrlsAsString(true);
723     if (menuLinks.isEmpty())
724     {
725       Cache.applicationProperties.remove("SEQUENCE_LINKS");
726     }
727     else
728     {
729       Cache.applicationProperties.setProperty("SEQUENCE_LINKS",
730               menuLinks.toString());
731     }
732
733     String nonMenuLinks = sequenceUrlLinks.writeUrlsAsString(false);
734     if (nonMenuLinks.isEmpty())
735     {
736       Cache.applicationProperties.remove("STORED_LINKS");
737     }
738     else
739     {
740       Cache.applicationProperties.setProperty("STORED_LINKS",
741               nonMenuLinks.toString());
742     }
743
744     Cache.applicationProperties.setProperty("DEFAULT_URL",
745             sequenceUrlLinks.getPrimaryUrlId());
746
747     Cache.applicationProperties.setProperty("USE_PROXY",
748             Boolean.toString(useProxy.isSelected()));
749
750     Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText());
751
752     Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText());
753
754     if (useProxy.isSelected())
755     {
756       System.setProperty("http.proxyHost", proxyServerTB.getText());
757       System.setProperty("http.proxyPort", proxyPortTB.getText());
758     }
759     else
760     {
761       System.setProperty("http.proxyHost", "");
762       System.setProperty("http.proxyPort", "");
763     }
764     Cache.setProperty("VERSION_CHECK",
765             Boolean.toString(versioncheck.isSelected()));
766     if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected())
767     {
768       // default is false - we only set this if the user has actively agreed
769       Cache.setProperty("USAGESTATS",
770               Boolean.toString(usagestats.isSelected()));
771     }
772     if (!questionnaire.isSelected())
773     {
774       Cache.setProperty("NOQUESTIONNAIRES", "true");
775     }
776     else
777     {
778       // special - made easy to edit a property file to disable questionnaires
779       // by just adding the given line
780       Cache.removeProperty("NOQUESTIONNAIRES");
781     }
782
783     /*
784      * Save Output settings
785      */
786     Cache.applicationProperties.setProperty("BLC_JVSUFFIX",
787             Boolean.toString(blcjv.isSelected()));
788     Cache.applicationProperties.setProperty("CLUSTAL_JVSUFFIX",
789             Boolean.toString(clustaljv.isSelected()));
790     Cache.applicationProperties.setProperty("FASTA_JVSUFFIX",
791             Boolean.toString(fastajv.isSelected()));
792     Cache.applicationProperties.setProperty("MSF_JVSUFFIX",
793             Boolean.toString(msfjv.isSelected()));
794     Cache.applicationProperties.setProperty("PFAM_JVSUFFIX",
795             Boolean.toString(pfamjv.isSelected()));
796     Cache.applicationProperties.setProperty("PILEUP_JVSUFFIX",
797             Boolean.toString(pileupjv.isSelected()));
798     Cache.applicationProperties.setProperty("PIR_JVSUFFIX",
799             Boolean.toString(pirjv.isSelected()));
800     Cache.applicationProperties.setProperty("PIR_MODELLER",
801             Boolean.toString(modellerOutput.isSelected()));
802     Cache.applicationProperties.setProperty("EXPORT_EMBBED_BIOJSON",
803             Boolean.toString(embbedBioJSON.isSelected()));
804     jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
805
806     Cache.applicationProperties.setProperty("FIGURE_AUTOIDWIDTH",
807             Boolean.toString(autoIdWidth.isSelected()));
808     userIdWidth_actionPerformed();
809     Cache.applicationProperties.setProperty("FIGURE_FIXEDIDWIDTH",
810             userIdWidth.getText());
811
812     /*
813      * Save Editing settings
814      */
815     Cache.applicationProperties.setProperty("AUTO_CALC_CONSENSUS",
816             Boolean.toString(autoCalculateConsCheck.isSelected()));
817     Cache.applicationProperties.setProperty("SORT_BY_TREE",
818             Boolean.toString(sortByTree.isSelected()));
819     Cache.applicationProperties.setProperty("PAD_GAPS",
820             Boolean.toString(padGaps.isSelected()));
821
822     if (!Platform.isJS())
823     {
824       wsPrefs.updateAndRefreshWsMenuConfig(false);
825     }
826     Cache.saveProperties();
827     Desktop.instance.doConfigureStructurePrefs();
828     try
829     {
830       frame.setClosed(true);
831     } catch (Exception ex)
832     {
833     }
834   }
835
836   /**
837    * Do any necessary validation before saving settings. Return focus to the
838    * first tab which fails validation.
839    * 
840    * @return
841    */
842   private boolean validateSettings()
843   {
844     if (!validateStructure())
845     {
846       structureTab.requestFocusInWindow();
847       return false;
848     }
849     return true;
850   }
851
852   @Override
853   protected boolean validateStructure()
854   {
855     return validateChimeraPath();
856
857   }
858
859   /**
860    * DOCUMENT ME!
861    */
862   @Override
863   public void startupFileTextfield_mouseClicked()
864   {
865     // TODO: JAL-3048 not needed for Jalview-JS
866     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
867     JalviewFileChooser chooser = JalviewFileChooser
868             .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
869     chooser.setFileView(new JalviewFileView());
870     chooser.setDialogTitle(
871             MessageManager.getString("label.select_startup_file"));
872
873     int value = chooser.showOpenDialog(this);
874
875     if (value == JalviewFileChooser.APPROVE_OPTION)
876     {
877       FileFormatI format = chooser.getSelectedFormat();
878       if (format != null)
879       {
880         Cache.applicationProperties.setProperty("DEFAULT_FILE_FORMAT",
881                 format.getName());
882       }
883       startupFileTextfield
884               .setText(chooser.getSelectedFile().getAbsolutePath());
885     }
886   }
887
888   /**
889    * DOCUMENT ME!
890    * 
891    * @param e
892    *          DOCUMENT ME!
893    */
894   @Override
895   public void cancel_actionPerformed(ActionEvent e)
896   {
897     try
898     {
899       if (!Platform.isJS())
900       {
901         wsPrefs.updateWsMenuConfig(true);
902         wsPrefs.refreshWs_actionPerformed(e);
903       }
904       frame.setClosed(true);
905     } catch (Exception ex)
906     {
907     }
908   }
909
910   /**
911    * DOCUMENT ME!
912    * 
913    * @param e
914    *          DOCUMENT ME!
915    */
916   @Override
917   public void annotations_actionPerformed(ActionEvent e)
918   {
919     conservation.setEnabled(annotations.isSelected());
920     quality.setEnabled(annotations.isSelected());
921     identity.setEnabled(annotations.isSelected());
922     showOccupancy.setEnabled(annotations.isSelected());
923     showGroupConsensus.setEnabled(annotations.isSelected());
924     showGroupConservation.setEnabled(annotations.isSelected());
925     showConsensHistogram.setEnabled(annotations.isSelected()
926             && (identity.isSelected() || showGroupConsensus.isSelected()));
927     showConsensLogo.setEnabled(annotations.isSelected()
928             && (identity.isSelected() || showGroupConsensus.isSelected()));
929   }
930
931   @Override
932   public void newLink_actionPerformed(ActionEvent e)
933   {
934     GSequenceLink link = new GSequenceLink();
935     boolean valid = false;
936     while (!valid)
937     {
938       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
939               MessageManager.getString("label.new_sequence_url_link"),
940               JvOptionPane.OK_CANCEL_OPTION, -1,
941               null) == JvOptionPane.OK_OPTION)
942       {
943         if (link.checkValid())
944         {
945           if (((UrlLinkTableModel) linkUrlTable.getModel())
946                   .isUniqueName(link.getName()))
947           {
948             ((UrlLinkTableModel) linkUrlTable.getModel())
949                     .insertRow(link.getName(), link.getURL());
950             valid = true;
951           }
952           else
953           {
954             link.notifyDuplicate();
955             continue;
956           }
957         }
958       }
959       else
960       {
961         break;
962       }
963     }
964   }
965
966   @Override
967   public void editLink_actionPerformed(ActionEvent e)
968   {
969     GSequenceLink link = new GSequenceLink();
970
971     int index = linkUrlTable.getSelectedRow();
972     if (index == -1)
973     {
974       // button no longer enabled if row is not selected
975       Cache.log.debug("Edit with no row selected in linkUrlTable");
976       return;
977     }
978
979     int nameCol = ((UrlLinkTableModel) linkUrlTable.getModel())
980             .getNameColumn();
981     int urlCol = ((UrlLinkTableModel) linkUrlTable.getModel())
982             .getUrlColumn();
983     String oldName = linkUrlTable.getValueAt(index, nameCol).toString();
984     link.setName(oldName);
985     link.setURL(linkUrlTable.getValueAt(index, urlCol).toString());
986
987     boolean valid = false;
988     while (!valid)
989     {
990       if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link,
991               MessageManager.getString("label.edit_sequence_url_link"),
992               JvOptionPane.OK_CANCEL_OPTION, -1,
993               null) == JvOptionPane.OK_OPTION)
994       {
995         if (link.checkValid())
996         {
997           if ((oldName.equals(link.getName()))
998                   || (((UrlLinkTableModel) linkUrlTable.getModel())
999                           .isUniqueName(link.getName())))
1000           {
1001             linkUrlTable.setValueAt(link.getName(), index, nameCol);
1002             linkUrlTable.setValueAt(link.getURL(), index, urlCol);
1003             valid = true;
1004           }
1005           else
1006           {
1007             link.notifyDuplicate();
1008             continue;
1009           }
1010         }
1011       }
1012       else
1013       {
1014         break;
1015       }
1016     }
1017   }
1018
1019   @Override
1020   public void deleteLink_actionPerformed(ActionEvent e)
1021   {
1022     int index = linkUrlTable.getSelectedRow();
1023     int modelIndex = -1;
1024     if (index == -1)
1025     {
1026       // button no longer enabled if row is not selected
1027       Cache.log.debug("Delete with no row selected in linkUrlTable");
1028       return;
1029     }
1030     else
1031     {
1032       modelIndex = linkUrlTable.convertRowIndexToModel(index);
1033     }
1034
1035     // make sure we use the model index to delete, and not the table index
1036     ((UrlLinkTableModel) linkUrlTable.getModel()).removeRow(modelIndex);
1037   }
1038
1039   @Override
1040   public void defaultBrowser_mouseClicked(MouseEvent e)
1041   {
1042     // TODO: JAL-3048 not needed for j2s
1043     /*
1044      * @j2sNative
1045      */
1046     {
1047       JFileChooser chooser = new JFileChooser(".");
1048       chooser.setDialogTitle(
1049               MessageManager.getString("label.select_default_browser"));
1050
1051       int value = chooser.showOpenDialog(this);
1052
1053       if (value == JFileChooser.APPROVE_OPTION)
1054       {
1055         defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
1056       }
1057     }
1058   }
1059
1060   /*
1061    * (non-Javadoc)
1062    * 
1063    * @see
1064    * jalview.jbgui.GPreferences#showunconserved_actionPerformed(java.awt.event
1065    * .ActionEvent)
1066    */
1067   @Override
1068   protected void showunconserved_actionPerformed(ActionEvent e)
1069   {
1070     // TODO Auto-generated method stub
1071     super.showunconserved_actionPerformed(e);
1072   }
1073
1074   public static List<String> getGroupURLLinks()
1075   {
1076     return groupURLLinks;
1077   }
1078
1079   @Override
1080   public void minColour_actionPerformed(JPanel panel)
1081   {
1082     JalviewColourChooser.showColourChooser(this,
1083             MessageManager.getString("label.select_colour_minimum_value"),
1084             panel);
1085   }
1086
1087   @Override
1088   public void maxColour_actionPerformed(JPanel panel)
1089   {
1090     JalviewColourChooser.showColourChooser(this,
1091             MessageManager.getString("label.select_colour_maximum_value"),
1092             panel);
1093   }
1094
1095   @Override
1096   public void gapColour_actionPerformed(JPanel gap)
1097   {
1098     if (!useLegacyGap.isSelected())
1099     {
1100       JalviewColourChooser.showColourChooser(this,
1101               MessageManager.getString("label.select_gap_colour"),
1102               gap);
1103     }
1104   }
1105
1106   @Override
1107   public void hiddenColour_actionPerformed(JPanel hidden)
1108   {
1109     JalviewColourChooser.showColourChooser(this,
1110             MessageManager.getString("label.select_hidden_colour"),
1111             hidden);
1112   }
1113
1114   @Override
1115   protected void useLegacyGaps_actionPerformed(ActionEvent e)
1116   {
1117     boolean enabled = useLegacyGap.isSelected();
1118     if (enabled)
1119     {
1120       gapColour.setBackground(
1121               jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
1122     }
1123     else
1124     {
1125       gapColour.setBackground(
1126               jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
1127     }
1128     gapColour.setEnabled(!enabled);
1129     gapLabel.setEnabled(!enabled);
1130   }
1131
1132   @Override
1133   protected void resetOvDefaults_actionPerformed(ActionEvent e)
1134   {
1135     useLegacyGap.setSelected(false);
1136     useLegacyGaps_actionPerformed(null);
1137     showHiddenAtStart.setSelected(true);
1138     hiddenColour.setBackground(
1139             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
1140   }
1141
1142   @Override
1143   protected void userIdWidth_actionPerformed()
1144   {
1145     try
1146     {
1147       String val = userIdWidth.getText().trim();
1148       if (val.length() > 0)
1149       {
1150         Integer iw = Integer.parseInt(val);
1151         if (iw.intValue() < 12)
1152         {
1153           throw new NumberFormatException();
1154         }
1155         userIdWidth.setText(iw.toString());
1156       }
1157     } catch (NumberFormatException x)
1158     {
1159       userIdWidth.setText("");
1160       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1161               MessageManager
1162                       .getString("warn.user_defined_width_requirements"),
1163               MessageManager.getString("label.invalid_id_column_width"),
1164               JvOptionPane.WARNING_MESSAGE);
1165     }
1166   }
1167
1168   @Override
1169   protected void autoIdWidth_actionPerformed()
1170   {
1171     userIdWidth.setEnabled(!autoIdWidth.isSelected());
1172     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
1173   }
1174
1175   /**
1176    * Returns true if chimera path is to a valid executable, else show an error
1177    * dialog.
1178    */
1179   private boolean validateChimeraPath()
1180   {
1181     if (chimeraPath.getText().trim().length() > 0)
1182     {
1183       File f = new File(chimeraPath.getText());
1184       if (!f.canExecute())
1185       {
1186         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
1187                 MessageManager.getString("label.invalid_chimera_path"),
1188                 MessageManager.getString("label.invalid_name"),
1189                 JvOptionPane.ERROR_MESSAGE);
1190         return false;
1191       }
1192     }
1193     return true;
1194   }
1195
1196   /**
1197    * If Chimera is selected, check it can be found on default or user-specified
1198    * path, if not show a warning/help dialog.
1199    */
1200   @Override
1201   protected void structureViewer_actionPerformed(String selectedItem)
1202   {
1203     if (!selectedItem.equals(ViewerType.CHIMERA.name()))
1204     {
1205       return;
1206     }
1207     boolean found = false;
1208
1209     /*
1210      * Try user-specified and standard paths for Chimera executable.
1211      */
1212     List<String> paths = StructureManager.getChimeraPaths();
1213     paths.add(0, chimeraPath.getText());
1214     for (String path : paths)
1215     {
1216       if (new File(path.trim()).canExecute())
1217       {
1218         found = true;
1219         break;
1220       }
1221     }
1222     if (!found)
1223     {
1224       String[] options = { "OK", "Help" };
1225       int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
1226               JvSwingUtils.wrapTooltip(true,
1227                       MessageManager.getString("label.chimera_missing")),
1228               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
1229               null, options, options[0]);
1230       if (showHelp == JvOptionPane.NO_OPTION)
1231       {
1232         try
1233         {
1234           Help.showHelpWindow(HelpId.StructureViewer);
1235         } catch (HelpSetException e)
1236         {
1237           e.printStackTrace();
1238         }
1239       }
1240     }
1241   }
1242
1243   public class OptionsParam
1244   {
1245     private String name;
1246
1247     private String code;
1248
1249     public OptionsParam(String name, String code)
1250     {
1251       this.name = name;
1252       this.code = code;
1253     }
1254
1255     public String getName()
1256     {
1257       return name;
1258     }
1259
1260     public void setName(String name)
1261     {
1262       this.name = name;
1263     }
1264
1265     public String getCode()
1266     {
1267       return code;
1268     }
1269
1270     public void setCode(String code)
1271     {
1272       this.code = code;
1273     }
1274
1275     @Override
1276     public String toString()
1277     {
1278       return name;
1279     }
1280
1281     @Override
1282     public boolean equals(Object that)
1283     {
1284       if (!(that instanceof OptionsParam))
1285       {
1286         return false;
1287       }
1288       return this.code.equalsIgnoreCase(((OptionsParam) that).code);
1289     }
1290
1291     @Override
1292     public int hashCode()
1293     {
1294       return name.hashCode() + code.hashCode();
1295     }
1296   }
1297
1298   private class UrlListSelectionHandler implements ListSelectionListener
1299   {
1300
1301     @Override
1302     public void valueChanged(ListSelectionEvent e)
1303     {
1304       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
1305
1306       int index = lsm.getMinSelectionIndex();
1307       if (index == -1)
1308       {
1309         // no selection, so disable delete/edit buttons
1310         editLink.setEnabled(false);
1311         deleteLink.setEnabled(false);
1312         return;
1313       }
1314       int modelIndex = linkUrlTable.convertRowIndexToModel(index);
1315
1316       // enable/disable edit and delete link buttons
1317       if (((UrlLinkTableModel) linkUrlTable.getModel())
1318               .isRowDeletable(modelIndex))
1319       {
1320         deleteLink.setEnabled(true);
1321       }
1322       else
1323       {
1324         deleteLink.setEnabled(false);
1325       }
1326
1327       if (((UrlLinkTableModel) linkUrlTable.getModel())
1328               .isRowEditable(modelIndex))
1329       {
1330         editLink.setEnabled(true);
1331       }
1332       else
1333       {
1334         editLink.setEnabled(false);
1335       }
1336     }
1337   }
1338 }