JAL-3141 Added Presets options in the Backups Preferences pane, with several presets...
[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 jalview.fts.core.FTSDataColumnPreferences;
24 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
25 import jalview.fts.service.pdb.PDBFTSRestClient;
26 import jalview.gui.JalviewBooleanRadioButtons;
27 import jalview.gui.JvSwingUtils;
28 import jalview.gui.StructureViewer.ViewerType;
29 import jalview.io.BackupFilenameFilter;
30 import jalview.io.BackupFiles;
31 import jalview.util.MessageManager;
32
33 import java.awt.BorderLayout;
34 import java.awt.Color;
35 import java.awt.Component;
36 import java.awt.Dimension;
37 import java.awt.FlowLayout;
38 import java.awt.Font;
39 import java.awt.FontMetrics;
40 import java.awt.GridBagConstraints;
41 import java.awt.GridBagLayout;
42 import java.awt.GridLayout;
43 import java.awt.Insets;
44 import java.awt.Rectangle;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.awt.event.FocusEvent;
48 import java.awt.event.KeyEvent;
49 import java.awt.event.KeyListener;
50 import java.awt.event.MouseAdapter;
51 import java.awt.event.MouseEvent;
52 import java.util.ArrayList;
53 import java.util.Map;
54 import java.util.HashMap;
55
56 import javax.swing.AbstractCellEditor;
57 import javax.swing.BorderFactory;
58 import javax.swing.ButtonGroup;
59 import javax.swing.DefaultListCellRenderer;
60 import javax.swing.JButton;
61 import javax.swing.JCheckBox;
62 import javax.swing.JComboBox;
63 import javax.swing.JFileChooser;
64 import javax.swing.JLabel;
65 import javax.swing.JPanel;
66 import javax.swing.JRadioButton;
67 import javax.swing.JScrollPane;
68 import javax.swing.JSpinner;
69 import javax.swing.JTabbedPane;
70 import javax.swing.JTable;
71 import javax.swing.JTextArea;
72 import javax.swing.JTextField;
73 import javax.swing.ListSelectionModel;
74 import javax.swing.SpinnerModel;
75 import javax.swing.SpinnerNumberModel;
76 import javax.swing.SwingConstants;
77 import javax.swing.border.Border;
78 import javax.swing.border.EmptyBorder;
79 import javax.swing.border.EtchedBorder;
80 import javax.swing.border.TitledBorder;
81 import javax.swing.event.ChangeEvent;
82 import javax.swing.event.ChangeListener;
83 import javax.swing.table.TableCellEditor;
84 import javax.swing.table.TableCellRenderer;
85
86 /**
87  * Base class for the Preferences panel.
88  * 
89  * @author $author$
90  * @version $Revision$
91  */
92 public class GPreferences extends JPanel
93 {
94   private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
95
96   private static final Font LABEL_FONT_ITALIC = JvSwingUtils
97           .getLabelFont(false, true);
98
99   private static final Font LABEL_FONT_BOLD = JvSwingUtils
100           .getLabelFont(true, false);
101
102   /*
103    * Visual tab components
104    */
105   protected JCheckBox fullScreen = new JCheckBox();
106
107   protected JCheckBox openoverv = new JCheckBox();
108
109   protected JCheckBox seqLimit = new JCheckBox();
110
111   protected JCheckBox rightAlign = new JCheckBox();
112
113   protected JComboBox<String> fontSizeCB = new JComboBox<>();
114
115   protected JComboBox<String> fontStyleCB = new JComboBox<>();
116
117   protected JComboBox<String> fontNameCB = new JComboBox<>();
118
119   protected JCheckBox showOccupancy = new JCheckBox();
120
121   protected JCheckBox showUnconserved = new JCheckBox();
122
123   protected JCheckBox idItalics = new JCheckBox();
124
125   protected JCheckBox smoothFont = new JCheckBox();
126
127   protected JCheckBox scaleProteinToCdna = new JCheckBox();
128
129   protected JComboBox<String> gapSymbolCB = new JComboBox<>();
130
131   protected JCheckBox wrap = new JCheckBox();
132
133   protected JComboBox<String> sortby = new JComboBox<>();
134
135   protected JComboBox<String> sortAnnBy = new JComboBox<>();
136
137   protected JComboBox<String> sortAutocalc = new JComboBox<>();
138
139   protected JCheckBox startupCheckbox = new JCheckBox();
140
141   protected JTextField startupFileTextfield = new JTextField();
142
143   // below are in the 'second column'
144   protected JCheckBox annotations = new JCheckBox();
145
146   protected JCheckBox quality = new JCheckBox();
147
148   protected JCheckBox conservation = new JCheckBox();
149
150   protected JCheckBox identity = new JCheckBox();
151
152   protected JCheckBox showGroupConsensus = new JCheckBox();
153
154   protected JCheckBox showGroupConservation = new JCheckBox();
155
156   protected JCheckBox showConsensHistogram = new JCheckBox();
157
158   protected JCheckBox showConsensLogo = new JCheckBox();
159
160   protected JCheckBox showDbRefTooltip = new JCheckBox();
161
162   protected JCheckBox showNpTooltip = new JCheckBox();
163
164   /*
165    * Structure tab and components
166    */
167   protected JPanel structureTab;
168
169   protected JCheckBox structFromPdb = new JCheckBox();
170
171   protected JCheckBox useRnaView = new JCheckBox();
172
173   protected JCheckBox addSecondaryStructure = new JCheckBox();
174
175   protected JCheckBox addTempFactor = new JCheckBox();
176
177   protected JComboBox<String> structViewer = new JComboBox<>();
178
179   protected JTextField chimeraPath = new JTextField();
180
181   protected ButtonGroup mappingMethod = new ButtonGroup();
182
183   protected JRadioButton siftsMapping = new JRadioButton();
184
185   protected JRadioButton nwMapping = new JRadioButton();
186
187   /*
188    * Colours tab components
189    */
190   protected JPanel minColour = new JPanel();
191
192   protected JPanel maxColour = new JPanel();
193
194   protected JComboBox<String> protColour = new JComboBox<>();
195
196   protected JComboBox<String> nucColour = new JComboBox<>();
197
198   /*
199    * Overview tab components
200    */
201   protected JPanel gapColour = new JPanel();
202
203   protected JPanel hiddenColour = new JPanel();
204
205   protected JCheckBox useLegacyGap;
206
207   protected JCheckBox showHiddenAtStart;
208
209   protected JLabel gapLabel;
210
211   /*
212    * Connections tab components
213    */
214   protected JTable linkUrlTable = new JTable();
215
216   protected JButton editLink = new JButton();
217
218   protected JButton deleteLink = new JButton();
219
220   protected JTextField filterTB = new JTextField();
221
222   protected JButton doReset = new JButton();
223
224   protected JButton userOnly = new JButton();
225
226   protected JLabel portLabel = new JLabel();
227
228   protected JLabel serverLabel = new JLabel();
229
230   protected JTextField proxyServerTB = new JTextField();
231
232   protected JTextField proxyPortTB = new JTextField();
233
234   protected JTextField defaultBrowser = new JTextField();
235
236   protected JCheckBox useProxy = new JCheckBox();
237
238   protected JCheckBox usagestats = new JCheckBox();
239
240   protected JCheckBox questionnaire = new JCheckBox();
241
242   protected JCheckBox versioncheck = new JCheckBox();
243
244   /*
245    * Output tab components
246    */
247   protected JComboBox<Object> epsRendering = new JComboBox<>();
248
249   protected JLabel userIdWidthlabel = new JLabel();
250
251   protected JCheckBox autoIdWidth = new JCheckBox();
252
253   protected JTextField userIdWidth = new JTextField();
254
255   protected JCheckBox blcjv = new JCheckBox();
256
257   protected JCheckBox pileupjv = new JCheckBox();
258
259   protected JCheckBox clustaljv = new JCheckBox();
260
261   protected JCheckBox msfjv = new JCheckBox();
262
263   protected JCheckBox fastajv = new JCheckBox();
264
265   protected JCheckBox pfamjv = new JCheckBox();
266
267   protected JCheckBox pirjv = new JCheckBox();
268
269   protected JCheckBox modellerOutput = new JCheckBox();
270
271   protected JCheckBox embbedBioJSON = new JCheckBox();
272
273   /*
274    * Editing tab components
275    */
276   protected JCheckBox autoCalculateConsCheck = new JCheckBox();
277
278   protected JCheckBox padGaps = new JCheckBox();
279
280   protected JCheckBox sortByTree = new JCheckBox();
281
282
283   /*
284    * Web Services tab
285    */
286   protected JPanel wsTab = new JPanel();
287
288   /*
289    * Backups tab components
290    * a lot of these are member variables instead of local variables only so that they
291    * can be enabled/disabled easily in one go
292    */
293
294   protected JCheckBox enableBackupFiles = new JCheckBox();
295
296   protected JPanel presetsPanel = new JPanel();
297
298   protected JComboBox<IntKeyStringValueEntry> backupfilesPresetsCombo = new JComboBox<>();
299
300   protected JPanel suffixPanel = new JPanel();
301
302   protected JPanel keepfilesPanel = new JPanel();
303
304   protected JPanel exampleFilesPanel = new JPanel();
305
306   protected JTextField suffixTemplate = new JTextField(null, 8);
307
308   protected JLabel suffixTemplateLabel = new JLabel();
309
310   protected JLabel suffixDigitsLabel = new JLabel();
311
312   protected JSpinner suffixDigitsSpinner = new JSpinner();
313
314   protected JalviewBooleanRadioButtons suffixReverse = new JalviewBooleanRadioButtons();
315
316   protected JalviewBooleanRadioButtons backupfilesKeepAll = new JalviewBooleanRadioButtons();
317
318   public JSpinner backupfilesRollMaxSpinner = new JSpinner();
319
320   protected JLabel oldBackupFilesLabel = new JLabel();
321
322   protected JalviewBooleanRadioButtons backupfilesConfirmDelete = new JalviewBooleanRadioButtons();
323
324   protected JTextArea backupfilesExampleLabel = new JTextArea();
325
326   /**
327    * Creates a new GPreferences object.
328    */
329   public GPreferences()
330   {
331     try
332     {
333       jbInit();
334     } catch (Exception ex)
335     {
336       ex.printStackTrace();
337     }
338   }
339
340   /**
341    * Construct the panel and its tabbed sub-panels.
342    * 
343    * @throws Exception
344    */
345   private void jbInit() throws Exception
346   {
347     final JTabbedPane tabbedPane = new JTabbedPane();
348     this.setLayout(new BorderLayout());
349     JPanel okCancelPanel = initOkCancelPanel();
350     this.add(tabbedPane, BorderLayout.CENTER);
351     this.add(okCancelPanel, BorderLayout.SOUTH);
352
353     tabbedPane.add(initVisualTab(),
354             MessageManager.getString("label.visual"));
355
356     tabbedPane.add(initColoursTab(),
357             MessageManager.getString("label.colours"));
358
359     tabbedPane.add(initOverviewTab(),
360             MessageManager.getString("label.overview"));
361
362     tabbedPane.add(initStructureTab(),
363             MessageManager.getString("label.structure"));
364
365     tabbedPane.add(initConnectionsTab(),
366             MessageManager.getString("label.connections"));
367
368     tabbedPane.add(initBackupsTab(),
369             MessageManager.getString("label.backups"));
370
371     tabbedPane.add(initLinksTab(),
372             MessageManager.getString("label.urllinks"));
373
374     tabbedPane.add(initOutputTab(),
375             MessageManager.getString("label.output"));
376
377     tabbedPane.add(initEditingTab(),
378             MessageManager.getString("label.editing"));
379
380     /*
381      * See WsPreferences for the real work of configuring this tab.
382      */
383     wsTab.setLayout(new BorderLayout());
384     tabbedPane.add(wsTab, MessageManager.getString("label.web_services"));
385
386     /*
387      * Handler to validate a tab before leaving it - currently only for
388      * Structure.
389      */
390     tabbedPane.addChangeListener(new ChangeListener()
391     {
392       private Component lastTab;
393
394       @Override
395       public void stateChanged(ChangeEvent e)
396       {
397         if (lastTab == structureTab
398                 && tabbedPane.getSelectedComponent() != structureTab)
399         {
400           if (!validateStructure())
401           {
402             tabbedPane.setSelectedComponent(structureTab);
403             return;
404           }
405         }
406         lastTab = tabbedPane.getSelectedComponent();
407       }
408
409     });
410   }
411
412   /**
413    * Initialises the Editing tabbed panel.
414    * 
415    * @return
416    */
417   private JPanel initEditingTab()
418   {
419     JPanel editingTab = new JPanel();
420     editingTab.setLayout(null);
421     autoCalculateConsCheck.setFont(LABEL_FONT);
422     autoCalculateConsCheck.setText(
423             MessageManager.getString("label.autocalculate_consensus"));
424     autoCalculateConsCheck.setBounds(new Rectangle(21, 52, 209, 23));
425     padGaps.setFont(LABEL_FONT);
426     padGaps.setText(
427             MessageManager.getString("label.pad_gaps_when_editing"));
428     padGaps.setBounds(new Rectangle(22, 94, 168, 23));
429     sortByTree.setFont(LABEL_FONT);
430     sortByTree
431             .setText(MessageManager.getString("label.sort_with_new_tree"));
432     sortByTree.setToolTipText(MessageManager.getString(
433             "label.any_trees_calculated_or_loaded_alignment_automatically_sort"));
434     sortByTree.setBounds(new Rectangle(22, 136, 168, 23));
435     editingTab.add(autoCalculateConsCheck);
436     editingTab.add(padGaps);
437     editingTab.add(sortByTree);
438     return editingTab;
439   }
440
441   /**
442    * Initialises the Output tabbed panel.
443    * 
444    * @return
445    */
446   private JPanel initOutputTab()
447   {
448     JPanel outputTab = new JPanel();
449     outputTab.setLayout(null);
450     JLabel epsLabel = new JLabel();
451     epsLabel.setFont(LABEL_FONT);
452     epsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
453     epsLabel.setText(MessageManager.getString("label.eps_rendering_style"));
454     epsLabel.setBounds(new Rectangle(9, 31, 140, 24));
455     epsRendering.setFont(LABEL_FONT);
456     epsRendering.setBounds(new Rectangle(154, 34, 187, 21));
457     JLabel jLabel1 = new JLabel();
458     jLabel1.setFont(LABEL_FONT);
459     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
460     jLabel1.setText(MessageManager.getString("label.append_start_end"));
461     jLabel1.setFont(LABEL_FONT);
462     fastajv.setFont(LABEL_FONT);
463     fastajv.setHorizontalAlignment(SwingConstants.LEFT);
464     clustaljv.setText(MessageManager.getString("label.clustal") + "     ");
465     blcjv.setText(MessageManager.getString("label.blc") + "     ");
466     fastajv.setText(MessageManager.getString("label.fasta") + "     ");
467     msfjv.setText(MessageManager.getString("label.msf") + "     ");
468     pfamjv.setText(MessageManager.getString("label.pfam") + "     ");
469     pileupjv.setText(MessageManager.getString("label.pileup") + "     ");
470     msfjv.setFont(LABEL_FONT);
471     msfjv.setHorizontalAlignment(SwingConstants.LEFT);
472     pirjv.setText(MessageManager.getString("label.pir") + "     ");
473     JPanel jPanel11 = new JPanel();
474     jPanel11.setFont(LABEL_FONT);
475     TitledBorder titledBorder2 = new TitledBorder(
476             MessageManager.getString("label.file_output"));
477     jPanel11.setBorder(titledBorder2);
478     jPanel11.setBounds(new Rectangle(30, 72, 196, 182));
479     GridLayout gridLayout3 = new GridLayout();
480     jPanel11.setLayout(gridLayout3);
481     gridLayout3.setRows(8);
482     blcjv.setFont(LABEL_FONT);
483     blcjv.setHorizontalAlignment(SwingConstants.LEFT);
484     clustaljv.setFont(LABEL_FONT);
485     clustaljv.setHorizontalAlignment(SwingConstants.LEFT);
486     pfamjv.setFont(LABEL_FONT);
487     pfamjv.setHorizontalAlignment(SwingConstants.LEFT);
488     pileupjv.setFont(LABEL_FONT);
489     pileupjv.setHorizontalAlignment(SwingConstants.LEFT);
490     pirjv.setFont(LABEL_FONT);
491     pirjv.setHorizontalAlignment(SwingConstants.LEFT);
492     autoIdWidth.setFont(LABEL_FONT);
493     autoIdWidth.setText(
494             MessageManager.getString("label.automatically_set_id_width"));
495     autoIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
496             .getString("label.adjusts_width_generated_eps_png")));
497     autoIdWidth.setBounds(new Rectangle(228, 96, 188, 23));
498     autoIdWidth.addActionListener(new ActionListener()
499     {
500
501       @Override
502       public void actionPerformed(ActionEvent e)
503       {
504         autoIdWidth_actionPerformed();
505       }
506     });
507     userIdWidthlabel.setFont(LABEL_FONT);
508     userIdWidthlabel.setText(
509             MessageManager.getString("label.figure_id_column_width"));
510     userIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
511             .getString("label.manually_specify_width_left_column")));
512     userIdWidthlabel.setToolTipText(
513             JvSwingUtils.wrapTooltip(true, MessageManager.getString(
514                     "label.manually_specify_width_left_column")));
515     userIdWidthlabel.setBounds(new Rectangle(236, 120, 168, 23));
516     userIdWidth.setFont(JvSwingUtils.getTextAreaFont());
517     userIdWidth.setText("");
518     userIdWidth.setBounds(new Rectangle(232, 144, 84, 23));
519     userIdWidth.addActionListener(new ActionListener()
520     {
521
522       @Override
523       public void actionPerformed(ActionEvent e)
524       {
525         userIdWidth_actionPerformed();
526       }
527     });
528     modellerOutput.setFont(LABEL_FONT);
529     modellerOutput
530             .setText(MessageManager.getString("label.use_modeller_output"));
531     modellerOutput.setBounds(new Rectangle(228, 226, 168, 23));
532     embbedBioJSON.setFont(LABEL_FONT);
533     embbedBioJSON.setText(MessageManager.getString("label.embbed_biojson"));
534     embbedBioJSON.setBounds(new Rectangle(228, 200, 250, 23));
535
536
537     TitledBorder backupFilesBorder = new TitledBorder(
538             MessageManager
539                     .getString("label.backup_files"));
540
541
542     jPanel11.add(jLabel1);
543     jPanel11.add(blcjv);
544     jPanel11.add(clustaljv);
545     jPanel11.add(fastajv);
546     jPanel11.add(msfjv);
547     jPanel11.add(pfamjv);
548     jPanel11.add(pileupjv);
549     jPanel11.add(pirjv);
550     outputTab.add(autoIdWidth);
551     outputTab.add(userIdWidth);
552     outputTab.add(userIdWidthlabel);
553     outputTab.add(modellerOutput);
554     outputTab.add(embbedBioJSON);
555     outputTab.add(epsLabel);
556     outputTab.add(epsRendering);
557     outputTab.add(jPanel11);
558     return outputTab;
559   }
560
561   /**
562    * Initialises the Connections tabbed panel.
563    * 
564    * @return
565    */
566   private JPanel initConnectionsTab()
567   {
568     JPanel connectTab = new JPanel();
569     connectTab.setLayout(new GridBagLayout());
570
571     // Label for browser text box
572     JLabel browserLabel = new JLabel();
573     browserLabel.setFont(LABEL_FONT);
574     browserLabel.setHorizontalAlignment(SwingConstants.TRAILING);
575     browserLabel.setText(
576             MessageManager.getString("label.default_browser_unix"));
577     defaultBrowser.setFont(LABEL_FONT);
578     defaultBrowser.setText("");
579     final String tooltip = JvSwingUtils.wrapTooltip(true,
580             MessageManager.getString("label.double_click_to_browse"));
581     defaultBrowser.setToolTipText(tooltip);
582     defaultBrowser.addMouseListener(new MouseAdapter()
583     {
584       @Override
585       public void mouseClicked(MouseEvent e)
586       {
587         if (e.getClickCount() > 1)
588         {
589           defaultBrowser_mouseClicked(e);
590         }
591       }
592     });
593
594     JPanel proxyPanel = initConnTabProxyPanel();
595     initConnTabCheckboxes();
596
597     // Add default Browser text box
598     connectTab.add(browserLabel,
599             new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
600                     GridBagConstraints.WEST, GridBagConstraints.NONE,
601                     new Insets(10, 0, 5, 5), 5, 1));
602     defaultBrowser.setFont(LABEL_FONT);
603     defaultBrowser.setText("");
604
605     connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0,
606             0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
607             new Insets(10, 0, 5, 10), 30, 1));
608
609     // Add proxy server panel
610     connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0,
611             GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
612             new Insets(10, 0, 5, 12), 4, 10));
613
614     // Add usage stats, version check and questionnaire checkboxes
615     connectTab.add(usagestats,
616             new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
617                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
618                     new Insets(0, 2, 5, 5), 70, 1));
619     connectTab.add(questionnaire,
620             new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
621                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
622                     new Insets(0, 2, 5, 10), 70, 1));
623     connectTab.add(versioncheck,
624             new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0,
625                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
626                     new Insets(0, 2, 5, 5), 70, 1));
627
628     // Add padding so the panel doesn't look ridiculous
629     JPanel spacePanel = new JPanel();
630     connectTab.add(spacePanel,
631             new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
632                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
633                     new Insets(0, 0, 0, 5), 70, 1));
634
635     return connectTab;
636   }
637
638   /**
639    * Initialises the Links tabbed panel.
640    * 
641    * @return
642    */
643   private JPanel initLinksTab()
644   {
645     JPanel linkTab = new JPanel();
646     linkTab.setLayout(new GridBagLayout());
647
648     // Set up table for Url links
649     linkUrlTable.setFillsViewportHeight(true);
650     linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
651     linkUrlTable.setAutoCreateRowSorter(true);
652     linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
653
654     // adjust row height so radio buttons actually fit
655     // don't do this in the renderer, it causes the awt thread to activate
656     // constantly
657     JRadioButton temp = new JRadioButton();
658     linkUrlTable.setRowHeight(temp.getMinimumSize().height);
659
660     // Table in scrollpane so that the table is given a scrollbar
661     JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
662     linkScrollPane.setBorder(null);
663
664     // Panel for links functionality
665     JPanel linkPanel = new JPanel(new GridBagLayout());
666     linkPanel.setBorder(new TitledBorder(
667             MessageManager.getString("label.url_linkfrom_sequence_id")));
668
669     // Put the Url links panel together
670
671     // Buttons go at top right, resizing only resizes the blank space vertically
672     JPanel buttonPanel = initLinkTabUrlButtons();
673     GridBagConstraints linkConstraints1 = new GridBagConstraints();
674     linkConstraints1.insets = new Insets(0, 0, 5, 0);
675     linkConstraints1.gridx = 0;
676     linkConstraints1.gridy = 0;
677     linkConstraints1.weightx = 1.0;
678     linkConstraints1.fill = GridBagConstraints.HORIZONTAL;
679     linkTab.add(buttonPanel, linkConstraints1);
680
681     // Links table goes at top left, resizing resizes the table
682     GridBagConstraints linkConstraints2 = new GridBagConstraints();
683     linkConstraints2.insets = new Insets(0, 0, 5, 5);
684     linkConstraints2.gridx = 0;
685     linkConstraints2.gridy = 1;
686     linkConstraints2.weightx = 1.0;
687     linkConstraints2.weighty = 1.0;
688     linkConstraints2.fill = GridBagConstraints.BOTH;
689     linkTab.add(linkScrollPane, linkConstraints2);
690
691     // Filter box and buttons goes at bottom left, resizing resizes the text box
692     JPanel filterPanel = initLinkTabFilterPanel();
693     GridBagConstraints linkConstraints3 = new GridBagConstraints();
694     linkConstraints3.insets = new Insets(0, 0, 0, 5);
695     linkConstraints3.gridx = 0;
696     linkConstraints3.gridy = 2;
697     linkConstraints3.weightx = 1.0;
698     linkConstraints3.fill = GridBagConstraints.HORIZONTAL;
699     linkTab.add(filterPanel, linkConstraints3);
700
701     return linkTab;
702   }
703
704   private JPanel initLinkTabFilterPanel()
705   {
706     // Filter textbox and reset button
707     JLabel filterLabel = new JLabel(
708             MessageManager.getString("label.filter"));
709     filterLabel.setFont(LABEL_FONT);
710     filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);
711     filterLabel.setHorizontalTextPosition(SwingConstants.LEADING);
712
713     filterTB.setFont(LABEL_FONT);
714     filterTB.setText("");
715
716     doReset.setText(MessageManager.getString("action.showall"));
717     userOnly.setText(MessageManager.getString("action.customfilter"));
718
719     // Panel for filter functionality
720     JPanel filterPanel = new JPanel(new GridBagLayout());
721     filterPanel.setBorder(new TitledBorder("Filter"));
722     GridBagConstraints gbc = new GridBagConstraints();
723     gbc.gridx = 0;
724     gbc.gridy = 0;
725     gbc.fill = GridBagConstraints.NONE;
726     gbc.anchor = GridBagConstraints.WEST;
727
728     filterPanel.add(filterLabel, gbc);
729
730     GridBagConstraints gbc1 = new GridBagConstraints();
731     gbc1.gridx = 1;
732     gbc1.gridwidth = 2;
733     gbc1.fill = GridBagConstraints.HORIZONTAL;
734     gbc1.anchor = GridBagConstraints.WEST;
735     gbc1.weightx = 1.0;
736     filterPanel.add(filterTB, gbc1);
737
738     GridBagConstraints gbc2 = new GridBagConstraints();
739     gbc2.gridx = 3;
740     gbc2.fill = GridBagConstraints.NONE;
741     gbc2.anchor = GridBagConstraints.WEST;
742     filterPanel.add(doReset, gbc2);
743
744     GridBagConstraints gbc3 = new GridBagConstraints();
745     gbc3.gridx = 4;
746     gbc3.fill = GridBagConstraints.NONE;
747     gbc3.anchor = GridBagConstraints.WEST;
748     filterPanel.add(userOnly, gbc3);
749
750     return filterPanel;
751   }
752
753   private JPanel initLinkTabUrlButtons()
754   {
755     // Buttons for new / edit / delete Url links
756     JButton newLink = new JButton();
757     newLink.setText(MessageManager.getString("action.new"));
758
759     editLink.setText(MessageManager.getString("action.edit"));
760
761     deleteLink.setText(MessageManager.getString("action.delete"));
762
763     // no current selection, so initially disable delete/edit buttons
764     editLink.setEnabled(false);
765     deleteLink.setEnabled(false);
766
767     newLink.addActionListener(new java.awt.event.ActionListener()
768     {
769       @Override
770       public void actionPerformed(ActionEvent e)
771       {
772         newLink_actionPerformed(e);
773       }
774     });
775
776     editLink.setText(MessageManager.getString("action.edit"));
777     editLink.addActionListener(new java.awt.event.ActionListener()
778     {
779       @Override
780       public void actionPerformed(ActionEvent e)
781       {
782         editLink_actionPerformed(e);
783       }
784     });
785
786     deleteLink.setText(MessageManager.getString("action.delete"));
787     deleteLink.addActionListener(new java.awt.event.ActionListener()
788     {
789       @Override
790       public void actionPerformed(ActionEvent e)
791       {
792         deleteLink_actionPerformed(e);
793       }
794     });
795
796     JPanel buttonPanel = new JPanel(new GridBagLayout());
797     buttonPanel.setBorder(new TitledBorder("Edit links"));
798     GridBagConstraints gbc = new GridBagConstraints();
799     gbc.gridx = 0;
800     gbc.gridy = 0;
801     gbc.fill = GridBagConstraints.NONE;
802     buttonPanel.add(newLink, gbc);
803
804     GridBagConstraints gbc1 = new GridBagConstraints();
805     gbc1.gridx = 1;
806     gbc1.gridy = 0;
807     gbc1.fill = GridBagConstraints.NONE;
808     buttonPanel.add(editLink, gbc1);
809
810     GridBagConstraints gbc2 = new GridBagConstraints();
811     gbc2.gridx = 2;
812     gbc2.gridy = 0;
813     gbc2.fill = GridBagConstraints.NONE;
814     buttonPanel.add(deleteLink, gbc2);
815
816     GridBagConstraints gbc3 = new GridBagConstraints();
817     gbc3.gridx = 3;
818     gbc3.gridy = 0;
819     gbc3.fill = GridBagConstraints.HORIZONTAL;
820     gbc3.weightx = 1.0;
821     JPanel spacePanel = new JPanel();
822     spacePanel.setBorder(null);
823     buttonPanel.add(spacePanel, gbc3);
824
825     return buttonPanel;
826   }
827
828   /**
829    * Initialises the proxy server panel in the Connections tab
830    * 
831    * @return the proxy server panel
832    */
833   private JPanel initConnTabProxyPanel()
834   {
835     // Label for server text box
836     serverLabel.setText(MessageManager.getString("label.address"));
837     serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
838     serverLabel.setFont(LABEL_FONT);
839
840     // Proxy server and port text boxes
841     proxyServerTB.setFont(LABEL_FONT);
842     proxyPortTB.setFont(LABEL_FONT);
843
844     // Label for Port text box
845     portLabel.setFont(LABEL_FONT);
846     portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
847     portLabel.setText(MessageManager.getString("label.port"));
848
849     // Use proxy server checkbox
850     useProxy.setFont(LABEL_FONT);
851     useProxy.setHorizontalAlignment(SwingConstants.RIGHT);
852     useProxy.setHorizontalTextPosition(SwingConstants.LEADING);
853     useProxy.setText(MessageManager.getString("label.use_proxy_server"));
854     useProxy.addActionListener(new ActionListener()
855     {
856       @Override
857       public void actionPerformed(ActionEvent e)
858       {
859         useProxy_actionPerformed();
860       }
861     });
862
863     // Make proxy server panel
864     JPanel proxyPanel = new JPanel();
865     TitledBorder titledBorder1 = new TitledBorder(
866             MessageManager.getString("label.proxy_server"));
867     proxyPanel.setBorder(titledBorder1);
868     proxyPanel.setLayout(new GridBagLayout());
869     proxyPanel.add(serverLabel,
870             new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
871                     GridBagConstraints.WEST, GridBagConstraints.NONE,
872                     new Insets(0, 2, 2, 0), 5, 0));
873     proxyPanel.add(portLabel,
874             new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
875                     GridBagConstraints.WEST, GridBagConstraints.NONE,
876                     new Insets(0, 0, 2, 0), 11, 0));
877     proxyPanel.add(useProxy,
878             new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
879                     GridBagConstraints.WEST, GridBagConstraints.NONE,
880                     new Insets(0, 2, 5, 185), 2, -4));
881     proxyPanel.add(proxyPortTB,
882             new GridBagConstraints(3, 1, 1, 1, 1.0, 0.0,
883                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
884                     new Insets(0, 2, 2, 2), 54, 1));
885     proxyPanel.add(proxyServerTB,
886             new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0,
887                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
888                     new Insets(0, 2, 2, 0), 263, 1));
889
890     return proxyPanel;
891   }
892
893   /**
894    * Initialises the checkboxes in the Connections tab
895    */
896   private void initConnTabCheckboxes()
897   {
898     // Usage stats checkbox label
899     usagestats.setText(
900             MessageManager.getString("label.send_usage_statistics"));
901     usagestats.setFont(LABEL_FONT);
902     usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
903     usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
904
905     // Questionnaire checkbox label
906     questionnaire.setText(
907             MessageManager.getString("label.check_for_questionnaires"));
908     questionnaire.setFont(LABEL_FONT);
909     questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
910     questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
911
912     // Check for latest version checkbox label
913     versioncheck.setText(
914             MessageManager.getString("label.check_for_latest_version"));
915     versioncheck.setFont(LABEL_FONT);
916     versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
917     versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
918   }
919
920   /**
921    * Initialises the parent panel which contains the tabbed sections.
922    * 
923    * @return
924    */
925   private JPanel initOkCancelPanel()
926   {
927     JButton ok = new JButton();
928     ok.setText(MessageManager.getString("action.ok"));
929     ok.addActionListener(new ActionListener()
930     {
931       @Override
932       public void actionPerformed(ActionEvent e)
933       {
934         ok_actionPerformed(e);
935       }
936     });
937     JButton cancel = new JButton();
938     cancel.setText(MessageManager.getString("action.cancel"));
939     cancel.addActionListener(new ActionListener()
940     {
941       @Override
942       public void actionPerformed(ActionEvent e)
943       {
944         cancel_actionPerformed(e);
945       }
946     });
947     JPanel okCancelPanel = new JPanel();
948     okCancelPanel.add(ok);
949     okCancelPanel.add(cancel);
950     return okCancelPanel;
951   }
952
953   /**
954    * Initialises the Colours tabbed panel.
955    * 
956    * @return
957    */
958   private JPanel initColoursTab()
959   {
960     JPanel coloursTab = new JPanel();
961     coloursTab.setBorder(new TitledBorder(
962             MessageManager.getString("action.open_new_alignment")));
963     coloursTab.setLayout(new FlowLayout());
964     JLabel mincolourLabel = new JLabel();
965     mincolourLabel.setFont(LABEL_FONT);
966     mincolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
967     mincolourLabel.setText(MessageManager.getString("label.min_colour"));
968     minColour.setFont(LABEL_FONT);
969     minColour.setBorder(BorderFactory.createEtchedBorder());
970     minColour.setPreferredSize(new Dimension(40, 20));
971     minColour.addMouseListener(new MouseAdapter()
972     {
973       @Override
974       public void mousePressed(MouseEvent e)
975       {
976         minColour_actionPerformed(minColour);
977       }
978     });
979     JLabel maxcolourLabel = new JLabel();
980     maxcolourLabel.setFont(LABEL_FONT);
981     maxcolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
982     maxcolourLabel.setText(MessageManager.getString("label.max_colour"));
983     maxColour.setFont(LABEL_FONT);
984     maxColour.setBorder(BorderFactory.createEtchedBorder());
985     maxColour.setPreferredSize(new Dimension(40, 20));
986     maxColour.addMouseListener(new MouseAdapter()
987     {
988       @Override
989       public void mousePressed(MouseEvent e)
990       {
991         maxColour_actionPerformed(maxColour);
992       }
993     });
994
995     protColour.setFont(LABEL_FONT);
996     protColour.setBounds(new Rectangle(172, 225, 155, 21));
997     JLabel protColourLabel = new JLabel();
998     protColourLabel.setFont(LABEL_FONT);
999     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1000     protColourLabel.setText(
1001             MessageManager.getString("label.prot_alignment_colour") + " ");
1002     JvSwingUtils.addtoLayout(coloursTab,
1003             MessageManager
1004                     .getString("label.default_colour_scheme_for_alignment"),
1005             protColourLabel, protColour);
1006
1007     nucColour.setFont(LABEL_FONT);
1008     nucColour.setBounds(new Rectangle(172, 240, 155, 21));
1009     JLabel nucColourLabel = new JLabel();
1010     nucColourLabel.setFont(LABEL_FONT);
1011     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1012     nucColourLabel.setText(
1013             MessageManager.getString("label.nuc_alignment_colour") + " ");
1014     JvSwingUtils.addtoLayout(coloursTab,
1015             MessageManager
1016                     .getString("label.default_colour_scheme_for_alignment"),
1017             nucColourLabel, nucColour);
1018
1019     JPanel annotationShding = new JPanel();
1020     annotationShding.setBorder(new TitledBorder(
1021             MessageManager.getString("label.annotation_shading_default")));
1022     annotationShding.setLayout(new GridLayout(1, 2));
1023     JvSwingUtils.addtoLayout(annotationShding,
1024             MessageManager.getString(
1025                     "label.default_minimum_colour_annotation_shading"),
1026             mincolourLabel, minColour);
1027     JvSwingUtils.addtoLayout(annotationShding,
1028             MessageManager.getString(
1029                     "label.default_maximum_colour_annotation_shading"),
1030             maxcolourLabel, maxColour);
1031     coloursTab.add(annotationShding); // , FlowLayout.LEFT);
1032     return coloursTab;
1033   }
1034
1035   /**
1036    * Initialises the Overview tabbed panel.
1037    * 
1038    * @return
1039    */
1040   private JPanel initOverviewTab()
1041   {
1042     JPanel overviewPanel = new JPanel();
1043     overviewPanel.setBorder(new TitledBorder(
1044             MessageManager.getString("label.overview_settings")));
1045
1046     gapColour.setFont(LABEL_FONT);
1047     // fixing the border colours stops apparent colour bleed from the panel
1048     gapColour.setBorder(
1049             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1050     gapColour.setPreferredSize(new Dimension(40, 20));
1051     gapColour.addMouseListener(new MouseAdapter()
1052     {
1053       @Override
1054       public void mousePressed(MouseEvent e)
1055       {
1056         gapColour_actionPerformed(gapColour);
1057       }
1058     });
1059
1060     hiddenColour.setFont(LABEL_FONT);
1061     // fixing the border colours stops apparent colour bleed from the panel
1062     hiddenColour.setBorder(
1063             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1064     hiddenColour.setPreferredSize(new Dimension(40, 20));
1065     hiddenColour.addMouseListener(new MouseAdapter()
1066     {
1067       @Override
1068       public void mousePressed(MouseEvent e)
1069       {
1070         hiddenColour_actionPerformed(hiddenColour);
1071       }
1072     });
1073     
1074     useLegacyGap = new JCheckBox(
1075             MessageManager.getString("label.ov_legacy_gap"));
1076     useLegacyGap.setFont(LABEL_FONT);
1077     useLegacyGap.setHorizontalAlignment(SwingConstants.LEFT);
1078     useLegacyGap.setVerticalTextPosition(SwingConstants.TOP);
1079     gapLabel = new JLabel(
1080             MessageManager.getString("label.gap_colour"));
1081     gapLabel.setFont(LABEL_FONT);
1082     gapLabel.setHorizontalAlignment(SwingConstants.LEFT);
1083     gapLabel.setVerticalTextPosition(SwingConstants.TOP);
1084     showHiddenAtStart = new JCheckBox(
1085             MessageManager.getString("label.ov_show_hide_default"));
1086     showHiddenAtStart.setFont(LABEL_FONT);
1087     showHiddenAtStart.setHorizontalAlignment(SwingConstants.LEFT);
1088     showHiddenAtStart.setVerticalTextPosition(SwingConstants.TOP);
1089     JLabel hiddenLabel = new JLabel(
1090             MessageManager.getString("label.hidden_colour"));
1091     hiddenLabel.setFont(LABEL_FONT);
1092     hiddenLabel.setHorizontalAlignment(SwingConstants.LEFT);
1093     hiddenLabel.setVerticalTextPosition(SwingConstants.TOP);
1094
1095     useLegacyGap.addActionListener(new ActionListener()
1096     {
1097       @Override
1098       public void actionPerformed(ActionEvent e)
1099       {
1100         useLegacyGaps_actionPerformed(e);
1101       }
1102     });
1103
1104     overviewPanel.setLayout(new GridBagLayout());
1105     GridBagConstraints c1 = new GridBagConstraints();
1106
1107     c1.fill = GridBagConstraints.HORIZONTAL;
1108     c1.gridx = 0;
1109     c1.gridy = 0;
1110     c1.weightx = 1;
1111     c1.ipady = 20;
1112     c1.anchor = GridBagConstraints.FIRST_LINE_START;
1113     overviewPanel.add(useLegacyGap, c1);
1114
1115     GridBagConstraints c2 = new GridBagConstraints();
1116     c2.fill = GridBagConstraints.HORIZONTAL;
1117     c2.gridx = 1;
1118     c2.gridy = 0;
1119     c2.insets = new Insets(0, 15, 0, 10);
1120     overviewPanel.add(gapLabel, c2);
1121
1122     GridBagConstraints c3 = new GridBagConstraints();
1123     c3.fill = GridBagConstraints.HORIZONTAL;
1124     c3.gridx = 2;
1125     c3.gridy = 0;
1126     c3.insets = new Insets(0, 0, 0, 15);
1127     overviewPanel.add(gapColour, c3);
1128
1129     GridBagConstraints c4 = new GridBagConstraints();
1130     c4.fill = GridBagConstraints.HORIZONTAL;
1131     c4.gridx = 0;
1132     c4.gridy = 1;
1133     c4.weightx = 1;
1134     overviewPanel.add(showHiddenAtStart, c4);
1135
1136     GridBagConstraints c5 = new GridBagConstraints();
1137     c5.fill = GridBagConstraints.HORIZONTAL;
1138     c5.gridx = 1;
1139     c5.gridy = 1;
1140     c5.insets = new Insets(0, 15, 0, 10);
1141     overviewPanel.add(hiddenLabel, c5);
1142
1143     GridBagConstraints c6 = new GridBagConstraints();
1144     c6.fill = GridBagConstraints.HORIZONTAL;
1145     c6.gridx = 2;
1146     c6.gridy = 1;
1147     c6.insets = new Insets(0, 0, 0, 15);
1148     overviewPanel.add(hiddenColour, c6);
1149
1150     JButton resetButton = new JButton(
1151             MessageManager.getString("label.reset_to_defaults"));
1152
1153     resetButton.addActionListener(new ActionListener()
1154     {
1155       @Override
1156       public void actionPerformed(ActionEvent e)
1157       {
1158         resetOvDefaults_actionPerformed(e);
1159       }
1160     });
1161
1162     GridBagConstraints c7 = new GridBagConstraints();
1163     c7.fill = GridBagConstraints.NONE;
1164     c7.gridx = 0;
1165     c7.gridy = 2;
1166     c7.insets = new Insets(10, 0, 0, 0);
1167     c7.anchor = GridBagConstraints.WEST;
1168     overviewPanel.add(resetButton, c7);
1169
1170     // Add padding so the panel doesn't look ridiculous
1171     JPanel spacePanel = new JPanel();
1172     overviewPanel.add(spacePanel,
1173             new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0,
1174                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
1175                     new Insets(0, 0, 0, 5), 0, 0));
1176
1177     return overviewPanel;
1178   }
1179
1180   /**
1181    * Initialises the Structure tabbed panel.
1182    * 
1183    * @return
1184    */
1185   private JPanel initStructureTab()
1186   {
1187     structureTab = new JPanel();
1188
1189     structureTab.setBorder(new TitledBorder(
1190             MessageManager.getString("label.structure_options")));
1191     structureTab.setLayout(null);
1192     final int width = 400;
1193     final int height = 22;
1194     final int lineSpacing = 25;
1195     int ypos = 15;
1196
1197     structFromPdb.setFont(LABEL_FONT);
1198     structFromPdb
1199             .setText(MessageManager.getString("label.struct_from_pdb"));
1200     structFromPdb.setBounds(new Rectangle(5, ypos, width, height));
1201     structFromPdb.addActionListener(new ActionListener()
1202     {
1203       @Override
1204       public void actionPerformed(ActionEvent e)
1205       {
1206         boolean selected = structFromPdb.isSelected();
1207         // enable other options only when the first is checked
1208         useRnaView.setEnabled(selected);
1209         addSecondaryStructure.setEnabled(selected);
1210         addTempFactor.setEnabled(selected);
1211       }
1212     });
1213     structureTab.add(structFromPdb);
1214
1215     // indent checkboxes that are conditional on the first one
1216     ypos += lineSpacing;
1217     useRnaView.setFont(LABEL_FONT);
1218     useRnaView.setText(MessageManager.getString("label.use_rnaview"));
1219     useRnaView.setBounds(new Rectangle(25, ypos, width, height));
1220     structureTab.add(useRnaView);
1221
1222     ypos += lineSpacing;
1223     addSecondaryStructure.setFont(LABEL_FONT);
1224     addSecondaryStructure
1225             .setText(MessageManager.getString("label.autoadd_secstr"));
1226     addSecondaryStructure.setBounds(new Rectangle(25, ypos, width, height));
1227     structureTab.add(addSecondaryStructure);
1228
1229     ypos += lineSpacing;
1230     addTempFactor.setFont(LABEL_FONT);
1231     addTempFactor.setText(MessageManager.getString("label.autoadd_temp"));
1232     addTempFactor.setBounds(new Rectangle(25, ypos, width, height));
1233     structureTab.add(addTempFactor);
1234
1235     ypos += lineSpacing;
1236     JLabel viewerLabel = new JLabel();
1237     viewerLabel.setFont(LABEL_FONT);
1238     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
1239     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
1240     viewerLabel.setBounds(new Rectangle(10, ypos, 200, height));
1241     structureTab.add(viewerLabel);
1242
1243     structViewer.setFont(LABEL_FONT);
1244     structViewer.setBounds(new Rectangle(160, ypos, 120, height));
1245     structViewer.addItem(ViewerType.JMOL.name());
1246     structViewer.addItem(ViewerType.CHIMERA.name());
1247     structViewer.addActionListener(new ActionListener()
1248     {
1249       @Override
1250       public void actionPerformed(ActionEvent e)
1251       {
1252         structureViewer_actionPerformed(
1253                 (String) structViewer.getSelectedItem());
1254       }
1255     });
1256     structureTab.add(structViewer);
1257
1258     ypos += lineSpacing;
1259     JLabel pathLabel = new JLabel();
1260     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
1261     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1262     pathLabel.setText(MessageManager.getString("label.chimera_path"));
1263     pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
1264     structureTab.add(pathLabel);
1265
1266     chimeraPath.setFont(LABEL_FONT);
1267     chimeraPath.setText("");
1268     final String tooltip = JvSwingUtils.wrapTooltip(true,
1269             MessageManager.getString("label.chimera_path_tip"));
1270     chimeraPath.setToolTipText(tooltip);
1271     chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
1272     chimeraPath.addMouseListener(new MouseAdapter()
1273     {
1274       @Override
1275       public void mouseClicked(MouseEvent e)
1276       {
1277         if (e.getClickCount() == 2)
1278         {
1279           String chosen = openFileChooser();
1280           if (chosen != null)
1281           {
1282             chimeraPath.setText(chosen);
1283           }
1284         }
1285       }
1286     });
1287     structureTab.add(chimeraPath);
1288
1289     ypos += lineSpacing;
1290     nwMapping.setFont(LABEL_FONT);
1291     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1292     siftsMapping.setFont(LABEL_FONT);
1293     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1294     mappingMethod.add(nwMapping);
1295     mappingMethod.add(siftsMapping);
1296     JPanel mappingPanel = new JPanel();
1297     mappingPanel.setFont(LABEL_FONT);
1298     TitledBorder mmTitledBorder = new TitledBorder(
1299             MessageManager.getString("label.mapping_method"));
1300     mmTitledBorder.setTitleFont(LABEL_FONT);
1301     mappingPanel.setBorder(mmTitledBorder);
1302     mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
1303     // GridLayout mappingLayout = new GridLayout();
1304     mappingPanel.setLayout(new GridLayout());
1305     mappingPanel.add(nwMapping);
1306     mappingPanel.add(siftsMapping);
1307     structureTab.add(mappingPanel);
1308
1309     ypos += lineSpacing;
1310     ypos += lineSpacing;
1311     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1312             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1313     docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
1314     structureTab.add(docFieldPref);
1315
1316     return structureTab;
1317   }
1318
1319   /**
1320    * Action on choosing a structure viewer from combobox options.
1321    * 
1322    * @param selectedItem
1323    */
1324   protected void structureViewer_actionPerformed(String selectedItem)
1325   {
1326   }
1327
1328   /**
1329    * Show a dialog for the user to choose a file. Returns the chosen path, or
1330    * null on Cancel.
1331    * 
1332    * @return
1333    */
1334   protected String openFileChooser()
1335   {
1336     String choice = null;
1337     JFileChooser chooser = new JFileChooser();
1338
1339     // chooser.setFileView(new JalviewFileView());
1340     chooser.setDialogTitle(
1341             MessageManager.getString("label.open_local_file"));
1342     chooser.setToolTipText(MessageManager.getString("action.open"));
1343
1344     int value = chooser.showOpenDialog(this);
1345
1346     if (value == JFileChooser.APPROVE_OPTION)
1347     {
1348       choice = chooser.getSelectedFile().getPath();
1349     }
1350     return choice;
1351   }
1352
1353   /**
1354    * Validate the structure tab preferences; if invalid, set focus on this tab.
1355    * 
1356    * @param e
1357    */
1358   protected boolean validateStructure(FocusEvent e)
1359   {
1360     if (!validateStructure())
1361     {
1362       e.getComponent().requestFocusInWindow();
1363       return false;
1364     }
1365     return true;
1366   }
1367
1368   protected boolean validateStructure()
1369   {
1370     return false;
1371   }
1372
1373   /**
1374    * Initialises the Visual tabbed panel.
1375    * 
1376    * @return
1377    */
1378   private JPanel initVisualTab()
1379   {
1380     JPanel visualTab = new JPanel();
1381     visualTab.setBorder(new TitledBorder(
1382             MessageManager.getString("action.open_new_alignment")));
1383     visualTab.setLayout(null);
1384     fullScreen.setFont(LABEL_FONT);
1385     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
1386     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
1387     fullScreen.setText(MessageManager.getString("label.maximize_window"));
1388     quality.setEnabled(false);
1389     quality.setFont(LABEL_FONT);
1390     quality.setHorizontalAlignment(SwingConstants.RIGHT);
1391     quality.setHorizontalTextPosition(SwingConstants.LEFT);
1392     quality.setSelected(true);
1393     quality.setText(MessageManager.getString("label.quality"));
1394     conservation.setEnabled(false);
1395     conservation.setFont(LABEL_FONT);
1396     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
1397     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
1398     conservation.setSelected(true);
1399     conservation.setText(MessageManager.getString("label.conservation"));
1400     identity.setEnabled(false);
1401     identity.setFont(LABEL_FONT);
1402     identity.setHorizontalAlignment(SwingConstants.RIGHT);
1403     identity.setHorizontalTextPosition(SwingConstants.LEFT);
1404     identity.setSelected(true);
1405     identity.setText(MessageManager.getString("label.consensus"));
1406     showOccupancy.setFont(LABEL_FONT);
1407     showOccupancy.setEnabled(false);
1408     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
1409     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
1410     showOccupancy.setSelected(true);
1411     showOccupancy.setText(MessageManager.getString("label.occupancy"));
1412
1413     JLabel showGroupbits = new JLabel();
1414     showGroupbits.setFont(LABEL_FONT);
1415     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
1416     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
1417     showGroupbits
1418             .setText(MessageManager.getString("action.show_group") + ":");
1419     JLabel showConsensbits = new JLabel();
1420     showConsensbits.setFont(LABEL_FONT);
1421     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
1422     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
1423     showConsensbits
1424             .setText(MessageManager.getString("label.consensus") + ":");
1425     showConsensHistogram.setEnabled(false);
1426     showConsensHistogram.setFont(LABEL_FONT);
1427     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
1428     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
1429     showConsensHistogram.setSelected(true);
1430     showConsensHistogram
1431             .setText(MessageManager.getString("label.histogram"));
1432     showConsensLogo.setEnabled(false);
1433     showConsensLogo.setFont(LABEL_FONT);
1434     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
1435     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
1436     showConsensLogo.setSelected(true);
1437     showConsensLogo.setText(MessageManager.getString("label.logo"));
1438     showGroupConsensus.setEnabled(false);
1439     showGroupConsensus.setFont(LABEL_FONT);
1440     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
1441     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
1442     showGroupConsensus.setSelected(true);
1443     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
1444     showGroupConservation.setEnabled(false);
1445     showGroupConservation.setFont(LABEL_FONT);
1446     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
1447     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
1448     showGroupConservation.setSelected(true);
1449     showGroupConservation
1450             .setText(MessageManager.getString("label.conservation"));
1451     showNpTooltip.setEnabled(true);
1452     showNpTooltip.setFont(LABEL_FONT);
1453     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1454     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1455     showNpTooltip.setSelected(true);
1456     showNpTooltip.setText(
1457             MessageManager.getString("label.non_positional_features"));
1458     showDbRefTooltip.setEnabled(true);
1459     showDbRefTooltip.setFont(LABEL_FONT);
1460     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1461     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1462     showDbRefTooltip.setSelected(true);
1463     showDbRefTooltip
1464             .setText(MessageManager.getString("label.database_references"));
1465     annotations.setFont(LABEL_FONT);
1466     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
1467     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
1468     annotations.setSelected(true);
1469     annotations.setText(MessageManager.getString("label.show_annotations"));
1470     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
1471     annotations.addActionListener(new ActionListener()
1472     {
1473       @Override
1474       public void actionPerformed(ActionEvent e)
1475       {
1476         annotations_actionPerformed(e);
1477       }
1478     });
1479     identity.addActionListener(new ActionListener()
1480     {
1481       @Override
1482       public void actionPerformed(ActionEvent e)
1483       {
1484         annotations_actionPerformed(e);
1485       }
1486     });
1487     showGroupConsensus.addActionListener(new ActionListener()
1488     {
1489       @Override
1490       public void actionPerformed(ActionEvent e)
1491       {
1492         annotations_actionPerformed(e);
1493       }
1494     });
1495     showUnconserved.setFont(LABEL_FONT);
1496     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
1497     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
1498     showUnconserved.setSelected(true);
1499     showUnconserved
1500             .setText(MessageManager.getString("action.show_unconserved"));
1501     showUnconserved.addActionListener(new ActionListener()
1502     {
1503       @Override
1504       public void actionPerformed(ActionEvent e)
1505       {
1506         showunconserved_actionPerformed(e);
1507       }
1508     });
1509
1510     // TODO these are not yet added to / action from Preferences
1511     // JCheckBox shareSelections = new JCheckBox();
1512     // shareSelections.setFont(verdana11);
1513     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
1514     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
1515     // shareSelections.setSelected(true);
1516     // shareSelections.setText(MessageManager
1517     // .getString("label.share_selection_across_views"));
1518     // JCheckBox followHighlight = new JCheckBox();
1519     // followHighlight.setFont(verdana11);
1520     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
1521     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
1522     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
1523     // followHighlight.setSelected(true);
1524     // followHighlight.setText(MessageManager
1525     // .getString("label.scroll_highlighted_regions"));
1526
1527     seqLimit.setFont(LABEL_FONT);
1528     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
1529     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
1530     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
1531     smoothFont.setFont(LABEL_FONT);
1532     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
1533     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
1534     smoothFont.setText(MessageManager.getString("label.smooth_font"));
1535     scaleProteinToCdna.setFont(LABEL_FONT);
1536     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
1537     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
1538     scaleProteinToCdna.setText(
1539             MessageManager.getString("label.scale_protein_to_cdna"));
1540     scaleProteinToCdna.setToolTipText(
1541             MessageManager.getString("label.scale_protein_to_cdna_tip"));
1542     JLabel gapLabel = new JLabel();
1543     gapLabel.setFont(LABEL_FONT);
1544     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1545     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
1546     JLabel fontLabel = new JLabel();
1547     fontLabel.setFont(LABEL_FONT);
1548     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1549     fontLabel.setText(MessageManager.getString("label.font"));
1550     fontSizeCB.setFont(LABEL_FONT);
1551     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
1552     fontStyleCB.setFont(LABEL_FONT);
1553     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
1554     fontNameCB.setFont(LABEL_FONT);
1555     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
1556     gapSymbolCB.setFont(LABEL_FONT);
1557     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
1558     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
1559     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
1560     gapSymbolCB.setRenderer(dlcr);
1561
1562     startupCheckbox.setText(MessageManager.getString("action.open_file"));
1563     startupCheckbox.setFont(LABEL_FONT);
1564     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
1565     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
1566     startupCheckbox.setSelected(true);
1567     startupFileTextfield.setFont(LABEL_FONT);
1568     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
1569     final String tooltip = JvSwingUtils.wrapTooltip(true,
1570             MessageManager.getString("label.double_click_to_browse"));
1571     startupFileTextfield.setToolTipText(tooltip);
1572     startupFileTextfield.addMouseListener(new MouseAdapter()
1573     {
1574       @Override
1575       public void mouseClicked(MouseEvent e)
1576       {
1577         if (e.getClickCount() > 1)
1578         {
1579           startupFileTextfield_mouseClicked();
1580         }
1581       }
1582     });
1583
1584     sortby.setFont(LABEL_FONT);
1585     sortby.setBounds(new Rectangle(172, 260, 155, 21));
1586     JLabel sortLabel = new JLabel();
1587     sortLabel.setFont(LABEL_FONT);
1588     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1589     sortLabel.setText(MessageManager.getString("label.sort_by"));
1590     sortAnnBy.setFont(LABEL_FONT);
1591     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
1592     JLabel sortAnnLabel = new JLabel();
1593     sortAnnLabel.setFont(LABEL_FONT);
1594     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1595     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
1596     sortAutocalc.setFont(LABEL_FONT);
1597     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
1598
1599     JPanel annsettingsPanel = new JPanel();
1600     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
1601     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
1602     annsettingsPanel.setBorder(new EtchedBorder());
1603     visualTab.add(annsettingsPanel);
1604     Border jb = new EmptyBorder(1, 1, 4, 5);
1605     annotations.setBorder(jb);
1606     showOccupancy.setBorder(jb);
1607     quality.setBorder(jb);
1608     conservation.setBorder(jb);
1609     identity.setBorder(jb);
1610     showConsensbits.setBorder(jb);
1611     showGroupbits.setBorder(jb);
1612     showGroupConsensus.setBorder(jb);
1613     showGroupConservation.setBorder(jb);
1614     showConsensHistogram.setBorder(jb);
1615     showConsensLogo.setBorder(jb);
1616
1617     JPanel autoAnnotSettings = new JPanel();
1618     annsettingsPanel.add(autoAnnotSettings);
1619     autoAnnotSettings.setLayout(new GridLayout(0, 2));
1620     autoAnnotSettings.add(annotations);
1621     autoAnnotSettings.add(quality);
1622     // second row of autoannotation box
1623     autoAnnotSettings = new JPanel();
1624     annsettingsPanel.add(autoAnnotSettings);
1625
1626     autoAnnotSettings.setLayout(new GridLayout(0, 3));
1627     autoAnnotSettings.add(conservation);
1628     autoAnnotSettings.add(identity);
1629     autoAnnotSettings.add(showOccupancy);
1630     autoAnnotSettings.add(showGroupbits);
1631     autoAnnotSettings.add(showGroupConservation);
1632     autoAnnotSettings.add(showGroupConsensus);
1633     autoAnnotSettings.add(showConsensbits);
1634     autoAnnotSettings.add(showConsensHistogram);
1635     autoAnnotSettings.add(showConsensLogo);
1636
1637     JPanel tooltipSettings = new JPanel();
1638     tooltipSettings.setBorder(new TitledBorder(
1639             MessageManager.getString("label.sequence_id_tooltip")));
1640     tooltipSettings.setBounds(173, 140, 220, 62);
1641     tooltipSettings.setLayout(new GridLayout(2, 1));
1642     tooltipSettings.add(showDbRefTooltip);
1643     tooltipSettings.add(showNpTooltip);
1644     visualTab.add(tooltipSettings);
1645
1646     wrap.setFont(LABEL_FONT);
1647     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
1648     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
1649     wrap.setText(MessageManager.getString("label.wrap_alignment"));
1650     rightAlign.setFont(LABEL_FONT);
1651     rightAlign.setForeground(Color.black);
1652     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
1653     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
1654     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
1655     idItalics.setFont(LABEL_FONT_ITALIC);
1656     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
1657     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
1658     idItalics.setText(
1659             MessageManager.getString("label.sequence_name_italics"));
1660     openoverv.setFont(LABEL_FONT);
1661     openoverv.setActionCommand(
1662             MessageManager.getString("label.open_overview"));
1663     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
1664     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
1665     openoverv.setText(MessageManager.getString("label.open_overview"));
1666     JPanel jPanel2 = new JPanel();
1667     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
1668     jPanel2.setLayout(new GridLayout(14, 1));
1669     jPanel2.add(fullScreen);
1670     jPanel2.add(openoverv);
1671     jPanel2.add(seqLimit);
1672     jPanel2.add(rightAlign);
1673     jPanel2.add(fontLabel);
1674     jPanel2.add(showUnconserved);
1675     jPanel2.add(idItalics);
1676     jPanel2.add(smoothFont);
1677     jPanel2.add(scaleProteinToCdna);
1678     jPanel2.add(gapLabel);
1679     jPanel2.add(wrap);
1680     jPanel2.add(sortLabel);
1681     jPanel2.add(sortAnnLabel);
1682     jPanel2.add(startupCheckbox);
1683     visualTab.add(jPanel2);
1684     visualTab.add(startupFileTextfield);
1685     visualTab.add(sortby);
1686     visualTab.add(sortAnnBy);
1687     visualTab.add(sortAutocalc);
1688     visualTab.add(gapSymbolCB);
1689     visualTab.add(fontNameCB);
1690     visualTab.add(fontSizeCB);
1691     visualTab.add(fontStyleCB);
1692     return visualTab;
1693   }
1694
1695   /**
1696    * Initialises the Backups tabbed panel.
1697    * 
1698    * @return
1699    */
1700   private JPanel initBackupsTab()
1701   {
1702     JPanel backupsTab = new JPanel();
1703     backupsTab.setBorder(new TitledBorder(MessageManager
1704           .getString("label.backup_files")));
1705     backupsTab.setLayout(new GridBagLayout());
1706
1707     GridBagConstraints gbc = new GridBagConstraints();
1708     gbc.weightx = 1.0;
1709     gbc.weighty = 0.0;
1710     gbc.anchor = GridBagConstraints.NORTHWEST;
1711     gbc.fill = GridBagConstraints.NONE;
1712
1713     initBackupsTabPresetsPanel();
1714     initBackupsTabSuffixPanel();
1715     initBackupsTabKeepFilesPanel();
1716     initBackupsTabFilenameExamplesPanel();
1717
1718     gbc.weightx = 0.5;
1719     enableBackupFiles.setFont(LABEL_FONT_BOLD);
1720     enableBackupFiles.setText(
1721             MessageManager.getString("label.enable_backupfiles"));
1722     enableBackupFiles.addActionListener(new ActionListener()
1723     {
1724       @Override
1725       public void actionPerformed(ActionEvent e)
1726       {
1727         boolean selected = enableBackupFiles.isSelected();
1728         // enable other options only when the first is checked
1729         backupsOptionsSetEnabled(selected);
1730       }
1731     });
1732
1733     // enable checkbox 1 row
1734     gbc.gridwidth = 1;
1735     gbc.gridx = 0;
1736     gbc.gridy = 0;
1737     backupsTab.add(enableBackupFiles, gbc);
1738
1739     gbc.gridx = 1;
1740     gbc.weightx = 1.0;
1741     gbc.gridheight = 2;
1742     //gbc.anchor = GridBagConstraints.NORTHEAST;
1743     //gbc.fill = GridBagConstraints.HORIZONTAL;
1744     backupsTab.add(exampleFilesPanel, gbc);
1745
1746     gbc.gridx = 0;
1747     gbc.gridy = 1;
1748     backupsTab.add(presetsPanel, gbc);
1749
1750     gbc.anchor = GridBagConstraints.NORTHWEST;
1751     gbc.fill = GridBagConstraints.NONE;
1752     gbc.gridwidth = 2;
1753     gbc.gridheight = 1;
1754     // whole suffix panel next row
1755     gbc.gridx = 0;
1756     gbc.gridy = 2;
1757     backupsTab.add(suffixPanel, gbc);
1758
1759     // keep files panel
1760     gbc.gridy = 3;
1761     backupsTab.add(keepfilesPanel, gbc);
1762
1763     /*
1764     // whole examples panel next row
1765     gbc.gridy = 3;
1766     backupsTab.add(exampleFilesPanel, gbc);
1767
1768     // fill empty space
1769     gbc.gridy = 4;
1770     gbc.weighty = 1.0;
1771     backupsTab.add(new JPanel(), gbc);
1772     */
1773
1774     backupsOptionsSetEnabled(enableBackupFiles.isSelected());
1775     return backupsTab;
1776   }
1777
1778   private final IntKeyStringValueEntry[] backupfilesPresetEntries = 
1779   {
1780     new IntKeyStringValueEntry(1, MessageManager.getString("label.default")),
1781     new IntKeyStringValueEntry(2, MessageManager.getString("label.single_file")),
1782     new IntKeyStringValueEntry(3, MessageManager.getString("label.keep_everything")),
1783     new IntKeyStringValueEntry(4, MessageManager.getString("label.rolled_backups")),
1784     // ...
1785     // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
1786     new IntKeyStringValueEntry(0, MessageManager.getString("label.custom"))
1787   };
1788
1789   private final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
1790   {{
1791       put(1, new BackupFilesPresetEntry(".v"+BackupFiles.NUM_PLACEHOLDER, 3, false, false, 4, false));
1792       put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
1793       put(3, new BackupFilesPresetEntry(".v"+BackupFiles.NUM_PLACEHOLDER, 3, false, true, 10, true));
1794       put(4, new BackupFilesPresetEntry("_bak."+BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9, false));
1795   }};
1796
1797   private JPanel initBackupsTabPresetsPanel()
1798   {
1799     presetsPanel.setBorder(new TitledBorder(
1800             MessageManager.getString("label.presets")));
1801
1802     for (int i = 0; i < backupfilesPresetEntries.length; i++)
1803     {
1804         backupfilesPresetsCombo.addItem(backupfilesPresetEntries[i]);
1805     }
1806
1807     backupfilesPresetsCombo.addActionListener(new ActionListener()
1808         {
1809             @Override
1810             public void actionPerformed(ActionEvent e)
1811             {
1812               backupsTabUpdatePresets();
1813             }
1814         }
1815     );
1816
1817     presetsPanel.add(backupfilesPresetsCombo);
1818     return presetsPanel;
1819   }
1820
1821   private void backupsTabUpdatePresets()
1822   {
1823     IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo.getSelectedItem();
1824     int key = entry.getKey();
1825     String value = entry.getValue();
1826     boolean custom = key==0;
1827
1828     if (custom)
1829     {
1830       //backupsSetCustomOptions();
1831     } else
1832     {
1833       if (backupfilesPresetEntriesValues.containsKey(key))
1834       {
1835         backupsSetOptions(backupfilesPresetEntriesValues.get(key));
1836       } else {
1837         System.out.println("Preset '"+value+"' not implemented yet");
1838       }
1839     }
1840
1841     updateBackupFilesExampleLabel();
1842     backupsCustomOptionsSetEnabled(custom);
1843   }
1844
1845   protected int getComboIntStringKey(JComboBox c)
1846   {
1847     IntKeyStringValueEntry e = (IntKeyStringValueEntry) c.getSelectedItem();
1848     return e!=null?e.getKey():0;
1849   }
1850
1851   protected void setComboIntStringKey(JComboBox<IntKeyStringValueEntry> c, int key)
1852   {
1853       for (int i=0; i < c.getItemCount(); i++)
1854       {
1855           IntKeyStringValueEntry e = c.getItemAt(i);
1856           int k = e.getKey();
1857           String v = e.getValue();
1858           if (e.getKey() == key)
1859           {
1860               c.setSelectedIndex(i);
1861               break;
1862           }
1863       }
1864       backupsTabUpdatePresets();
1865   }
1866
1867   private JPanel initBackupsTabSuffixPanel()
1868   {
1869     suffixPanel.setBorder(new TitledBorder(
1870             MessageManager.getString("label.suffix_format")));
1871     suffixPanel.setLayout(new GridBagLayout());
1872
1873     suffixTemplateLabel
1874             .setText(MessageManager.getString("label.suffix_template"));
1875     suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
1876     suffixTemplateLabel.setFont(LABEL_FONT);
1877
1878     final String tooltip = JvSwingUtils.wrapTooltip(true, MessageManager
1879             .getString("label.suffix_template_tooltip"));
1880     suffixTemplate.setToolTipText(tooltip);
1881     suffixTemplate.addActionListener(new ActionListener()
1882     {
1883       @Override
1884       public void actionPerformed(ActionEvent e)
1885       {
1886         updateBackupFilesExampleLabel();
1887       }
1888
1889     });
1890     KeyListener kl = new KeyListener()
1891     {
1892       @Override
1893       public void keyReleased(KeyEvent e)
1894       {
1895         updateBackupFilesExampleLabel();
1896       }
1897
1898       @Override
1899       public void keyPressed(KeyEvent e)
1900       {
1901       }
1902
1903       // disable use of ':'
1904       @Override
1905       public void keyTyped(KeyEvent e)
1906       {
1907         char c = e.getKeyChar();
1908         if (c == ':')
1909         {
1910           // don't process ':'
1911           e.consume();
1912         }
1913       }
1914
1915     };
1916     suffixTemplate.addKeyListener(kl);
1917
1918     // digits spinner
1919     suffixDigitsLabel
1920             .setText(MessageManager.getString("label.index_digits"));
1921     suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
1922     suffixDigitsLabel.setFont(LABEL_FONT);
1923     int defaultmin = 1;
1924     int defaultmax = 6;
1925     ChangeListener c = new ChangeListener()
1926     {
1927       @Override
1928       public void stateChanged(ChangeEvent e)
1929       {
1930         updateBackupFilesExampleLabel();
1931       }
1932
1933     };
1934     setIntegerSpinner(suffixDigitsSpinner, defaultmin, defaultmax, 3, c);
1935
1936     suffixReverse.setLabels(
1937             MessageManager.getString("label.reverse_roll"),
1938             MessageManager.getString("label.increment_index"));
1939     suffixReverse.addActionListener(new ActionListener()
1940     {
1941       @Override
1942       public void actionPerformed(ActionEvent e)
1943       {
1944         updateBackupFilesExampleLabel();
1945       }
1946     });
1947
1948     GridBagConstraints sgbc = new GridBagConstraints();
1949
1950     // first row (template text box)
1951     sgbc.anchor = GridBagConstraints.WEST;
1952     sgbc.gridx = 0;
1953     sgbc.gridy = 0;
1954     sgbc.gridwidth = 1;
1955     sgbc.gridheight = 1;
1956     sgbc.weightx = 1.0;
1957     sgbc.weighty = 0.0;
1958     sgbc.fill = GridBagConstraints.NONE;
1959     suffixPanel.add(suffixTemplateLabel,sgbc);
1960     
1961     sgbc.gridx = 1;
1962     sgbc.fill = GridBagConstraints.HORIZONTAL;
1963     suffixPanel.add(suffixTemplate, sgbc);
1964     
1965     // second row (number of digits spinner)
1966     sgbc.gridy = 1;
1967     
1968     sgbc.gridx = 0;
1969     sgbc.fill = GridBagConstraints.NONE;
1970     suffixPanel.add(suffixDigitsLabel, sgbc);
1971
1972     sgbc.gridx = 1;
1973     sgbc.fill = GridBagConstraints.HORIZONTAL;
1974     suffixPanel.add(suffixDigitsSpinner, sgbc);
1975
1976     // third row (forward order radio selection)
1977     sgbc.gridx = 0;
1978     sgbc.gridy = 2;
1979     sgbc.gridwidth = GridBagConstraints.REMAINDER;
1980     sgbc.fill = GridBagConstraints.HORIZONTAL;
1981     suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
1982
1983     // fourth row (reverse order radio selection)
1984     sgbc.gridy = 3;
1985     suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
1986     return suffixPanel;
1987   }
1988
1989   private void backupfilesKeepAllEnabled(boolean enabled)
1990   {
1991     backupfilesKeepAll.setEnabled(enabled);
1992     keepRollMaxOptionsEnabled();
1993   }
1994
1995   private JPanel initBackupsTabKeepFilesPanel()
1996   {
1997     keepfilesPanel.setBorder(
1998             new TitledBorder(MessageManager.getString("label.keep_files")));
1999     keepfilesPanel.setLayout(new GridBagLayout());
2000
2001     backupfilesKeepAll.setLabels(
2002             MessageManager.getString("label.keep_all_backup_files"),
2003             MessageManager.getString(
2004                     "label.keep_only_this_number_of_backup_files"));
2005     backupfilesKeepAll.addTrueActionListener(new ActionListener()
2006     {
2007       @Override
2008       public void actionPerformed(ActionEvent e)
2009       {
2010         updateBackupFilesExampleLabel();
2011       }
2012     });
2013     backupfilesKeepAll.addActionListener(new ActionListener()
2014     {
2015       @Override
2016       public void actionPerformed(ActionEvent e)
2017       {
2018         boolean selected = backupfilesKeepAll.isSelected();
2019         keepRollMaxOptionsEnabled();
2020         updateBackupFilesExampleLabel();
2021       }
2022     });
2023
2024     ChangeListener c = new ChangeListener()
2025     {
2026       @Override
2027       public void stateChanged(ChangeEvent e)
2028       {
2029         updateBackupFilesExampleLabel();
2030       }
2031
2032     };
2033     setIntegerSpinner(backupfilesRollMaxSpinner, 1, 999, 4, true, c);
2034
2035     backupfilesConfirmDelete.setLabels(
2036             MessageManager.getString("label.confirm_delete"),
2037             MessageManager.getString("label.auto_delete"));
2038     // update the enabled section
2039     keepRollMaxOptionsEnabled();
2040
2041     GridBagConstraints kgbc = new GridBagConstraints();
2042
2043     // first row (template text box)
2044     kgbc.anchor = GridBagConstraints.WEST;
2045     kgbc.gridx = 0;
2046     kgbc.gridy = 0;
2047     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2048     kgbc.gridheight = 1;
2049     kgbc.weightx = 1.0;
2050     kgbc.weighty = 0.0;
2051     kgbc.fill = GridBagConstraints.HORIZONTAL;
2052     keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
2053
2054     // second row
2055     kgbc.gridy = 1;
2056
2057     kgbc.gridx = 0;
2058     kgbc.gridwidth = GridBagConstraints.RELATIVE;
2059     keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
2060
2061     kgbc.gridx = 1;
2062     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2063     keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
2064
2065     // third row (indented)
2066     kgbc.gridy = 2;
2067     kgbc.insets = new Insets(0, 20, 0, 0);
2068
2069     kgbc.gridx = 0;
2070     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2071     kgbc.fill = GridBagConstraints.HORIZONTAL;
2072     kgbc.weightx = 1.0;
2073     /*
2074     keepfilesPanel.add(backupfilesConfirmDelete.getTrueButton(), kgbc);
2075     
2076     // fourth row (indented)
2077     kgbc.gridy = 3;
2078     keepfilesPanel.add(backupfilesConfirmDelete.getFalseButton(), kgbc);
2079     */
2080
2081     JPanel jp = new JPanel();
2082     jp.setLayout(new FlowLayout());
2083     oldBackupFilesLabel
2084             .setText(MessageManager.getString("label.old_backup_files"));
2085     oldBackupFilesLabel.setFont(LABEL_FONT);
2086     oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
2087     jp.add(oldBackupFilesLabel);
2088     jp.add(backupfilesConfirmDelete.getTrueButton());
2089     jp.add(backupfilesConfirmDelete.getFalseButton());
2090     keepfilesPanel.add(jp, kgbc);
2091     
2092     return keepfilesPanel;
2093   }
2094
2095   private JPanel initBackupsTabFilenameExamplesPanel()
2096   {
2097     String title = MessageManager.getString("label.example_filenames");
2098     TitledBorder tb = new TitledBorder(title);
2099     //tb.setTitleFont(LABEL_FONT);
2100     exampleFilesPanel.setBorder(tb);
2101     exampleFilesPanel.setLayout(new GridBagLayout());
2102
2103     //inordinately difficult to get this titledborder the right size for the title
2104
2105     backupfilesExampleLabel.setEditable(false);
2106     backupfilesExampleLabel.setPreferredSize(new Dimension(280, 85));
2107     backupfilesExampleLabel.setAlignmentX(LEFT_ALIGNMENT);
2108     backupfilesExampleLabel.setAlignmentY(TOP_ALIGNMENT);
2109     
2110     backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
2111     backupfilesExampleLabel
2112             .setBackground(exampleFilesPanel.getBackground());
2113
2114     updateBackupFilesExampleLabel();
2115     exampleFilesPanel.setMinimumSize(new Dimension(280, 85));
2116
2117     GridBagConstraints gbc = new GridBagConstraints();
2118     gbc.anchor = GridBagConstraints.EAST;
2119
2120     gbc.gridy = 0;
2121     exampleFilesPanel.add(backupfilesExampleLabel, gbc);
2122     return exampleFilesPanel;
2123   }
2124
2125   protected void updateBackupFilesExampleLabel()
2126   {
2127     int exampleindex = 12;
2128     String base = MessageManager.getString("label.filename");
2129     if (base == null || base.length() > 0)
2130     {
2131       base = "filename.fa";
2132     }
2133
2134     String suffix = suffixTemplate.getText();
2135     int digits = 3;
2136     try {
2137       suffixDigitsSpinner.commitEdit();
2138       digits = (Integer) suffixDigitsSpinner.getValue();
2139       digits = digits < 1 ? 1 : digits;
2140     } catch (Exception e)
2141     {
2142       System.out.println("Failed casting (Integer) suffixTemplateSpinner.getValue()");
2143     }
2144     boolean reverse = suffixReverse.isSelected();
2145     boolean keepAll = backupfilesKeepAll.isSelected();
2146     int rollMax = 4;
2147     try
2148     {
2149       backupfilesRollMaxSpinner.commitEdit();
2150       rollMax = (Integer) backupfilesRollMaxSpinner.getValue();
2151       rollMax = rollMax < 1 ? 1 : rollMax;
2152     } catch (Exception e)
2153     {
2154       System.out.println(
2155               "Failed casting (Integer) backupfilesRollMaxSpinner.getValue()");
2156     }
2157
2158     int lowersurround = 2;
2159     int uppersurround = 0;
2160     StringBuilder exampleSB = new StringBuilder();
2161     boolean firstLine = true;
2162     if (reverse)
2163     {
2164
2165       int min = 1;
2166       int max = keepAll ? exampleindex : rollMax;
2167       for (int index = min; index <= max; index++)
2168       {
2169         if (index == min + lowersurround && index < max - uppersurround - 1)
2170         {
2171           exampleSB.append("\n...");
2172         }
2173         else if (index > min + lowersurround && index < max - uppersurround)
2174         {
2175           // nothing
2176         }
2177         else
2178         {
2179           if (firstLine)
2180           {
2181             firstLine = false;
2182           }
2183           else
2184           {
2185             exampleSB.append("\n");
2186           }
2187           exampleSB.append(BackupFilenameFilter.getBackupFilename(index,
2188                   base, suffix, digits));
2189           if (min == max)
2190           {
2191             // no extra text needed
2192           }
2193           else if (index == min)
2194           {
2195             String newest = MessageManager.getString("label.braced_newest");
2196             if (newest != null && newest.length() > 0)
2197             {
2198               exampleSB.append(" "+newest);
2199             }
2200           }
2201           else if (index == max)
2202           {
2203             String oldest = MessageManager.getString("label.braced_oldest");
2204             if (oldest != null && oldest.length() > 0)
2205             {
2206               exampleSB.append(" "+oldest);
2207             }
2208           }
2209         }
2210       }
2211     }
2212     else
2213     {
2214
2215       int min = (keepAll || exampleindex - rollMax < 0) ? 1
2216               : exampleindex - rollMax + 1;
2217       int max = exampleindex;
2218
2219       for (int index = min; index <= max; index++)
2220       {
2221
2222         if (index == min + lowersurround && index < max - uppersurround - 1)
2223         {
2224           exampleSB.append("\n...");
2225         }
2226         else if (index > min + lowersurround && index < max - uppersurround)
2227         {
2228           // nothing
2229         }
2230         else
2231         {
2232           if (firstLine)
2233           {
2234             firstLine = false;
2235           }
2236           else
2237           {
2238             exampleSB.append("\n");
2239           }
2240           exampleSB.append(BackupFilenameFilter.getBackupFilename(index,
2241                   base, suffix, digits));
2242           if (min == max)
2243           {
2244             // no extra text needed
2245           }
2246           else if (index == min)
2247           {
2248             String oldest = MessageManager.getString("label.braced_oldest");
2249             if (oldest != null && oldest.length() > 0)
2250             {
2251               exampleSB.append(" "+oldest);
2252             }
2253           }
2254           else if (index == max)
2255           {
2256             String newest = MessageManager.getString("label.braced_newest");
2257             if (newest != null && newest.length() > 0)
2258             {
2259               exampleSB.append(" "+newest);
2260             }
2261           }
2262         }
2263       }
2264
2265     }
2266
2267     backupfilesExampleLabel.setText(exampleSB.toString());
2268   }
2269
2270   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2271           boolean useExistingVal, ChangeListener c)
2272   {
2273     int i = def;
2274     if (useExistingVal)
2275     {
2276       try
2277       {
2278         i = Integer.parseInt((String) s.getValue());
2279       } catch (Exception e)
2280       {
2281         System.out.println(
2282                 "Exception casting the initial value of s.getValue()");
2283       }
2284     }
2285
2286     setIntegerSpinner(s, min, max, i, c);
2287   }
2288
2289   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2290           ChangeListener c)
2291   {
2292     // integer spinner for number of digits
2293     if (def > max)
2294     {
2295       max = def;
2296     }
2297     SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
2298     s.setModel(sModel);
2299
2300     s.addChangeListener(c);
2301
2302   }
2303
2304   protected static int getSpinnerInt(JSpinner s, int def)
2305   {
2306     int i = def;
2307     try
2308     {
2309       s.commitEdit();
2310       i = (Integer) s.getValue();
2311     } catch (Exception e)
2312     {
2313       System.out.println("Failed casting (Integer) JSpinner s.getValue()");
2314     }
2315     return i;
2316   }
2317
2318   protected void keepRollMaxOptionsEnabled()
2319   {
2320     keepRollMaxOptionsEnabled(backupfilesKeepAll.isEnabled());
2321   }
2322
2323   protected void keepRollMaxOptionsEnabled(boolean tryEnabled)
2324   {
2325     boolean enabled = tryEnabled && !backupfilesKeepAll.isSelected();
2326     oldBackupFilesLabel.setEnabled(enabled);
2327     backupfilesRollMaxSpinner.setEnabled(enabled);
2328     backupfilesConfirmDelete.setEnabled(enabled);
2329   }
2330
2331   protected void backupsCustomOptionsSetEnabled(boolean enabled)
2332   {
2333       backupsOptionsSetEnabled(enabled, false);
2334   }
2335
2336   protected void backupsOptionsSetEnabled(boolean enabled)
2337   {
2338       backupsOptionsSetEnabled(enabled, true);
2339   }
2340
2341   protected void backupsOptionsSetEnabled(boolean enabled, boolean all)
2342   {
2343
2344     if (all)
2345     {
2346         presetsPanel.setEnabled(enabled);
2347         exampleFilesPanel.setEnabled(enabled);
2348
2349         backupfilesPresetsCombo.setEnabled(enabled);
2350         backupfilesExampleLabel.setEnabled(enabled);
2351     }
2352     suffixPanel.setEnabled(enabled);
2353     keepfilesPanel.setEnabled(enabled);
2354
2355     suffixTemplate.setEnabled(enabled);
2356     suffixTemplateLabel.setEnabled(enabled);
2357     suffixDigitsLabel.setEnabled(enabled);
2358     suffixDigitsSpinner.setEnabled(enabled);
2359     suffixReverse.setEnabled(enabled);
2360     oldBackupFilesLabel.setEnabled(enabled);
2361     backupfilesKeepAllEnabled(enabled);
2362
2363     if (enabled && all)
2364     {
2365       backupsTabUpdatePresets();
2366     }
2367   }
2368
2369   protected void backupsSetOptions(String suffix, int digits, boolean reverse, boolean keepAll, int rollMax, boolean confirmDelete)
2370   {
2371     suffixTemplate.setText(suffix);
2372     suffixDigitsSpinner.setValue(digits);
2373     suffixReverse.setSelected(reverse);
2374     backupfilesKeepAll.setSelected(keepAll);
2375     backupfilesRollMaxSpinner.setValue(rollMax);
2376     backupfilesConfirmDelete.setSelected(confirmDelete);
2377   }
2378
2379   protected void backupsSetOptions(BackupFilesPresetEntry p)
2380   {
2381     backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax, p.confirmDelete);
2382   }
2383
2384   protected void autoIdWidth_actionPerformed()
2385   {
2386     // TODO Auto-generated method stub
2387
2388   }
2389
2390   protected void userIdWidth_actionPerformed()
2391   {
2392     // TODO Auto-generated method stub
2393
2394   }
2395
2396   protected void maxColour_actionPerformed(JPanel panel)
2397   {
2398   }
2399
2400   protected void minColour_actionPerformed(JPanel panel)
2401   {
2402   }
2403
2404   protected void gapColour_actionPerformed(JPanel panel)
2405   {
2406   }
2407
2408   protected void hiddenColour_actionPerformed(JPanel panel)
2409   {
2410   }
2411
2412   protected void showunconserved_actionPerformed(ActionEvent e)
2413   {
2414     // TODO Auto-generated method stub
2415
2416   }
2417
2418   protected void useLegacyGaps_actionPerformed(ActionEvent e)
2419   {
2420   }
2421
2422   protected void resetOvDefaults_actionPerformed(ActionEvent e)
2423   {
2424   }
2425
2426   /**
2427    * DOCUMENT ME!
2428    * 
2429    * @param e
2430    *          DOCUMENT ME!
2431    */
2432   public void ok_actionPerformed(ActionEvent e)
2433   {
2434   }
2435
2436   /**
2437    * DOCUMENT ME!
2438    * 
2439    * @param e
2440    *          DOCUMENT ME!
2441    */
2442   public void cancel_actionPerformed(ActionEvent e)
2443   {
2444   }
2445
2446   /**
2447    * DOCUMENT ME!
2448    * 
2449    * @param e
2450    *          DOCUMENT ME!
2451    */
2452   public void annotations_actionPerformed(ActionEvent e)
2453   {
2454   }
2455
2456   /**
2457    * DOCUMENT ME!
2458    */
2459   public void startupFileTextfield_mouseClicked()
2460   {
2461   }
2462
2463   public void newLink_actionPerformed(ActionEvent e)
2464   {
2465
2466   }
2467
2468   public void editLink_actionPerformed(ActionEvent e)
2469   {
2470
2471   }
2472
2473   public void deleteLink_actionPerformed(ActionEvent e)
2474   {
2475
2476   }
2477
2478   public void defaultBrowser_mouseClicked(MouseEvent e)
2479   {
2480
2481   }
2482
2483   public void linkURLList_keyTyped(KeyEvent e)
2484   {
2485
2486   }
2487
2488   public void useProxy_actionPerformed()
2489   {
2490     boolean enabled = useProxy.isSelected();
2491     portLabel.setEnabled(enabled);
2492     serverLabel.setEnabled(enabled);
2493     proxyServerTB.setEnabled(enabled);
2494     proxyPortTB.setEnabled(enabled);
2495   }
2496
2497   /**
2498    * Customer renderer for JTable: supports column of radio buttons
2499    */
2500   public class RadioButtonRenderer extends JRadioButton
2501           implements TableCellRenderer
2502   {
2503     public RadioButtonRenderer()
2504     {
2505       setHorizontalAlignment(CENTER);
2506       setToolTipText(MessageManager.getString("label.urltooltip"));
2507     }
2508
2509     @Override
2510     public Component getTableCellRendererComponent(JTable table,
2511             Object value, boolean isSelected, boolean hasFocus, int row,
2512             int column)
2513     {
2514       setSelected((boolean) value);
2515
2516       // set colours to match rest of table
2517       if (isSelected)
2518       {
2519         setBackground(table.getSelectionBackground());
2520         setForeground(table.getSelectionForeground());
2521       }
2522       else
2523       {
2524         setBackground(table.getBackground());
2525         setForeground(table.getForeground());
2526       }
2527       return this;
2528     }
2529   }
2530
2531   /**
2532    * Customer cell editor for JTable: supports column of radio buttons in
2533    * conjunction with renderer
2534    */
2535   public class RadioButtonEditor extends AbstractCellEditor
2536           implements TableCellEditor
2537   {
2538     private JRadioButton button = new JRadioButton();
2539
2540     public RadioButtonEditor()
2541     {
2542       button.setHorizontalAlignment(SwingConstants.CENTER);
2543       this.button.addActionListener(new ActionListener()
2544       {
2545         @Override
2546         public void actionPerformed(ActionEvent e)
2547         {
2548           fireEditingStopped();
2549         }
2550       });
2551     }
2552
2553     @Override
2554     public Component getTableCellEditorComponent(JTable table, Object value,
2555             boolean isSelected, int row, int column)
2556     {
2557       button.setSelected((boolean) value);
2558       return button;
2559     }
2560
2561     @Override
2562     public Object getCellEditorValue()
2563     {
2564       return button.isSelected();
2565     }
2566
2567   }
2568 }
2569
2570 class IntKeyStringValueEntry {
2571   int k;
2572   String v;
2573   public IntKeyStringValueEntry(int k, String v)
2574   {
2575     this.k = k;
2576     this.v = v;
2577   }
2578   @Override
2579   public String toString()
2580   {
2581     return this.getValue();
2582   }
2583   public int getKey()
2584   {
2585     return k;
2586   }
2587   public String getValue()
2588   {
2589     return v;
2590   }
2591 }
2592
2593 class BackupFilesPresetEntry {
2594   String suffix;
2595   int digits;
2596   boolean reverse;
2597   boolean keepAll;
2598   int rollMax;
2599   boolean confirmDelete;
2600   public BackupFilesPresetEntry(String suffix, int digits, boolean reverse, boolean keepAll, int rollMax, boolean confirmDelete)
2601   {
2602     this.suffix = suffix;
2603     this.digits = digits;
2604     this.reverse = reverse;
2605     this.keepAll = keepAll;
2606     this.rollMax = rollMax;
2607     this.confirmDelete = confirmDelete;
2608   }
2609 }