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