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