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