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