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