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