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