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