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