JAL-3275 JAL-3633: JAL-3275 Turned Preferences into a Singleton that checks renews...
[jalview.git] / src / jalview / jbgui / GPreferences.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.jbgui;
22
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Dimension;
27 import java.awt.FlowLayout;
28 import java.awt.Font;
29 import java.awt.GridBagConstraints;
30 import java.awt.GridBagLayout;
31 import java.awt.GridLayout;
32 import java.awt.Insets;
33 import java.awt.Rectangle;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.FocusEvent;
37 import java.awt.event.KeyEvent;
38 import java.awt.event.KeyListener;
39 import java.awt.event.MouseAdapter;
40 import java.awt.event.MouseEvent;
41 import java.util.Arrays;
42 import java.util.List;
43
44 import javax.swing.AbstractCellEditor;
45 import javax.swing.BorderFactory;
46 import javax.swing.ButtonGroup;
47 import javax.swing.DefaultListCellRenderer;
48 import javax.swing.JButton;
49 import javax.swing.JCheckBox;
50 import javax.swing.JComboBox;
51 import javax.swing.JFileChooser;
52 import javax.swing.JLabel;
53 import javax.swing.JPanel;
54 import javax.swing.JPasswordField;
55 import javax.swing.JRadioButton;
56 import javax.swing.JScrollPane;
57 import javax.swing.JSpinner;
58 import javax.swing.JTabbedPane;
59 import javax.swing.JTable;
60 import javax.swing.JTextArea;
61 import javax.swing.JTextField;
62 import javax.swing.ListSelectionModel;
63 import javax.swing.SpinnerModel;
64 import javax.swing.SpinnerNumberModel;
65 import javax.swing.SwingConstants;
66 import javax.swing.border.Border;
67 import javax.swing.border.EmptyBorder;
68 import javax.swing.border.EtchedBorder;
69 import javax.swing.border.TitledBorder;
70 import javax.swing.event.ChangeEvent;
71 import javax.swing.event.ChangeListener;
72 import javax.swing.event.DocumentEvent;
73 import javax.swing.event.DocumentListener;
74 import javax.swing.table.TableCellEditor;
75 import javax.swing.table.TableCellRenderer;
76
77 import jalview.bin.Cache;
78 import jalview.fts.core.FTSDataColumnPreferences;
79 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
80 import jalview.fts.service.pdb.PDBFTSRestClient;
81 import jalview.gui.Desktop;
82 import jalview.gui.JalviewBooleanRadioButtons;
83 import jalview.gui.JvOptionPane;
84 import jalview.gui.JvSwingUtils;
85 import jalview.gui.StructureViewer.ViewerType;
86 import jalview.io.BackupFilenameParts;
87 import jalview.io.BackupFiles;
88 import jalview.io.BackupFilesPresetEntry;
89 import jalview.io.IntKeyStringValueEntry;
90 import jalview.util.MessageManager;
91
92 /**
93  * Base class for the Preferences panel.
94  * 
95  * @author $author$
96  * @version $Revision$
97  */
98 public class GPreferences extends JPanel
99 {
100   private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
101
102   private static final Font LABEL_FONT_ITALIC = JvSwingUtils
103           .getLabelFont(false, true);
104
105   private static final Font LABEL_FONT_BOLD = JvSwingUtils
106           .getLabelFont(true, false);
107
108   /*
109    * Visual tab components
110    */
111   protected JCheckBox fullScreen = new JCheckBox();
112
113   protected JCheckBox openoverv = new JCheckBox();
114
115   protected JCheckBox seqLimit = new JCheckBox();
116
117   protected JCheckBox rightAlign = new JCheckBox();
118
119   protected JComboBox<String> fontSizeCB = new JComboBox<>();
120
121   protected JComboBox<String> fontStyleCB = new JComboBox<>();
122
123   protected JComboBox<String> fontNameCB = new JComboBox<>();
124
125   protected JCheckBox showOccupancy = new JCheckBox();
126
127   protected JCheckBox showUnconserved = new JCheckBox();
128
129   protected JCheckBox idItalics = new JCheckBox();
130
131   protected JCheckBox smoothFont = new JCheckBox();
132
133   protected JCheckBox scaleProteinToCdna = new JCheckBox();
134
135   protected JComboBox<String> gapSymbolCB = new JComboBox<>();
136
137   protected JCheckBox wrap = new JCheckBox();
138
139   protected JComboBox<String> sortby = new JComboBox<>();
140
141   protected JComboBox<String> sortAnnBy = new JComboBox<>();
142
143   protected JComboBox<String> sortAutocalc = new JComboBox<>();
144
145   protected JCheckBox startupCheckbox = new JCheckBox();
146
147   protected JTextField startupFileTextfield = new JTextField();
148
149   // below are in the 'second column'
150   protected JCheckBox annotations = new JCheckBox();
151
152   protected JCheckBox quality = new JCheckBox();
153
154   protected JCheckBox conservation = new JCheckBox();
155
156   protected JCheckBox identity = new JCheckBox();
157
158   protected JCheckBox showGroupConsensus = new JCheckBox();
159
160   protected JCheckBox showGroupConservation = new JCheckBox();
161
162   protected JCheckBox showConsensHistogram = new JCheckBox();
163
164   protected JCheckBox showConsensLogo = new JCheckBox();
165
166   protected JCheckBox showDbRefTooltip = new JCheckBox();
167
168   protected JCheckBox showNpTooltip = new JCheckBox();
169
170   /*
171    * Structure tab and components
172    */
173   protected JPanel structureTab;
174
175   protected JCheckBox structFromPdb = new JCheckBox();
176
177   protected JCheckBox useRnaView = new JCheckBox();
178
179   protected JCheckBox addSecondaryStructure = new JCheckBox();
180
181   protected JCheckBox addTempFactor = new JCheckBox();
182
183   protected JComboBox<String> structViewer = new JComboBox<>();
184
185   protected JTextField chimeraPath = new JTextField();
186
187   protected ButtonGroup mappingMethod = new ButtonGroup();
188
189   protected JRadioButton siftsMapping = new JRadioButton();
190
191   protected JRadioButton nwMapping = new JRadioButton();
192
193   /*
194    * Colours tab components
195    */
196   protected JPanel minColour = new JPanel();
197
198   protected JPanel maxColour = new JPanel();
199
200   protected JComboBox<String> protColour = new JComboBox<>();
201
202   protected JComboBox<String> nucColour = new JComboBox<>();
203
204   /*
205    * Overview tab components
206    */
207   protected JPanel gapColour = new JPanel();
208
209   protected JPanel hiddenColour = new JPanel();
210
211   protected JCheckBox useLegacyGap;
212
213   protected JCheckBox showHiddenAtStart;
214
215   protected JLabel gapLabel;
216
217   /*
218    * Connections tab components
219    */
220   protected JPanel connectTab;
221
222   protected JTable linkUrlTable = new JTable();
223
224   protected JButton editLink = new JButton();
225
226   protected JButton deleteLink = new JButton();
227
228   protected JTextField filterTB = new JTextField();
229
230   protected JButton doReset = new JButton();
231
232   protected JButton userOnly = new JButton();
233
234   protected JLabel httpLabel = new JLabel();
235
236   protected JLabel httpsLabel = new JLabel();
237
238   protected JLabel portLabel = new JLabel();
239
240   protected JLabel serverLabel = new JLabel();
241
242   protected JLabel portLabel2 = new JLabel();
243
244   protected JLabel serverLabel2 = new JLabel();
245
246   protected JLabel proxyAuthUsernameLabel = new JLabel();
247
248   protected JLabel proxyAuthPasswordLabel = new JLabel();
249
250   protected JLabel passwordNotStoredLabel = new JLabel();
251
252   protected JTextField proxyServerHttpTB = new JTextField();
253
254   protected JTextField proxyPortHttpTB = new JTextField();
255
256   protected JTextField proxyServerHttpsTB = new JTextField();
257
258   protected JTextField proxyPortHttpsTB = new JTextField();
259
260   protected JCheckBox proxyAuth = new JCheckBox();
261
262   protected JTextField proxyAuthUsernameTB = new JTextField();
263
264   protected JPasswordField proxyAuthPasswordPB = new JPasswordField();
265
266   protected JTextField defaultBrowser = new JTextField();
267
268   protected ButtonGroup proxyType = new ButtonGroup();
269
270   protected JRadioButton noProxy = new JRadioButton();
271
272   protected JRadioButton systemProxy = new JRadioButton();
273
274   protected JRadioButton customProxy = new JRadioButton();
275
276   protected JButton applyProxyButton = new JButton();
277
278   protected JCheckBox usagestats = new JCheckBox();
279
280   protected JCheckBox questionnaire = new JCheckBox();
281
282   protected JCheckBox versioncheck = new JCheckBox();
283
284   /*
285    * Output tab components
286    */
287   protected JComboBox<Object> epsRendering = new JComboBox<>();
288
289   protected JLabel userIdWidthlabel = new JLabel();
290
291   protected JCheckBox autoIdWidth = new JCheckBox();
292
293   protected JTextField userIdWidth = new JTextField();
294
295   protected JCheckBox blcjv = new JCheckBox();
296
297   protected JCheckBox pileupjv = new JCheckBox();
298
299   protected JCheckBox clustaljv = new JCheckBox();
300
301   protected JCheckBox msfjv = new JCheckBox();
302
303   protected JCheckBox fastajv = new JCheckBox();
304
305   protected JCheckBox pfamjv = new JCheckBox();
306
307   protected JCheckBox pirjv = new JCheckBox();
308
309   protected JCheckBox modellerOutput = new JCheckBox();
310
311   protected JCheckBox embbedBioJSON = new JCheckBox();
312
313   /*
314    * Editing tab components
315    */
316   protected JCheckBox autoCalculateConsCheck = new JCheckBox();
317
318   protected JCheckBox padGaps = new JCheckBox();
319
320   protected JCheckBox sortByTree = new JCheckBox();
321
322   /*
323    * Web Services tab
324    */
325   protected JPanel wsTab = new JPanel();
326
327   /*
328    * Backups tab components
329    * a lot of these are member variables instead of local variables only so that they
330    * can be enabled/disabled easily in one go
331    */
332
333   protected JCheckBox enableBackupFiles = new JCheckBox();
334
335   protected JPanel presetsPanel = new JPanel();
336
337   protected JLabel presetsComboLabel = new JLabel();
338
339   protected JCheckBox customiseCheckbox = new JCheckBox();
340
341   protected JButton revertButton = new JButton();
342
343   protected JComboBox<Object> backupfilesPresetsCombo = new JComboBox<>();
344
345   private int backupfilesPresetsComboLastSelected = 0;
346
347   protected JPanel suffixPanel = new JPanel();
348
349   protected JPanel keepfilesPanel = new JPanel();
350
351   protected JPanel exampleFilesPanel = new JPanel();
352
353   protected JTextField suffixTemplate = new JTextField(null, 8);
354
355   protected JLabel suffixTemplateLabel = new JLabel();
356
357   protected JLabel suffixDigitsLabel = new JLabel();
358
359   protected JSpinner suffixDigitsSpinner = new JSpinner();
360
361   protected JalviewBooleanRadioButtons suffixReverse = new JalviewBooleanRadioButtons();
362
363   protected JalviewBooleanRadioButtons backupfilesKeepAll = new JalviewBooleanRadioButtons();
364
365   public JSpinner backupfilesRollMaxSpinner = new JSpinner();
366
367   protected JLabel oldBackupFilesLabel = new JLabel();
368
369   protected JalviewBooleanRadioButtons backupfilesConfirmDelete = new JalviewBooleanRadioButtons();
370
371   protected JTextArea backupfilesExampleLabel = new JTextArea();
372
373   private final JTabbedPane tabbedPane = new JTabbedPane();
374
375   private JLabel messageLabel = new JLabel("", JLabel.CENTER);
376
377   /**
378    * Creates a new GPreferences object.
379    */
380   public GPreferences()
381   {
382     try
383     {
384       jbInit();
385     } catch (Exception ex)
386     {
387       ex.printStackTrace();
388     }
389   }
390
391   /**
392    * Construct the panel and its tabbed sub-panels.
393    * 
394    * @throws Exception
395    */
396   private void jbInit() throws Exception
397   {
398     // final JTabbedPane tabbedPane = new JTabbedPane();
399     this.setLayout(new BorderLayout());
400
401     // message label at top
402     this.add(messageLabel, BorderLayout.NORTH);
403
404     JPanel okCancelPanel = initOkCancelPanel();
405     this.add(tabbedPane, BorderLayout.CENTER);
406     this.add(okCancelPanel, BorderLayout.SOUTH);
407
408     tabbedPane.add(initVisualTab(),
409             MessageManager.getString("label.visual"));
410
411     tabbedPane.add(initColoursTab(),
412             MessageManager.getString("label.colours"));
413
414     tabbedPane.add(initOverviewTab(),
415             MessageManager.getString("label.overview"));
416
417     tabbedPane.add(initStructureTab(),
418             MessageManager.getString("label.structure"));
419
420     tabbedPane.add(initConnectionsTab(),
421             MessageManager.getString("label.connections"));
422
423     tabbedPane.add(initBackupsTab(),
424             MessageManager.getString("label.backups"));
425
426     tabbedPane.add(initLinksTab(),
427             MessageManager.getString("label.urllinks"));
428
429     tabbedPane.add(initOutputTab(),
430             MessageManager.getString("label.output"));
431
432     tabbedPane.add(initEditingTab(),
433             MessageManager.getString("label.editing"));
434
435     /*
436      * See WsPreferences for the real work of configuring this tab.
437      */
438     wsTab.setLayout(new BorderLayout());
439     tabbedPane.add(wsTab, MessageManager.getString("label.web_services"));
440
441     /*
442      * Handler to validate a tab before leaving it - currently only for
443      * Structure.
444      * Adding a clearMessage() so messages are cleared when changing tabs.
445      */
446     tabbedPane.addChangeListener(new ChangeListener()
447     {
448       private Component lastTab;
449
450       @Override
451       public void stateChanged(ChangeEvent e)
452       {
453         if (lastTab == structureTab
454                 && tabbedPane.getSelectedComponent() != structureTab)
455         {
456           if (!validateStructure())
457           {
458             tabbedPane.setSelectedComponent(structureTab);
459             return;
460           }
461         }
462         lastTab = tabbedPane.getSelectedComponent();
463
464         clearMessage();
465       }
466
467     });
468   }
469
470   public void setMessage(String message)
471   {
472     if (message != null)
473     {
474       messageLabel.setText(message);
475       messageLabel.setFont(LABEL_FONT_BOLD);
476       messageLabel.setForeground(Color.RED.darker());
477       messageLabel.revalidate();
478       messageLabel.repaint();
479     }
480     // note message not cleared if message is null. call clearMessage()
481     // directly.
482     this.revalidate();
483     this.repaint();
484   }
485
486   public void clearMessage()
487   {
488     // only repaint if message exists
489     if (messageLabel.getText() != null
490             && messageLabel.getText().length() > 0)
491     {
492       messageLabel.setText("");
493       messageLabel.revalidate();
494       messageLabel.repaint();
495       this.revalidate();
496       this.repaint();
497     }
498   }
499
500   public final static int CONNECTIONS_TAB = 5;
501
502   public void selectTab(int selectTab)
503   {
504     // select a given tab - currently only for Connections
505     switch (selectTab)
506     {
507     case CONNECTIONS_TAB:
508       tabbedPane.setSelectedComponent(connectTab);
509       break;
510     default:
511     }
512   }
513
514   /**
515    * Initialises the Editing tabbed panel.
516    * 
517    * @return
518    */
519   private JPanel initEditingTab()
520   {
521     JPanel editingTab = new JPanel();
522     editingTab.setLayout(null);
523     autoCalculateConsCheck.setFont(LABEL_FONT);
524     autoCalculateConsCheck.setText(
525             MessageManager.getString("label.autocalculate_consensus"));
526     autoCalculateConsCheck.setBounds(new Rectangle(21, 52, 209, 23));
527     padGaps.setFont(LABEL_FONT);
528     padGaps.setText(
529             MessageManager.getString("label.pad_gaps_when_editing"));
530     padGaps.setBounds(new Rectangle(22, 94, 168, 23));
531     sortByTree.setFont(LABEL_FONT);
532     sortByTree
533             .setText(MessageManager.getString("label.sort_with_new_tree"));
534     sortByTree.setToolTipText(MessageManager.getString(
535             "label.any_trees_calculated_or_loaded_alignment_automatically_sort"));
536     sortByTree.setBounds(new Rectangle(22, 136, 168, 23));
537     editingTab.add(autoCalculateConsCheck);
538     editingTab.add(padGaps);
539     editingTab.add(sortByTree);
540     return editingTab;
541   }
542
543   /**
544    * Initialises the Output tabbed panel.
545    * 
546    * @return
547    */
548   private JPanel initOutputTab()
549   {
550     JPanel outputTab = new JPanel();
551     outputTab.setLayout(null);
552     JLabel epsLabel = new JLabel();
553     epsLabel.setFont(LABEL_FONT);
554     epsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
555     epsLabel.setText(MessageManager.getString("label.eps_rendering_style"));
556     epsLabel.setBounds(new Rectangle(9, 31, 140, 24));
557     epsRendering.setFont(LABEL_FONT);
558     epsRendering.setBounds(new Rectangle(154, 34, 187, 21));
559     JLabel jLabel1 = new JLabel();
560     jLabel1.setFont(LABEL_FONT);
561     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
562     jLabel1.setText(MessageManager.getString("label.append_start_end"));
563     jLabel1.setFont(LABEL_FONT);
564     fastajv.setFont(LABEL_FONT);
565     fastajv.setHorizontalAlignment(SwingConstants.LEFT);
566     clustaljv.setText(MessageManager.getString("label.clustal") + "     ");
567     blcjv.setText(MessageManager.getString("label.blc") + "     ");
568     fastajv.setText(MessageManager.getString("label.fasta") + "     ");
569     msfjv.setText(MessageManager.getString("label.msf") + "     ");
570     pfamjv.setText(MessageManager.getString("label.pfam") + "     ");
571     pileupjv.setText(MessageManager.getString("label.pileup") + "     ");
572     msfjv.setFont(LABEL_FONT);
573     msfjv.setHorizontalAlignment(SwingConstants.LEFT);
574     pirjv.setText(MessageManager.getString("label.pir") + "     ");
575     JPanel jPanel11 = new JPanel();
576     jPanel11.setFont(LABEL_FONT);
577     TitledBorder titledBorder2 = new TitledBorder(
578             MessageManager.getString("label.file_output"));
579     jPanel11.setBorder(titledBorder2);
580     jPanel11.setBounds(new Rectangle(30, 72, 196, 182));
581     GridLayout gridLayout3 = new GridLayout();
582     jPanel11.setLayout(gridLayout3);
583     gridLayout3.setRows(8);
584     blcjv.setFont(LABEL_FONT);
585     blcjv.setHorizontalAlignment(SwingConstants.LEFT);
586     clustaljv.setFont(LABEL_FONT);
587     clustaljv.setHorizontalAlignment(SwingConstants.LEFT);
588     pfamjv.setFont(LABEL_FONT);
589     pfamjv.setHorizontalAlignment(SwingConstants.LEFT);
590     pileupjv.setFont(LABEL_FONT);
591     pileupjv.setHorizontalAlignment(SwingConstants.LEFT);
592     pirjv.setFont(LABEL_FONT);
593     pirjv.setHorizontalAlignment(SwingConstants.LEFT);
594     autoIdWidth.setFont(LABEL_FONT);
595     autoIdWidth.setText(
596             MessageManager.getString("label.automatically_set_id_width"));
597     autoIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
598             .getString("label.adjusts_width_generated_eps_png")));
599     autoIdWidth.setBounds(new Rectangle(228, 96, 188, 23));
600     autoIdWidth.addActionListener(new ActionListener()
601     {
602
603       @Override
604       public void actionPerformed(ActionEvent e)
605       {
606         autoIdWidth_actionPerformed();
607       }
608     });
609     userIdWidthlabel.setFont(LABEL_FONT);
610     userIdWidthlabel.setText(
611             MessageManager.getString("label.figure_id_column_width"));
612     userIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
613             .getString("label.manually_specify_width_left_column")));
614     userIdWidthlabel.setToolTipText(
615             JvSwingUtils.wrapTooltip(true, MessageManager.getString(
616                     "label.manually_specify_width_left_column")));
617     userIdWidthlabel.setBounds(new Rectangle(236, 120, 168, 23));
618     userIdWidth.setFont(JvSwingUtils.getTextAreaFont());
619     userIdWidth.setText("");
620     userIdWidth.setBounds(new Rectangle(232, 144, 84, 23));
621     userIdWidth.addActionListener(new ActionListener()
622     {
623
624       @Override
625       public void actionPerformed(ActionEvent e)
626       {
627         userIdWidth_actionPerformed();
628       }
629     });
630     modellerOutput.setFont(LABEL_FONT);
631     modellerOutput
632             .setText(MessageManager.getString("label.use_modeller_output"));
633     modellerOutput.setBounds(new Rectangle(228, 226, 168, 23));
634     embbedBioJSON.setFont(LABEL_FONT);
635     embbedBioJSON.setText(MessageManager.getString("label.embbed_biojson"));
636     embbedBioJSON.setBounds(new Rectangle(228, 200, 250, 23));
637
638     jPanel11.add(jLabel1);
639     jPanel11.add(blcjv);
640     jPanel11.add(clustaljv);
641     jPanel11.add(fastajv);
642     jPanel11.add(msfjv);
643     jPanel11.add(pfamjv);
644     jPanel11.add(pileupjv);
645     jPanel11.add(pirjv);
646     outputTab.add(autoIdWidth);
647     outputTab.add(userIdWidth);
648     outputTab.add(userIdWidthlabel);
649     outputTab.add(modellerOutput);
650     outputTab.add(embbedBioJSON);
651     outputTab.add(epsLabel);
652     outputTab.add(epsRendering);
653     outputTab.add(jPanel11);
654     return outputTab;
655   }
656
657   /**
658    * Initialises the Connections tabbed panel.
659    * 
660    * @return
661    */
662   private JPanel initConnectionsTab()
663   {
664     connectTab = new JPanel();
665     connectTab.setLayout(new GridBagLayout());
666
667     // Label for browser text box
668     JLabel browserLabel = new JLabel();
669     browserLabel.setFont(LABEL_FONT);
670     browserLabel.setHorizontalAlignment(SwingConstants.TRAILING);
671     browserLabel.setText(
672             MessageManager.getString("label.default_browser_unix"));
673     defaultBrowser.setFont(LABEL_FONT);
674     defaultBrowser.setText("");
675     final String tooltip = JvSwingUtils.wrapTooltip(true,
676             MessageManager.getString("label.double_click_to_browse"));
677     defaultBrowser.setToolTipText(tooltip);
678     defaultBrowser.addMouseListener(new MouseAdapter()
679     {
680       @Override
681       public void mouseClicked(MouseEvent e)
682       {
683         if (e.getClickCount() > 1)
684         {
685           defaultBrowser_mouseClicked(e);
686         }
687       }
688     });
689
690     JPanel proxyPanel = initConnTabProxyPanel();
691     initConnTabCheckboxes();
692
693     // Add default Browser text box
694     connectTab.add(browserLabel,
695             new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
696                     GridBagConstraints.WEST, GridBagConstraints.NONE,
697                     new Insets(10, 0, 5, 5), 5, 1));
698     defaultBrowser.setFont(LABEL_FONT);
699     defaultBrowser.setText("");
700
701     connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0,
702             0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
703             new Insets(10, 0, 5, 10), 30, 1));
704
705     // Add proxy server panel
706     connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0,
707             GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
708             new Insets(10, 0, 5, 12), 4, 10));
709
710     // Add usage stats, version check and questionnaire checkboxes
711     connectTab.add(usagestats,
712             new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
713                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
714                     new Insets(0, 2, 5, 5), 70, 1));
715     connectTab.add(questionnaire,
716             new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
717                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
718                     new Insets(0, 2, 5, 10), 70, 1));
719     connectTab.add(versioncheck,
720             new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0,
721                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
722                     new Insets(0, 2, 5, 5), 70, 1));
723
724     versioncheck.setVisible(false);
725
726     // Add padding so the panel doesn't look ridiculous
727     JPanel spacePanel = new JPanel();
728     connectTab.add(spacePanel,
729             new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
730                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
731                     new Insets(0, 0, 0, 5), 70, 1));
732
733     return connectTab;
734   }
735
736   /**
737    * Initialises the Links tabbed panel.
738    * 
739    * @return
740    */
741   private JPanel initLinksTab()
742   {
743     JPanel linkTab = new JPanel();
744     linkTab.setLayout(new GridBagLayout());
745
746     // Set up table for Url links
747     linkUrlTable.getTableHeader().setReorderingAllowed(false);
748     linkUrlTable.setFillsViewportHeight(true);
749     linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
750     linkUrlTable.setAutoCreateRowSorter(true);
751     linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
752
753     // adjust row height so radio buttons actually fit
754     // don't do this in the renderer, it causes the awt thread to activate
755     // constantly
756     JRadioButton temp = new JRadioButton();
757     linkUrlTable.setRowHeight(temp.getMinimumSize().height);
758
759     // Table in scrollpane so that the table is given a scrollbar
760     JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
761     linkScrollPane.setBorder(null);
762
763     // Panel for links functionality
764     JPanel linkPanel = new JPanel(new GridBagLayout());
765     linkPanel.setBorder(new TitledBorder(
766             MessageManager.getString("label.url_linkfrom_sequence_id")));
767
768     // Put the Url links panel together
769
770     // Buttons go at top right, resizing only resizes the blank space vertically
771     JPanel buttonPanel = initLinkTabUrlButtons();
772     GridBagConstraints linkConstraints1 = new GridBagConstraints();
773     linkConstraints1.insets = new Insets(0, 0, 5, 0);
774     linkConstraints1.gridx = 0;
775     linkConstraints1.gridy = 0;
776     linkConstraints1.weightx = 1.0;
777     linkConstraints1.fill = GridBagConstraints.HORIZONTAL;
778     linkTab.add(buttonPanel, linkConstraints1);
779
780     // Links table goes at top left, resizing resizes the table
781     GridBagConstraints linkConstraints2 = new GridBagConstraints();
782     linkConstraints2.insets = new Insets(0, 0, 5, 5);
783     linkConstraints2.gridx = 0;
784     linkConstraints2.gridy = 1;
785     linkConstraints2.weightx = 1.0;
786     linkConstraints2.weighty = 1.0;
787     linkConstraints2.fill = GridBagConstraints.BOTH;
788     linkTab.add(linkScrollPane, linkConstraints2);
789
790     // Filter box and buttons goes at bottom left, resizing resizes the text box
791     JPanel filterPanel = initLinkTabFilterPanel();
792     GridBagConstraints linkConstraints3 = new GridBagConstraints();
793     linkConstraints3.insets = new Insets(0, 0, 0, 5);
794     linkConstraints3.gridx = 0;
795     linkConstraints3.gridy = 2;
796     linkConstraints3.weightx = 1.0;
797     linkConstraints3.fill = GridBagConstraints.HORIZONTAL;
798     linkTab.add(filterPanel, linkConstraints3);
799
800     return linkTab;
801   }
802
803   private JPanel initLinkTabFilterPanel()
804   {
805     // Filter textbox and reset button
806     JLabel filterLabel = new JLabel(
807             MessageManager.getString("label.filter"));
808     filterLabel.setFont(LABEL_FONT);
809     filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);
810     filterLabel.setHorizontalTextPosition(SwingConstants.LEADING);
811
812     filterTB.setFont(LABEL_FONT);
813     filterTB.setText("");
814
815     doReset.setText(MessageManager.getString("action.showall"));
816     userOnly.setText(MessageManager.getString("action.customfilter"));
817
818     // Panel for filter functionality
819     JPanel filterPanel = new JPanel(new GridBagLayout());
820     filterPanel.setBorder(new TitledBorder("Filter"));
821     GridBagConstraints gbc = new GridBagConstraints();
822     gbc.gridx = 0;
823     gbc.gridy = 0;
824     gbc.fill = GridBagConstraints.NONE;
825     gbc.anchor = GridBagConstraints.WEST;
826
827     filterPanel.add(filterLabel, gbc);
828
829     GridBagConstraints gbc1 = new GridBagConstraints();
830     gbc1.gridx = 1;
831     gbc1.gridwidth = 2;
832     gbc1.fill = GridBagConstraints.HORIZONTAL;
833     gbc1.anchor = GridBagConstraints.WEST;
834     gbc1.weightx = 1.0;
835     filterPanel.add(filterTB, gbc1);
836
837     GridBagConstraints gbc2 = new GridBagConstraints();
838     gbc2.gridx = 3;
839     gbc2.fill = GridBagConstraints.NONE;
840     gbc2.anchor = GridBagConstraints.WEST;
841     filterPanel.add(doReset, gbc2);
842
843     GridBagConstraints gbc3 = new GridBagConstraints();
844     gbc3.gridx = 4;
845     gbc3.fill = GridBagConstraints.NONE;
846     gbc3.anchor = GridBagConstraints.WEST;
847     filterPanel.add(userOnly, gbc3);
848
849     return filterPanel;
850   }
851
852   private JPanel initLinkTabUrlButtons()
853   {
854     // Buttons for new / edit / delete Url links
855     JButton newLink = new JButton();
856     newLink.setText(MessageManager.getString("action.new"));
857
858     editLink.setText(MessageManager.getString("action.edit"));
859
860     deleteLink.setText(MessageManager.getString("action.delete"));
861
862     // no current selection, so initially disable delete/edit buttons
863     editLink.setEnabled(false);
864     deleteLink.setEnabled(false);
865
866     newLink.addActionListener(new java.awt.event.ActionListener()
867     {
868       @Override
869       public void actionPerformed(ActionEvent e)
870       {
871         newLink_actionPerformed(e);
872       }
873     });
874
875     editLink.setText(MessageManager.getString("action.edit"));
876     editLink.addActionListener(new java.awt.event.ActionListener()
877     {
878       @Override
879       public void actionPerformed(ActionEvent e)
880       {
881         editLink_actionPerformed(e);
882       }
883     });
884
885     deleteLink.setText(MessageManager.getString("action.delete"));
886     deleteLink.addActionListener(new java.awt.event.ActionListener()
887     {
888       @Override
889       public void actionPerformed(ActionEvent e)
890       {
891         deleteLink_actionPerformed(e);
892       }
893     });
894
895     JPanel buttonPanel = new JPanel(new GridBagLayout());
896     buttonPanel.setBorder(new TitledBorder("Edit links"));
897     GridBagConstraints gbc = new GridBagConstraints();
898     gbc.gridx = 0;
899     gbc.gridy = 0;
900     gbc.fill = GridBagConstraints.NONE;
901     buttonPanel.add(newLink, gbc);
902
903     GridBagConstraints gbc1 = new GridBagConstraints();
904     gbc1.gridx = 1;
905     gbc1.gridy = 0;
906     gbc1.fill = GridBagConstraints.NONE;
907     buttonPanel.add(editLink, gbc1);
908
909     GridBagConstraints gbc2 = new GridBagConstraints();
910     gbc2.gridx = 2;
911     gbc2.gridy = 0;
912     gbc2.fill = GridBagConstraints.NONE;
913     buttonPanel.add(deleteLink, gbc2);
914
915     GridBagConstraints gbc3 = new GridBagConstraints();
916     gbc3.gridx = 3;
917     gbc3.gridy = 0;
918     gbc3.fill = GridBagConstraints.HORIZONTAL;
919     gbc3.weightx = 1.0;
920     JPanel spacePanel = new JPanel();
921     spacePanel.setBorder(null);
922     buttonPanel.add(spacePanel, gbc3);
923
924     return buttonPanel;
925   }
926
927   /**
928    * Initialises the proxy server panel in the Connections tab
929    * 
930    * @return the proxy server panel
931    */
932   private JPanel initConnTabProxyPanel()
933   {
934     // Label for server text box
935     serverLabel.setText(MessageManager.getString("label.host") + ": ");
936     serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
937     serverLabel.setFont(LABEL_FONT);
938     serverLabel2.setText(MessageManager.getString("label.host") + ": ");
939     serverLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
940     serverLabel2.setFont(LABEL_FONT);
941
942     // Proxy server and port text boxes
943     proxyServerHttpTB.setFont(LABEL_FONT);
944     proxyServerHttpTB.setColumns(40);
945     proxyPortHttpTB.setFont(LABEL_FONT);
946     proxyPortHttpTB.setColumns(4);
947     proxyServerHttpsTB.setFont(LABEL_FONT);
948     proxyServerHttpsTB.setColumns(40);
949     proxyPortHttpsTB.setFont(LABEL_FONT);
950     proxyPortHttpsTB.setColumns(4);
951     proxyAuthUsernameTB.setFont(LABEL_FONT);
952     proxyAuthUsernameTB.setColumns(30);
953     proxyAuthPasswordPB.setFont(LABEL_FONT);
954     proxyAuthPasswordPB.setColumns(30);
955     proxyAuthPasswordPB.getDocument()
956             .addDocumentListener(new DocumentListener()
957             {
958               @Override
959               public void changedUpdate(DocumentEvent e)
960               {
961                 if (!proxyAuthPasswordPB.getBackground()
962                         .equals(Color.WHITE))
963                   proxyAuthPasswordPB.setBackground(Color.WHITE);
964               }
965
966               @Override
967               public void insertUpdate(DocumentEvent e)
968               {
969                 if (!proxyAuthPasswordPB.getBackground()
970                         .equals(Color.WHITE))
971                   proxyAuthPasswordPB.setBackground(Color.WHITE);
972               }
973
974               @Override
975               public void removeUpdate(DocumentEvent e)
976               {
977                 if (!proxyAuthPasswordPB.getBackground()
978                         .equals(Color.WHITE))
979                   proxyAuthPasswordPB.setBackground(Color.WHITE);
980               }
981
982             });
983
984     // Label for Port text box
985     portLabel.setFont(LABEL_FONT);
986     portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
987     portLabel.setText(MessageManager.getString("label.port") + ": ");
988     portLabel2.setFont(LABEL_FONT);
989     portLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
990     portLabel2.setText(MessageManager.getString("label.port") + ": ");
991
992     httpLabel.setText("HTTP");
993     httpLabel.setFont(LABEL_FONT_BOLD);
994     httpLabel.setHorizontalAlignment(SwingConstants.LEFT);
995     httpsLabel.setText("HTTPS");
996     httpsLabel.setFont(LABEL_FONT_BOLD);
997     httpsLabel.setHorizontalAlignment(SwingConstants.LEFT);
998
999     proxyAuthUsernameLabel
1000             .setText(MessageManager.getString("label.username") + ": ");
1001     proxyAuthUsernameLabel.setFont(LABEL_FONT);
1002     proxyAuthUsernameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1003     proxyAuthPasswordLabel
1004             .setText(MessageManager.getString("label.password") + ": ");
1005     proxyAuthPasswordLabel.setFont(LABEL_FONT);
1006     proxyAuthPasswordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1007     passwordNotStoredLabel.setText(
1008             "(" + MessageManager.getString("label.not_stored") + ")");
1009     passwordNotStoredLabel.setFont(LABEL_FONT_ITALIC);
1010     passwordNotStoredLabel.setHorizontalAlignment(SwingConstants.LEFT);
1011
1012     // Proxy type radio buttons
1013     noProxy.setFont(LABEL_FONT);
1014     noProxy.setHorizontalAlignment(SwingConstants.LEFT);
1015     noProxy.setText(MessageManager.getString("label.no_proxy"));
1016     systemProxy.setFont(LABEL_FONT);
1017     systemProxy.setHorizontalAlignment(SwingConstants.LEFT);
1018     systemProxy.setText(MessageManager.formatMessage("label.system_proxy",
1019             displayUserHostPort(Cache.startupProxyProperties[4],
1020                     Cache.startupProxyProperties[0],
1021                     Cache.startupProxyProperties[1]),
1022             displayUserHostPort(Cache.startupProxyProperties[6],
1023                     Cache.startupProxyProperties[2],
1024                     Cache.startupProxyProperties[3])));
1025     customProxy.setFont(LABEL_FONT);
1026     customProxy.setHorizontalAlignment(SwingConstants.LEFT);
1027     customProxy.setText(
1028             MessageManager.getString("label.use_proxy_server") + ":");
1029     ActionListener al = new ActionListener()
1030     {
1031       @Override
1032       public void actionPerformed(ActionEvent e)
1033       {
1034         proxyType_actionPerformed();
1035       }
1036     };
1037     noProxy.addActionListener(al);
1038     systemProxy.addActionListener(al);
1039     customProxy.addActionListener(al);
1040     proxyType.add(noProxy);
1041     proxyType.add(systemProxy);
1042     proxyType.add(customProxy);
1043
1044     proxyAuth.setFont(LABEL_FONT);
1045     proxyAuth.setHorizontalAlignment(SwingConstants.LEFT);
1046     proxyAuth.setText(MessageManager.getString("label.auth_required"));
1047     proxyAuth.addActionListener(new ActionListener()
1048     {
1049       @Override
1050       public void actionPerformed(ActionEvent e)
1051       {
1052         proxyAuth_actionPerformed();
1053       }
1054     });
1055
1056     setCustomProxyEnabled();
1057
1058     // Make proxy server panel
1059     JPanel proxyPanel = new JPanel();
1060     TitledBorder titledBorder1 = new TitledBorder(
1061             MessageManager.getString("label.proxy_servers"));
1062     proxyPanel.setBorder(titledBorder1);
1063     proxyPanel.setLayout(new GridBagLayout());
1064     GridBagConstraints gbc = new GridBagConstraints();
1065     gbc.fill = GridBagConstraints.HORIZONTAL;
1066     gbc.weightx = 1.0;
1067
1068     GridBagConstraints c = new GridBagConstraints();
1069     // Proxy type radio buttons (3)
1070     JPanel ptPanel = new JPanel();
1071     ptPanel.setLayout(new GridBagLayout());
1072     c.weightx = 1.0;
1073     c.gridy = 0;
1074     c.gridx = 0;
1075     c.gridwidth = 1;
1076     c.fill = GridBagConstraints.HORIZONTAL;
1077     ptPanel.add(noProxy, c);
1078     c.gridy++;
1079     ptPanel.add(systemProxy, c);
1080     c.gridy++;
1081     ptPanel.add(customProxy, c);
1082
1083     gbc.gridy = 0;
1084     proxyPanel.add(ptPanel, gbc);
1085
1086     // host and port text boxes
1087     JPanel hpPanel = new JPanel();
1088     hpPanel.setLayout(new GridBagLayout());
1089     // HTTP host port row
1090     c.gridy = 0;
1091     c.gridx = 0;
1092
1093     c.weightx = 0.1;
1094     c.anchor = GridBagConstraints.LINE_START;
1095     hpPanel.add(httpLabel, c);
1096
1097     c.gridx++;
1098     c.weightx = 0.1;
1099     c.anchor = GridBagConstraints.LINE_END;
1100     hpPanel.add(serverLabel, c);
1101
1102     c.gridx++;
1103     c.weightx = 1.0;
1104     c.anchor = GridBagConstraints.LINE_START;
1105     hpPanel.add(proxyServerHttpTB, c);
1106
1107     c.gridx++;
1108     c.weightx = 0.1;
1109     c.anchor = GridBagConstraints.LINE_END;
1110     hpPanel.add(portLabel, c);
1111
1112     c.gridx++;
1113     c.weightx = 0.2;
1114     c.anchor = GridBagConstraints.LINE_START;
1115     hpPanel.add(proxyPortHttpTB, c);
1116
1117     // HTTPS host port row
1118     c.gridy++;
1119     c.gridx = 0;
1120     c.gridwidth = 1;
1121
1122     c.anchor = GridBagConstraints.LINE_START;
1123     hpPanel.add(httpsLabel, c);
1124
1125     c.gridx++;
1126     c.anchor = GridBagConstraints.LINE_END;
1127     hpPanel.add(serverLabel2, c);
1128
1129     c.gridx++;
1130     c.anchor = GridBagConstraints.LINE_START;
1131     hpPanel.add(proxyServerHttpsTB, c);
1132
1133     c.gridx++;
1134     c.anchor = GridBagConstraints.LINE_END;
1135     hpPanel.add(portLabel2, c);
1136
1137     c.gridx++;
1138     c.anchor = GridBagConstraints.LINE_START;
1139     hpPanel.add(proxyPortHttpsTB, c);
1140
1141     gbc.gridy++;
1142     proxyPanel.add(hpPanel, gbc);
1143
1144     // Require authentication checkbox
1145     gbc.gridy++;
1146     proxyPanel.add(proxyAuth, gbc);
1147
1148     // username and password
1149     JPanel upPanel = new JPanel();
1150     upPanel.setLayout(new GridBagLayout());
1151     // username row
1152     c.gridy = 0;
1153     c.gridx = 0;
1154     c.gridwidth = 1;
1155     c.weightx = 0.4;
1156     c.anchor = GridBagConstraints.LINE_END;
1157     upPanel.add(proxyAuthUsernameLabel, c);
1158
1159     c.gridx++;
1160     c.weightx = 1.0;
1161     c.anchor = GridBagConstraints.LINE_START;
1162     upPanel.add(proxyAuthUsernameTB, c);
1163
1164     // password row
1165     c.gridy++;
1166     c.gridx = 0;
1167     c.weightx = 0.4;
1168     c.anchor = GridBagConstraints.LINE_END;
1169     upPanel.add(proxyAuthPasswordLabel, c);
1170
1171     c.gridx++;
1172     c.weightx = 1.0;
1173     c.anchor = GridBagConstraints.LINE_START;
1174     upPanel.add(proxyAuthPasswordPB, c);
1175
1176     c.gridx++;
1177     c.weightx = 0.4;
1178     c.anchor = GridBagConstraints.LINE_START;
1179     upPanel.add(passwordNotStoredLabel, c);
1180
1181     gbc.gridy++;
1182     proxyPanel.add(upPanel, gbc);
1183
1184     applyProxyButton.setText(MessageManager.getString("action.apply"));
1185     applyProxyButton.addActionListener(new ActionListener()
1186     {
1187       @Override
1188       public void actionPerformed(ActionEvent e)
1189       {
1190         saveProxySettings();
1191       }
1192     });
1193     gbc.gridy++;
1194     gbc.fill = GridBagConstraints.NONE;
1195     gbc.anchor = GridBagConstraints.LINE_END;
1196     proxyPanel.add(applyProxyButton, gbc);
1197
1198     return proxyPanel;
1199   }
1200
1201   public void proxyAuthPasswordFocus()
1202   {
1203     proxyAuthPasswordPB.grabFocus();
1204     proxyAuthPasswordPB.setBackground(Color.PINK);
1205   }
1206
1207   public void saveProxySettings()
1208   {
1209     // overridden in Preferences
1210   }
1211
1212   private String displayUserHostPort(String user, String host, String port)
1213   {
1214     boolean hostBlank = (host == null || host.isEmpty());
1215     boolean portBlank = (port == null || port.isEmpty());
1216     if (hostBlank && portBlank)
1217     {
1218       return MessageManager.getString("label.none");
1219     }
1220
1221     StringBuilder sb = new StringBuilder();
1222     if (user != null)
1223     {
1224       sb.append(user.isEmpty() || user.indexOf(" ") > -1 ? '"' + user + '"'
1225               : user);
1226       sb.append("@");
1227     }
1228     sb.append(hostBlank ? "" : host);
1229     if (!portBlank)
1230     {
1231       sb.append(":");
1232       sb.append(port);
1233     }
1234     return sb.toString();
1235   }
1236
1237   /**
1238    * Initialises the checkboxes in the Connections tab
1239    */
1240   private void initConnTabCheckboxes()
1241   {
1242     // Usage stats checkbox label
1243     usagestats.setText(
1244             MessageManager.getString("label.send_usage_statistics"));
1245     usagestats.setFont(LABEL_FONT);
1246     usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
1247     usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
1248
1249     // Questionnaire checkbox label
1250     questionnaire.setText(
1251             MessageManager.getString("label.check_for_questionnaires"));
1252     questionnaire.setFont(LABEL_FONT);
1253     questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
1254     questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
1255
1256     // Check for latest version checkbox label
1257     versioncheck.setText(
1258             MessageManager.getString("label.check_for_latest_version"));
1259     versioncheck.setFont(LABEL_FONT);
1260     versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
1261     versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
1262   }
1263
1264   /**
1265    * Initialises the parent panel which contains the tabbed sections.
1266    * 
1267    * @return
1268    */
1269   private JPanel initOkCancelPanel()
1270   {
1271     JButton ok = new JButton();
1272     ok.setText(MessageManager.getString("action.ok"));
1273     ok.addActionListener(new ActionListener()
1274     {
1275       @Override
1276       public void actionPerformed(ActionEvent e)
1277       {
1278         ok_actionPerformed(e);
1279       }
1280     });
1281     JButton cancel = new JButton();
1282     cancel.setText(MessageManager.getString("action.cancel"));
1283     cancel.addActionListener(new ActionListener()
1284     {
1285       @Override
1286       public void actionPerformed(ActionEvent e)
1287       {
1288         cancel_actionPerformed(e);
1289       }
1290     });
1291     JPanel okCancelPanel = new JPanel();
1292     okCancelPanel.add(ok);
1293     okCancelPanel.add(cancel);
1294     return okCancelPanel;
1295   }
1296
1297   /**
1298    * Initialises the Colours tabbed panel.
1299    * 
1300    * @return
1301    */
1302   private JPanel initColoursTab()
1303   {
1304     JPanel coloursTab = new JPanel();
1305     coloursTab.setBorder(new TitledBorder(
1306             MessageManager.getString("action.open_new_alignment")));
1307     coloursTab.setLayout(new FlowLayout());
1308     JLabel mincolourLabel = new JLabel();
1309     mincolourLabel.setFont(LABEL_FONT);
1310     mincolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1311     mincolourLabel.setText(MessageManager.getString("label.min_colour"));
1312     minColour.setFont(LABEL_FONT);
1313     minColour.setBorder(BorderFactory.createEtchedBorder());
1314     minColour.setPreferredSize(new Dimension(40, 20));
1315     minColour.addMouseListener(new MouseAdapter()
1316     {
1317       @Override
1318       public void mousePressed(MouseEvent e)
1319       {
1320         minColour_actionPerformed(minColour);
1321       }
1322     });
1323     JLabel maxcolourLabel = new JLabel();
1324     maxcolourLabel.setFont(LABEL_FONT);
1325     maxcolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1326     maxcolourLabel.setText(MessageManager.getString("label.max_colour"));
1327     maxColour.setFont(LABEL_FONT);
1328     maxColour.setBorder(BorderFactory.createEtchedBorder());
1329     maxColour.setPreferredSize(new Dimension(40, 20));
1330     maxColour.addMouseListener(new MouseAdapter()
1331     {
1332       @Override
1333       public void mousePressed(MouseEvent e)
1334       {
1335         maxColour_actionPerformed(maxColour);
1336       }
1337     });
1338
1339     protColour.setFont(LABEL_FONT);
1340     protColour.setBounds(new Rectangle(172, 225, 155, 21));
1341     JLabel protColourLabel = new JLabel();
1342     protColourLabel.setFont(LABEL_FONT);
1343     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1344     protColourLabel.setText(
1345             MessageManager.getString("label.prot_alignment_colour") + " ");
1346     JvSwingUtils.addtoLayout(coloursTab,
1347             MessageManager
1348                     .getString("label.default_colour_scheme_for_alignment"),
1349             protColourLabel, protColour);
1350
1351     nucColour.setFont(LABEL_FONT);
1352     nucColour.setBounds(new Rectangle(172, 240, 155, 21));
1353     JLabel nucColourLabel = new JLabel();
1354     nucColourLabel.setFont(LABEL_FONT);
1355     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1356     nucColourLabel.setText(
1357             MessageManager.getString("label.nuc_alignment_colour") + " ");
1358     JvSwingUtils.addtoLayout(coloursTab,
1359             MessageManager
1360                     .getString("label.default_colour_scheme_for_alignment"),
1361             nucColourLabel, nucColour);
1362
1363     JPanel annotationShding = new JPanel();
1364     annotationShding.setBorder(new TitledBorder(
1365             MessageManager.getString("label.annotation_shading_default")));
1366     annotationShding.setLayout(new GridLayout(1, 2));
1367     JvSwingUtils.addtoLayout(annotationShding,
1368             MessageManager.getString(
1369                     "label.default_minimum_colour_annotation_shading"),
1370             mincolourLabel, minColour);
1371     JvSwingUtils.addtoLayout(annotationShding,
1372             MessageManager.getString(
1373                     "label.default_maximum_colour_annotation_shading"),
1374             maxcolourLabel, maxColour);
1375     coloursTab.add(annotationShding); // , FlowLayout.LEFT);
1376     return coloursTab;
1377   }
1378
1379   /**
1380    * Initialises the Overview tabbed panel.
1381    * 
1382    * @return
1383    */
1384   private JPanel initOverviewTab()
1385   {
1386     JPanel overviewPanel = new JPanel();
1387     overviewPanel.setBorder(new TitledBorder(
1388             MessageManager.getString("label.overview_settings")));
1389
1390     gapColour.setFont(LABEL_FONT);
1391     // fixing the border colours stops apparent colour bleed from the panel
1392     gapColour.setBorder(
1393             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1394     gapColour.setPreferredSize(new Dimension(40, 20));
1395     gapColour.addMouseListener(new MouseAdapter()
1396     {
1397       @Override
1398       public void mousePressed(MouseEvent e)
1399       {
1400         gapColour_actionPerformed(gapColour);
1401       }
1402     });
1403
1404     hiddenColour.setFont(LABEL_FONT);
1405     // fixing the border colours stops apparent colour bleed from the panel
1406     hiddenColour.setBorder(
1407             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1408     hiddenColour.setPreferredSize(new Dimension(40, 20));
1409     hiddenColour.addMouseListener(new MouseAdapter()
1410     {
1411       @Override
1412       public void mousePressed(MouseEvent e)
1413       {
1414         hiddenColour_actionPerformed(hiddenColour);
1415       }
1416     });
1417
1418     useLegacyGap = new JCheckBox(
1419             MessageManager.getString("label.ov_legacy_gap"));
1420     useLegacyGap.setFont(LABEL_FONT);
1421     useLegacyGap.setHorizontalAlignment(SwingConstants.LEFT);
1422     useLegacyGap.setVerticalTextPosition(SwingConstants.TOP);
1423     gapLabel = new JLabel(MessageManager.getString("label.gap_colour"));
1424     gapLabel.setFont(LABEL_FONT);
1425     gapLabel.setHorizontalAlignment(SwingConstants.LEFT);
1426     gapLabel.setVerticalTextPosition(SwingConstants.TOP);
1427     showHiddenAtStart = new JCheckBox(
1428             MessageManager.getString("label.ov_show_hide_default"));
1429     showHiddenAtStart.setFont(LABEL_FONT);
1430     showHiddenAtStart.setHorizontalAlignment(SwingConstants.LEFT);
1431     showHiddenAtStart.setVerticalTextPosition(SwingConstants.TOP);
1432     JLabel hiddenLabel = new JLabel(
1433             MessageManager.getString("label.hidden_colour"));
1434     hiddenLabel.setFont(LABEL_FONT);
1435     hiddenLabel.setHorizontalAlignment(SwingConstants.LEFT);
1436     hiddenLabel.setVerticalTextPosition(SwingConstants.TOP);
1437
1438     useLegacyGap.addActionListener(new ActionListener()
1439     {
1440       @Override
1441       public void actionPerformed(ActionEvent e)
1442       {
1443         useLegacyGaps_actionPerformed(e);
1444       }
1445     });
1446
1447     overviewPanel.setLayout(new GridBagLayout());
1448     GridBagConstraints c1 = new GridBagConstraints();
1449
1450     c1.fill = GridBagConstraints.HORIZONTAL;
1451     c1.gridx = 0;
1452     c1.gridy = 0;
1453     c1.weightx = 1;
1454     c1.ipady = 20;
1455     c1.anchor = GridBagConstraints.FIRST_LINE_START;
1456     overviewPanel.add(useLegacyGap, c1);
1457
1458     GridBagConstraints c2 = new GridBagConstraints();
1459     c2.fill = GridBagConstraints.HORIZONTAL;
1460     c2.gridx = 1;
1461     c2.gridy = 0;
1462     c2.insets = new Insets(0, 15, 0, 10);
1463     overviewPanel.add(gapLabel, c2);
1464
1465     GridBagConstraints c3 = new GridBagConstraints();
1466     c3.fill = GridBagConstraints.HORIZONTAL;
1467     c3.gridx = 2;
1468     c3.gridy = 0;
1469     c3.insets = new Insets(0, 0, 0, 15);
1470     overviewPanel.add(gapColour, c3);
1471
1472     GridBagConstraints c4 = new GridBagConstraints();
1473     c4.fill = GridBagConstraints.HORIZONTAL;
1474     c4.gridx = 0;
1475     c4.gridy = 1;
1476     c4.weightx = 1;
1477     overviewPanel.add(showHiddenAtStart, c4);
1478
1479     GridBagConstraints c5 = new GridBagConstraints();
1480     c5.fill = GridBagConstraints.HORIZONTAL;
1481     c5.gridx = 1;
1482     c5.gridy = 1;
1483     c5.insets = new Insets(0, 15, 0, 10);
1484     overviewPanel.add(hiddenLabel, c5);
1485
1486     GridBagConstraints c6 = new GridBagConstraints();
1487     c6.fill = GridBagConstraints.HORIZONTAL;
1488     c6.gridx = 2;
1489     c6.gridy = 1;
1490     c6.insets = new Insets(0, 0, 0, 15);
1491     overviewPanel.add(hiddenColour, c6);
1492
1493     JButton resetButton = new JButton(
1494             MessageManager.getString("label.reset_to_defaults"));
1495
1496     resetButton.addActionListener(new ActionListener()
1497     {
1498       @Override
1499       public void actionPerformed(ActionEvent e)
1500       {
1501         resetOvDefaults_actionPerformed(e);
1502       }
1503     });
1504
1505     GridBagConstraints c7 = new GridBagConstraints();
1506     c7.fill = GridBagConstraints.NONE;
1507     c7.gridx = 0;
1508     c7.gridy = 2;
1509     c7.insets = new Insets(10, 0, 0, 0);
1510     c7.anchor = GridBagConstraints.WEST;
1511     overviewPanel.add(resetButton, c7);
1512
1513     // Add padding so the panel doesn't look ridiculous
1514     JPanel spacePanel = new JPanel();
1515     overviewPanel.add(spacePanel,
1516             new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0,
1517                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
1518                     new Insets(0, 0, 0, 5), 0, 0));
1519
1520     return overviewPanel;
1521   }
1522
1523   /**
1524    * Initialises the Structure tabbed panel.
1525    * 
1526    * @return
1527    */
1528   private JPanel initStructureTab()
1529   {
1530     structureTab = new JPanel();
1531
1532     structureTab.setBorder(new TitledBorder(
1533             MessageManager.getString("label.structure_options")));
1534     structureTab.setLayout(null);
1535     final int width = 400;
1536     final int height = 22;
1537     final int lineSpacing = 25;
1538     int ypos = 15;
1539
1540     structFromPdb.setFont(LABEL_FONT);
1541     structFromPdb
1542             .setText(MessageManager.getString("label.struct_from_pdb"));
1543     structFromPdb.setBounds(new Rectangle(5, ypos, width, height));
1544     structFromPdb.addActionListener(new ActionListener()
1545     {
1546       @Override
1547       public void actionPerformed(ActionEvent e)
1548       {
1549         boolean selected = structFromPdb.isSelected();
1550         // enable other options only when the first is checked
1551         useRnaView.setEnabled(selected);
1552         addSecondaryStructure.setEnabled(selected);
1553         addTempFactor.setEnabled(selected);
1554       }
1555     });
1556     structureTab.add(structFromPdb);
1557
1558     // indent checkboxes that are conditional on the first one
1559     ypos += lineSpacing;
1560     useRnaView.setFont(LABEL_FONT);
1561     useRnaView.setText(MessageManager.getString("label.use_rnaview"));
1562     useRnaView.setBounds(new Rectangle(25, ypos, width, height));
1563     structureTab.add(useRnaView);
1564
1565     ypos += lineSpacing;
1566     addSecondaryStructure.setFont(LABEL_FONT);
1567     addSecondaryStructure
1568             .setText(MessageManager.getString("label.autoadd_secstr"));
1569     addSecondaryStructure.setBounds(new Rectangle(25, ypos, width, height));
1570     structureTab.add(addSecondaryStructure);
1571
1572     ypos += lineSpacing;
1573     addTempFactor.setFont(LABEL_FONT);
1574     addTempFactor.setText(MessageManager.getString("label.autoadd_temp"));
1575     addTempFactor.setBounds(new Rectangle(25, ypos, width, height));
1576     structureTab.add(addTempFactor);
1577
1578     ypos += lineSpacing;
1579     JLabel viewerLabel = new JLabel();
1580     viewerLabel.setFont(LABEL_FONT);
1581     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
1582     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
1583     viewerLabel.setBounds(new Rectangle(10, ypos, 200, height));
1584     structureTab.add(viewerLabel);
1585
1586     structViewer.setFont(LABEL_FONT);
1587     structViewer.setBounds(new Rectangle(160, ypos, 120, height));
1588     structViewer.addItem(ViewerType.JMOL.name());
1589     structViewer.addItem(ViewerType.CHIMERA.name());
1590     structViewer.addActionListener(new ActionListener()
1591     {
1592       @Override
1593       public void actionPerformed(ActionEvent e)
1594       {
1595         structureViewer_actionPerformed(
1596                 (String) structViewer.getSelectedItem());
1597       }
1598     });
1599     structureTab.add(structViewer);
1600
1601     ypos += lineSpacing;
1602     JLabel pathLabel = new JLabel();
1603     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
1604     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1605     pathLabel.setText(MessageManager.getString("label.chimera_path"));
1606     pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
1607     structureTab.add(pathLabel);
1608
1609     chimeraPath.setFont(LABEL_FONT);
1610     chimeraPath.setText("");
1611     final String tooltip = JvSwingUtils.wrapTooltip(true,
1612             MessageManager.getString("label.chimera_path_tip"));
1613     chimeraPath.setToolTipText(tooltip);
1614     chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
1615     chimeraPath.addMouseListener(new MouseAdapter()
1616     {
1617       @Override
1618       public void mouseClicked(MouseEvent e)
1619       {
1620         if (e.getClickCount() == 2)
1621         {
1622           String chosen = openFileChooser();
1623           if (chosen != null)
1624           {
1625             chimeraPath.setText(chosen);
1626           }
1627         }
1628       }
1629     });
1630     structureTab.add(chimeraPath);
1631
1632     ypos += lineSpacing;
1633     nwMapping.setFont(LABEL_FONT);
1634     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1635     siftsMapping.setFont(LABEL_FONT);
1636     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1637     mappingMethod.add(nwMapping);
1638     mappingMethod.add(siftsMapping);
1639     JPanel mappingPanel = new JPanel();
1640     mappingPanel.setFont(LABEL_FONT);
1641     TitledBorder mmTitledBorder = new TitledBorder(
1642             MessageManager.getString("label.mapping_method"));
1643     mmTitledBorder.setTitleFont(LABEL_FONT);
1644     mappingPanel.setBorder(mmTitledBorder);
1645     mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
1646     // GridLayout mappingLayout = new GridLayout();
1647     mappingPanel.setLayout(new GridLayout());
1648     mappingPanel.add(nwMapping);
1649     mappingPanel.add(siftsMapping);
1650     structureTab.add(mappingPanel);
1651
1652     ypos += lineSpacing;
1653     ypos += lineSpacing;
1654     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1655             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1656     docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
1657     structureTab.add(docFieldPref);
1658
1659     return structureTab;
1660   }
1661
1662   /**
1663    * Action on choosing a structure viewer from combobox options.
1664    * 
1665    * @param selectedItem
1666    */
1667   protected void structureViewer_actionPerformed(String selectedItem)
1668   {
1669   }
1670
1671   /**
1672    * Show a dialog for the user to choose a file. Returns the chosen path, or
1673    * null on Cancel.
1674    * 
1675    * @return
1676    */
1677   protected String openFileChooser()
1678   {
1679     String choice = null;
1680     JFileChooser chooser = new JFileChooser();
1681
1682     // chooser.setFileView(new JalviewFileView());
1683     chooser.setDialogTitle(
1684             MessageManager.getString("label.open_local_file"));
1685     chooser.setToolTipText(MessageManager.getString("action.open"));
1686
1687     int value = chooser.showOpenDialog(this);
1688
1689     if (value == JFileChooser.APPROVE_OPTION)
1690     {
1691       choice = chooser.getSelectedFile().getPath();
1692     }
1693     return choice;
1694   }
1695
1696   /**
1697    * Validate the structure tab preferences; if invalid, set focus on this tab.
1698    * 
1699    * @param e
1700    */
1701   protected boolean validateStructure(FocusEvent e)
1702   {
1703     if (!validateStructure())
1704     {
1705       e.getComponent().requestFocusInWindow();
1706       return false;
1707     }
1708     return true;
1709   }
1710
1711   protected boolean validateStructure()
1712   {
1713     return false;
1714   }
1715
1716   /**
1717    * Initialises the Visual tabbed panel.
1718    * 
1719    * @return
1720    */
1721   private JPanel initVisualTab()
1722   {
1723     JPanel visualTab = new JPanel();
1724     visualTab.setBorder(new TitledBorder(
1725             MessageManager.getString("action.open_new_alignment")));
1726     visualTab.setLayout(null);
1727     fullScreen.setFont(LABEL_FONT);
1728     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
1729     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
1730     fullScreen.setText(MessageManager.getString("label.maximize_window"));
1731     quality.setEnabled(false);
1732     quality.setFont(LABEL_FONT);
1733     quality.setHorizontalAlignment(SwingConstants.RIGHT);
1734     quality.setHorizontalTextPosition(SwingConstants.LEFT);
1735     quality.setSelected(true);
1736     quality.setText(MessageManager.getString("label.quality"));
1737     conservation.setEnabled(false);
1738     conservation.setFont(LABEL_FONT);
1739     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
1740     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
1741     conservation.setSelected(true);
1742     conservation.setText(MessageManager.getString("label.conservation"));
1743     identity.setEnabled(false);
1744     identity.setFont(LABEL_FONT);
1745     identity.setHorizontalAlignment(SwingConstants.RIGHT);
1746     identity.setHorizontalTextPosition(SwingConstants.LEFT);
1747     identity.setSelected(true);
1748     identity.setText(MessageManager.getString("label.consensus"));
1749     showOccupancy.setFont(LABEL_FONT);
1750     showOccupancy.setEnabled(false);
1751     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
1752     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
1753     showOccupancy.setSelected(true);
1754     showOccupancy.setText(MessageManager.getString("label.occupancy"));
1755
1756     JLabel showGroupbits = new JLabel();
1757     showGroupbits.setFont(LABEL_FONT);
1758     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
1759     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
1760     showGroupbits
1761             .setText(MessageManager.getString("action.show_group") + ":");
1762     JLabel showConsensbits = new JLabel();
1763     showConsensbits.setFont(LABEL_FONT);
1764     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
1765     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
1766     showConsensbits
1767             .setText(MessageManager.getString("label.consensus") + ":");
1768     showConsensHistogram.setEnabled(false);
1769     showConsensHistogram.setFont(LABEL_FONT);
1770     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
1771     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
1772     showConsensHistogram.setSelected(true);
1773     showConsensHistogram
1774             .setText(MessageManager.getString("label.histogram"));
1775     showConsensLogo.setEnabled(false);
1776     showConsensLogo.setFont(LABEL_FONT);
1777     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
1778     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
1779     showConsensLogo.setSelected(true);
1780     showConsensLogo.setText(MessageManager.getString("label.logo"));
1781     showGroupConsensus.setEnabled(false);
1782     showGroupConsensus.setFont(LABEL_FONT);
1783     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
1784     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
1785     showGroupConsensus.setSelected(true);
1786     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
1787     showGroupConservation.setEnabled(false);
1788     showGroupConservation.setFont(LABEL_FONT);
1789     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
1790     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
1791     showGroupConservation.setSelected(true);
1792     showGroupConservation
1793             .setText(MessageManager.getString("label.conservation"));
1794     showNpTooltip.setEnabled(true);
1795     showNpTooltip.setFont(LABEL_FONT);
1796     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1797     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1798     showNpTooltip.setSelected(true);
1799     showNpTooltip.setText(
1800             MessageManager.getString("label.non_positional_features"));
1801     showDbRefTooltip.setEnabled(true);
1802     showDbRefTooltip.setFont(LABEL_FONT);
1803     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1804     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1805     showDbRefTooltip.setSelected(true);
1806     showDbRefTooltip
1807             .setText(MessageManager.getString("label.database_references"));
1808     annotations.setFont(LABEL_FONT);
1809     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
1810     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
1811     annotations.setSelected(true);
1812     annotations.setText(MessageManager.getString("label.show_annotations"));
1813     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
1814     annotations.addActionListener(new ActionListener()
1815     {
1816       @Override
1817       public void actionPerformed(ActionEvent e)
1818       {
1819         annotations_actionPerformed(e);
1820       }
1821     });
1822     identity.addActionListener(new ActionListener()
1823     {
1824       @Override
1825       public void actionPerformed(ActionEvent e)
1826       {
1827         annotations_actionPerformed(e);
1828       }
1829     });
1830     showGroupConsensus.addActionListener(new ActionListener()
1831     {
1832       @Override
1833       public void actionPerformed(ActionEvent e)
1834       {
1835         annotations_actionPerformed(e);
1836       }
1837     });
1838     showUnconserved.setFont(LABEL_FONT);
1839     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
1840     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
1841     showUnconserved.setSelected(true);
1842     showUnconserved
1843             .setText(MessageManager.getString("action.show_unconserved"));
1844     showUnconserved.addActionListener(new ActionListener()
1845     {
1846       @Override
1847       public void actionPerformed(ActionEvent e)
1848       {
1849         showunconserved_actionPerformed(e);
1850       }
1851     });
1852
1853     // TODO these are not yet added to / action from Preferences
1854     // JCheckBox shareSelections = new JCheckBox();
1855     // shareSelections.setFont(verdana11);
1856     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
1857     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
1858     // shareSelections.setSelected(true);
1859     // shareSelections.setText(MessageManager
1860     // .getString("label.share_selection_across_views"));
1861     // JCheckBox followHighlight = new JCheckBox();
1862     // followHighlight.setFont(verdana11);
1863     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
1864     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
1865     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
1866     // followHighlight.setSelected(true);
1867     // followHighlight.setText(MessageManager
1868     // .getString("label.scroll_highlighted_regions"));
1869
1870     seqLimit.setFont(LABEL_FONT);
1871     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
1872     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
1873     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
1874     smoothFont.setFont(LABEL_FONT);
1875     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
1876     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
1877     smoothFont.setText(MessageManager.getString("label.smooth_font"));
1878     scaleProteinToCdna.setFont(LABEL_FONT);
1879     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
1880     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
1881     scaleProteinToCdna.setText(
1882             MessageManager.getString("label.scale_protein_to_cdna"));
1883     scaleProteinToCdna.setToolTipText(
1884             MessageManager.getString("label.scale_protein_to_cdna_tip"));
1885     JLabel gapLabel = new JLabel();
1886     gapLabel.setFont(LABEL_FONT);
1887     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1888     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
1889     JLabel fontLabel = new JLabel();
1890     fontLabel.setFont(LABEL_FONT);
1891     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1892     fontLabel.setText(MessageManager.getString("label.font"));
1893     fontSizeCB.setFont(LABEL_FONT);
1894     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
1895     fontStyleCB.setFont(LABEL_FONT);
1896     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
1897     fontNameCB.setFont(LABEL_FONT);
1898     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
1899     gapSymbolCB.setFont(LABEL_FONT);
1900     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
1901     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
1902     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
1903     gapSymbolCB.setRenderer(dlcr);
1904
1905     startupCheckbox.setText(MessageManager.getString("action.open_file"));
1906     startupCheckbox.setFont(LABEL_FONT);
1907     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
1908     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
1909     startupCheckbox.setSelected(true);
1910     startupFileTextfield.setFont(LABEL_FONT);
1911     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
1912     final String tooltip = JvSwingUtils.wrapTooltip(true,
1913             MessageManager.getString("label.double_click_to_browse"));
1914     startupFileTextfield.setToolTipText(tooltip);
1915     startupFileTextfield.addMouseListener(new MouseAdapter()
1916     {
1917       @Override
1918       public void mouseClicked(MouseEvent e)
1919       {
1920         if (e.getClickCount() > 1)
1921         {
1922           startupFileTextfield_mouseClicked();
1923         }
1924       }
1925     });
1926
1927     sortby.setFont(LABEL_FONT);
1928     sortby.setBounds(new Rectangle(172, 260, 155, 21));
1929     JLabel sortLabel = new JLabel();
1930     sortLabel.setFont(LABEL_FONT);
1931     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1932     sortLabel.setText(MessageManager.getString("label.sort_by"));
1933     sortAnnBy.setFont(LABEL_FONT);
1934     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
1935     JLabel sortAnnLabel = new JLabel();
1936     sortAnnLabel.setFont(LABEL_FONT);
1937     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1938     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
1939     sortAutocalc.setFont(LABEL_FONT);
1940     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
1941
1942     JPanel annsettingsPanel = new JPanel();
1943     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
1944     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
1945     annsettingsPanel.setBorder(new EtchedBorder());
1946     visualTab.add(annsettingsPanel);
1947     Border jb = new EmptyBorder(1, 1, 4, 5);
1948     annotations.setBorder(jb);
1949     showOccupancy.setBorder(jb);
1950     quality.setBorder(jb);
1951     conservation.setBorder(jb);
1952     identity.setBorder(jb);
1953     showConsensbits.setBorder(jb);
1954     showGroupbits.setBorder(jb);
1955     showGroupConsensus.setBorder(jb);
1956     showGroupConservation.setBorder(jb);
1957     showConsensHistogram.setBorder(jb);
1958     showConsensLogo.setBorder(jb);
1959
1960     JPanel autoAnnotSettings = new JPanel();
1961     annsettingsPanel.add(autoAnnotSettings);
1962     autoAnnotSettings.setLayout(new GridLayout(0, 2));
1963     autoAnnotSettings.add(annotations);
1964     autoAnnotSettings.add(quality);
1965     // second row of autoannotation box
1966     autoAnnotSettings = new JPanel();
1967     annsettingsPanel.add(autoAnnotSettings);
1968
1969     autoAnnotSettings.setLayout(new GridLayout(0, 3));
1970     autoAnnotSettings.add(conservation);
1971     autoAnnotSettings.add(identity);
1972     autoAnnotSettings.add(showOccupancy);
1973     autoAnnotSettings.add(showGroupbits);
1974     autoAnnotSettings.add(showGroupConservation);
1975     autoAnnotSettings.add(showGroupConsensus);
1976     autoAnnotSettings.add(showConsensbits);
1977     autoAnnotSettings.add(showConsensHistogram);
1978     autoAnnotSettings.add(showConsensLogo);
1979
1980     JPanel tooltipSettings = new JPanel();
1981     tooltipSettings.setBorder(new TitledBorder(
1982             MessageManager.getString("label.sequence_id_tooltip")));
1983     tooltipSettings.setBounds(173, 140, 220, 62);
1984     tooltipSettings.setLayout(new GridLayout(2, 1));
1985     tooltipSettings.add(showDbRefTooltip);
1986     tooltipSettings.add(showNpTooltip);
1987     visualTab.add(tooltipSettings);
1988
1989     wrap.setFont(LABEL_FONT);
1990     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
1991     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
1992     wrap.setText(MessageManager.getString("label.wrap_alignment"));
1993     rightAlign.setFont(LABEL_FONT);
1994     rightAlign.setForeground(Color.black);
1995     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
1996     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
1997     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
1998     idItalics.setFont(LABEL_FONT_ITALIC);
1999     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
2000     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
2001     idItalics.setText(
2002             MessageManager.getString("label.sequence_name_italics"));
2003     openoverv.setFont(LABEL_FONT);
2004     openoverv.setActionCommand(
2005             MessageManager.getString("label.open_overview"));
2006     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
2007     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
2008     openoverv.setText(MessageManager.getString("label.open_overview"));
2009     JPanel jPanel2 = new JPanel();
2010     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
2011     jPanel2.setLayout(new GridLayout(14, 1));
2012     jPanel2.add(fullScreen);
2013     jPanel2.add(openoverv);
2014     jPanel2.add(seqLimit);
2015     jPanel2.add(rightAlign);
2016     jPanel2.add(fontLabel);
2017     jPanel2.add(showUnconserved);
2018     jPanel2.add(idItalics);
2019     jPanel2.add(smoothFont);
2020     jPanel2.add(scaleProteinToCdna);
2021     jPanel2.add(gapLabel);
2022     jPanel2.add(wrap);
2023     jPanel2.add(sortLabel);
2024     jPanel2.add(sortAnnLabel);
2025     jPanel2.add(startupCheckbox);
2026     visualTab.add(jPanel2);
2027     visualTab.add(startupFileTextfield);
2028     visualTab.add(sortby);
2029     visualTab.add(sortAnnBy);
2030     visualTab.add(sortAutocalc);
2031     visualTab.add(gapSymbolCB);
2032     visualTab.add(fontNameCB);
2033     visualTab.add(fontSizeCB);
2034     visualTab.add(fontStyleCB);
2035     return visualTab;
2036   }
2037
2038   /**
2039    * Load the saved Backups options EXCEPT "Enabled" and "Scheme"
2040    */
2041
2042   protected void loadLastSavedBackupsOptions()
2043   {
2044     BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
2045             .getSavedBackupEntry();
2046     enableBackupFiles
2047             .setSelected(Cache.getDefault(BackupFiles.ENABLED, true));
2048
2049     BackupFilesPresetEntry backupfilesCustomEntry = BackupFilesPresetEntry
2050             .createBackupFilesPresetEntry(Cache
2051                     .getDefault(BackupFilesPresetEntry.CUSTOMCONFIG, null));
2052     if (backupfilesCustomEntry == null)
2053     {
2054       backupfilesCustomEntry = BackupFilesPresetEntry.backupfilesPresetEntriesValues
2055               .get(BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT);
2056     }
2057     BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
2058             BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM,
2059             backupfilesCustomEntry);
2060
2061     setComboIntStringKey(backupfilesPresetsCombo,
2062             Cache.getDefault(BackupFiles.NS + "_PRESET",
2063                     BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT));
2064
2065     backupsSetOptions(savedPreset);
2066
2067     backupsOptionsSetEnabled();
2068     updateBackupFilesExampleLabel();
2069   }
2070
2071   private boolean warnAboutSuffixReverseChange()
2072   {
2073     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
2074             .getSavedBackupEntry();
2075     boolean savedSuffixReverse = bfpe.reverse;
2076     int savedSuffixDigits = bfpe.digits;
2077     String savedSuffixTemplate = bfpe.suffix;
2078
2079     boolean nowSuffixReverse = suffixReverse.isSelected();
2080     int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3);
2081     String nowSuffixTemplate = suffixTemplate.getText();
2082     return nowSuffixReverse != savedSuffixReverse
2083             && nowSuffixDigits == savedSuffixDigits
2084             && nowSuffixTemplate != null
2085             && nowSuffixTemplate.equals(savedSuffixTemplate);
2086   }
2087
2088   /**
2089    * Initialises the Backups tabbed panel.
2090    * 
2091    * @return
2092    */
2093   private JPanel initBackupsTab()
2094   {
2095     JPanel backupsTab = new JPanel();
2096     backupsTab.setBorder(new TitledBorder(
2097             MessageManager.getString("label.backup_files")));
2098     backupsTab.setLayout(new GridBagLayout());
2099
2100     GridBagConstraints gbc = new GridBagConstraints();
2101     gbc.weightx = 0.0;
2102     gbc.weighty = 0.0;
2103     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2104     gbc.fill = GridBagConstraints.NONE;
2105
2106     initBackupsTabPresetsPanel();
2107     initBackupsTabSuffixPanel();
2108     initBackupsTabKeepFilesPanel();
2109     initBackupsTabFilenameExamplesPanel();
2110
2111     enableBackupFiles.setFont(LABEL_FONT_BOLD);
2112     enableBackupFiles
2113             .setText(MessageManager.getString("label.enable_backupfiles"));
2114     enableBackupFiles.addActionListener(new ActionListener()
2115     {
2116       @Override
2117       public void actionPerformed(ActionEvent e)
2118       {
2119         // enable other options only when the first is checked
2120         backupsOptionsSetEnabled();
2121       }
2122     });
2123
2124     // enable checkbox 1 col
2125     gbc.gridwidth = 1;
2126     gbc.gridheight = 1;
2127     gbc.gridx = 0;
2128     gbc.gridy = 0; // row 0
2129     backupsTab.add(enableBackupFiles, gbc);
2130
2131     // summary of scheme box (over two rows)
2132     gbc.gridx = 1;
2133     gbc.weightx = 0.0;
2134     gbc.gridheight = 2;
2135     gbc.anchor = GridBagConstraints.FIRST_LINE_END;
2136     gbc.fill = GridBagConstraints.BOTH;
2137     backupsTab.add(exampleFilesPanel, gbc);
2138     gbc.gridheight = 1;
2139     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2140     gbc.fill = GridBagConstraints.NONE;
2141
2142     // fill empty space on right
2143     gbc.gridx++;
2144     gbc.weightx = 1.0;
2145     backupsTab.add(new JPanel(), gbc);
2146
2147     // schemes box
2148     gbc.weightx = 0.0;
2149     gbc.gridx = 0;
2150     gbc.gridy++; // row 1
2151     backupsTab.add(presetsPanel, gbc);
2152
2153     // now using whole row
2154     gbc.gridwidth = 2;
2155     gbc.gridheight = 1;
2156     // keep files box
2157     gbc.gridx = 0;
2158     gbc.gridy++; // row 2
2159     backupsTab.add(keepfilesPanel, gbc);
2160
2161     // filename strategy box
2162     gbc.gridy++; // row 3
2163     backupsTab.add(suffixPanel, gbc);
2164
2165     // fill empty space
2166     gbc.gridy++; // row 4
2167     gbc.weighty = 1.0;
2168     backupsTab.add(new JPanel(), gbc);
2169
2170     backupsOptionsSetEnabled();
2171     return backupsTab;
2172   }
2173
2174   private JPanel initBackupsTabPresetsPanel()
2175   {
2176
2177     String title = MessageManager.getString("label.schemes");
2178
2179     presetsPanel.setLayout(new GridBagLayout());
2180
2181     GridBagConstraints gbc = new GridBagConstraints();
2182     gbc.weightx = 0.0;
2183     gbc.weighty = 0.0;
2184     gbc.anchor = GridBagConstraints.BASELINE_LEADING;
2185     gbc.fill = GridBagConstraints.NONE;
2186     gbc.gridwidth = 1;
2187     gbc.gridheight = 1;
2188
2189     // "Scheme: "
2190     gbc.gridx = 0;
2191     gbc.gridy = 0;
2192
2193     presetsComboLabel = new JLabel(title + ":");
2194     presetsPanel.add(presetsComboLabel, gbc);
2195
2196     List<Object> entries = Arrays.asList(
2197             (Object[]) BackupFilesPresetEntry.backupfilesPresetEntries);
2198     List<String> tooltips = Arrays.asList(
2199             BackupFilesPresetEntry.backupfilesPresetEntryDescriptions);
2200     backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries,
2201             tooltips);
2202     /*
2203     for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++)
2204     {
2205       backupfilesPresetsCombo
2206               .addItem(BackupFilesPresetEntry.backupfilesPresetEntries[i]);
2207     }
2208     */
2209
2210     backupfilesPresetsCombo.addActionListener(new ActionListener()
2211     {
2212       @Override
2213       public void actionPerformed(ActionEvent e)
2214       {
2215         int key = getComboIntStringKey(backupfilesPresetsCombo);
2216         if (!customiseCheckbox.isSelected())
2217         {
2218           backupfilesPresetsComboLastSelected = key;
2219         }
2220         if (key == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
2221         {
2222           if (customiseCheckbox.isSelected())
2223           {
2224             // got here by clicking on customiseCheckbox so don't change the
2225             // values
2226             backupfilesCustomOptionsSetEnabled();
2227           }
2228           else
2229           {
2230             backupsTabUpdatePresets();
2231             backupfilesCustomOptionsSetEnabled();
2232           }
2233         }
2234         else
2235         {
2236           customiseCheckbox.setSelected(false);
2237           backupsTabUpdatePresets();
2238           backupfilesCustomOptionsSetEnabled();
2239         }
2240       }
2241     });
2242
2243     // dropdown list of preset schemes
2244     gbc.gridx = 1;
2245     presetsPanel.add(backupfilesPresetsCombo, gbc);
2246
2247     revertButton.setText(MessageManager.getString("label.cancel_changes"));
2248     revertButton.setToolTipText(
2249             MessageManager.getString("label.cancel_changes_description"));
2250     revertButton.addActionListener(new ActionListener()
2251     {
2252       @Override
2253       public void actionPerformed(ActionEvent e)
2254       {
2255         backupsSetOptions(
2256                 BackupFilesPresetEntry.backupfilesPresetEntriesValues.get(
2257                         BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM));
2258         backupfilesCustomOptionsSetEnabled();
2259       }
2260
2261     });
2262     revertButton.setFont(LABEL_FONT);
2263
2264     customiseCheckbox.setFont(LABEL_FONT);
2265     customiseCheckbox.setText(MessageManager.getString("label.customise"));
2266     customiseCheckbox.addActionListener(new ActionListener()
2267     {
2268       @Override
2269       public void actionPerformed(ActionEvent e)
2270       {
2271         int currently = getComboIntStringKey(backupfilesPresetsCombo);
2272         if (customiseCheckbox.isSelected())
2273         {
2274           backupfilesPresetsComboLastSelected = currently;
2275           setComboIntStringKey(backupfilesPresetsCombo,
2276                   BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
2277         }
2278         else
2279         {
2280           setComboIntStringKey(backupfilesPresetsCombo,
2281                   backupfilesPresetsComboLastSelected);
2282
2283         }
2284         backupfilesCustomOptionsSetEnabled();
2285       }
2286     });
2287     customiseCheckbox.setToolTipText(
2288             MessageManager.getString("label.customise_description"));
2289
2290     // customise checkbox
2291     gbc.gridx = 0;
2292     gbc.gridy++;
2293     presetsPanel.add(customiseCheckbox, gbc);
2294
2295     // "Cancel changes" button (aligned with combo box above)
2296     gbc.gridx = 1;
2297     presetsPanel.add(revertButton, gbc);
2298
2299     return presetsPanel;
2300   }
2301
2302   private JPanel initBackupsTabFilenameExamplesPanel()
2303   {
2304     String title = MessageManager.getString("label.scheme_examples");
2305     TitledBorder tb = new TitledBorder(title);
2306     exampleFilesPanel.setBorder(tb);
2307     exampleFilesPanel.setLayout(new GridBagLayout());
2308
2309     backupfilesExampleLabel.setEditable(false);
2310     backupfilesExampleLabel
2311             .setBackground(exampleFilesPanel.getBackground());
2312
2313     updateBackupFilesExampleLabel();
2314
2315     GridBagConstraints gbc = new GridBagConstraints();
2316     gbc.weightx = 1.0;
2317     gbc.weighty = 1.0;
2318     gbc.fill = GridBagConstraints.NONE;
2319     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2320
2321     exampleFilesPanel.add(backupfilesExampleLabel, gbc);
2322     return exampleFilesPanel;
2323   }
2324
2325   private void backupsTabUpdatePresets()
2326   {
2327     IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo
2328             .getSelectedItem();
2329     int key = entry.k;
2330     String value = entry.v;
2331
2332     if (BackupFilesPresetEntry.backupfilesPresetEntriesValues
2333             .containsKey(key))
2334     {
2335       backupsSetOptions(
2336               BackupFilesPresetEntry.backupfilesPresetEntriesValues
2337                       .get(key));
2338     }
2339     else
2340     {
2341       Cache.log.error(
2342               "Preset '" + value + "' [key:" + key + "] not implemented");
2343     }
2344
2345     // Custom options will now be enabled when the customiseCheckbox is checked
2346     // (performed above)
2347     // backupfilesCustomOptionsSetEnabled();
2348     updateBackupFilesExampleLabel();
2349   }
2350
2351   protected int getComboIntStringKey(
2352           JComboBox<Object> backupfilesPresetsCombo2)
2353   {
2354     IntKeyStringValueEntry e;
2355     try
2356     {
2357       e = (IntKeyStringValueEntry) backupfilesPresetsCombo2
2358               .getSelectedItem();
2359     } catch (Exception ex)
2360     {
2361       Cache.log.error(
2362               "Problem casting Combo entry to IntKeyStringValueEntry.");
2363       e = null;
2364     }
2365     return e != null ? e.k : 0;
2366   }
2367
2368   protected void setComboIntStringKey(
2369           JComboBox<Object> backupfilesPresetsCombo2, int key)
2370   {
2371     for (int i = 0; i < backupfilesPresetsCombo2.getItemCount(); i++)
2372     {
2373       IntKeyStringValueEntry e;
2374       try
2375       {
2376         e = (IntKeyStringValueEntry) backupfilesPresetsCombo2.getItemAt(i);
2377       } catch (Exception ex)
2378       {
2379         Cache.log.error(
2380                 "Problem casting Combo entry to IntKeyStringValueEntry. Skipping item. ");
2381         continue;
2382       }
2383       if (e.k == key)
2384       {
2385         backupfilesPresetsCombo2.setSelectedIndex(i);
2386         break;
2387       }
2388     }
2389     // backupsTabUpdatePresets();
2390   }
2391
2392   private JPanel initBackupsTabSuffixPanel()
2393   {
2394     suffixPanel.setBorder(new TitledBorder(
2395             MessageManager.getString("label.backup_filename_strategy")));
2396     suffixPanel.setLayout(new GridBagLayout());
2397
2398     suffixTemplateLabel
2399             .setText(MessageManager.getString("label.append_to_filename"));
2400     suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
2401     suffixTemplateLabel.setFont(LABEL_FONT);
2402
2403     final String tooltip = JvSwingUtils.wrapTooltip(true,
2404             MessageManager.getString("label.append_to_filename_tooltip"));
2405     suffixTemplate.setToolTipText(tooltip);
2406     suffixTemplate.addActionListener(new ActionListener()
2407     {
2408       @Override
2409       public void actionPerformed(ActionEvent e)
2410       {
2411         updateBackupFilesExampleLabel();
2412         backupfilesCustomOptionsSetEnabled();
2413         backupfilesRevertButtonSetEnabled(true);
2414       }
2415
2416     });
2417     suffixTemplate.addKeyListener(new KeyListener()
2418     {
2419       @Override
2420       public void keyReleased(KeyEvent e)
2421       {
2422         updateBackupFilesExampleLabel();
2423         backupfilesCustomOptionsSetEnabled();
2424         backupfilesRevertButtonSetEnabled(true);
2425       }
2426
2427       @Override
2428       public void keyPressed(KeyEvent e)
2429       {
2430       }
2431
2432       // disable use of ':' or '/' or '\'
2433       @Override
2434       public void keyTyped(KeyEvent e)
2435       {
2436         char c = e.getKeyChar();
2437         if (c == ':' || c == '/' || c == '\\')
2438         {
2439           // don't process ':' or '/' or '\'
2440           e.consume();
2441         }
2442       }
2443
2444     });
2445
2446     // digits spinner
2447     suffixDigitsLabel
2448             .setText(MessageManager.getString("label.index_digits"));
2449     suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
2450     suffixDigitsLabel.setFont(LABEL_FONT);
2451     ChangeListener c = new ChangeListener()
2452     {
2453       @Override
2454       public void stateChanged(ChangeEvent e)
2455       {
2456         backupfilesRevertButtonSetEnabled(true);
2457         updateBackupFilesExampleLabel();
2458       }
2459
2460     };
2461     setIntegerSpinner(suffixDigitsSpinner, BackupFilesPresetEntry.DIGITSMIN,
2462             BackupFilesPresetEntry.DIGITSMAX, 3, c);
2463
2464     suffixReverse.setLabels(MessageManager.getString("label.reverse_roll"),
2465             MessageManager.getString("label.increment_index"));
2466     suffixReverse.addActionListener(new ActionListener()
2467     {
2468       @Override
2469       public void actionPerformed(ActionEvent e)
2470       {
2471         boolean okay = true;
2472         if (warnAboutSuffixReverseChange())
2473         {
2474           // Warning popup
2475           okay = confirmSuffixReverseChange();
2476         }
2477         if (okay)
2478         {
2479           backupfilesRevertButtonSetEnabled(true);
2480           updateBackupFilesExampleLabel();
2481         }
2482         else
2483         {
2484           boolean savedSuffixReverse = BackupFilesPresetEntry
2485                   .getSavedBackupEntry().reverse;
2486           suffixReverse.setSelected(savedSuffixReverse);
2487         }
2488       }
2489     });
2490
2491     GridBagConstraints sgbc = new GridBagConstraints();
2492
2493     // first row (template text box)
2494     sgbc.anchor = GridBagConstraints.WEST;
2495     sgbc.gridx = 0;
2496     sgbc.gridy = 0;
2497     sgbc.gridwidth = 1;
2498     sgbc.gridheight = 1;
2499     sgbc.weightx = 1.0;
2500     sgbc.weighty = 0.0;
2501     sgbc.fill = GridBagConstraints.NONE;
2502     suffixPanel.add(suffixTemplateLabel, sgbc);
2503
2504     sgbc.gridx = 1;
2505     sgbc.fill = GridBagConstraints.HORIZONTAL;
2506     suffixPanel.add(suffixTemplate, sgbc);
2507
2508     // second row (number of digits spinner)
2509     sgbc.gridy = 1;
2510
2511     sgbc.gridx = 0;
2512     sgbc.fill = GridBagConstraints.NONE;
2513     suffixPanel.add(suffixDigitsLabel, sgbc);
2514
2515     sgbc.gridx = 1;
2516     sgbc.fill = GridBagConstraints.HORIZONTAL;
2517     suffixPanel.add(suffixDigitsSpinner, sgbc);
2518
2519     // third row (forward order radio selection)
2520     sgbc.gridx = 0;
2521     sgbc.gridy = 2;
2522     sgbc.gridwidth = GridBagConstraints.REMAINDER;
2523     sgbc.fill = GridBagConstraints.HORIZONTAL;
2524     suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
2525
2526     // fourth row (reverse order radio selection)
2527     sgbc.gridy = 3;
2528     suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
2529     return suffixPanel;
2530   }
2531
2532   private boolean confirmSuffixReverseChange()
2533   {
2534     boolean ret = false;
2535     String warningMessage = MessageManager
2536             .getString("label.warning_confirm_change_reverse");
2537     int confirm = JvOptionPane.showConfirmDialog(Desktop.desktop,
2538             warningMessage,
2539             MessageManager.getString("label.change_increment_decrement"),
2540             JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
2541
2542     ret = (confirm == JvOptionPane.YES_OPTION);
2543     return ret;
2544   }
2545
2546   private JPanel initBackupsTabKeepFilesPanel()
2547   {
2548     keepfilesPanel.setBorder(
2549             new TitledBorder(MessageManager.getString("label.keep_files")));
2550     keepfilesPanel.setLayout(new GridBagLayout());
2551
2552     backupfilesKeepAll.setLabels(
2553             MessageManager.getString("label.keep_all_backup_files"),
2554             MessageManager.getString(
2555                     "label.keep_only_this_number_of_backup_files"));
2556     backupfilesKeepAll.addTrueActionListener(new ActionListener()
2557     {
2558       @Override
2559       public void actionPerformed(ActionEvent e)
2560       {
2561         backupfilesRevertButtonSetEnabled(true);
2562         updateBackupFilesExampleLabel();
2563       }
2564     });
2565     backupfilesKeepAll.addActionListener(new ActionListener()
2566     {
2567       @Override
2568       public void actionPerformed(ActionEvent e)
2569       {
2570         backupfilesRevertButtonSetEnabled(true);
2571         keepRollMaxOptionsEnabled();
2572         updateBackupFilesExampleLabel();
2573       }
2574     });
2575
2576     ChangeListener c = new ChangeListener()
2577     {
2578       @Override
2579       public void stateChanged(ChangeEvent e)
2580       {
2581         backupfilesRevertButtonSetEnabled(true);
2582         updateBackupFilesExampleLabel();
2583       }
2584
2585     };
2586     setIntegerSpinner(backupfilesRollMaxSpinner,
2587             BackupFilesPresetEntry.ROLLMAXMIN,
2588             BackupFilesPresetEntry.ROLLMAXMAX, 4, true, c);
2589
2590     backupfilesConfirmDelete.setLabels(
2591             MessageManager.getString("label.always_ask"),
2592             MessageManager.getString("label.auto_delete"));
2593     backupfilesConfirmDelete.addActionListener(new ActionListener()
2594     {
2595       @Override
2596       public void actionPerformed(ActionEvent e)
2597       {
2598         backupfilesRevertButtonSetEnabled(true);
2599       }
2600     });
2601     // update the enabled section
2602     keepRollMaxOptionsEnabled();
2603
2604     GridBagConstraints kgbc = new GridBagConstraints();
2605
2606     // first row (template text box)
2607     kgbc.anchor = GridBagConstraints.WEST;
2608     kgbc.gridx = 0;
2609     kgbc.gridy = 0;
2610     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2611     kgbc.gridheight = 1;
2612     kgbc.weightx = 1.0;
2613     kgbc.weighty = 0.0;
2614     kgbc.fill = GridBagConstraints.HORIZONTAL;
2615     keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
2616
2617     // second row
2618     kgbc.gridy = 1;
2619
2620     kgbc.gridx = 0;
2621     kgbc.gridwidth = GridBagConstraints.RELATIVE;
2622     keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
2623
2624     kgbc.gridx = 1;
2625     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2626     keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
2627
2628     // third row (indented)
2629     kgbc.gridy = 2;
2630     kgbc.insets = new Insets(0, 20, 0, 0);
2631
2632     kgbc.gridx = 0;
2633     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2634     kgbc.fill = GridBagConstraints.HORIZONTAL;
2635     kgbc.weightx = 1.0;
2636
2637     JPanel jp = new JPanel();
2638     jp.setLayout(new FlowLayout());
2639     oldBackupFilesLabel.setText(
2640             MessageManager.getString("label.autodelete_old_backup_files"));
2641     oldBackupFilesLabel.setFont(LABEL_FONT);
2642     oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
2643     jp.add(oldBackupFilesLabel);
2644     jp.add(backupfilesConfirmDelete.getTrueButton());
2645     jp.add(backupfilesConfirmDelete.getFalseButton());
2646     keepfilesPanel.add(jp, kgbc);
2647
2648     return keepfilesPanel;
2649   }
2650
2651   protected void updateBackupFilesExampleLabel()
2652   {
2653     int exampleindex = 12;
2654     String base = MessageManager.getString("label.filename") + ".fa";
2655     if (base == null || base.length() == 0)
2656     {
2657       base = "file_name.fa";
2658     }
2659
2660     boolean reverse = suffixReverse.isSelected();
2661     boolean keepAll = backupfilesKeepAll.isSelected();
2662     int rollMax = 4;
2663     String suffix = suffixTemplate.getText();
2664     int digits = 3;
2665
2666     backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
2667     if (suffix == null || suffix.length() == 0)
2668     {
2669       backupfilesExampleLabel
2670               .setText(MessageManager.getString("label.no_backup_files"));
2671       backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
2672       return;
2673     }
2674
2675     rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4);
2676     rollMax = rollMax < 1 ? 1 : rollMax;
2677
2678     if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
2679     {
2680       rollMax = 1;
2681     }
2682
2683     digits = getSpinnerInt(suffixDigitsSpinner, 3);
2684     digits = digits < 1 ? 1 : digits;
2685
2686     int lowersurround = 2;
2687     int uppersurround = 0;
2688     StringBuilder exampleSB = new StringBuilder();
2689     boolean firstLine = true;
2690     int lineNumber = 0;
2691     if (reverse)
2692     {
2693
2694       int min = 1;
2695       int max = keepAll ? exampleindex : rollMax;
2696       for (int index = min; index <= max; index++)
2697       {
2698         if (index == min + lowersurround && index < max - uppersurround - 1)
2699         {
2700           exampleSB.append("\n...");
2701           lineNumber++;
2702         }
2703         else if (index > min + lowersurround && index < max - uppersurround)
2704         {
2705           // nothing
2706         }
2707         else
2708         {
2709           if (firstLine)
2710           {
2711             firstLine = false;
2712           }
2713           else
2714           {
2715             exampleSB.append("\n");
2716             lineNumber++;
2717           }
2718           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
2719                   base, suffix, digits));
2720           if (min == max)
2721           {
2722             // no extra text needed
2723           }
2724           else if (index == min)
2725           {
2726             String newest = MessageManager.getString("label.braced_newest");
2727             if (newest != null && newest.length() > 0)
2728             {
2729               exampleSB.append(" " + newest);
2730             }
2731           }
2732           else if (index == max)
2733           {
2734             String oldest = MessageManager.getString("label.braced_oldest");
2735             if (oldest != null && oldest.length() > 0)
2736             {
2737               exampleSB.append(" " + oldest);
2738             }
2739           }
2740         }
2741       }
2742     }
2743     else
2744     {
2745
2746       int min = (keepAll || exampleindex - rollMax < 0) ? 1
2747               : exampleindex - rollMax + 1;
2748       int max = exampleindex;
2749
2750       for (int index = min; index <= max; index++)
2751       {
2752
2753         if (index == min + lowersurround && index < max - uppersurround - 1)
2754         {
2755           exampleSB.append("\n...");
2756           lineNumber++;
2757         }
2758         else if (index > min + lowersurround && index < max - uppersurround)
2759         {
2760           // nothing
2761         }
2762         else
2763         {
2764           if (firstLine)
2765           {
2766             firstLine = false;
2767           }
2768           else
2769           {
2770             exampleSB.append("\n");
2771             lineNumber++;
2772           }
2773           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
2774                   base, suffix, digits));
2775           if (min == max)
2776           {
2777             // no extra text needed
2778           }
2779           else if (index == min)
2780           {
2781             String oldest = MessageManager.getString("label.braced_oldest");
2782             if (oldest != null && oldest.length() > 0)
2783             {
2784               exampleSB.append(" " + oldest);
2785             }
2786           }
2787           else if (index == max)
2788           {
2789             String newest = MessageManager.getString("label.braced_newest");
2790             if (newest != null && newest.length() > 0)
2791             {
2792               exampleSB.append(" " + newest);
2793             }
2794           }
2795         }
2796       }
2797
2798     }
2799
2800     // add some extra empty lines to pad out the example files box. ugh, please
2801     // tell
2802     // me how to do this better
2803     int remainingLines = lowersurround + uppersurround + 1 - lineNumber;
2804     if (remainingLines > 0)
2805     {
2806       for (int i = 0; i < remainingLines; i++)
2807       {
2808         exampleSB.append("\n ");
2809         lineNumber++;
2810       }
2811     }
2812
2813     backupfilesExampleLabel.setText(exampleSB.toString());
2814   }
2815
2816   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2817           boolean useExistingVal, ChangeListener c)
2818   {
2819     int i = def;
2820     if (useExistingVal)
2821     {
2822       try
2823       {
2824         i = ((Integer) s.getValue()).intValue();
2825       } catch (Exception e)
2826       {
2827         Cache.log.error(
2828                 "Exception casting the initial value of s.getValue()");
2829       }
2830     }
2831
2832     setIntegerSpinner(s, min, max, i, c);
2833   }
2834
2835   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2836           ChangeListener c)
2837   {
2838     // integer spinner for number of digits
2839     if (def > max)
2840     {
2841       max = def;
2842     }
2843     if (def < min)
2844     {
2845       def = min;
2846     }
2847     SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
2848     s.setModel(sModel);
2849
2850     s.addChangeListener(c);
2851
2852   }
2853
2854   protected static int getSpinnerInt(JSpinner s, int def)
2855   {
2856     int i = def;
2857     try
2858     {
2859       s.commitEdit();
2860       i = (Integer) s.getValue();
2861     } catch (Exception e)
2862     {
2863       Cache.log.error("Failed casting (Integer) JSpinner s.getValue()");
2864     }
2865     return i;
2866   }
2867
2868   private void keepRollMaxOptionsEnabled()
2869   {
2870     boolean enabled = backupfilesKeepAll.isEnabled()
2871             && !backupfilesKeepAll.isSelected();
2872     oldBackupFilesLabel.setEnabled(enabled);
2873     backupfilesRollMaxSpinner.setEnabled(enabled);
2874     backupfilesConfirmDelete.setEnabled(enabled);
2875   }
2876
2877   private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
2878   {
2879     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2880             && customiseCheckbox.isSelected() && suffixTemplate.getText()
2881                     .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
2882     keepfilesPanel.setEnabled(enabled);
2883     backupfilesKeepAll.setEnabled(enabled);
2884     oldBackupFilesLabel.setEnabled(enabled);
2885     keepRollMaxOptionsEnabled();
2886   }
2887
2888   private void backupfilesSuffixTemplateDigitsSetEnabled()
2889   {
2890     boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
2891             .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
2892     suffixDigitsLabel.setEnabled(enabled);
2893     suffixDigitsSpinner.setEnabled(enabled);
2894     suffixReverse.setEnabled(enabled);
2895   }
2896
2897   private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
2898   {
2899     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2900             && customiseCheckbox.isSelected();
2901     suffixPanel.setEnabled(enabled);
2902     suffixTemplateLabel.setEnabled(enabled);
2903     suffixTemplate.setEnabled(enabled);
2904     backupfilesSuffixTemplateDigitsSetEnabled();
2905   }
2906
2907   private void backupfilesRevertButtonSetEnabled(boolean tryEnabled)
2908   {
2909     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2910             && customiseCheckbox.isSelected() && backupfilesCustomChanged();
2911     revertButton.setEnabled(enabled);
2912   }
2913
2914   private boolean backupfilesCustomChanged()
2915   {
2916     BackupFilesPresetEntry custom = BackupFilesPresetEntry.backupfilesPresetEntriesValues
2917             .get(BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
2918     BackupFilesPresetEntry current = getBackupfilesCurrentEntry();
2919     return !custom.equals(current);
2920   }
2921
2922   protected BackupFilesPresetEntry getBackupfilesCurrentEntry()
2923   {
2924     String suffix = suffixTemplate.getText();
2925     int digits = getSpinnerInt(suffixDigitsSpinner, 3);
2926     boolean reverse = suffixReverse.isSelected();
2927     boolean keepAll = backupfilesKeepAll.isSelected();
2928     int rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 3);
2929     boolean confirmDelete = backupfilesConfirmDelete.isSelected();
2930
2931     BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits,
2932             reverse, keepAll, rollMax, confirmDelete);
2933
2934     return bfpe;
2935   }
2936
2937   protected void backupfilesCustomOptionsSetEnabled()
2938   {
2939     boolean enabled = customiseCheckbox.isSelected();
2940
2941     backupfilesRevertButtonSetEnabled(enabled);
2942     backupfilesSuffixTemplateSetEnabled(enabled);
2943     backupfilesKeepAllSetEnabled(enabled);
2944   }
2945
2946   private void backupfilesSummarySetEnabled()
2947   {
2948     boolean enabled = enableBackupFiles.isSelected();
2949     backupfilesExampleLabel.setEnabled(enabled);
2950     exampleFilesPanel.setEnabled(enabled);
2951   }
2952
2953   private void backupfilesPresetsSetEnabled()
2954   {
2955     boolean enabled = enableBackupFiles.isSelected();
2956     presetsPanel.setEnabled(enabled);
2957     presetsComboLabel.setEnabled(enabled);
2958     backupfilesPresetsCombo.setEnabled(enabled);
2959     customiseCheckbox.setEnabled(enabled);
2960     revertButton.setEnabled(enabled);
2961   }
2962
2963   protected void backupsOptionsSetEnabled()
2964   {
2965     backupfilesPresetsSetEnabled();
2966     backupfilesSummarySetEnabled();
2967     backupfilesCustomOptionsSetEnabled();
2968   }
2969
2970   protected void backupsSetOptions(String suffix, int digits,
2971           boolean reverse, boolean keepAll, int rollMax,
2972           boolean confirmDelete)
2973   {
2974     suffixTemplate.setText(suffix);
2975     suffixDigitsSpinner.setValue(digits);
2976     suffixReverse.setSelected(reverse);
2977     backupfilesKeepAll.setSelected(keepAll);
2978     backupfilesRollMaxSpinner.setValue(rollMax);
2979     backupfilesConfirmDelete.setSelected(confirmDelete);
2980   }
2981
2982   protected void backupsSetOptions(BackupFilesPresetEntry p)
2983   {
2984     backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax,
2985             p.confirmDelete);
2986   }
2987
2988   protected void autoIdWidth_actionPerformed()
2989   {
2990     // TODO Auto-generated method stub
2991
2992   }
2993
2994   protected void userIdWidth_actionPerformed()
2995   {
2996     // TODO Auto-generated method stub
2997
2998   }
2999
3000   protected void maxColour_actionPerformed(JPanel panel)
3001   {
3002   }
3003
3004   protected void minColour_actionPerformed(JPanel panel)
3005   {
3006   }
3007
3008   protected void gapColour_actionPerformed(JPanel panel)
3009   {
3010   }
3011
3012   protected void hiddenColour_actionPerformed(JPanel panel)
3013   {
3014   }
3015
3016   protected void showunconserved_actionPerformed(ActionEvent e)
3017   {
3018     // TODO Auto-generated method stub
3019
3020   }
3021
3022   protected void useLegacyGaps_actionPerformed(ActionEvent e)
3023   {
3024   }
3025
3026   protected void resetOvDefaults_actionPerformed(ActionEvent e)
3027   {
3028   }
3029
3030   /**
3031    * DOCUMENT ME!
3032    * 
3033    * @param e
3034    *          DOCUMENT ME!
3035    */
3036   public void ok_actionPerformed(ActionEvent e)
3037   {
3038   }
3039
3040   /**
3041    * DOCUMENT ME!
3042    * 
3043    * @param e
3044    *          DOCUMENT ME!
3045    */
3046   public void cancel_actionPerformed(ActionEvent e)
3047   {
3048   }
3049
3050   /**
3051    * DOCUMENT ME!
3052    * 
3053    * @param e
3054    *          DOCUMENT ME!
3055    */
3056   public void annotations_actionPerformed(ActionEvent e)
3057   {
3058   }
3059
3060   /**
3061    * DOCUMENT ME!
3062    */
3063   public void startupFileTextfield_mouseClicked()
3064   {
3065   }
3066
3067   public void newLink_actionPerformed(ActionEvent e)
3068   {
3069
3070   }
3071
3072   public void editLink_actionPerformed(ActionEvent e)
3073   {
3074
3075   }
3076
3077   public void deleteLink_actionPerformed(ActionEvent e)
3078   {
3079
3080   }
3081
3082   public void defaultBrowser_mouseClicked(MouseEvent e)
3083   {
3084
3085   }
3086
3087   public void linkURLList_keyTyped(KeyEvent e)
3088   {
3089
3090   }
3091
3092   public void setProxyAuthEnabled()
3093   {
3094     boolean enabled = proxyAuth.isSelected() && proxyAuth.isEnabled();
3095     proxyAuthUsernameLabel.setEnabled(enabled);
3096     proxyAuthPasswordLabel.setEnabled(enabled);
3097     passwordNotStoredLabel.setEnabled(enabled);
3098     proxyAuthUsernameTB.setEnabled(enabled);
3099     proxyAuthPasswordPB.setEnabled(enabled);
3100   }
3101
3102   public void setCustomProxyEnabled()
3103   {
3104     boolean enabled = customProxy.isSelected();
3105     portLabel.setEnabled(enabled);
3106     serverLabel.setEnabled(enabled);
3107     portLabel2.setEnabled(enabled);
3108     serverLabel2.setEnabled(enabled);
3109     httpLabel.setEnabled(enabled);
3110     httpsLabel.setEnabled(enabled);
3111     proxyServerHttpTB.setEnabled(enabled);
3112     proxyPortHttpTB.setEnabled(enabled);
3113     proxyServerHttpsTB.setEnabled(enabled);
3114     proxyPortHttpsTB.setEnabled(enabled);
3115     proxyAuth.setEnabled(enabled);
3116     setProxyAuthEnabled();
3117   }
3118
3119   public void proxyType_actionPerformed()
3120   {
3121     setCustomProxyEnabled();
3122   }
3123
3124   public void proxyAuth_actionPerformed()
3125   {
3126     setProxyAuthEnabled();
3127   }
3128
3129   /**
3130    * Customer renderer for JTable: supports column of radio buttons
3131    */
3132   public class RadioButtonRenderer extends JRadioButton
3133           implements TableCellRenderer
3134   {
3135     public RadioButtonRenderer()
3136     {
3137       setHorizontalAlignment(CENTER);
3138       setToolTipText(MessageManager.getString("label.urltooltip"));
3139     }
3140
3141     @Override
3142     public Component getTableCellRendererComponent(JTable table,
3143             Object value, boolean isSelected, boolean hasFocus, int row,
3144             int column)
3145     {
3146       setSelected((boolean) value);
3147
3148       // set colours to match rest of table
3149       if (isSelected)
3150       {
3151         setBackground(table.getSelectionBackground());
3152         setForeground(table.getSelectionForeground());
3153       }
3154       else
3155       {
3156         setBackground(table.getBackground());
3157         setForeground(table.getForeground());
3158       }
3159       return this;
3160     }
3161   }
3162
3163   /**
3164    * Customer cell editor for JTable: supports column of radio buttons in
3165    * conjunction with renderer
3166    */
3167   public class RadioButtonEditor extends AbstractCellEditor
3168           implements TableCellEditor
3169   {
3170     private JRadioButton button = new JRadioButton();
3171
3172     public RadioButtonEditor()
3173     {
3174       button.setHorizontalAlignment(SwingConstants.CENTER);
3175       this.button.addActionListener(new ActionListener()
3176       {
3177         @Override
3178         public void actionPerformed(ActionEvent e)
3179         {
3180           fireEditingStopped();
3181         }
3182       });
3183     }
3184
3185     @Override
3186     public Component getTableCellEditorComponent(JTable table, Object value,
3187             boolean isSelected, int row, int column)
3188     {
3189       button.setSelected((boolean) value);
3190       return button;
3191     }
3192
3193     @Override
3194     public Object getCellEditorValue()
3195     {
3196       return button.isSelected();
3197     }
3198
3199   }
3200 }