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