JAL-3633 last minute refinement so password box doesn't get focus all the time
[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
994     // check for any change to enable applyProxyButton
995     DocumentListener d = new DocumentListener()
996     {
997       @Override
998       public void changedUpdate(DocumentEvent e)
999       {
1000         applyProxyButtonEnabled(true);
1001       }
1002
1003       @Override
1004       public void insertUpdate(DocumentEvent e)
1005       {
1006         applyProxyButtonEnabled(true);
1007       }
1008
1009       @Override
1010       public void removeUpdate(DocumentEvent e)
1011       {
1012         applyProxyButtonEnabled(true);
1013       }
1014     };
1015     proxyServerHttpTB.getDocument().addDocumentListener(d);
1016     proxyPortHttpTB.getDocument().addDocumentListener(d);
1017     proxyServerHttpsTB.getDocument().addDocumentListener(d);
1018     proxyPortHttpsTB.getDocument().addDocumentListener(d);
1019     proxyAuthUsernameTB.getDocument().addDocumentListener(d);
1020     proxyAuthPasswordPB.setFont(LABEL_FONT);
1021     proxyAuthPasswordPB.setColumns(30);
1022     proxyAuthPasswordPB.getDocument()
1023             .addDocumentListener(new DocumentListener()
1024             {
1025               @Override
1026               public void changedUpdate(DocumentEvent e)
1027               {
1028                 proxyAuthPasswordCheckHighlight(true);
1029                 applyProxyButtonEnabled(true);
1030               }
1031
1032               @Override
1033               public void insertUpdate(DocumentEvent e)
1034               {
1035                 proxyAuthPasswordCheckHighlight(true);
1036                 applyProxyButtonEnabled(true);
1037               }
1038
1039               @Override
1040               public void removeUpdate(DocumentEvent e)
1041               {
1042                 proxyAuthPasswordCheckHighlight(true);
1043                 applyProxyButtonEnabled(true);
1044               }
1045
1046             });
1047
1048     // Label for Port text box
1049     portLabel.setFont(LABEL_FONT);
1050     portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1051     portLabel.setText(MessageManager.getString("label.port") + ": ");
1052     portLabel2.setFont(LABEL_FONT);
1053     portLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
1054     portLabel2.setText(MessageManager.getString("label.port") + ": ");
1055
1056     httpLabel.setText("HTTP");
1057     httpLabel.setFont(LABEL_FONT_BOLD);
1058     httpLabel.setHorizontalAlignment(SwingConstants.LEFT);
1059     httpsLabel.setText("HTTPS");
1060     httpsLabel.setFont(LABEL_FONT_BOLD);
1061     httpsLabel.setHorizontalAlignment(SwingConstants.LEFT);
1062
1063     proxyAuthUsernameLabel
1064             .setText(MessageManager.getString("label.username") + ": ");
1065     proxyAuthUsernameLabel.setFont(LABEL_FONT);
1066     proxyAuthUsernameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1067     proxyAuthPasswordLabel
1068             .setText(MessageManager.getString("label.password") + ": ");
1069     proxyAuthPasswordLabel.setFont(LABEL_FONT);
1070     proxyAuthPasswordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1071     passwordNotStoredLabel.setText(
1072             "(" + MessageManager.getString("label.not_stored") + ")");
1073     passwordNotStoredLabel.setFont(LABEL_FONT_ITALIC);
1074     passwordNotStoredLabel.setHorizontalAlignment(SwingConstants.LEFT);
1075
1076     // Proxy type radio buttons
1077     noProxy.setFont(LABEL_FONT);
1078     noProxy.setHorizontalAlignment(SwingConstants.LEFT);
1079     noProxy.setText(MessageManager.getString("label.no_proxy"));
1080     systemProxy.setFont(LABEL_FONT);
1081     systemProxy.setHorizontalAlignment(SwingConstants.LEFT);
1082     systemProxy.setText(MessageManager.formatMessage("label.system_proxy",
1083             displayUserHostPort(Cache.startupProxyProperties[4],
1084                     Cache.startupProxyProperties[0],
1085                     Cache.startupProxyProperties[1]),
1086             displayUserHostPort(Cache.startupProxyProperties[6],
1087                     Cache.startupProxyProperties[2],
1088                     Cache.startupProxyProperties[3])));
1089     customProxy.setFont(LABEL_FONT);
1090     customProxy.setHorizontalAlignment(SwingConstants.LEFT);
1091     customProxy.setText(
1092             MessageManager.getString("label.use_proxy_server") + ":");
1093     ActionListener al = new ActionListener()
1094     {
1095       @Override
1096       public void actionPerformed(ActionEvent e)
1097       {
1098         proxyType_actionPerformed();
1099       }
1100     };
1101     noProxy.addActionListener(al);
1102     systemProxy.addActionListener(al);
1103     customProxy.addActionListener(al);
1104     proxyType.add(noProxy);
1105     proxyType.add(systemProxy);
1106     proxyType.add(customProxy);
1107
1108     proxyAuth.setFont(LABEL_FONT);
1109     proxyAuth.setHorizontalAlignment(SwingConstants.LEFT);
1110     proxyAuth.setText(MessageManager.getString("label.auth_required"));
1111     proxyAuth.addActionListener(new ActionListener()
1112     {
1113       @Override
1114       public void actionPerformed(ActionEvent e)
1115       {
1116         proxyAuth_actionPerformed();
1117       }
1118     });
1119
1120     setCustomProxyEnabled();
1121
1122     // Make proxy server panel
1123     JPanel proxyPanel = new JPanel();
1124     TitledBorder titledBorder1 = new TitledBorder(
1125             MessageManager.getString("label.proxy_servers"));
1126     proxyPanel.setBorder(titledBorder1);
1127     proxyPanel.setLayout(new GridBagLayout());
1128     GridBagConstraints gbc = new GridBagConstraints();
1129     gbc.fill = GridBagConstraints.HORIZONTAL;
1130     gbc.weightx = 1.0;
1131
1132     GridBagConstraints c = new GridBagConstraints();
1133     // Proxy type radio buttons (3)
1134     JPanel ptPanel = new JPanel();
1135     ptPanel.setLayout(new GridBagLayout());
1136     c.weightx = 1.0;
1137     c.gridy = 0;
1138     c.gridx = 0;
1139     c.gridwidth = 1;
1140     c.fill = GridBagConstraints.HORIZONTAL;
1141     ptPanel.add(noProxy, c);
1142     c.gridy++;
1143     ptPanel.add(systemProxy, c);
1144     c.gridy++;
1145     ptPanel.add(customProxy, c);
1146
1147     gbc.gridy = 0;
1148     proxyPanel.add(ptPanel, gbc);
1149
1150     // host and port text boxes
1151     JPanel hpPanel = new JPanel();
1152     hpPanel.setLayout(new GridBagLayout());
1153     // HTTP host port row
1154     c.gridy = 0;
1155     c.gridx = 0;
1156
1157     c.weightx = 0.1;
1158     c.anchor = GridBagConstraints.LINE_START;
1159     hpPanel.add(httpLabel, c);
1160
1161     c.gridx++;
1162     c.weightx = 0.1;
1163     c.anchor = GridBagConstraints.LINE_END;
1164     hpPanel.add(serverLabel, c);
1165
1166     c.gridx++;
1167     c.weightx = 1.0;
1168     c.anchor = GridBagConstraints.LINE_START;
1169     hpPanel.add(proxyServerHttpTB, c);
1170
1171     c.gridx++;
1172     c.weightx = 0.1;
1173     c.anchor = GridBagConstraints.LINE_END;
1174     hpPanel.add(portLabel, c);
1175
1176     c.gridx++;
1177     c.weightx = 0.2;
1178     c.anchor = GridBagConstraints.LINE_START;
1179     hpPanel.add(proxyPortHttpTB, c);
1180
1181     // HTTPS host port row
1182     c.gridy++;
1183     c.gridx = 0;
1184     c.gridwidth = 1;
1185
1186     c.anchor = GridBagConstraints.LINE_START;
1187     hpPanel.add(httpsLabel, c);
1188
1189     c.gridx++;
1190     c.anchor = GridBagConstraints.LINE_END;
1191     hpPanel.add(serverLabel2, c);
1192
1193     c.gridx++;
1194     c.anchor = GridBagConstraints.LINE_START;
1195     hpPanel.add(proxyServerHttpsTB, c);
1196
1197     c.gridx++;
1198     c.anchor = GridBagConstraints.LINE_END;
1199     hpPanel.add(portLabel2, c);
1200
1201     c.gridx++;
1202     c.anchor = GridBagConstraints.LINE_START;
1203     hpPanel.add(proxyPortHttpsTB, c);
1204
1205     gbc.gridy++;
1206     proxyPanel.add(hpPanel, gbc);
1207
1208     // Require authentication checkbox
1209     gbc.gridy++;
1210     proxyPanel.add(proxyAuth, gbc);
1211
1212     // username and password
1213     JPanel upPanel = new JPanel();
1214     upPanel.setLayout(new GridBagLayout());
1215     // username row
1216     c.gridy = 0;
1217     c.gridx = 0;
1218     c.gridwidth = 1;
1219     c.weightx = 0.4;
1220     c.anchor = GridBagConstraints.LINE_END;
1221     upPanel.add(proxyAuthUsernameLabel, c);
1222
1223     c.gridx++;
1224     c.weightx = 1.0;
1225     c.anchor = GridBagConstraints.LINE_START;
1226     upPanel.add(proxyAuthUsernameTB, c);
1227
1228     // password row
1229     c.gridy++;
1230     c.gridx = 0;
1231     c.weightx = 0.4;
1232     c.anchor = GridBagConstraints.LINE_END;
1233     upPanel.add(proxyAuthPasswordLabel, c);
1234
1235     c.gridx++;
1236     c.weightx = 1.0;
1237     c.anchor = GridBagConstraints.LINE_START;
1238     upPanel.add(proxyAuthPasswordPB, c);
1239
1240     c.gridx++;
1241     c.weightx = 0.4;
1242     c.anchor = GridBagConstraints.LINE_START;
1243     upPanel.add(passwordNotStoredLabel, c);
1244
1245     gbc.gridy++;
1246     proxyPanel.add(upPanel, gbc);
1247
1248     applyProxyButton.setText(MessageManager.getString("action.apply"));
1249     applyProxyButton.addActionListener(new ActionListener()
1250     {
1251       @Override
1252       public void actionPerformed(ActionEvent e)
1253       {
1254         saveProxySettings();
1255         applyProxyButton.setEnabled(false);
1256       }
1257     });
1258     gbc.gridy++;
1259     gbc.fill = GridBagConstraints.NONE;
1260     gbc.anchor = GridBagConstraints.LINE_END;
1261     proxyPanel.add(applyProxyButton, gbc);
1262
1263     return proxyPanel;
1264   }
1265
1266   public void proxyAuthPasswordCheckHighlight(boolean enabled)
1267   {
1268     proxyAuthPasswordCheckHighlight(enabled, false);
1269   }
1270
1271   public void proxyAuthPasswordCheckHighlight(boolean enabled,
1272           boolean grabFocus)
1273   {
1274     if (enabled && proxyType.isSelected(customProxy.getModel())
1275             && proxyAuth.isSelected()
1276             && !proxyAuthUsernameTB.getText().isEmpty()
1277             && proxyAuthPasswordPB.getDocument().getLength() == 0)
1278     {
1279       if (grabFocus)
1280         proxyAuthPasswordPB.grabFocus();
1281       proxyAuthPasswordPB.setBackground(Color.PINK);
1282     }
1283     else
1284     {
1285       proxyAuthPasswordPB.setBackground(Color.WHITE);
1286     }
1287   }
1288
1289   public void applyProxyButtonEnabled(boolean enabled)
1290   {
1291     applyProxyButton.setEnabled(enabled);
1292   }
1293
1294   public void saveProxySettings()
1295   {
1296     // overridden in Preferences
1297   }
1298
1299   private String displayUserHostPort(String user, String host, String port)
1300   {
1301     boolean hostBlank = (host == null || host.isEmpty());
1302     boolean portBlank = (port == null || port.isEmpty());
1303     if (hostBlank && portBlank)
1304     {
1305       return MessageManager.getString("label.none");
1306     }
1307
1308     StringBuilder sb = new StringBuilder();
1309     if (user != null)
1310     {
1311       sb.append(user.isEmpty() || user.indexOf(" ") > -1 ? '"' + user + '"'
1312               : user);
1313       sb.append("@");
1314     }
1315     sb.append(hostBlank ? "" : host);
1316     if (!portBlank)
1317     {
1318       sb.append(":");
1319       sb.append(port);
1320     }
1321     return sb.toString();
1322   }
1323
1324   /**
1325    * Initialises the checkboxes in the Connections tab
1326    */
1327   private void initConnTabCheckboxes()
1328   {
1329     // Usage stats checkbox label
1330     usagestats.setText(
1331             MessageManager.getString("label.send_usage_statistics"));
1332     usagestats.setFont(LABEL_FONT);
1333     usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
1334     usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
1335
1336     // Questionnaire checkbox label
1337     questionnaire.setText(
1338             MessageManager.getString("label.check_for_questionnaires"));
1339     questionnaire.setFont(LABEL_FONT);
1340     questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
1341     questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
1342
1343     // Check for latest version checkbox label
1344     versioncheck.setText(
1345             MessageManager.getString("label.check_for_latest_version"));
1346     versioncheck.setFont(LABEL_FONT);
1347     versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
1348     versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
1349   }
1350
1351   /**
1352    * Initialises the parent panel which contains the tabbed sections.
1353    * 
1354    * @return
1355    */
1356   private JPanel initOkCancelPanel()
1357   {
1358     JButton ok = new JButton();
1359     ok.setText(MessageManager.getString("action.ok"));
1360     ok.addActionListener(new ActionListener()
1361     {
1362       @Override
1363       public void actionPerformed(ActionEvent e)
1364       {
1365         ok_actionPerformed(e);
1366       }
1367     });
1368     JButton cancel = new JButton();
1369     cancel.setText(MessageManager.getString("action.cancel"));
1370     cancel.addActionListener(new ActionListener()
1371     {
1372       @Override
1373       public void actionPerformed(ActionEvent e)
1374       {
1375         cancel_actionPerformed(e);
1376       }
1377     });
1378     JPanel okCancelPanel = new JPanel();
1379     okCancelPanel.add(ok);
1380     okCancelPanel.add(cancel);
1381     return okCancelPanel;
1382   }
1383
1384   /**
1385    * Initialises the Colours tabbed panel.
1386    * 
1387    * @return
1388    */
1389   private JPanel initColoursTab()
1390   {
1391     JPanel coloursTab = new JPanel();
1392     coloursTab.setBorder(new TitledBorder(
1393             MessageManager.getString("action.open_new_alignment")));
1394     coloursTab.setLayout(new FlowLayout());
1395     JLabel mincolourLabel = new JLabel();
1396     mincolourLabel.setFont(LABEL_FONT);
1397     mincolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1398     mincolourLabel.setText(MessageManager.getString("label.min_colour"));
1399     minColour.setFont(LABEL_FONT);
1400     minColour.setBorder(BorderFactory.createEtchedBorder());
1401     minColour.setPreferredSize(new Dimension(40, 20));
1402     minColour.addMouseListener(new MouseAdapter()
1403     {
1404       @Override
1405       public void mousePressed(MouseEvent e)
1406       {
1407         minColour_actionPerformed(minColour);
1408       }
1409     });
1410     JLabel maxcolourLabel = new JLabel();
1411     maxcolourLabel.setFont(LABEL_FONT);
1412     maxcolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1413     maxcolourLabel.setText(MessageManager.getString("label.max_colour"));
1414     maxColour.setFont(LABEL_FONT);
1415     maxColour.setBorder(BorderFactory.createEtchedBorder());
1416     maxColour.setPreferredSize(new Dimension(40, 20));
1417     maxColour.addMouseListener(new MouseAdapter()
1418     {
1419       @Override
1420       public void mousePressed(MouseEvent e)
1421       {
1422         maxColour_actionPerformed(maxColour);
1423       }
1424     });
1425
1426     protColour.setFont(LABEL_FONT);
1427     protColour.setBounds(new Rectangle(172, 225, 155, 21));
1428     JLabel protColourLabel = new JLabel();
1429     protColourLabel.setFont(LABEL_FONT);
1430     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1431     protColourLabel.setText(
1432             MessageManager.getString("label.prot_alignment_colour") + " ");
1433     JvSwingUtils.addtoLayout(coloursTab,
1434             MessageManager
1435                     .getString("label.default_colour_scheme_for_alignment"),
1436             protColourLabel, protColour);
1437
1438     nucColour.setFont(LABEL_FONT);
1439     nucColour.setBounds(new Rectangle(172, 240, 155, 21));
1440     JLabel nucColourLabel = new JLabel();
1441     nucColourLabel.setFont(LABEL_FONT);
1442     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1443     nucColourLabel.setText(
1444             MessageManager.getString("label.nuc_alignment_colour") + " ");
1445     JvSwingUtils.addtoLayout(coloursTab,
1446             MessageManager
1447                     .getString("label.default_colour_scheme_for_alignment"),
1448             nucColourLabel, nucColour);
1449
1450     JPanel annotationShding = new JPanel();
1451     annotationShding.setBorder(new TitledBorder(
1452             MessageManager.getString("label.annotation_shading_default")));
1453     annotationShding.setLayout(new GridLayout(1, 2));
1454     JvSwingUtils.addtoLayout(annotationShding,
1455             MessageManager.getString(
1456                     "label.default_minimum_colour_annotation_shading"),
1457             mincolourLabel, minColour);
1458     JvSwingUtils.addtoLayout(annotationShding,
1459             MessageManager.getString(
1460                     "label.default_maximum_colour_annotation_shading"),
1461             maxcolourLabel, maxColour);
1462     coloursTab.add(annotationShding); // , FlowLayout.LEFT);
1463     return coloursTab;
1464   }
1465
1466   /**
1467    * Initialises the Overview tabbed panel.
1468    * 
1469    * @return
1470    */
1471   private JPanel initOverviewTab()
1472   {
1473     JPanel overviewPanel = new JPanel();
1474     overviewPanel.setBorder(new TitledBorder(
1475             MessageManager.getString("label.overview_settings")));
1476
1477     gapColour.setFont(LABEL_FONT);
1478     // fixing the border colours stops apparent colour bleed from the panel
1479     gapColour.setBorder(
1480             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1481     gapColour.setPreferredSize(new Dimension(40, 20));
1482     gapColour.addMouseListener(new MouseAdapter()
1483     {
1484       @Override
1485       public void mousePressed(MouseEvent e)
1486       {
1487         gapColour_actionPerformed(gapColour);
1488       }
1489     });
1490
1491     hiddenColour.setFont(LABEL_FONT);
1492     // fixing the border colours stops apparent colour bleed from the panel
1493     hiddenColour.setBorder(
1494             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1495     hiddenColour.setPreferredSize(new Dimension(40, 20));
1496     hiddenColour.addMouseListener(new MouseAdapter()
1497     {
1498       @Override
1499       public void mousePressed(MouseEvent e)
1500       {
1501         hiddenColour_actionPerformed(hiddenColour);
1502       }
1503     });
1504
1505     useLegacyGap = new JCheckBox(
1506             MessageManager.getString("label.ov_legacy_gap"));
1507     useLegacyGap.setFont(LABEL_FONT);
1508     useLegacyGap.setHorizontalAlignment(SwingConstants.LEFT);
1509     useLegacyGap.setVerticalTextPosition(SwingConstants.TOP);
1510     gapLabel = new JLabel(MessageManager.getString("label.gap_colour"));
1511     gapLabel.setFont(LABEL_FONT);
1512     gapLabel.setHorizontalAlignment(SwingConstants.LEFT);
1513     gapLabel.setVerticalTextPosition(SwingConstants.TOP);
1514     showHiddenAtStart = new JCheckBox(
1515             MessageManager.getString("label.ov_show_hide_default"));
1516     showHiddenAtStart.setFont(LABEL_FONT);
1517     showHiddenAtStart.setHorizontalAlignment(SwingConstants.LEFT);
1518     showHiddenAtStart.setVerticalTextPosition(SwingConstants.TOP);
1519     JLabel hiddenLabel = new JLabel(
1520             MessageManager.getString("label.hidden_colour"));
1521     hiddenLabel.setFont(LABEL_FONT);
1522     hiddenLabel.setHorizontalAlignment(SwingConstants.LEFT);
1523     hiddenLabel.setVerticalTextPosition(SwingConstants.TOP);
1524
1525     useLegacyGap.addActionListener(new ActionListener()
1526     {
1527       @Override
1528       public void actionPerformed(ActionEvent e)
1529       {
1530         useLegacyGaps_actionPerformed(e);
1531       }
1532     });
1533
1534     overviewPanel.setLayout(new GridBagLayout());
1535     GridBagConstraints c1 = new GridBagConstraints();
1536
1537     c1.fill = GridBagConstraints.HORIZONTAL;
1538     c1.gridx = 0;
1539     c1.gridy = 0;
1540     c1.weightx = 1;
1541     c1.ipady = 20;
1542     c1.anchor = GridBagConstraints.FIRST_LINE_START;
1543     overviewPanel.add(useLegacyGap, c1);
1544
1545     GridBagConstraints c2 = new GridBagConstraints();
1546     c2.fill = GridBagConstraints.HORIZONTAL;
1547     c2.gridx = 1;
1548     c2.gridy = 0;
1549     c2.insets = new Insets(0, 15, 0, 10);
1550     overviewPanel.add(gapLabel, c2);
1551
1552     GridBagConstraints c3 = new GridBagConstraints();
1553     c3.fill = GridBagConstraints.HORIZONTAL;
1554     c3.gridx = 2;
1555     c3.gridy = 0;
1556     c3.insets = new Insets(0, 0, 0, 15);
1557     overviewPanel.add(gapColour, c3);
1558
1559     GridBagConstraints c4 = new GridBagConstraints();
1560     c4.fill = GridBagConstraints.HORIZONTAL;
1561     c4.gridx = 0;
1562     c4.gridy = 1;
1563     c4.weightx = 1;
1564     overviewPanel.add(showHiddenAtStart, c4);
1565
1566     GridBagConstraints c5 = new GridBagConstraints();
1567     c5.fill = GridBagConstraints.HORIZONTAL;
1568     c5.gridx = 1;
1569     c5.gridy = 1;
1570     c5.insets = new Insets(0, 15, 0, 10);
1571     overviewPanel.add(hiddenLabel, c5);
1572
1573     GridBagConstraints c6 = new GridBagConstraints();
1574     c6.fill = GridBagConstraints.HORIZONTAL;
1575     c6.gridx = 2;
1576     c6.gridy = 1;
1577     c6.insets = new Insets(0, 0, 0, 15);
1578     overviewPanel.add(hiddenColour, c6);
1579
1580     JButton resetButton = new JButton(
1581             MessageManager.getString("label.reset_to_defaults"));
1582
1583     resetButton.addActionListener(new ActionListener()
1584     {
1585       @Override
1586       public void actionPerformed(ActionEvent e)
1587       {
1588         resetOvDefaults_actionPerformed(e);
1589       }
1590     });
1591
1592     GridBagConstraints c7 = new GridBagConstraints();
1593     c7.fill = GridBagConstraints.NONE;
1594     c7.gridx = 0;
1595     c7.gridy = 2;
1596     c7.insets = new Insets(10, 0, 0, 0);
1597     c7.anchor = GridBagConstraints.WEST;
1598     overviewPanel.add(resetButton, c7);
1599
1600     // Add padding so the panel doesn't look ridiculous
1601     JPanel spacePanel = new JPanel();
1602     overviewPanel.add(spacePanel,
1603             new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0,
1604                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
1605                     new Insets(0, 0, 0, 5), 0, 0));
1606
1607     return overviewPanel;
1608   }
1609
1610   /**
1611    * Initialises the Structure tabbed panel.
1612    * 
1613    * @return
1614    */
1615   private JPanel initStructureTab()
1616   {
1617     structureTab = new JPanel();
1618
1619     structureTab.setBorder(new TitledBorder(
1620             MessageManager.getString("label.structure_options")));
1621     structureTab.setLayout(null);
1622     final int width = 420;
1623     final int height = 22;
1624     final int lineSpacing = 25;
1625     int ypos = 15;
1626
1627     structFromPdb.setFont(LABEL_FONT);
1628     structFromPdb
1629             .setText(MessageManager.getString("label.struct_from_pdb"));
1630     structFromPdb.setBounds(new Rectangle(5, ypos, width, height));
1631     structFromPdb.addActionListener(new ActionListener()
1632     {
1633       @Override
1634       public void actionPerformed(ActionEvent e)
1635       {
1636         boolean selected = structFromPdb.isSelected();
1637         // enable other options only when the first is checked
1638         useRnaView.setEnabled(selected);
1639         addSecondaryStructure.setEnabled(selected);
1640         addTempFactor.setEnabled(selected);
1641       }
1642     });
1643     structureTab.add(structFromPdb);
1644
1645     // indent checkboxes that are conditional on the first one
1646     ypos += lineSpacing;
1647     useRnaView.setFont(LABEL_FONT);
1648     useRnaView.setText(MessageManager.getString("label.use_rnaview"));
1649     useRnaView.setBounds(new Rectangle(25, ypos, width, height));
1650     structureTab.add(useRnaView);
1651
1652     ypos += lineSpacing;
1653     addSecondaryStructure.setFont(LABEL_FONT);
1654     addSecondaryStructure
1655             .setText(MessageManager.getString("label.autoadd_secstr"));
1656     addSecondaryStructure.setBounds(new Rectangle(25, ypos, width, height));
1657     structureTab.add(addSecondaryStructure);
1658
1659     ypos += lineSpacing;
1660     addTempFactor.setFont(LABEL_FONT);
1661     addTempFactor.setText(MessageManager.getString("label.autoadd_temp"));
1662     addTempFactor.setBounds(new Rectangle(25, ypos, width, height));
1663     structureTab.add(addTempFactor);
1664
1665     ypos += lineSpacing;
1666     JLabel viewerLabel = new JLabel();
1667     viewerLabel.setFont(LABEL_FONT);
1668     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
1669     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
1670     viewerLabel.setBounds(new Rectangle(10, ypos, 220, height));
1671     structureTab.add(viewerLabel);
1672
1673     /*
1674      * add all external viewers as options here - check 
1675      * when selected whether the program is installed
1676      */
1677     structViewer.setFont(LABEL_FONT);
1678     structViewer.setBounds(new Rectangle(190, ypos, 120, height));
1679     structViewer.addItem(ViewerType.JMOL.name());
1680     structViewer.addItem(ViewerType.CHIMERA.name());
1681     structViewer.addItem(ViewerType.CHIMERAX.name());
1682     structViewer.addItem(ViewerType.PYMOL.name());
1683     structViewer.addActionListener(new ActionListener()
1684     {
1685       @Override
1686       public void actionPerformed(ActionEvent e)
1687       {
1688         structureViewer_actionPerformed(
1689                 (String) structViewer.getSelectedItem());
1690       }
1691     });
1692     structureTab.add(structViewer);
1693
1694     ypos += lineSpacing;
1695     structureViewerPathLabel = new JLabel();
1696     structureViewerPathLabel.setFont(LABEL_FONT);// new Font("SansSerif", 0, 11));
1697     structureViewerPathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1698     structureViewerPathLabel.setText(MessageManager
1699             .formatMessage("label.viewer_path", "Chimera(X)"));
1700     structureViewerPathLabel.setBounds(new Rectangle(10, ypos, 170, height));
1701     structureViewerPathLabel.setEnabled(false);
1702     structureTab.add(structureViewerPathLabel);
1703
1704     structureViewerPath.setFont(LABEL_FONT);
1705     structureViewerPath.setText("");
1706     structureViewerPath.setEnabled(false);
1707     final String tooltip = JvSwingUtils.wrapTooltip(true,
1708             MessageManager.getString("label.viewer_path_tip"));
1709     structureViewerPath.setToolTipText(tooltip);
1710     structureViewerPath.setBounds(new Rectangle(190, ypos, 290, height));
1711     structureViewerPath.addMouseListener(new MouseAdapter()
1712     {
1713       @Override
1714       public void mouseClicked(MouseEvent e)
1715       {
1716         if (structureViewerPath.isEnabled() && e.getClickCount() == 2)
1717         {
1718           String chosen = openFileChooser();
1719           if (chosen != null)
1720           {
1721             structureViewerPath.setText(chosen);
1722           }
1723         }
1724       }
1725     });
1726     structureTab.add(structureViewerPath);
1727
1728     ypos += lineSpacing;
1729     nwMapping.setFont(LABEL_FONT);
1730     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1731     siftsMapping.setFont(LABEL_FONT);
1732     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1733     mappingMethod.add(nwMapping);
1734     mappingMethod.add(siftsMapping);
1735     JPanel mappingPanel = new JPanel();
1736     mappingPanel.setFont(LABEL_FONT);
1737     TitledBorder mmTitledBorder = new TitledBorder(
1738             MessageManager.getString("label.mapping_method"));
1739     mmTitledBorder.setTitleFont(LABEL_FONT);
1740     mappingPanel.setBorder(mmTitledBorder);
1741     mappingPanel.setBounds(new Rectangle(10, ypos, 472, 45));
1742     // GridLayout mappingLayout = new GridLayout();
1743     mappingPanel.setLayout(new GridLayout());
1744     mappingPanel.add(nwMapping);
1745     mappingPanel.add(siftsMapping);
1746     structureTab.add(mappingPanel);
1747
1748     ypos += lineSpacing;
1749     ypos += lineSpacing;
1750     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1751             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1752     docFieldPref.setBounds(new Rectangle(10, ypos, 470, 120));
1753     structureTab.add(docFieldPref);
1754
1755     /*
1756      * hide Chimera options in JalviewJS
1757      */
1758     if (Platform.isJS()) 
1759     {
1760       structureViewerPathLabel.setVisible(false);
1761       structureViewerPath.setVisible(false);
1762       viewerLabel.setVisible(false);
1763       structViewer.setVisible(false);
1764     }
1765     
1766     return structureTab;
1767   }
1768
1769   /**
1770    * Action on choosing a structure viewer from combobox options.
1771    * 
1772    * @param selectedItem
1773    */
1774   protected void structureViewer_actionPerformed(String selectedItem)
1775   {
1776   }
1777
1778   /**
1779    * Show a dialog for the user to choose a file. Returns the chosen path, or
1780    * null on Cancel.
1781    * 
1782    * @return
1783    */
1784   protected String openFileChooser()
1785   {
1786     String choice = null;
1787     JFileChooser chooser = new JFileChooser();
1788
1789     // chooser.setFileView(new JalviewFileView());
1790     chooser.setDialogTitle(
1791             MessageManager.getString("label.open_local_file"));
1792     chooser.setToolTipText(MessageManager.getString("action.open"));
1793
1794     int value = chooser.showOpenDialog(this);
1795
1796     if (value == JFileChooser.APPROVE_OPTION)
1797     {
1798       choice = chooser.getSelectedFile().getPath();
1799     }
1800     return choice;
1801   }
1802
1803   /**
1804    * Validate the structure tab preferences; if invalid, set focus on this tab.
1805    * 
1806    * @param e
1807    */
1808   protected boolean validateStructure(FocusEvent e)
1809   {
1810     if (!validateStructure())
1811     {
1812       e.getComponent().requestFocusInWindow();
1813       return false;
1814     }
1815     return true;
1816   }
1817
1818   protected boolean validateStructure()
1819   {
1820     return false;
1821   }
1822
1823   /**
1824    * Initialises the Visual tabbed panel.
1825    * 
1826    * @return
1827    */
1828   private JPanel initVisualTab()
1829   {
1830     JPanel visualTab = new JPanel();
1831     visualTab.setBorder(new TitledBorder(
1832             MessageManager.getString("action.open_new_alignment")));
1833     visualTab.setLayout(null);
1834     fullScreen.setFont(LABEL_FONT);
1835     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
1836     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
1837     fullScreen.setText(MessageManager.getString("label.maximize_window"));
1838     quality.setEnabled(false);
1839     quality.setFont(LABEL_FONT);
1840     quality.setHorizontalAlignment(SwingConstants.RIGHT);
1841     quality.setHorizontalTextPosition(SwingConstants.LEFT);
1842     quality.setSelected(true);
1843     quality.setText(MessageManager.getString("label.quality"));
1844     conservation.setEnabled(false);
1845     conservation.setFont(LABEL_FONT);
1846     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
1847     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
1848     conservation.setSelected(true);
1849     conservation.setText(MessageManager.getString("label.conservation"));
1850     identity.setEnabled(false);
1851     identity.setFont(LABEL_FONT);
1852     identity.setHorizontalAlignment(SwingConstants.RIGHT);
1853     identity.setHorizontalTextPosition(SwingConstants.LEFT);
1854     identity.setSelected(true);
1855     identity.setText(MessageManager.getString("label.consensus"));
1856     showOccupancy.setFont(LABEL_FONT);
1857     showOccupancy.setEnabled(false);
1858     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
1859     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
1860     showOccupancy.setSelected(true);
1861     showOccupancy.setText(MessageManager.getString("label.occupancy"));
1862
1863     JLabel showGroupbits = new JLabel();
1864     showGroupbits.setFont(LABEL_FONT);
1865     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
1866     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
1867     showGroupbits
1868             .setText(MessageManager.getString("action.show_group") + ":");
1869     JLabel showConsensbits = new JLabel();
1870     showConsensbits.setFont(LABEL_FONT);
1871     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
1872     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
1873     showConsensbits
1874             .setText(MessageManager.getString("label.consensus") + ":");
1875     showConsensHistogram.setEnabled(false);
1876     showConsensHistogram.setFont(LABEL_FONT);
1877     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
1878     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
1879     showConsensHistogram.setSelected(true);
1880     showConsensHistogram
1881             .setText(MessageManager.getString("label.histogram"));
1882     showConsensLogo.setEnabled(false);
1883     showConsensLogo.setFont(LABEL_FONT);
1884     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
1885     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
1886     showConsensLogo.setSelected(true);
1887     showConsensLogo.setText(MessageManager.getString("label.logo"));
1888     showGroupConsensus.setEnabled(false);
1889     showGroupConsensus.setFont(LABEL_FONT);
1890     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
1891     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
1892     showGroupConsensus.setSelected(true);
1893     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
1894     showGroupConservation.setEnabled(false);
1895     showGroupConservation.setFont(LABEL_FONT);
1896     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
1897     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
1898     showGroupConservation.setSelected(true);
1899     showGroupConservation
1900             .setText(MessageManager.getString("label.conservation"));
1901     showNpTooltip.setEnabled(true);
1902     showNpTooltip.setFont(LABEL_FONT);
1903     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1904     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1905     showNpTooltip.setSelected(true);
1906     showNpTooltip.setText(
1907             MessageManager.getString("label.non_positional_features"));
1908     showDbRefTooltip.setEnabled(true);
1909     showDbRefTooltip.setFont(LABEL_FONT);
1910     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1911     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1912     showDbRefTooltip.setSelected(true);
1913     showDbRefTooltip
1914             .setText(MessageManager.getString("label.database_references"));
1915     annotations.setFont(LABEL_FONT);
1916     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
1917     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
1918     annotations.setSelected(true);
1919     annotations.setText(MessageManager.getString("label.show_annotations"));
1920     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
1921     annotations.addActionListener(new ActionListener()
1922     {
1923       @Override
1924       public void actionPerformed(ActionEvent e)
1925       {
1926         annotations_actionPerformed(e);
1927       }
1928     });
1929     identity.addActionListener(new ActionListener()
1930     {
1931       @Override
1932       public void actionPerformed(ActionEvent e)
1933       {
1934         annotations_actionPerformed(e);
1935       }
1936     });
1937     showGroupConsensus.addActionListener(new ActionListener()
1938     {
1939       @Override
1940       public void actionPerformed(ActionEvent e)
1941       {
1942         annotations_actionPerformed(e);
1943       }
1944     });
1945     showUnconserved.setFont(LABEL_FONT);
1946     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
1947     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
1948     showUnconserved.setSelected(true);
1949     showUnconserved
1950             .setText(MessageManager.getString("action.show_unconserved"));
1951     showUnconserved.addActionListener(new ActionListener()
1952     {
1953       @Override
1954       public void actionPerformed(ActionEvent e)
1955       {
1956         showunconserved_actionPerformed(e);
1957       }
1958     });
1959
1960     // TODO these are not yet added to / action from Preferences
1961     // JCheckBox shareSelections = new JCheckBox();
1962     // shareSelections.setFont(verdana11);
1963     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
1964     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
1965     // shareSelections.setSelected(true);
1966     // shareSelections.setText(MessageManager
1967     // .getString("label.share_selection_across_views"));
1968     // JCheckBox followHighlight = new JCheckBox();
1969     // followHighlight.setFont(verdana11);
1970     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
1971     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
1972     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
1973     // followHighlight.setSelected(true);
1974     // followHighlight.setText(MessageManager
1975     // .getString("label.scroll_highlighted_regions"));
1976
1977     seqLimit.setFont(LABEL_FONT);
1978     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
1979     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
1980     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
1981     smoothFont.setFont(LABEL_FONT);
1982     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
1983     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
1984     smoothFont.setText(MessageManager.getString("label.smooth_font"));
1985     scaleProteinToCdna.setFont(LABEL_FONT);
1986     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
1987     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
1988     scaleProteinToCdna.setText(
1989             MessageManager.getString("label.scale_protein_to_cdna"));
1990     scaleProteinToCdna.setToolTipText(
1991             MessageManager.getString("label.scale_protein_to_cdna_tip"));
1992     JLabel gapLabel = new JLabel();
1993     gapLabel.setFont(LABEL_FONT);
1994     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1995     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
1996     JLabel fontLabel = new JLabel();
1997     fontLabel.setFont(LABEL_FONT);
1998     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1999     fontLabel.setText(MessageManager.getString("label.font"));
2000     fontSizeCB.setFont(LABEL_FONT);
2001     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
2002     fontStyleCB.setFont(LABEL_FONT);
2003     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
2004     fontNameCB.setFont(LABEL_FONT);
2005     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
2006     gapSymbolCB.setFont(LABEL_FONT);
2007     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
2008     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
2009     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
2010     gapSymbolCB.setRenderer(dlcr);
2011
2012     startupCheckbox.setText(MessageManager.getString("action.open_file"));
2013     startupCheckbox.setFont(LABEL_FONT);
2014     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
2015     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
2016     startupCheckbox.setSelected(true);
2017     startupFileTextfield.setFont(LABEL_FONT);
2018     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
2019     final String tooltip = JvSwingUtils.wrapTooltip(true,
2020             MessageManager.getString("label.double_click_to_browse"));
2021     startupFileTextfield.setToolTipText(tooltip);
2022     startupFileTextfield.addMouseListener(new MouseAdapter()
2023     {
2024       @Override
2025       public void mouseClicked(MouseEvent e)
2026       {
2027         if (e.getClickCount() > 1)
2028         {
2029           startupFileTextfield_mouseClicked();
2030         }
2031       }
2032     });
2033
2034     sortby.setFont(LABEL_FONT);
2035     sortby.setBounds(new Rectangle(172, 260, 155, 21));
2036     JLabel sortLabel = new JLabel();
2037     sortLabel.setFont(LABEL_FONT);
2038     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
2039     sortLabel.setText(MessageManager.getString("label.sort_by"));
2040     sortAnnBy.setFont(LABEL_FONT);
2041     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
2042     JLabel sortAnnLabel = new JLabel();
2043     sortAnnLabel.setFont(LABEL_FONT);
2044     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
2045     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
2046     sortAutocalc.setFont(LABEL_FONT);
2047     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
2048
2049     JPanel annsettingsPanel = new JPanel();
2050     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
2051     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
2052     annsettingsPanel.setBorder(new EtchedBorder());
2053     visualTab.add(annsettingsPanel);
2054     Border jb = new EmptyBorder(1, 1, 4, 5);
2055     annotations.setBorder(jb);
2056     showOccupancy.setBorder(jb);
2057     quality.setBorder(jb);
2058     conservation.setBorder(jb);
2059     identity.setBorder(jb);
2060     showConsensbits.setBorder(jb);
2061     showGroupbits.setBorder(jb);
2062     showGroupConsensus.setBorder(jb);
2063     showGroupConservation.setBorder(jb);
2064     showConsensHistogram.setBorder(jb);
2065     showConsensLogo.setBorder(jb);
2066
2067     JPanel autoAnnotSettings = new JPanel();
2068     annsettingsPanel.add(autoAnnotSettings);
2069     autoAnnotSettings.setLayout(new GridLayout(0, 2));
2070     autoAnnotSettings.add(annotations);
2071     autoAnnotSettings.add(quality);
2072     // second row of autoannotation box
2073     autoAnnotSettings = new JPanel();
2074     annsettingsPanel.add(autoAnnotSettings);
2075
2076     autoAnnotSettings.setLayout(new GridLayout(0, 3));
2077     autoAnnotSettings.add(conservation);
2078     autoAnnotSettings.add(identity);
2079     autoAnnotSettings.add(showOccupancy);
2080     autoAnnotSettings.add(showGroupbits);
2081     autoAnnotSettings.add(showGroupConservation);
2082     autoAnnotSettings.add(showGroupConsensus);
2083     autoAnnotSettings.add(showConsensbits);
2084     autoAnnotSettings.add(showConsensHistogram);
2085     autoAnnotSettings.add(showConsensLogo);
2086
2087     JPanel tooltipSettings = new JPanel();
2088     tooltipSettings.setBorder(new TitledBorder(
2089             MessageManager.getString("label.sequence_id_tooltip")));
2090     tooltipSettings.setBounds(173, 140, 220, 62);
2091     tooltipSettings.setLayout(new GridLayout(2, 1));
2092     tooltipSettings.add(showDbRefTooltip);
2093     tooltipSettings.add(showNpTooltip);
2094     visualTab.add(tooltipSettings);
2095
2096     wrap.setFont(LABEL_FONT);
2097     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
2098     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
2099     wrap.setText(MessageManager.getString("label.wrap_alignment"));
2100     rightAlign.setFont(LABEL_FONT);
2101     rightAlign.setForeground(Color.black);
2102     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
2103     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
2104     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
2105     idItalics.setFont(LABEL_FONT_ITALIC);
2106     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
2107     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
2108     idItalics.setText(
2109             MessageManager.getString("label.sequence_name_italics"));
2110     openoverv.setFont(LABEL_FONT);
2111     openoverv.setActionCommand(
2112             MessageManager.getString("label.open_overview"));
2113     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
2114     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
2115     openoverv.setText(MessageManager.getString("label.open_overview"));
2116     JPanel jPanel2 = new JPanel();
2117     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
2118     jPanel2.setLayout(new GridLayout(14, 1));
2119     jPanel2.add(fullScreen);
2120     jPanel2.add(openoverv);
2121     jPanel2.add(seqLimit);
2122     jPanel2.add(rightAlign);
2123     jPanel2.add(fontLabel);
2124     jPanel2.add(showUnconserved);
2125     jPanel2.add(idItalics);
2126     jPanel2.add(smoothFont);
2127     jPanel2.add(scaleProteinToCdna);
2128     jPanel2.add(gapLabel);
2129     jPanel2.add(wrap);
2130     jPanel2.add(sortLabel);
2131     jPanel2.add(sortAnnLabel);
2132     jPanel2.add(startupCheckbox);
2133     visualTab.add(jPanel2);
2134     visualTab.add(startupFileTextfield);
2135     visualTab.add(sortby);
2136     visualTab.add(sortAnnBy);
2137     visualTab.add(sortAutocalc);
2138     visualTab.add(gapSymbolCB);
2139     visualTab.add(fontNameCB);
2140     visualTab.add(fontSizeCB);
2141     visualTab.add(fontStyleCB);
2142     
2143     if (Platform.isJS())
2144     {
2145       startupCheckbox.setVisible(false);
2146       startupFileTextfield.setVisible(false);
2147     }
2148     
2149     return visualTab;
2150   }
2151
2152   /**
2153    * Load the saved Backups options EXCEPT "Enabled" and "Scheme"
2154    */
2155
2156   protected void loadLastSavedBackupsOptions()
2157   {
2158     BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
2159             .getSavedBackupEntry();
2160     enableBackupFiles
2161             .setSelected(Cache.getDefault(BackupFiles.ENABLED, !Platform.isJS()));
2162
2163     BackupFilesPresetEntry backupfilesCustomEntry = BackupFilesPresetEntry
2164             .createBackupFilesPresetEntry(Cache
2165                     .getDefault(BackupFilesPresetEntry.CUSTOMCONFIG, null));
2166     if (backupfilesCustomEntry == null)
2167     {
2168       backupfilesCustomEntry = BackupFilesPresetEntry.backupfilesPresetEntriesValues
2169               .get(BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT);
2170     }
2171     BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
2172             BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM,
2173             backupfilesCustomEntry);
2174
2175     setComboIntStringKey(backupfilesPresetsCombo,
2176             Cache.getDefault(BackupFiles.NS + "_PRESET",
2177                     BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT));
2178
2179     backupsSetOptions(savedPreset);
2180
2181     backupsOptionsSetEnabled();
2182     updateBackupFilesExampleLabel();
2183   }
2184
2185   private boolean warnAboutSuffixReverseChange()
2186   {
2187     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
2188             .getSavedBackupEntry();
2189     boolean savedSuffixReverse = bfpe.reverse;
2190     int savedSuffixDigits = bfpe.digits;
2191     String savedSuffixTemplate = bfpe.suffix;
2192
2193     boolean nowSuffixReverse = suffixReverse.isSelected();
2194     int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3);
2195     String nowSuffixTemplate = suffixTemplate.getText();
2196     return nowSuffixReverse != savedSuffixReverse
2197             && nowSuffixDigits == savedSuffixDigits
2198             && nowSuffixTemplate != null
2199             && nowSuffixTemplate.equals(savedSuffixTemplate);
2200   }
2201
2202   /**
2203    * Initialises the Backups tabbed panel.
2204    * 
2205    * @return
2206    */
2207   private JPanel initBackupsTab()
2208   {
2209     JPanel backupsTab = new JPanel();
2210     backupsTab.setBorder(new TitledBorder(
2211             MessageManager.getString("label.backup_files")));
2212     backupsTab.setLayout(new GridBagLayout());
2213
2214     GridBagConstraints gbc = new GridBagConstraints();
2215     gbc.weightx = 0.0;
2216     gbc.weighty = 0.0;
2217     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2218     gbc.fill = GridBagConstraints.NONE;
2219
2220     initBackupsTabPresetsPanel();
2221     initBackupsTabSuffixPanel();
2222     initBackupsTabKeepFilesPanel();
2223     initBackupsTabFilenameExamplesPanel();
2224
2225     enableBackupFiles.setFont(LABEL_FONT_BOLD);
2226     enableBackupFiles
2227             .setText(MessageManager.getString("label.enable_backupfiles"));
2228     enableBackupFiles.addActionListener(new ActionListener()
2229     {
2230       @Override
2231       public void actionPerformed(ActionEvent e)
2232       {
2233         // enable other options only when the first is checked
2234         backupsOptionsSetEnabled();
2235       }
2236     });
2237
2238
2239     // enable checkbox 1 col
2240     gbc.gridwidth = 1;
2241     gbc.gridheight = 1;
2242     gbc.gridx = 0;
2243     gbc.gridy = 0; // row 0
2244     backupsTab.add(enableBackupFiles, gbc);
2245
2246     // summary of scheme box (over two rows)
2247     gbc.gridx = 1;
2248     gbc.weightx = 0.0;
2249     gbc.gridheight = 2;
2250     gbc.anchor = GridBagConstraints.FIRST_LINE_END;
2251     gbc.fill = GridBagConstraints.BOTH;
2252     backupsTab.add(exampleFilesPanel, gbc);
2253     gbc.gridheight = 1;
2254     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2255     gbc.fill = GridBagConstraints.NONE;
2256
2257     // fill empty space on right
2258     gbc.gridx++;
2259     gbc.weightx = 1.0;
2260     backupsTab.add(new JPanel(), gbc);
2261
2262     // schemes box
2263     gbc.weightx = 0.0;
2264     gbc.gridx = 0;
2265     gbc.gridy++; // row 1
2266     backupsTab.add(presetsPanel, gbc);
2267
2268     // now using whole row
2269     gbc.gridwidth = 2;
2270     gbc.gridheight = 1;
2271     // keep files box
2272     gbc.gridx = 0;
2273     gbc.gridy++; // row 2
2274     backupsTab.add(keepfilesPanel, gbc);
2275
2276     // filename strategy box
2277     gbc.gridy++; // row 3
2278     backupsTab.add(suffixPanel, gbc);
2279
2280     // fill empty space
2281     gbc.gridy++; // row 4
2282     gbc.weighty = 1.0;
2283     backupsTab.add(new JPanel(), gbc);
2284
2285     backupsOptionsSetEnabled();
2286     return backupsTab;
2287   }
2288
2289   private JPanel initBackupsTabPresetsPanel()
2290   {
2291
2292     String title = MessageManager.getString("label.schemes");
2293
2294     presetsPanel.setLayout(new GridBagLayout());
2295
2296     GridBagConstraints gbc = new GridBagConstraints();
2297     gbc.weightx = 0.0;
2298     gbc.weighty = 0.0;
2299     gbc.anchor = GridBagConstraints.BASELINE_LEADING;
2300     gbc.fill = GridBagConstraints.NONE;
2301     gbc.gridwidth = 1;
2302     gbc.gridheight = 1;
2303
2304     // "Scheme: "
2305     gbc.gridx = 0;
2306     gbc.gridy = 0;
2307
2308     presetsComboLabel = new JLabel(title + ":");
2309     presetsPanel.add(presetsComboLabel, gbc);
2310
2311     List<Object> entries = Arrays
2312             .asList((Object[]) BackupFilesPresetEntry.backupfilesPresetEntries);
2313     List<String> tooltips = Arrays.asList(
2314             BackupFilesPresetEntry.backupfilesPresetEntryDescriptions);
2315     backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries,
2316             tooltips);
2317     /*
2318     for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++)
2319     {
2320       backupfilesPresetsCombo
2321               .addItem(BackupFilesPresetEntry.backupfilesPresetEntries[i]);
2322     }
2323     */
2324
2325     backupfilesPresetsCombo.addActionListener(new ActionListener()
2326     {
2327       @Override
2328       public void actionPerformed(ActionEvent e)
2329       {
2330         int key = getComboIntStringKey(backupfilesPresetsCombo);
2331         if (!customiseCheckbox.isSelected())
2332         {
2333           backupfilesPresetsComboLastSelected = key;
2334         }
2335         if (key == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
2336         {
2337           if (customiseCheckbox.isSelected())
2338           {
2339             // got here by clicking on customiseCheckbox so don't change the values
2340             backupfilesCustomOptionsSetEnabled();
2341           }
2342           else
2343           {
2344             backupsTabUpdatePresets();
2345             backupfilesCustomOptionsSetEnabled();
2346           }
2347         }
2348         else
2349         {
2350           customiseCheckbox.setSelected(false);
2351           backupsTabUpdatePresets();
2352           backupfilesCustomOptionsSetEnabled();
2353         }
2354       }
2355     });
2356
2357     // dropdown list of preset schemes
2358     gbc.gridx = 1;
2359     presetsPanel.add(backupfilesPresetsCombo, gbc);
2360
2361     revertButton.setText(MessageManager.getString("label.cancel_changes"));
2362     revertButton.setToolTipText(
2363             MessageManager.getString("label.cancel_changes_description"));
2364     revertButton.addActionListener(new ActionListener()
2365     {
2366       @Override
2367       public void actionPerformed(ActionEvent e)
2368       {
2369         backupsSetOptions(
2370                 BackupFilesPresetEntry.backupfilesPresetEntriesValues.get(
2371                         BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM));
2372         backupfilesCustomOptionsSetEnabled();
2373       }
2374
2375     });
2376     revertButton.setFont(LABEL_FONT);
2377
2378     customiseCheckbox.setFont(LABEL_FONT);
2379     customiseCheckbox.setText(MessageManager.getString("label.customise"));
2380     customiseCheckbox.addActionListener(new ActionListener()
2381     {
2382       @Override
2383       public void actionPerformed(ActionEvent e)
2384       {
2385         int currently = getComboIntStringKey(backupfilesPresetsCombo);
2386         if (customiseCheckbox.isSelected())
2387         {
2388           backupfilesPresetsComboLastSelected = currently;
2389           setComboIntStringKey(backupfilesPresetsCombo,
2390                   BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
2391         }
2392         else
2393         {
2394           setComboIntStringKey(backupfilesPresetsCombo,
2395                   backupfilesPresetsComboLastSelected);
2396
2397         }
2398         backupfilesCustomOptionsSetEnabled();
2399       }
2400     });
2401     customiseCheckbox.setToolTipText(
2402             MessageManager.getString("label.customise_description"));
2403
2404     // customise checkbox
2405     gbc.gridx = 0;
2406     gbc.gridy++;
2407     presetsPanel.add(customiseCheckbox, gbc);
2408
2409     // "Cancel changes" button (aligned with combo box above)
2410     gbc.gridx = 1;
2411     presetsPanel.add(revertButton, gbc);
2412
2413     return presetsPanel;
2414   }
2415
2416   private JPanel initBackupsTabFilenameExamplesPanel()
2417   {
2418     String title = MessageManager
2419             .getString("label.scheme_examples");
2420     TitledBorder tb = new TitledBorder(title);
2421     exampleFilesPanel.setBorder(tb);
2422     exampleFilesPanel.setLayout(new GridBagLayout());
2423
2424
2425     backupfilesExampleLabel.setEditable(false);
2426     backupfilesExampleLabel
2427             .setBackground(exampleFilesPanel.getBackground());
2428
2429     updateBackupFilesExampleLabel();
2430
2431     GridBagConstraints gbc = new GridBagConstraints();
2432     gbc.weightx = 1.0;
2433     gbc.weighty = 1.0;
2434     gbc.fill = GridBagConstraints.NONE;
2435     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2436
2437     exampleFilesPanel.add(backupfilesExampleLabel, gbc);
2438     return exampleFilesPanel;
2439   }
2440
2441   private void backupsTabUpdatePresets()
2442   {
2443     IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo
2444             .getSelectedItem();
2445     int key = entry.k;
2446     String value = entry.v;
2447
2448     if (BackupFilesPresetEntry.backupfilesPresetEntriesValues
2449             .containsKey(key))
2450     {
2451       backupsSetOptions(
2452               BackupFilesPresetEntry.backupfilesPresetEntriesValues
2453                       .get(key));
2454     }
2455     else
2456     {
2457       Cache.log.error(
2458               "Preset '" + value + "' [key:" + key + "] not implemented");
2459     }
2460
2461     // Custom options will now be enabled when the customiseCheckbox is checked
2462     // (performed above)
2463     // backupfilesCustomOptionsSetEnabled();
2464     updateBackupFilesExampleLabel();
2465   }
2466
2467   protected int getComboIntStringKey(
2468           JComboBox<Object> backupfilesPresetsCombo2)
2469   {
2470     IntKeyStringValueEntry e;
2471     try
2472     {
2473       e = (IntKeyStringValueEntry) backupfilesPresetsCombo2
2474               .getSelectedItem();
2475     } catch (Exception ex)
2476     {
2477       Cache.log.error(
2478               "Problem casting Combo entry to IntKeyStringValueEntry.");
2479       e = null;
2480     }
2481     return e != null ? e.k : 0;
2482   }
2483
2484   protected void setComboIntStringKey(
2485           JComboBox<Object> backupfilesPresetsCombo2,
2486           int key)
2487   {
2488     for (int i = 0; i < backupfilesPresetsCombo2.getItemCount(); i++)
2489     {
2490       IntKeyStringValueEntry e;
2491       try
2492       {
2493         e = (IntKeyStringValueEntry) backupfilesPresetsCombo2.getItemAt(i);
2494       } catch (Exception ex)
2495       {
2496         Cache.log.error(
2497                 "Problem casting Combo entry to IntKeyStringValueEntry. Skipping item. ");
2498         continue;
2499       }
2500       if (e.k == key)
2501       {
2502         backupfilesPresetsCombo2.setSelectedIndex(i);
2503         break;
2504       }
2505     }
2506     // backupsTabUpdatePresets();
2507   }
2508
2509   private JPanel initBackupsTabSuffixPanel()
2510   {
2511     suffixPanel.setBorder(new TitledBorder(
2512             MessageManager.getString("label.backup_filename_strategy")));
2513     suffixPanel.setLayout(new GridBagLayout());
2514
2515     suffixTemplateLabel
2516             .setText(MessageManager.getString("label.append_to_filename"));
2517     suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
2518     suffixTemplateLabel.setFont(LABEL_FONT);
2519
2520     final String tooltip = JvSwingUtils.wrapTooltip(true,
2521             MessageManager.getString("label.append_to_filename_tooltip"));
2522     suffixTemplate.setToolTipText(tooltip);
2523     suffixTemplate.addActionListener(new ActionListener()
2524     {
2525       @Override
2526       public void actionPerformed(ActionEvent e)
2527       {
2528         updateBackupFilesExampleLabel();
2529         backupfilesCustomOptionsSetEnabled();
2530         backupfilesRevertButtonSetEnabled(true);
2531       }
2532
2533     });
2534     suffixTemplate.addKeyListener(new KeyListener()
2535     {
2536       @Override
2537       public void keyReleased(KeyEvent e)
2538       {
2539         updateBackupFilesExampleLabel();
2540         backupfilesCustomOptionsSetEnabled();
2541         backupfilesRevertButtonSetEnabled(true);
2542       }
2543
2544       @Override
2545       public void keyPressed(KeyEvent e)
2546       {
2547       }
2548
2549       // disable use of ':' or '/' or '\'
2550       @Override
2551       public void keyTyped(KeyEvent e)
2552       {
2553         char c = e.getKeyChar();
2554         if (c == ':' || c == '/' || c == '\\')
2555         {
2556           // don't process ':' or '/' or '\'
2557           e.consume();
2558         }
2559       }
2560
2561     });
2562
2563     // digits spinner
2564     suffixDigitsLabel
2565             .setText(MessageManager.getString("label.index_digits"));
2566     suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
2567     suffixDigitsLabel.setFont(LABEL_FONT);
2568     ChangeListener c = new ChangeListener()
2569     {
2570       @Override
2571       public void stateChanged(ChangeEvent e)
2572       {
2573         backupfilesRevertButtonSetEnabled(true);
2574         updateBackupFilesExampleLabel();
2575       }
2576
2577     };
2578     setIntegerSpinner(suffixDigitsSpinner, BackupFilesPresetEntry.DIGITSMIN,
2579             BackupFilesPresetEntry.DIGITSMAX, 3, c);
2580
2581     suffixReverse.setLabels(MessageManager.getString("label.reverse_roll"),
2582             MessageManager.getString("label.increment_index"));
2583     suffixReverse.addActionListener(new ActionListener()
2584     {
2585       @Override
2586       public void actionPerformed(ActionEvent e)
2587       {
2588         boolean okay = true;
2589         if (warnAboutSuffixReverseChange())
2590         {
2591           // Warning popup
2592           okay = confirmSuffixReverseChange();
2593         }
2594         if (okay)
2595         {
2596           backupfilesRevertButtonSetEnabled(true);
2597           updateBackupFilesExampleLabel();
2598         }
2599         else
2600         {
2601           boolean savedSuffixReverse = BackupFilesPresetEntry
2602                   .getSavedBackupEntry().reverse;
2603           suffixReverse.setSelected(savedSuffixReverse);
2604         }
2605       }
2606     });
2607
2608     GridBagConstraints sgbc = new GridBagConstraints();
2609
2610     // first row (template text box)
2611     sgbc.anchor = GridBagConstraints.WEST;
2612     sgbc.gridx = 0;
2613     sgbc.gridy = 0;
2614     sgbc.gridwidth = 1;
2615     sgbc.gridheight = 1;
2616     sgbc.weightx = 1.0;
2617     sgbc.weighty = 0.0;
2618     sgbc.fill = GridBagConstraints.NONE;
2619     suffixPanel.add(suffixTemplateLabel, sgbc);
2620
2621     sgbc.gridx = 1;
2622     sgbc.fill = GridBagConstraints.HORIZONTAL;
2623     suffixPanel.add(suffixTemplate, sgbc);
2624
2625     // second row (number of digits spinner)
2626     sgbc.gridy = 1;
2627
2628     sgbc.gridx = 0;
2629     sgbc.fill = GridBagConstraints.NONE;
2630     suffixPanel.add(suffixDigitsLabel, sgbc);
2631
2632     sgbc.gridx = 1;
2633     sgbc.fill = GridBagConstraints.HORIZONTAL;
2634     suffixPanel.add(suffixDigitsSpinner, sgbc);
2635
2636     // third row (forward order radio selection)
2637     sgbc.gridx = 0;
2638     sgbc.gridy = 2;
2639     sgbc.gridwidth = GridBagConstraints.REMAINDER;
2640     sgbc.fill = GridBagConstraints.HORIZONTAL;
2641     suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
2642
2643     // fourth row (reverse order radio selection)
2644     sgbc.gridy = 3;
2645     suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
2646     return suffixPanel;
2647   }
2648
2649   private boolean confirmSuffixReverseChange()
2650   {
2651     boolean ret = false;
2652     String warningMessage = MessageManager
2653             .getString("label.warning_confirm_change_reverse");
2654     int confirm = JvOptionPane.showConfirmDialog(Desktop.desktop,
2655             warningMessage,
2656             MessageManager.getString("label.change_increment_decrement"),
2657             JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
2658
2659     ret = (confirm == JvOptionPane.YES_OPTION);
2660     return ret;
2661   }
2662
2663   private JPanel initBackupsTabKeepFilesPanel()
2664   {
2665     keepfilesPanel.setBorder(
2666             new TitledBorder(MessageManager.getString("label.keep_files")));
2667     keepfilesPanel.setLayout(new GridBagLayout());
2668
2669     backupfilesKeepAll.setLabels(
2670             MessageManager.getString("label.keep_all_backup_files"),
2671             MessageManager.getString(
2672                     "label.keep_only_this_number_of_backup_files"));
2673     backupfilesKeepAll.addTrueActionListener(new ActionListener()
2674     {
2675       @Override
2676       public void actionPerformed(ActionEvent e)
2677       {
2678         backupfilesRevertButtonSetEnabled(true);
2679         updateBackupFilesExampleLabel();
2680       }
2681     });
2682     backupfilesKeepAll.addActionListener(new ActionListener()
2683     {
2684       @Override
2685       public void actionPerformed(ActionEvent e)
2686       {
2687         backupfilesRevertButtonSetEnabled(true);
2688         keepRollMaxOptionsEnabled();
2689         updateBackupFilesExampleLabel();
2690       }
2691     });
2692
2693     ChangeListener c = new ChangeListener()
2694     {
2695       @Override
2696       public void stateChanged(ChangeEvent e)
2697       {
2698         backupfilesRevertButtonSetEnabled(true);
2699         updateBackupFilesExampleLabel();
2700       }
2701
2702     };
2703     setIntegerSpinner(backupfilesRollMaxSpinner,
2704             BackupFilesPresetEntry.ROLLMAXMIN,
2705             BackupFilesPresetEntry.ROLLMAXMAX, 4, true, c);
2706
2707     backupfilesConfirmDelete.setLabels(
2708             MessageManager.getString("label.always_ask"),
2709             MessageManager.getString("label.auto_delete"));
2710     backupfilesConfirmDelete.addActionListener(new ActionListener()
2711     {
2712       @Override
2713       public void actionPerformed(ActionEvent e)
2714       {
2715         backupfilesRevertButtonSetEnabled(true);
2716       }
2717     });
2718     // update the enabled section
2719     keepRollMaxOptionsEnabled();
2720
2721     GridBagConstraints kgbc = new GridBagConstraints();
2722
2723     // first row (template text box)
2724     kgbc.anchor = GridBagConstraints.WEST;
2725     kgbc.gridx = 0;
2726     kgbc.gridy = 0;
2727     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2728     kgbc.gridheight = 1;
2729     kgbc.weightx = 1.0;
2730     kgbc.weighty = 0.0;
2731     kgbc.fill = GridBagConstraints.HORIZONTAL;
2732     keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
2733
2734     // second row
2735     kgbc.gridy = 1;
2736
2737     kgbc.gridx = 0;
2738     kgbc.gridwidth = GridBagConstraints.RELATIVE;
2739     keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
2740
2741     kgbc.gridx = 1;
2742     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2743     keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
2744
2745     // third row (indented)
2746     kgbc.gridy = 2;
2747     kgbc.insets = new Insets(0, 20, 0, 0);
2748
2749     kgbc.gridx = 0;
2750     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2751     kgbc.fill = GridBagConstraints.HORIZONTAL;
2752     kgbc.weightx = 1.0;
2753
2754     JPanel jp = new JPanel();
2755     jp.setLayout(new FlowLayout());
2756     oldBackupFilesLabel
2757             .setText(MessageManager
2758                     .getString("label.autodelete_old_backup_files"));
2759     oldBackupFilesLabel.setFont(LABEL_FONT);
2760     oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
2761     jp.add(oldBackupFilesLabel);
2762     jp.add(backupfilesConfirmDelete.getTrueButton());
2763     jp.add(backupfilesConfirmDelete.getFalseButton());
2764     keepfilesPanel.add(jp, kgbc);
2765
2766     return keepfilesPanel;
2767   }
2768
2769   protected void updateBackupFilesExampleLabel()
2770   {
2771     int exampleindex = 12;
2772     String base = MessageManager.getString("label.filename") + ".fa";
2773     if (base == null || base.length() == 0)
2774     {
2775       base = "file_name.fa";
2776     }
2777
2778     boolean reverse = suffixReverse.isSelected();
2779     boolean keepAll = backupfilesKeepAll.isSelected();
2780     int rollMax = 4;
2781     String suffix = suffixTemplate.getText();
2782     int digits = 3;
2783
2784     backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
2785     if (suffix == null || suffix.length() == 0)
2786     {
2787       backupfilesExampleLabel
2788               .setText(MessageManager.getString("label.no_backup_files"));
2789       backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
2790       return;
2791     }
2792
2793     rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4);
2794     rollMax = rollMax < 1 ? 1 : rollMax;
2795
2796     if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
2797     {
2798       rollMax = 1;
2799     }
2800
2801     digits = getSpinnerInt(suffixDigitsSpinner, 3);
2802     digits = digits < 1 ? 1 : digits;
2803
2804     int lowersurround = 2;
2805     int uppersurround = 0;
2806     StringBuilder exampleSB = new StringBuilder();
2807     boolean firstLine = true;
2808     int lineNumber = 0;
2809     if (reverse)
2810     {
2811
2812       int min = 1;
2813       int max = keepAll ? exampleindex : rollMax;
2814       for (int index = min; index <= max; index++)
2815       {
2816         if (index == min + lowersurround && index < max - uppersurround - 1)
2817         {
2818           exampleSB.append("\n...");
2819           lineNumber++;
2820         }
2821         else if (index > min + lowersurround && index < max - uppersurround)
2822         {
2823           // nothing
2824         }
2825         else
2826         {
2827           if (firstLine)
2828           {
2829             firstLine = false;
2830           }
2831           else
2832           {
2833             exampleSB.append("\n");
2834             lineNumber++;
2835           }
2836           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
2837                   base, suffix, digits));
2838           if (min == max)
2839           {
2840             // no extra text needed
2841           }
2842           else if (index == min)
2843           {
2844             String newest = MessageManager.getString("label.braced_newest");
2845             if (newest != null && newest.length() > 0)
2846             {
2847               exampleSB.append(" " + newest);
2848             }
2849           }
2850           else if (index == max)
2851           {
2852             String oldest = MessageManager.getString("label.braced_oldest");
2853             if (oldest != null && oldest.length() > 0)
2854             {
2855               exampleSB.append(" " + oldest);
2856             }
2857           }
2858         }
2859       }
2860     }
2861     else
2862     {
2863
2864       int min = (keepAll || exampleindex - rollMax < 0) ? 1
2865               : exampleindex - rollMax + 1;
2866       int max = exampleindex;
2867
2868       for (int index = min; index <= max; index++)
2869       {
2870
2871         if (index == min + lowersurround && index < max - uppersurround - 1)
2872         {
2873           exampleSB.append("\n...");
2874           lineNumber++;
2875         }
2876         else if (index > min + lowersurround && index < max - uppersurround)
2877         {
2878           // nothing
2879         }
2880         else
2881         {
2882           if (firstLine)
2883           {
2884             firstLine = false;
2885           }
2886           else
2887           {
2888             exampleSB.append("\n");
2889             lineNumber++;
2890           }
2891           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
2892                   base, suffix, digits));
2893           if (min == max)
2894           {
2895             // no extra text needed
2896           }
2897           else if (index == min)
2898           {
2899             String oldest = MessageManager.getString("label.braced_oldest");
2900             if (oldest != null && oldest.length() > 0)
2901             {
2902               exampleSB.append(" " + oldest);
2903             }
2904           }
2905           else if (index == max)
2906           {
2907             String newest = MessageManager.getString("label.braced_newest");
2908             if (newest != null && newest.length() > 0)
2909             {
2910               exampleSB.append(" " + newest);
2911             }
2912           }
2913         }
2914       }
2915
2916     }
2917
2918     // add some extra empty lines to pad out the example files box. ugh, please tell
2919     // me how to do this better
2920     int remainingLines = lowersurround + uppersurround + 1 - lineNumber;
2921     if (remainingLines > 0)
2922     {
2923       for (int i = 0; i < remainingLines; i++)
2924       {
2925         exampleSB.append("\n ");
2926         lineNumber++;
2927       }
2928     }
2929
2930     backupfilesExampleLabel.setText(exampleSB.toString());
2931   }
2932
2933   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2934           boolean useExistingVal, ChangeListener c)
2935   {
2936     int i = def;
2937     if (useExistingVal)
2938     {
2939       try
2940       {
2941         i = ((Integer) s.getValue()).intValue();
2942       } catch (Exception e)
2943       {
2944         Cache.log.error(
2945                 "Exception casting the initial value of s.getValue()");
2946       }
2947     }
2948
2949     setIntegerSpinner(s, min, max, i, c);
2950   }
2951
2952   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2953           ChangeListener c)
2954   {
2955     // integer spinner for number of digits
2956     if (def > max)
2957     {
2958       max = def;
2959     }
2960     if (def < min)
2961     {
2962       def = min;
2963     }
2964     SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
2965     s.setModel(sModel);
2966
2967     s.addChangeListener(c);
2968
2969   }
2970
2971   protected static int getSpinnerInt(JSpinner s, int def)
2972   {
2973     int i = def;
2974     try
2975     {
2976       s.commitEdit();
2977       i = (Integer) s.getValue();
2978     } catch (Exception e)
2979     {
2980       Cache.log.error("Failed casting (Integer) JSpinner s.getValue()");
2981     }
2982     return i;
2983   }
2984
2985   private void keepRollMaxOptionsEnabled()
2986   {
2987     boolean enabled = backupfilesKeepAll.isEnabled()
2988             && !backupfilesKeepAll.isSelected();
2989     oldBackupFilesLabel.setEnabled(enabled);
2990     backupfilesRollMaxSpinner.setEnabled(enabled);
2991     backupfilesConfirmDelete.setEnabled(enabled);
2992   }
2993
2994   private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
2995   {
2996     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2997             && customiseCheckbox.isSelected()
2998             && suffixTemplate.getText()
2999                     .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
3000     keepfilesPanel.setEnabled(enabled);
3001     backupfilesKeepAll.setEnabled(enabled);
3002     oldBackupFilesLabel.setEnabled(enabled);
3003     keepRollMaxOptionsEnabled();
3004   }
3005
3006   private void backupfilesSuffixTemplateDigitsSetEnabled()
3007   {
3008     boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
3009             .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
3010     suffixDigitsLabel.setEnabled(enabled);
3011     suffixDigitsSpinner.setEnabled(enabled);
3012     suffixReverse.setEnabled(enabled);
3013   }
3014
3015   private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
3016   {
3017     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
3018             && customiseCheckbox.isSelected();
3019     suffixPanel.setEnabled(enabled);
3020     suffixTemplateLabel.setEnabled(enabled);
3021     suffixTemplate.setEnabled(enabled);
3022     backupfilesSuffixTemplateDigitsSetEnabled();
3023   }
3024
3025   private void backupfilesRevertButtonSetEnabled(boolean tryEnabled)
3026   {
3027     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
3028             && customiseCheckbox.isSelected() && backupfilesCustomChanged();
3029     revertButton.setEnabled(enabled);
3030   }
3031
3032   private boolean backupfilesCustomChanged()
3033   {
3034     BackupFilesPresetEntry custom = BackupFilesPresetEntry.backupfilesPresetEntriesValues
3035             .get(BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
3036     BackupFilesPresetEntry current = getBackupfilesCurrentEntry();
3037     return !custom.equals(current);
3038   }
3039
3040   protected BackupFilesPresetEntry getBackupfilesCurrentEntry()
3041   {
3042     String suffix = suffixTemplate.getText();
3043     int digits = getSpinnerInt(suffixDigitsSpinner, 3);
3044     boolean reverse = suffixReverse.isSelected();
3045     boolean keepAll = backupfilesKeepAll.isSelected();
3046     int rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 3);
3047     boolean confirmDelete = backupfilesConfirmDelete.isSelected();
3048
3049     BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits,
3050             reverse, keepAll, rollMax, confirmDelete);
3051
3052     return bfpe;
3053   }
3054
3055   protected void backupfilesCustomOptionsSetEnabled()
3056   {
3057     boolean enabled = customiseCheckbox.isSelected();
3058
3059     backupfilesRevertButtonSetEnabled(enabled);
3060     backupfilesSuffixTemplateSetEnabled(enabled);
3061     backupfilesKeepAllSetEnabled(enabled);
3062   }
3063
3064   private void backupfilesSummarySetEnabled()
3065   {
3066     boolean enabled = enableBackupFiles.isSelected();
3067     backupfilesExampleLabel.setEnabled(enabled);
3068     exampleFilesPanel.setEnabled(enabled);
3069   }
3070
3071   private void backupfilesPresetsSetEnabled()
3072   {
3073     boolean enabled = enableBackupFiles.isSelected();
3074     presetsPanel.setEnabled(enabled);
3075     presetsComboLabel.setEnabled(enabled);
3076     backupfilesPresetsCombo.setEnabled(enabled);
3077     customiseCheckbox.setEnabled(enabled);
3078     revertButton.setEnabled(enabled);
3079   }
3080
3081   protected void backupsOptionsSetEnabled()
3082   {
3083     backupfilesPresetsSetEnabled();
3084     backupfilesSummarySetEnabled();
3085     backupfilesCustomOptionsSetEnabled();
3086   }
3087
3088   protected void backupsSetOptions(String suffix, int digits,
3089           boolean reverse, boolean keepAll, int rollMax,
3090           boolean confirmDelete)
3091   {
3092     suffixTemplate.setText(suffix);
3093     suffixDigitsSpinner.setValue(digits);
3094     suffixReverse.setSelected(reverse);
3095     backupfilesKeepAll.setSelected(keepAll);
3096     backupfilesRollMaxSpinner.setValue(rollMax);
3097     backupfilesConfirmDelete.setSelected(confirmDelete);
3098   }
3099
3100   protected void backupsSetOptions(BackupFilesPresetEntry p)
3101   {
3102     backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax,
3103             p.confirmDelete);
3104   }
3105
3106   protected void autoIdWidth_actionPerformed()
3107   {
3108     // TODO Auto-generated method stub
3109
3110   }
3111
3112   protected void userIdWidth_actionPerformed()
3113   {
3114     // TODO Auto-generated method stub
3115
3116   }
3117
3118   protected void maxColour_actionPerformed(JPanel panel)
3119   {
3120   }
3121
3122   protected void minColour_actionPerformed(JPanel panel)
3123   {
3124   }
3125
3126   protected void gapColour_actionPerformed(JPanel panel)
3127   {
3128   }
3129
3130   protected void hiddenColour_actionPerformed(JPanel panel)
3131   {
3132   }
3133
3134   protected void showunconserved_actionPerformed(ActionEvent e)
3135   {
3136     // TODO Auto-generated method stub
3137
3138   }
3139
3140   protected void useLegacyGaps_actionPerformed(ActionEvent e)
3141   {
3142   }
3143
3144   protected void resetOvDefaults_actionPerformed(ActionEvent e)
3145   {
3146   }
3147
3148   /**
3149    * DOCUMENT ME!
3150    * 
3151    * @param e
3152    *          DOCUMENT ME!
3153    */
3154   public void ok_actionPerformed(ActionEvent e)
3155   {
3156   }
3157
3158   /**
3159    * DOCUMENT ME!
3160    * 
3161    * @param e
3162    *          DOCUMENT ME!
3163    */
3164   public void cancel_actionPerformed(ActionEvent e)
3165   {
3166   }
3167
3168   /**
3169    * DOCUMENT ME!
3170    * 
3171    * @param e
3172    *          DOCUMENT ME!
3173    */
3174   public void annotations_actionPerformed(ActionEvent e)
3175   {
3176   }
3177
3178   /**
3179    * DOCUMENT ME!
3180    */
3181   public void startupFileTextfield_mouseClicked()
3182   {
3183   }
3184
3185   public void newLink_actionPerformed(ActionEvent e)
3186   {
3187
3188   }
3189
3190   public void editLink_actionPerformed(ActionEvent e)
3191   {
3192
3193   }
3194
3195   public void deleteLink_actionPerformed(ActionEvent e)
3196   {
3197
3198   }
3199
3200   public void defaultBrowser_mouseClicked(MouseEvent e)
3201   {
3202
3203   }
3204
3205   public void linkURLList_keyTyped(KeyEvent e)
3206   {
3207
3208   }
3209
3210   public void setProxyAuthEnabled()
3211   {
3212     boolean enabled = proxyAuth.isSelected() && proxyAuth.isEnabled();
3213     proxyAuthUsernameLabel.setEnabled(enabled);
3214     proxyAuthPasswordLabel.setEnabled(enabled);
3215     passwordNotStoredLabel.setEnabled(enabled);
3216     proxyAuthUsernameTB.setEnabled(enabled);
3217     proxyAuthPasswordPB.setEnabled(enabled);
3218   }
3219
3220   public void setCustomProxyEnabled()
3221   {
3222     boolean enabled = customProxy.isSelected();
3223     portLabel.setEnabled(enabled);
3224     serverLabel.setEnabled(enabled);
3225     portLabel2.setEnabled(enabled);
3226     serverLabel2.setEnabled(enabled);
3227     httpLabel.setEnabled(enabled);
3228     httpsLabel.setEnabled(enabled);
3229     proxyServerHttpTB.setEnabled(enabled);
3230     proxyPortHttpTB.setEnabled(enabled);
3231     proxyServerHttpsTB.setEnabled(enabled);
3232     proxyPortHttpsTB.setEnabled(enabled);
3233     proxyAuth.setEnabled(enabled);
3234     setProxyAuthEnabled();
3235   }
3236
3237   public void proxyType_actionPerformed()
3238   {
3239     setCustomProxyEnabled();
3240     proxyAuthPasswordCheckHighlight(true);
3241     applyProxyButtonEnabled(true);
3242   }
3243
3244   public void proxyAuth_actionPerformed()
3245   {
3246     setProxyAuthEnabled();
3247     proxyAuthPasswordCheckHighlight(true);
3248     applyProxyButtonEnabled(true);
3249   }
3250
3251   /**
3252    * Customer renderer for JTable: supports column of radio buttons
3253    */
3254   public class RadioButtonRenderer extends JRadioButton
3255           implements TableCellRenderer
3256   {
3257     public RadioButtonRenderer()
3258     {
3259       setHorizontalAlignment(CENTER);
3260       setToolTipText(MessageManager.getString("label.urltooltip"));
3261     }
3262
3263     @Override
3264     public Component getTableCellRendererComponent(JTable table,
3265             Object value, boolean isSelected, boolean hasFocus, int row,
3266             int column)
3267     {
3268       setSelected((boolean) value);
3269
3270       // set colours to match rest of table
3271       if (isSelected)
3272       {
3273         setBackground(table.getSelectionBackground());
3274         setForeground(table.getSelectionForeground());
3275       }
3276       else
3277       {
3278         setBackground(table.getBackground());
3279         setForeground(table.getForeground());
3280       }
3281       return this;
3282     }
3283   }
3284
3285   /**
3286    * Customer cell editor for JTable: supports column of radio buttons in
3287    * conjunction with renderer
3288    */
3289   public class RadioButtonEditor extends AbstractCellEditor
3290           implements TableCellEditor
3291   {
3292     private JRadioButton button = new JRadioButton();
3293
3294     public RadioButtonEditor()
3295     {
3296       button.setHorizontalAlignment(SwingConstants.CENTER);
3297       this.button.addActionListener(new ActionListener()
3298       {
3299         @Override
3300         public void actionPerformed(ActionEvent e)
3301         {
3302           fireEditingStopped();
3303         }
3304       });
3305     }
3306
3307     @Override
3308     public Component getTableCellEditorComponent(JTable table, Object value,
3309             boolean isSelected, int row, int column)
3310     {
3311       button.setSelected((boolean) value);
3312       return button;
3313     }
3314
3315     @Override
3316     public Object getCellEditorValue()
3317     {
3318       return button.isSelected();
3319     }
3320
3321   }
3322 }
3323