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