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