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