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