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