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