26c37d0034488ac2c460e24ef4602e178e797d50
[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     if (!Platform.isJS())
1448     {
1449       structViewer.setFont(LABEL_FONT);
1450       structViewer.setBounds(new Rectangle(160, ypos, 120, height));
1451       structViewer.addItem(ViewerType.JMOL.name());
1452       structViewer.addItem(ViewerType.CHIMERA.name());
1453       structViewer.addActionListener(new ActionListener()
1454       {
1455         @Override
1456         public void actionPerformed(ActionEvent e)
1457         {
1458           structureViewer_actionPerformed(
1459                   (String) structViewer.getSelectedItem());
1460         }
1461       });
1462       structureTab.add(structViewer);
1463     }
1464
1465     ypos += lineSpacing;
1466     JLabel pathLabel = new JLabel();
1467     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
1468     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1469     pathLabel.setText(MessageManager.getString("label.chimera_path"));
1470     pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
1471     structureTab.add(pathLabel);
1472
1473     chimeraPath.setFont(LABEL_FONT);
1474     chimeraPath.setText("");
1475     final String tooltip = JvSwingUtils.wrapTooltip(true,
1476             MessageManager.getString("label.chimera_path_tip"));
1477     chimeraPath.setToolTipText(tooltip);
1478     chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
1479     chimeraPath.addMouseListener(new MouseAdapter()
1480     {
1481       @Override
1482       public void mouseClicked(MouseEvent e)
1483       {
1484         if (e.getClickCount() == 2)
1485         {
1486           String chosen = openFileChooser(false);
1487           if (chosen != null)
1488           {
1489             chimeraPath.setText(chosen);
1490           }
1491         }
1492       }
1493     });
1494     structureTab.add(chimeraPath);
1495
1496     ypos += lineSpacing;
1497     nwMapping.setFont(LABEL_FONT);
1498     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1499     siftsMapping.setFont(LABEL_FONT);
1500     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1501     mappingMethod.add(nwMapping);
1502     mappingMethod.add(siftsMapping);
1503     JPanel mappingPanel = new JPanel();
1504     mappingPanel.setFont(LABEL_FONT);
1505     TitledBorder mmTitledBorder = new TitledBorder(
1506             MessageManager.getString("label.mapping_method"));
1507     mmTitledBorder.setTitleFont(LABEL_FONT);
1508     mappingPanel.setBorder(mmTitledBorder);
1509     mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
1510     // GridLayout mappingLayout = new GridLayout();
1511     mappingPanel.setLayout(new GridLayout());
1512     mappingPanel.add(nwMapping);
1513     mappingPanel.add(siftsMapping);
1514     structureTab.add(mappingPanel);
1515
1516     ypos += lineSpacing;
1517     ypos += lineSpacing;
1518     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1519             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1520     docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
1521     structureTab.add(docFieldPref);
1522
1523     /*
1524      * hide Chimera options in JalviewJS
1525      */
1526     if (Platform.isJS())
1527     {
1528       pathLabel.setVisible(false);
1529       chimeraPath.setVisible(false);
1530       viewerLabel.setVisible(false);
1531       structViewer.setVisible(false);
1532     }
1533
1534     return structureTab;
1535   }
1536
1537   /**
1538    * Action on choosing a structure viewer from combobox options.
1539    * 
1540    * @param selectedItem
1541    */
1542   protected void structureViewer_actionPerformed(String selectedItem)
1543   {
1544   }
1545
1546   /**
1547    * Show a dialog for the user to choose a file. Returns the chosen path, or
1548    * null on Cancel.
1549    * 
1550    * @return
1551    */
1552   protected String openFileChooser(boolean forFolder)
1553   {
1554     String choice = null;
1555     JFileChooser chooser = new JFileChooser();
1556     if (forFolder)
1557     {
1558       chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1559     }
1560
1561     // chooser.setFileView(new JalviewFileView());
1562     chooser.setDialogTitle(
1563             MessageManager.getString("label.open_local_file"));
1564     chooser.setToolTipText(MessageManager.getString("action.open"));
1565
1566     int value = chooser.showOpenDialog(this);
1567
1568     if (value == JFileChooser.APPROVE_OPTION)
1569     {
1570       choice = chooser.getSelectedFile().getPath();
1571     }
1572     return choice;
1573   }
1574
1575   protected boolean validateStructure()
1576   {
1577     return false;
1578   }
1579
1580   /**
1581    * Initialises the Visual tabbed panel.
1582    * 
1583    * @return
1584    */
1585   private JPanel initVisualTab()
1586   {
1587     JPanel visualTab = new JPanel();
1588     visualTab.setBorder(new TitledBorder(
1589             MessageManager.getString("action.open_new_alignment")));
1590     visualTab.setLayout(null);
1591     fullScreen.setFont(LABEL_FONT);
1592     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
1593     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
1594     fullScreen.setText(MessageManager.getString("label.maximize_window"));
1595     quality.setEnabled(false);
1596     quality.setFont(LABEL_FONT);
1597     quality.setHorizontalAlignment(SwingConstants.RIGHT);
1598     quality.setHorizontalTextPosition(SwingConstants.LEFT);
1599     quality.setSelected(true);
1600     quality.setText(MessageManager.getString("label.quality"));
1601     conservation.setEnabled(false);
1602     conservation.setFont(LABEL_FONT);
1603     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
1604     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
1605     conservation.setSelected(true);
1606     conservation.setText(MessageManager.getString("label.conservation"));
1607     identity.setEnabled(false);
1608     identity.setFont(LABEL_FONT);
1609     identity.setHorizontalAlignment(SwingConstants.RIGHT);
1610     identity.setHorizontalTextPosition(SwingConstants.LEFT);
1611     identity.setSelected(true);
1612     identity.setText(MessageManager.getString("label.consensus"));
1613     showOccupancy.setFont(LABEL_FONT);
1614     showOccupancy.setEnabled(false);
1615     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
1616     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
1617     showOccupancy.setSelected(true);
1618     showOccupancy.setText(MessageManager.getString("label.occupancy"));
1619
1620     JLabel showGroupbits = new JLabel();
1621     showGroupbits.setFont(LABEL_FONT);
1622     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
1623     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
1624     showGroupbits
1625             .setText(MessageManager.getString("action.show_group") + ":");
1626     JLabel showConsensbits = new JLabel();
1627     showConsensbits.setFont(LABEL_FONT);
1628     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
1629     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
1630     showConsensbits
1631             .setText(MessageManager.getString("label.consensus") + ":");
1632     showConsensHistogram.setEnabled(false);
1633     showConsensHistogram.setFont(LABEL_FONT);
1634     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
1635     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
1636     showConsensHistogram.setSelected(true);
1637     showConsensHistogram
1638             .setText(MessageManager.getString("label.histogram"));
1639     showConsensLogo.setEnabled(false);
1640     showConsensLogo.setFont(LABEL_FONT);
1641     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
1642     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
1643     showConsensLogo.setSelected(true);
1644     showConsensLogo.setText(MessageManager.getString("label.logo"));
1645     showGroupConsensus.setEnabled(false);
1646     showGroupConsensus.setFont(LABEL_FONT);
1647     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
1648     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
1649     showGroupConsensus.setSelected(true);
1650     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
1651     showGroupConservation.setEnabled(false);
1652     showGroupConservation.setFont(LABEL_FONT);
1653     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
1654     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
1655     showGroupConservation.setSelected(true);
1656     showGroupConservation
1657             .setText(MessageManager.getString("label.conservation"));
1658     showNpTooltip.setEnabled(true);
1659     showNpTooltip.setFont(LABEL_FONT);
1660     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1661     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1662     showNpTooltip.setSelected(true);
1663     showNpTooltip.setText(
1664             MessageManager.getString("label.non_positional_features"));
1665     showDbRefTooltip.setEnabled(true);
1666     showDbRefTooltip.setFont(LABEL_FONT);
1667     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1668     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1669     showDbRefTooltip.setSelected(true);
1670     showDbRefTooltip
1671             .setText(MessageManager.getString("label.database_references"));
1672     annotations.setFont(LABEL_FONT);
1673     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
1674     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
1675     annotations.setSelected(true);
1676     annotations.setText(MessageManager.getString("label.show_annotations"));
1677     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
1678     annotations.addActionListener(new ActionListener()
1679     {
1680       @Override
1681       public void actionPerformed(ActionEvent e)
1682       {
1683         annotations_actionPerformed(e);
1684       }
1685     });
1686     identity.addActionListener(new ActionListener()
1687     {
1688       @Override
1689       public void actionPerformed(ActionEvent e)
1690       {
1691         annotations_actionPerformed(e);
1692       }
1693     });
1694     showGroupConsensus.addActionListener(new ActionListener()
1695     {
1696       @Override
1697       public void actionPerformed(ActionEvent e)
1698       {
1699         annotations_actionPerformed(e);
1700       }
1701     });
1702     showUnconserved.setFont(LABEL_FONT);
1703     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
1704     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
1705     showUnconserved.setSelected(true);
1706     showUnconserved
1707             .setText(MessageManager.getString("action.show_unconserved"));
1708     showUnconserved.addActionListener(new ActionListener()
1709     {
1710       @Override
1711       public void actionPerformed(ActionEvent e)
1712       {
1713         showunconserved_actionPerformed(e);
1714       }
1715     });
1716
1717     // TODO these are not yet added to / action from Preferences
1718     // JCheckBox shareSelections = new JCheckBox();
1719     // shareSelections.setFont(verdana11);
1720     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
1721     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
1722     // shareSelections.setSelected(true);
1723     // shareSelections.setText(MessageManager
1724     // .getString("label.share_selection_across_views"));
1725     // JCheckBox followHighlight = new JCheckBox();
1726     // followHighlight.setFont(verdana11);
1727     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
1728     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
1729     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
1730     // followHighlight.setSelected(true);
1731     // followHighlight.setText(MessageManager
1732     // .getString("label.scroll_highlighted_regions"));
1733
1734     seqLimit.setFont(LABEL_FONT);
1735     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
1736     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
1737     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
1738     smoothFont.setFont(LABEL_FONT);
1739     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
1740     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
1741     smoothFont.setText(MessageManager.getString("label.smooth_font"));
1742     scaleProteinToCdna.setFont(LABEL_FONT);
1743     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
1744     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
1745     scaleProteinToCdna.setText(
1746             MessageManager.getString("label.scale_protein_to_cdna"));
1747     scaleProteinToCdna.setToolTipText(
1748             MessageManager.getString("label.scale_protein_to_cdna_tip"));
1749     JLabel gapLabel = new JLabel();
1750     gapLabel.setFont(LABEL_FONT);
1751     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1752     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
1753     JLabel fontLabel = new JLabel();
1754     fontLabel.setFont(LABEL_FONT);
1755     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1756     fontLabel.setText(MessageManager.getString("label.font"));
1757     fontSizeCB.setFont(LABEL_FONT);
1758     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
1759     fontStyleCB.setFont(LABEL_FONT);
1760     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
1761     fontNameCB.setFont(LABEL_FONT);
1762     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
1763     gapSymbolCB.setFont(LABEL_FONT);
1764     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
1765     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
1766     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
1767     gapSymbolCB.setRenderer(dlcr);
1768
1769     startupCheckbox.setText(MessageManager.getString("action.open_file"));
1770     startupCheckbox.setFont(LABEL_FONT);
1771     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
1772     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
1773     startupCheckbox.setSelected(true);
1774     startupFileTextfield.setFont(LABEL_FONT);
1775     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
1776     final String tooltip = JvSwingUtils.wrapTooltip(true,
1777             MessageManager.getString("label.double_click_to_browse"));
1778     startupFileTextfield.setToolTipText(tooltip);
1779     startupFileTextfield.addMouseListener(new MouseAdapter()
1780     {
1781       @Override
1782       public void mouseClicked(MouseEvent e)
1783       {
1784         if (e.getClickCount() > 1)
1785         {
1786           startupFileTextfield_mouseClicked();
1787         }
1788       }
1789     });
1790
1791     sortby.setFont(LABEL_FONT);
1792     sortby.setBounds(new Rectangle(172, 260, 155, 21));
1793     JLabel sortLabel = new JLabel();
1794     sortLabel.setFont(LABEL_FONT);
1795     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1796     sortLabel.setText(MessageManager.getString("label.sort_by"));
1797     sortAnnBy.setFont(LABEL_FONT);
1798     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
1799     JLabel sortAnnLabel = new JLabel();
1800     sortAnnLabel.setFont(LABEL_FONT);
1801     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1802     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
1803     sortAutocalc.setFont(LABEL_FONT);
1804     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
1805
1806     JPanel annsettingsPanel = new JPanel();
1807     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
1808     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
1809     annsettingsPanel.setBorder(new EtchedBorder());
1810     visualTab.add(annsettingsPanel);
1811     Border jb = new EmptyBorder(1, 1, 4, 5);
1812     annotations.setBorder(jb);
1813     showOccupancy.setBorder(jb);
1814     quality.setBorder(jb);
1815     conservation.setBorder(jb);
1816     identity.setBorder(jb);
1817     showConsensbits.setBorder(jb);
1818     showGroupbits.setBorder(jb);
1819     showGroupConsensus.setBorder(jb);
1820     showGroupConservation.setBorder(jb);
1821     showConsensHistogram.setBorder(jb);
1822     showConsensLogo.setBorder(jb);
1823
1824     JPanel autoAnnotSettings = new JPanel();
1825     annsettingsPanel.add(autoAnnotSettings);
1826     autoAnnotSettings.setLayout(new GridLayout(0, 2));
1827     autoAnnotSettings.add(annotations);
1828     autoAnnotSettings.add(quality);
1829     // second row of autoannotation box
1830     autoAnnotSettings = new JPanel();
1831     annsettingsPanel.add(autoAnnotSettings);
1832
1833     autoAnnotSettings.setLayout(new GridLayout(0, 3));
1834     autoAnnotSettings.add(conservation);
1835     autoAnnotSettings.add(identity);
1836     autoAnnotSettings.add(showOccupancy);
1837     autoAnnotSettings.add(showGroupbits);
1838     autoAnnotSettings.add(showGroupConservation);
1839     autoAnnotSettings.add(showGroupConsensus);
1840     autoAnnotSettings.add(showConsensbits);
1841     autoAnnotSettings.add(showConsensHistogram);
1842     autoAnnotSettings.add(showConsensLogo);
1843
1844     JPanel tooltipSettings = new JPanel();
1845     tooltipSettings.setBorder(new TitledBorder(
1846             MessageManager.getString("label.sequence_id_tooltip")));
1847     tooltipSettings.setBounds(173, 140, 220, 62);
1848     tooltipSettings.setLayout(new GridLayout(2, 1));
1849     tooltipSettings.add(showDbRefTooltip);
1850     tooltipSettings.add(showNpTooltip);
1851     visualTab.add(tooltipSettings);
1852
1853     wrap.setFont(LABEL_FONT);
1854     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
1855     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
1856     wrap.setText(MessageManager.getString("label.wrap_alignment"));
1857     rightAlign.setFont(LABEL_FONT);
1858     rightAlign.setForeground(Color.black);
1859     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
1860     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
1861     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
1862     idItalics.setFont(LABEL_FONT_ITALIC);
1863     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
1864     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
1865     idItalics.setText(
1866             MessageManager.getString("label.sequence_name_italics"));
1867     openoverv.setFont(LABEL_FONT);
1868     openoverv.setActionCommand(
1869             MessageManager.getString("label.open_overview"));
1870     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
1871     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
1872     openoverv.setText(MessageManager.getString("label.open_overview"));
1873     JPanel jPanel2 = new JPanel();
1874     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
1875     jPanel2.setLayout(new GridLayout(14, 1));
1876     jPanel2.add(fullScreen);
1877     jPanel2.add(openoverv);
1878     jPanel2.add(seqLimit);
1879     jPanel2.add(rightAlign);
1880     jPanel2.add(fontLabel);
1881     jPanel2.add(showUnconserved);
1882     jPanel2.add(idItalics);
1883     jPanel2.add(smoothFont);
1884     jPanel2.add(scaleProteinToCdna);
1885     jPanel2.add(gapLabel);
1886     jPanel2.add(wrap);
1887     jPanel2.add(sortLabel);
1888     jPanel2.add(sortAnnLabel);
1889     jPanel2.add(startupCheckbox);
1890     visualTab.add(jPanel2);
1891     visualTab.add(startupFileTextfield);
1892     visualTab.add(sortby);
1893     visualTab.add(sortAnnBy);
1894     visualTab.add(sortAutocalc);
1895     visualTab.add(gapSymbolCB);
1896     visualTab.add(fontNameCB);
1897     visualTab.add(fontSizeCB);
1898     visualTab.add(fontStyleCB);
1899     
1900     if (Platform.isJS())
1901     {
1902       startupCheckbox.setVisible(false);
1903       startupFileTextfield.setVisible(false);
1904     }
1905     
1906     return visualTab;
1907   }
1908
1909   /**
1910    * Load the saved Backups options EXCEPT "Enabled" and "Scheme"
1911    */
1912
1913   protected void loadLastSavedBackupsOptions()
1914   {
1915     BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
1916             .getSavedBackupEntry();
1917     enableBackupFiles
1918             .setSelected(Cache.getDefault(BackupFiles.ENABLED, !Platform.isJS()));
1919
1920     BackupFilesPresetEntry backupfilesCustomEntry = BackupFilesPresetEntry
1921             .createBackupFilesPresetEntry(Cache
1922                     .getDefault(BackupFilesPresetEntry.CUSTOMCONFIG, null));
1923     if (backupfilesCustomEntry == null)
1924     {
1925       backupfilesCustomEntry = BackupFilesPresetEntry.backupfilesPresetEntriesValues
1926               .get(BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT);
1927     }
1928     BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
1929             BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM,
1930             backupfilesCustomEntry);
1931
1932     setComboIntStringKey(backupfilesPresetsCombo,
1933             Cache.getDefault(BackupFiles.NS + "_PRESET",
1934                     BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT));
1935
1936     backupsSetOptions(savedPreset);
1937
1938     backupsOptionsSetEnabled();
1939     updateBackupFilesExampleLabel();
1940   }
1941
1942   private boolean warnAboutSuffixReverseChange()
1943   {
1944     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
1945             .getSavedBackupEntry();
1946     boolean savedSuffixReverse = bfpe.reverse;
1947     int savedSuffixDigits = bfpe.digits;
1948     String savedSuffixTemplate = bfpe.suffix;
1949
1950     boolean nowSuffixReverse = suffixReverse.isSelected();
1951     int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3);
1952     String nowSuffixTemplate = suffixTemplate.getText();
1953     return nowSuffixReverse != savedSuffixReverse
1954             && nowSuffixDigits == savedSuffixDigits
1955             && nowSuffixTemplate != null
1956             && nowSuffixTemplate.equals(savedSuffixTemplate);
1957   }
1958
1959   /**
1960    * Initialises the Backups tabbed panel.
1961    * 
1962    * @return
1963    */
1964   private JPanel initBackupsTab()
1965   {
1966     JPanel backupsTab = new JPanel();
1967     backupsTab.setBorder(new TitledBorder(
1968             MessageManager.getString("label.backup_files")));
1969     backupsTab.setLayout(new GridBagLayout());
1970
1971     GridBagConstraints gbc = new GridBagConstraints();
1972     gbc.weightx = 0.0;
1973     gbc.weighty = 0.0;
1974     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
1975     gbc.fill = GridBagConstraints.NONE;
1976
1977     initBackupsTabPresetsPanel();
1978     initBackupsTabSuffixPanel();
1979     initBackupsTabKeepFilesPanel();
1980     initBackupsTabFilenameExamplesPanel();
1981
1982     enableBackupFiles.setFont(LABEL_FONT_BOLD);
1983     enableBackupFiles
1984             .setText(MessageManager.getString("label.enable_backupfiles"));
1985     enableBackupFiles.addActionListener(new ActionListener()
1986     {
1987       @Override
1988       public void actionPerformed(ActionEvent e)
1989       {
1990         // enable other options only when the first is checked
1991         backupsOptionsSetEnabled();
1992       }
1993     });
1994
1995
1996     // enable checkbox 1 col
1997     gbc.gridwidth = 1;
1998     gbc.gridheight = 1;
1999     gbc.gridx = 0;
2000     gbc.gridy = 0; // row 0
2001     backupsTab.add(enableBackupFiles, gbc);
2002
2003     // summary of scheme box (over two rows)
2004     gbc.gridx = 1;
2005     gbc.weightx = 0.0;
2006     gbc.gridheight = 2;
2007     gbc.anchor = GridBagConstraints.FIRST_LINE_END;
2008     gbc.fill = GridBagConstraints.BOTH;
2009     backupsTab.add(exampleFilesPanel, gbc);
2010     gbc.gridheight = 1;
2011     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2012     gbc.fill = GridBagConstraints.NONE;
2013
2014     // fill empty space on right
2015     gbc.gridx++;
2016     gbc.weightx = 1.0;
2017     backupsTab.add(new JPanel(), gbc);
2018
2019     // schemes box
2020     gbc.weightx = 0.0;
2021     gbc.gridx = 0;
2022     gbc.gridy++; // row 1
2023     backupsTab.add(presetsPanel, gbc);
2024
2025     // now using whole row
2026     gbc.gridwidth = 2;
2027     gbc.gridheight = 1;
2028     // keep files box
2029     gbc.gridx = 0;
2030     gbc.gridy++; // row 2
2031     backupsTab.add(keepfilesPanel, gbc);
2032
2033     // filename strategy box
2034     gbc.gridy++; // row 3
2035     backupsTab.add(suffixPanel, gbc);
2036
2037     // fill empty space
2038     gbc.gridy++; // row 4
2039     gbc.weighty = 1.0;
2040     backupsTab.add(new JPanel(), gbc);
2041
2042     backupsOptionsSetEnabled();
2043     return backupsTab;
2044   }
2045
2046   private JPanel initBackupsTabPresetsPanel()
2047   {
2048
2049     String title = MessageManager.getString("label.schemes");
2050
2051     presetsPanel.setLayout(new GridBagLayout());
2052
2053     GridBagConstraints gbc = new GridBagConstraints();
2054     gbc.weightx = 0.0;
2055     gbc.weighty = 0.0;
2056     gbc.anchor = GridBagConstraints.BASELINE_LEADING;
2057     gbc.fill = GridBagConstraints.NONE;
2058     gbc.gridwidth = 1;
2059     gbc.gridheight = 1;
2060
2061     // "Scheme: "
2062     gbc.gridx = 0;
2063     gbc.gridy = 0;
2064
2065     presetsComboLabel = new JLabel(title + ":");
2066     presetsPanel.add(presetsComboLabel, gbc);
2067
2068     List<Object> entries = Arrays
2069             .asList((Object[]) BackupFilesPresetEntry.backupfilesPresetEntries);
2070     List<String> tooltips = Arrays.asList(
2071             BackupFilesPresetEntry.backupfilesPresetEntryDescriptions);
2072     backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries,
2073             tooltips);
2074     /*
2075     for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++)
2076     {
2077       backupfilesPresetsCombo
2078               .addItem(BackupFilesPresetEntry.backupfilesPresetEntries[i]);
2079     }
2080     */
2081
2082     backupfilesPresetsCombo.addActionListener(new ActionListener()
2083     {
2084       @Override
2085       public void actionPerformed(ActionEvent e)
2086       {
2087         int key = getComboIntStringKey(backupfilesPresetsCombo);
2088         if (!customiseCheckbox.isSelected())
2089         {
2090           backupfilesPresetsComboLastSelected = key;
2091         }
2092         if (key == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
2093         {
2094           if (customiseCheckbox.isSelected())
2095           {
2096             // got here by clicking on customiseCheckbox so don't change the values
2097             backupfilesCustomOptionsSetEnabled();
2098           }
2099           else
2100           {
2101             backupsTabUpdatePresets();
2102             backupfilesCustomOptionsSetEnabled();
2103           }
2104         }
2105         else
2106         {
2107           customiseCheckbox.setSelected(false);
2108           backupsTabUpdatePresets();
2109           backupfilesCustomOptionsSetEnabled();
2110         }
2111       }
2112     });
2113
2114     // dropdown list of preset schemes
2115     gbc.gridx = 1;
2116     presetsPanel.add(backupfilesPresetsCombo, gbc);
2117
2118     revertButton.setText(MessageManager.getString("label.cancel_changes"));
2119     revertButton.setToolTipText(
2120             MessageManager.getString("label.cancel_changes_description"));
2121     revertButton.addActionListener(new ActionListener()
2122     {
2123       @Override
2124       public void actionPerformed(ActionEvent e)
2125       {
2126         backupsSetOptions(
2127                 BackupFilesPresetEntry.backupfilesPresetEntriesValues.get(
2128                         BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM));
2129         backupfilesCustomOptionsSetEnabled();
2130       }
2131
2132     });
2133     revertButton.setFont(LABEL_FONT);
2134
2135     customiseCheckbox.setFont(LABEL_FONT);
2136     customiseCheckbox.setText(MessageManager.getString("label.customise"));
2137     customiseCheckbox.addActionListener(new ActionListener()
2138     {
2139       @Override
2140       public void actionPerformed(ActionEvent e)
2141       {
2142         int currently = getComboIntStringKey(backupfilesPresetsCombo);
2143         if (customiseCheckbox.isSelected())
2144         {
2145           backupfilesPresetsComboLastSelected = currently;
2146           setComboIntStringKey(backupfilesPresetsCombo,
2147                   BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
2148         }
2149         else
2150         {
2151           setComboIntStringKey(backupfilesPresetsCombo,
2152                   backupfilesPresetsComboLastSelected);
2153
2154         }
2155         backupfilesCustomOptionsSetEnabled();
2156       }
2157     });
2158     customiseCheckbox.setToolTipText(
2159             MessageManager.getString("label.customise_description"));
2160
2161     // customise checkbox
2162     gbc.gridx = 0;
2163     gbc.gridy++;
2164     presetsPanel.add(customiseCheckbox, gbc);
2165
2166     // "Cancel changes" button (aligned with combo box above)
2167     gbc.gridx = 1;
2168     presetsPanel.add(revertButton, gbc);
2169
2170     return presetsPanel;
2171   }
2172
2173   private JPanel initBackupsTabFilenameExamplesPanel()
2174   {
2175     String title = MessageManager
2176             .getString("label.scheme_examples");
2177     TitledBorder tb = new TitledBorder(title);
2178     exampleFilesPanel.setBorder(tb);
2179     exampleFilesPanel.setLayout(new GridBagLayout());
2180
2181
2182     backupfilesExampleLabel.setEditable(false);
2183     backupfilesExampleLabel
2184             .setBackground(exampleFilesPanel.getBackground());
2185
2186     updateBackupFilesExampleLabel();
2187
2188     GridBagConstraints gbc = new GridBagConstraints();
2189     gbc.weightx = 1.0;
2190     gbc.weighty = 1.0;
2191     gbc.fill = GridBagConstraints.NONE;
2192     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2193
2194     exampleFilesPanel.add(backupfilesExampleLabel, gbc);
2195     return exampleFilesPanel;
2196   }
2197
2198   private void backupsTabUpdatePresets()
2199   {
2200     IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo
2201             .getSelectedItem();
2202     int key = entry.k;
2203     String value = entry.v;
2204
2205     if (BackupFilesPresetEntry.backupfilesPresetEntriesValues
2206             .containsKey(key))
2207     {
2208       backupsSetOptions(
2209               BackupFilesPresetEntry.backupfilesPresetEntriesValues
2210                       .get(key));
2211     }
2212     else
2213     {
2214       Cache.log.error(
2215               "Preset '" + value + "' [key:" + key + "] not implemented");
2216     }
2217
2218     // Custom options will now be enabled when the customiseCheckbox is checked
2219     // (performed above)
2220     // backupfilesCustomOptionsSetEnabled();
2221     updateBackupFilesExampleLabel();
2222   }
2223
2224   protected int getComboIntStringKey(
2225           JComboBox<Object> backupfilesPresetsCombo2)
2226   {
2227     IntKeyStringValueEntry e;
2228     try
2229     {
2230       e = (IntKeyStringValueEntry) backupfilesPresetsCombo2
2231               .getSelectedItem();
2232     } catch (Exception ex)
2233     {
2234       Cache.log.error(
2235               "Problem casting Combo entry to IntKeyStringValueEntry.");
2236       e = null;
2237     }
2238     return e != null ? e.k : 0;
2239   }
2240
2241   protected void setComboIntStringKey(
2242           JComboBox<Object> backupfilesPresetsCombo2,
2243           int key)
2244   {
2245     for (int i = 0; i < backupfilesPresetsCombo2.getItemCount(); i++)
2246     {
2247       IntKeyStringValueEntry e;
2248       try
2249       {
2250         e = (IntKeyStringValueEntry) backupfilesPresetsCombo2.getItemAt(i);
2251       } catch (Exception ex)
2252       {
2253         Cache.log.error(
2254                 "Problem casting Combo entry to IntKeyStringValueEntry. Skipping item. ");
2255         continue;
2256       }
2257       if (e.k == key)
2258       {
2259         backupfilesPresetsCombo2.setSelectedIndex(i);
2260         break;
2261       }
2262     }
2263     // backupsTabUpdatePresets();
2264   }
2265
2266   private JPanel initBackupsTabSuffixPanel()
2267   {
2268     suffixPanel.setBorder(new TitledBorder(
2269             MessageManager.getString("label.backup_filename_strategy")));
2270     suffixPanel.setLayout(new GridBagLayout());
2271
2272     suffixTemplateLabel
2273             .setText(MessageManager.getString("label.append_to_filename"));
2274     suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
2275     suffixTemplateLabel.setFont(LABEL_FONT);
2276
2277     final String tooltip = JvSwingUtils.wrapTooltip(true,
2278             MessageManager.getString("label.append_to_filename_tooltip"));
2279     suffixTemplate.setToolTipText(tooltip);
2280     suffixTemplate.addActionListener(new ActionListener()
2281     {
2282       @Override
2283       public void actionPerformed(ActionEvent e)
2284       {
2285         updateBackupFilesExampleLabel();
2286         backupfilesCustomOptionsSetEnabled();
2287         backupfilesRevertButtonSetEnabled(true);
2288       }
2289
2290     });
2291     suffixTemplate.addKeyListener(new KeyListener()
2292     {
2293       @Override
2294       public void keyReleased(KeyEvent e)
2295       {
2296         updateBackupFilesExampleLabel();
2297         backupfilesCustomOptionsSetEnabled();
2298         backupfilesRevertButtonSetEnabled(true);
2299       }
2300
2301       @Override
2302       public void keyPressed(KeyEvent e)
2303       {
2304       }
2305
2306       // disable use of ':' or '/' or '\'
2307       @Override
2308       public void keyTyped(KeyEvent e)
2309       {
2310         char c = e.getKeyChar();
2311         if (c == ':' || c == '/' || c == '\\')
2312         {
2313           // don't process ':' or '/' or '\'
2314           e.consume();
2315         }
2316       }
2317
2318     });
2319
2320     // digits spinner
2321     suffixDigitsLabel
2322             .setText(MessageManager.getString("label.index_digits"));
2323     suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
2324     suffixDigitsLabel.setFont(LABEL_FONT);
2325     ChangeListener c = new ChangeListener()
2326     {
2327       @Override
2328       public void stateChanged(ChangeEvent e)
2329       {
2330         backupfilesRevertButtonSetEnabled(true);
2331         updateBackupFilesExampleLabel();
2332       }
2333
2334     };
2335     setIntegerSpinner(suffixDigitsSpinner, BackupFilesPresetEntry.DIGITSMIN,
2336             BackupFilesPresetEntry.DIGITSMAX, 3, c);
2337
2338     suffixReverse.setLabels(MessageManager.getString("label.reverse_roll"),
2339             MessageManager.getString("label.increment_index"));
2340     suffixReverse.addActionListener(new ActionListener()
2341     {
2342       @Override
2343       public void actionPerformed(ActionEvent e)
2344       {
2345         boolean okay = true;
2346         if (warnAboutSuffixReverseChange())
2347         {
2348           // Warning popup
2349           okay = confirmSuffixReverseChange();
2350         }
2351         if (okay)
2352         {
2353           backupfilesRevertButtonSetEnabled(true);
2354           updateBackupFilesExampleLabel();
2355         }
2356         else
2357         {
2358           boolean savedSuffixReverse = BackupFilesPresetEntry
2359                   .getSavedBackupEntry().reverse;
2360           suffixReverse.setSelected(savedSuffixReverse);
2361         }
2362       }
2363     });
2364
2365     GridBagConstraints sgbc = new GridBagConstraints();
2366
2367     // first row (template text box)
2368     sgbc.anchor = GridBagConstraints.WEST;
2369     sgbc.gridx = 0;
2370     sgbc.gridy = 0;
2371     sgbc.gridwidth = 1;
2372     sgbc.gridheight = 1;
2373     sgbc.weightx = 1.0;
2374     sgbc.weighty = 0.0;
2375     sgbc.fill = GridBagConstraints.NONE;
2376     suffixPanel.add(suffixTemplateLabel, sgbc);
2377
2378     sgbc.gridx = 1;
2379     sgbc.fill = GridBagConstraints.HORIZONTAL;
2380     suffixPanel.add(suffixTemplate, sgbc);
2381
2382     // second row (number of digits spinner)
2383     sgbc.gridy = 1;
2384
2385     sgbc.gridx = 0;
2386     sgbc.fill = GridBagConstraints.NONE;
2387     suffixPanel.add(suffixDigitsLabel, sgbc);
2388
2389     sgbc.gridx = 1;
2390     sgbc.fill = GridBagConstraints.HORIZONTAL;
2391     suffixPanel.add(suffixDigitsSpinner, sgbc);
2392
2393     // third row (forward order radio selection)
2394     sgbc.gridx = 0;
2395     sgbc.gridy = 2;
2396     sgbc.gridwidth = GridBagConstraints.REMAINDER;
2397     sgbc.fill = GridBagConstraints.HORIZONTAL;
2398     suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
2399
2400     // fourth row (reverse order radio selection)
2401     sgbc.gridy = 3;
2402     suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
2403     return suffixPanel;
2404   }
2405
2406   private boolean confirmSuffixReverseChange()
2407   {
2408     boolean ret = false;
2409     String warningMessage = MessageManager
2410             .getString("label.warning_confirm_change_reverse");
2411     int confirm = JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(),
2412             warningMessage,
2413             MessageManager.getString("label.change_increment_decrement"),
2414             JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
2415
2416     ret = (confirm == JvOptionPane.YES_OPTION);
2417     return ret;
2418   }
2419
2420   private JPanel initBackupsTabKeepFilesPanel()
2421   {
2422     keepfilesPanel.setBorder(
2423             new TitledBorder(MessageManager.getString("label.keep_files")));
2424     keepfilesPanel.setLayout(new GridBagLayout());
2425
2426     backupfilesKeepAll.setLabels(
2427             MessageManager.getString("label.keep_all_backup_files"),
2428             MessageManager.getString(
2429                     "label.keep_only_this_number_of_backup_files"));
2430     backupfilesKeepAll.addTrueActionListener(new ActionListener()
2431     {
2432       @Override
2433       public void actionPerformed(ActionEvent e)
2434       {
2435         backupfilesRevertButtonSetEnabled(true);
2436         updateBackupFilesExampleLabel();
2437       }
2438     });
2439     backupfilesKeepAll.addActionListener(new ActionListener()
2440     {
2441       @Override
2442       public void actionPerformed(ActionEvent e)
2443       {
2444         backupfilesRevertButtonSetEnabled(true);
2445         keepRollMaxOptionsEnabled();
2446         updateBackupFilesExampleLabel();
2447       }
2448     });
2449
2450     ChangeListener c = new ChangeListener()
2451     {
2452       @Override
2453       public void stateChanged(ChangeEvent e)
2454       {
2455         backupfilesRevertButtonSetEnabled(true);
2456         updateBackupFilesExampleLabel();
2457       }
2458
2459     };
2460     setIntegerSpinner(backupfilesRollMaxSpinner,
2461             BackupFilesPresetEntry.ROLLMAXMIN,
2462             BackupFilesPresetEntry.ROLLMAXMAX, 4, true, c);
2463
2464     backupfilesConfirmDelete.setLabels(
2465             MessageManager.getString("label.always_ask"),
2466             MessageManager.getString("label.auto_delete"));
2467     backupfilesConfirmDelete.addActionListener(new ActionListener()
2468     {
2469       @Override
2470       public void actionPerformed(ActionEvent e)
2471       {
2472         backupfilesRevertButtonSetEnabled(true);
2473       }
2474     });
2475     // update the enabled section
2476     keepRollMaxOptionsEnabled();
2477
2478     GridBagConstraints kgbc = new GridBagConstraints();
2479
2480     // first row (template text box)
2481     kgbc.anchor = GridBagConstraints.WEST;
2482     kgbc.gridx = 0;
2483     kgbc.gridy = 0;
2484     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2485     kgbc.gridheight = 1;
2486     kgbc.weightx = 1.0;
2487     kgbc.weighty = 0.0;
2488     kgbc.fill = GridBagConstraints.HORIZONTAL;
2489     keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
2490
2491     // second row
2492     kgbc.gridy = 1;
2493
2494     kgbc.gridx = 0;
2495     kgbc.gridwidth = GridBagConstraints.RELATIVE;
2496     keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
2497
2498     kgbc.gridx = 1;
2499     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2500     keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
2501
2502     // third row (indented)
2503     kgbc.gridy = 2;
2504     kgbc.insets = new Insets(0, 20, 0, 0);
2505
2506     kgbc.gridx = 0;
2507     kgbc.gridwidth = GridBagConstraints.REMAINDER;
2508     kgbc.fill = GridBagConstraints.HORIZONTAL;
2509     kgbc.weightx = 1.0;
2510
2511     JPanel jp = new JPanel();
2512     jp.setLayout(new FlowLayout());
2513     oldBackupFilesLabel
2514             .setText(MessageManager
2515                     .getString("label.autodelete_old_backup_files"));
2516     oldBackupFilesLabel.setFont(LABEL_FONT);
2517     oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
2518     jp.add(oldBackupFilesLabel);
2519     jp.add(backupfilesConfirmDelete.getTrueButton());
2520     jp.add(backupfilesConfirmDelete.getFalseButton());
2521     keepfilesPanel.add(jp, kgbc);
2522
2523     return keepfilesPanel;
2524   }
2525
2526   protected void updateBackupFilesExampleLabel()
2527   {
2528     int exampleindex = 12;
2529     String base = MessageManager.getString("label.filename") + ".fa";
2530     if (base == null || base.length() == 0)
2531     {
2532       base = "file_name.fa";
2533     }
2534
2535     boolean reverse = suffixReverse.isSelected();
2536     boolean keepAll = backupfilesKeepAll.isSelected();
2537     int rollMax = 4;
2538     String suffix = suffixTemplate.getText();
2539     int digits = 3;
2540
2541     backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
2542     if (suffix == null || suffix.length() == 0)
2543     {
2544       backupfilesExampleLabel
2545               .setText(MessageManager.getString("label.no_backup_files"));
2546       backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
2547       return;
2548     }
2549
2550     rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4);
2551     rollMax = rollMax < 1 ? 1 : rollMax;
2552
2553     if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
2554     {
2555       rollMax = 1;
2556     }
2557
2558     digits = getSpinnerInt(suffixDigitsSpinner, 3);
2559     digits = digits < 1 ? 1 : digits;
2560
2561     int lowersurround = 2;
2562     int uppersurround = 0;
2563     StringBuilder exampleSB = new StringBuilder();
2564     boolean firstLine = true;
2565     int lineNumber = 0;
2566     if (reverse)
2567     {
2568
2569       int min = 1;
2570       int max = keepAll ? exampleindex : rollMax;
2571       for (int index = min; index <= max; index++)
2572       {
2573         if (index == min + lowersurround && index < max - uppersurround - 1)
2574         {
2575           exampleSB.append("\n...");
2576           lineNumber++;
2577         }
2578         else if (index > min + lowersurround && index < max - uppersurround)
2579         {
2580           // nothing
2581         }
2582         else
2583         {
2584           if (firstLine)
2585           {
2586             firstLine = false;
2587           }
2588           else
2589           {
2590             exampleSB.append("\n");
2591             lineNumber++;
2592           }
2593           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
2594                   base, suffix, digits));
2595           if (min == max)
2596           {
2597             // no extra text needed
2598           }
2599           else if (index == min)
2600           {
2601             String newest = MessageManager.getString("label.braced_newest");
2602             if (newest != null && newest.length() > 0)
2603             {
2604               exampleSB.append(" " + newest);
2605             }
2606           }
2607           else if (index == max)
2608           {
2609             String oldest = MessageManager.getString("label.braced_oldest");
2610             if (oldest != null && oldest.length() > 0)
2611             {
2612               exampleSB.append(" " + oldest);
2613             }
2614           }
2615         }
2616       }
2617     }
2618     else
2619     {
2620
2621       int min = (keepAll || exampleindex - rollMax < 0) ? 1
2622               : exampleindex - rollMax + 1;
2623       int max = exampleindex;
2624
2625       for (int index = min; index <= max; index++)
2626       {
2627
2628         if (index == min + lowersurround && index < max - uppersurround - 1)
2629         {
2630           exampleSB.append("\n...");
2631           lineNumber++;
2632         }
2633         else if (index > min + lowersurround && index < max - uppersurround)
2634         {
2635           // nothing
2636         }
2637         else
2638         {
2639           if (firstLine)
2640           {
2641             firstLine = false;
2642           }
2643           else
2644           {
2645             exampleSB.append("\n");
2646             lineNumber++;
2647           }
2648           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
2649                   base, suffix, digits));
2650           if (min == max)
2651           {
2652             // no extra text needed
2653           }
2654           else if (index == min)
2655           {
2656             String oldest = MessageManager.getString("label.braced_oldest");
2657             if (oldest != null && oldest.length() > 0)
2658             {
2659               exampleSB.append(" " + oldest);
2660             }
2661           }
2662           else if (index == max)
2663           {
2664             String newest = MessageManager.getString("label.braced_newest");
2665             if (newest != null && newest.length() > 0)
2666             {
2667               exampleSB.append(" " + newest);
2668             }
2669           }
2670         }
2671       }
2672
2673     }
2674
2675     // add some extra empty lines to pad out the example files box. ugh, please tell
2676     // me how to do this better
2677     int remainingLines = lowersurround + uppersurround + 1 - lineNumber;
2678     if (remainingLines > 0)
2679     {
2680       for (int i = 0; i < remainingLines; i++)
2681       {
2682         exampleSB.append("\n ");
2683         lineNumber++;
2684       }
2685     }
2686
2687     backupfilesExampleLabel.setText(exampleSB.toString());
2688   }
2689
2690   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2691           boolean useExistingVal, ChangeListener c)
2692   {
2693     int i = def;
2694     if (useExistingVal)
2695     {
2696       try
2697       {
2698         i = ((Integer) s.getValue()).intValue();
2699       } catch (Exception e)
2700       {
2701         Cache.log.error(
2702                 "Exception casting the initial value of s.getValue()");
2703       }
2704     }
2705
2706     setIntegerSpinner(s, min, max, i, c);
2707   }
2708
2709   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
2710           ChangeListener c)
2711   {
2712     // integer spinner for number of digits
2713     if (def > max)
2714     {
2715       max = def;
2716     }
2717     if (def < min)
2718     {
2719       def = min;
2720     }
2721     SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
2722     s.setModel(sModel);
2723
2724     s.addChangeListener(c);
2725
2726   }
2727
2728   protected static int getSpinnerInt(JSpinner s, int def)
2729   {
2730     int i = def;
2731     try
2732     {
2733       s.commitEdit();
2734       i = (Integer) s.getValue();
2735     } catch (Exception e)
2736     {
2737       Cache.log.error("Failed casting (Integer) JSpinner s.getValue()");
2738     }
2739     return i;
2740   }
2741
2742   private void keepRollMaxOptionsEnabled()
2743   {
2744     boolean enabled = backupfilesKeepAll.isEnabled()
2745             && !backupfilesKeepAll.isSelected();
2746     oldBackupFilesLabel.setEnabled(enabled);
2747     backupfilesRollMaxSpinner.setEnabled(enabled);
2748     backupfilesConfirmDelete.setEnabled(enabled);
2749   }
2750
2751   private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
2752   {
2753     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2754             && customiseCheckbox.isSelected()
2755             && suffixTemplate.getText()
2756                     .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
2757     keepfilesPanel.setEnabled(enabled);
2758     backupfilesKeepAll.setEnabled(enabled);
2759     oldBackupFilesLabel.setEnabled(enabled);
2760     keepRollMaxOptionsEnabled();
2761   }
2762
2763   private void backupfilesSuffixTemplateDigitsSetEnabled()
2764   {
2765     boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
2766             .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
2767     suffixDigitsLabel.setEnabled(enabled);
2768     suffixDigitsSpinner.setEnabled(enabled);
2769     suffixReverse.setEnabled(enabled);
2770   }
2771
2772   private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
2773   {
2774     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2775             && customiseCheckbox.isSelected();
2776     suffixPanel.setEnabled(enabled);
2777     suffixTemplateLabel.setEnabled(enabled);
2778     suffixTemplate.setEnabled(enabled);
2779     backupfilesSuffixTemplateDigitsSetEnabled();
2780   }
2781
2782   private void backupfilesRevertButtonSetEnabled(boolean tryEnabled)
2783   {
2784     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
2785             && customiseCheckbox.isSelected() && backupfilesCustomChanged();
2786     revertButton.setEnabled(enabled);
2787   }
2788
2789   private boolean backupfilesCustomChanged()
2790   {
2791     BackupFilesPresetEntry custom = BackupFilesPresetEntry.backupfilesPresetEntriesValues
2792             .get(BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
2793     BackupFilesPresetEntry current = getBackupfilesCurrentEntry();
2794     return !custom.equals(current);
2795   }
2796
2797   protected BackupFilesPresetEntry getBackupfilesCurrentEntry()
2798   {
2799     String suffix = suffixTemplate.getText();
2800     int digits = getSpinnerInt(suffixDigitsSpinner, 3);
2801     boolean reverse = suffixReverse.isSelected();
2802     boolean keepAll = backupfilesKeepAll.isSelected();
2803     int rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 3);
2804     boolean confirmDelete = backupfilesConfirmDelete.isSelected();
2805
2806     BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits,
2807             reverse, keepAll, rollMax, confirmDelete);
2808
2809     return bfpe;
2810   }
2811
2812   protected void backupfilesCustomOptionsSetEnabled()
2813   {
2814     boolean enabled = customiseCheckbox.isSelected();
2815
2816     backupfilesRevertButtonSetEnabled(enabled);
2817     backupfilesSuffixTemplateSetEnabled(enabled);
2818     backupfilesKeepAllSetEnabled(enabled);
2819   }
2820
2821   private void backupfilesSummarySetEnabled()
2822   {
2823     boolean enabled = enableBackupFiles.isSelected();
2824     backupfilesExampleLabel.setEnabled(enabled);
2825     exampleFilesPanel.setEnabled(enabled);
2826   }
2827
2828   private void backupfilesPresetsSetEnabled()
2829   {
2830     boolean enabled = enableBackupFiles.isSelected();
2831     presetsPanel.setEnabled(enabled);
2832     presetsComboLabel.setEnabled(enabled);
2833     backupfilesPresetsCombo.setEnabled(enabled);
2834     customiseCheckbox.setEnabled(enabled);
2835     revertButton.setEnabled(enabled);
2836   }
2837
2838   protected void backupsOptionsSetEnabled()
2839   {
2840     backupfilesPresetsSetEnabled();
2841     backupfilesSummarySetEnabled();
2842     backupfilesCustomOptionsSetEnabled();
2843   }
2844
2845   protected void backupsSetOptions(String suffix, int digits,
2846           boolean reverse, boolean keepAll, int rollMax,
2847           boolean confirmDelete)
2848   {
2849     suffixTemplate.setText(suffix);
2850     suffixDigitsSpinner.setValue(digits);
2851     suffixReverse.setSelected(reverse);
2852     backupfilesKeepAll.setSelected(keepAll);
2853     backupfilesRollMaxSpinner.setValue(rollMax);
2854     backupfilesConfirmDelete.setSelected(confirmDelete);
2855   }
2856
2857   protected void backupsSetOptions(BackupFilesPresetEntry p)
2858   {
2859     backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax,
2860             p.confirmDelete);
2861   }
2862
2863   protected void autoIdWidth_actionPerformed()
2864   {
2865     // TODO Auto-generated method stub
2866
2867   }
2868
2869   protected void userIdWidth_actionPerformed()
2870   {
2871     // TODO Auto-generated method stub
2872
2873   }
2874
2875   protected void maxColour_actionPerformed(JPanel panel)
2876   {
2877   }
2878
2879   protected void minColour_actionPerformed(JPanel panel)
2880   {
2881   }
2882
2883   protected void gapColour_actionPerformed(JPanel panel)
2884   {
2885   }
2886
2887   protected void hiddenColour_actionPerformed(JPanel panel)
2888   {
2889   }
2890
2891   protected void showunconserved_actionPerformed(ActionEvent e)
2892   {
2893     // TODO Auto-generated method stub
2894
2895   }
2896
2897   protected void useLegacyGaps_actionPerformed(ActionEvent e)
2898   {
2899   }
2900
2901   protected void resetOvDefaults_actionPerformed(ActionEvent e)
2902   {
2903   }
2904
2905   /**
2906    * DOCUMENT ME!
2907    * 
2908    * @param e
2909    *          DOCUMENT ME!
2910    */
2911   public void ok_actionPerformed(ActionEvent e)
2912   {
2913   }
2914
2915   /**
2916    * DOCUMENT ME!
2917    * 
2918    * @param e
2919    *          DOCUMENT ME!
2920    */
2921   public void cancel_actionPerformed(ActionEvent e)
2922   {
2923   }
2924
2925   /**
2926    * DOCUMENT ME!
2927    * 
2928    * @param e
2929    *          DOCUMENT ME!
2930    */
2931   public void annotations_actionPerformed(ActionEvent e)
2932   {
2933   }
2934
2935   /**
2936    * DOCUMENT ME!
2937    */
2938   public void startupFileTextfield_mouseClicked()
2939   {
2940   }
2941
2942   public void newLink_actionPerformed(ActionEvent e)
2943   {
2944
2945   }
2946
2947   public void editLink_actionPerformed(ActionEvent e)
2948   {
2949
2950   }
2951
2952   public void deleteLink_actionPerformed(ActionEvent e)
2953   {
2954
2955   }
2956
2957   public void defaultBrowser_mouseClicked(MouseEvent e)
2958   {
2959
2960   }
2961
2962   public void linkURLList_keyTyped(KeyEvent e)
2963   {
2964
2965   }
2966
2967   public void useProxy_actionPerformed()
2968   {
2969     boolean enabled = useProxy.isSelected();
2970     portLabel.setEnabled(enabled);
2971     serverLabel.setEnabled(enabled);
2972     proxyServerTB.setEnabled(enabled);
2973     proxyPortTB.setEnabled(enabled);
2974   }
2975
2976   /**
2977    * Customer renderer for JTable: supports column of radio buttons
2978    */
2979   public class RadioButtonRenderer extends JRadioButton
2980           implements TableCellRenderer
2981   {
2982     public RadioButtonRenderer()
2983     {
2984       setHorizontalAlignment(CENTER);
2985       setToolTipText(MessageManager.getString("label.urltooltip"));
2986     }
2987
2988     @Override
2989     public Component getTableCellRendererComponent(JTable table,
2990             Object value, boolean isSelected, boolean hasFocus, int row,
2991             int column)
2992     {
2993       setSelected((boolean) value);
2994
2995       // set colours to match rest of table
2996       if (isSelected)
2997       {
2998         setBackground(table.getSelectionBackground());
2999         setForeground(table.getSelectionForeground());
3000       }
3001       else
3002       {
3003         setBackground(table.getBackground());
3004         setForeground(table.getForeground());
3005       }
3006       return this;
3007     }
3008   }
3009
3010   /**
3011    * Customer cell editor for JTable: supports column of radio buttons in
3012    * conjunction with renderer
3013    */
3014   public class RadioButtonEditor extends AbstractCellEditor
3015           implements TableCellEditor
3016   {
3017     private JRadioButton button = new JRadioButton();
3018
3019     public RadioButtonEditor()
3020     {
3021       button.setHorizontalAlignment(SwingConstants.CENTER);
3022       this.button.addActionListener(new ActionListener()
3023       {
3024         @Override
3025         public void actionPerformed(ActionEvent e)
3026         {
3027           fireEditingStopped();
3028         }
3029       });
3030     }
3031
3032     @Override
3033     public Component getTableCellEditorComponent(JTable table, Object value,
3034             boolean isSelected, int row, int column)
3035     {
3036       button.setSelected((boolean) value);
3037       return button;
3038     }
3039
3040     @Override
3041     public Object getCellEditorValue()
3042     {
3043       return button.isSelected();
3044     }
3045
3046   }
3047
3048   protected void validateHmmerPath()
3049   {
3050   }
3051
3052   protected void validateCygwinPath()
3053   {
3054   }
3055
3056   /**
3057    * A helper method to add a panel containing a label and a component to a
3058    * panel
3059    * 
3060    * @param panel
3061    * @param tooltip
3062    * @param label
3063    * @param valBox
3064    */
3065   protected static void addtoLayout(JPanel panel, String tooltip,
3066           JComponent label, JComponent valBox)
3067   {
3068     JPanel laypanel = new JPanel(new GridLayout(1, 2));
3069     JPanel labPanel = new JPanel(new BorderLayout());
3070     JPanel valPanel = new JPanel();
3071     labPanel.setBounds(new Rectangle(7, 7, 158, 23));
3072     valPanel.setBounds(new Rectangle(172, 7, 270, 23));
3073     labPanel.add(label, BorderLayout.WEST);
3074     valPanel.add(valBox);
3075     laypanel.add(labPanel);
3076     laypanel.add(valPanel);
3077     valPanel.setToolTipText(tooltip);
3078     labPanel.setToolTipText(tooltip);
3079     valBox.setToolTipText(tooltip);
3080     panel.add(laypanel);
3081     panel.validate();
3082   }
3083 }
3084