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