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