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