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