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