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