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