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