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