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