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