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