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