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