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