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