dfe08edd68b37fe19781da67e0602b7251d7326b
[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.bin.Console;
25 import jalview.bin.MemorySetting;
26 import jalview.fts.core.FTSDataColumnPreferences;
27 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
28 import jalview.fts.service.pdb.PDBFTSRestClient;
29 import jalview.gui.Desktop;
30 import jalview.gui.JalviewBooleanRadioButtons;
31 import jalview.gui.JvOptionPane;
32 import jalview.gui.JvSwingUtils;
33 import jalview.gui.StructureViewer.ViewerType;
34 import jalview.io.BackupFilenameParts;
35 import jalview.io.BackupFiles;
36 import jalview.io.BackupFilesPresetEntry;
37 import jalview.io.IntKeyStringValueEntry;
38 import jalview.util.MessageManager;
39 import jalview.util.Platform;
40 import jalview.util.StringUtils;
41
42 import java.awt.BorderLayout;
43 import java.awt.Color;
44 import java.awt.Component;
45 import java.awt.Dimension;
46 import java.awt.FlowLayout;
47 import java.awt.Font;
48 import java.awt.GridBagConstraints;
49 import java.awt.GridBagLayout;
50 import java.awt.GridLayout;
51 import java.awt.Insets;
52 import java.awt.Rectangle;
53 import java.awt.event.ActionEvent;
54 import java.awt.event.ActionListener;
55 import java.awt.event.FocusEvent;
56 import java.awt.event.KeyEvent;
57 import java.awt.event.KeyListener;
58 import java.awt.event.MouseAdapter;
59 import java.awt.event.MouseEvent;
60 import java.util.Arrays;
61 import java.util.List;
62
63 import javax.swing.AbstractButton;
64 import javax.swing.AbstractCellEditor;
65 import javax.swing.BorderFactory;
66 import javax.swing.BoxLayout;
67 import javax.swing.ButtonGroup;
68 import javax.swing.DefaultListCellRenderer;
69 import javax.swing.JButton;
70 import javax.swing.JCheckBox;
71 import javax.swing.JComboBox;
72 import javax.swing.JComponent;
73 import javax.swing.JFileChooser;
74 import javax.swing.JLabel;
75 import javax.swing.JPanel;
76 import javax.swing.JPasswordField;
77 import javax.swing.JRadioButton;
78 import javax.swing.JScrollPane;
79 import javax.swing.JSlider;
80 import javax.swing.JSpinner;
81 import javax.swing.JTabbedPane;
82 import javax.swing.JTable;
83 import javax.swing.JTextArea;
84 import javax.swing.JTextField;
85 import javax.swing.ListSelectionModel;
86 import javax.swing.SpinnerModel;
87 import javax.swing.SpinnerNumberModel;
88 import javax.swing.SwingConstants;
89 import javax.swing.border.Border;
90 import javax.swing.border.EmptyBorder;
91 import javax.swing.border.EtchedBorder;
92 import javax.swing.border.TitledBorder;
93 import javax.swing.event.ChangeEvent;
94 import javax.swing.event.ChangeListener;
95 import javax.swing.event.DocumentEvent;
96 import javax.swing.event.DocumentListener;
97 import javax.swing.table.TableCellEditor;
98 import javax.swing.table.TableCellRenderer;
99
100 import net.miginfocom.swing.MigLayout;
101
102 /**
103  * Base class for the Preferences panel.
104  * 
105  * @author $author$
106  * @version $Revision$
107  */
108 public class GPreferences extends JPanel
109 {
110   private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
111
112   private static final Font LABEL_FONT_ITALIC = JvSwingUtils
113           .getLabelFont(false, true);
114
115   private static final Font LABEL_FONT_BOLD = JvSwingUtils
116           .getLabelFont(true, false);
117
118   /*
119    * Visual tab components
120    */
121   protected JCheckBox fullScreen = new JCheckBox();
122
123   protected JCheckBox openoverv = new JCheckBox();
124
125   protected JCheckBox seqLimit = new JCheckBox();
126
127   protected JCheckBox rightAlign = new JCheckBox();
128
129   protected JComboBox<String> fontSizeCB = new JComboBox<>();
130
131   protected JComboBox<String> fontStyleCB = new JComboBox<>();
132
133   protected JComboBox<String> fontNameCB = new JComboBox<>();
134
135   protected JCheckBox showOccupancy = new JCheckBox();
136
137   protected JCheckBox showUnconserved = new JCheckBox();
138
139   protected JCheckBox idItalics = new JCheckBox();
140
141   protected JCheckBox smoothFont = new JCheckBox();
142
143   protected JCheckBox scaleProteinToCdna = new JCheckBox();
144
145   protected JComboBox<String> gapSymbolCB = new JComboBox<>();
146
147   protected JCheckBox wrap = new JCheckBox();
148
149   protected JComboBox<String> sortby = new JComboBox<>();
150
151   protected JComboBox<String> sortAnnBy = new JComboBox<>();
152
153   protected JComboBox<String> sortAutocalc = new JComboBox<>();
154
155   protected JCheckBox startupCheckbox = new JCheckBox();
156
157   protected JTextField startupFileTextfield = new JTextField();
158
159   // below are in the 'second column'
160   protected JCheckBox annotations = new JCheckBox();
161
162   protected JCheckBox quality = new JCheckBox();
163
164   protected JCheckBox conservation = new JCheckBox();
165
166   protected JCheckBox identity = new JCheckBox();
167
168   protected JCheckBox showGroupConsensus = new JCheckBox();
169
170   protected JCheckBox showGroupConservation = new JCheckBox();
171
172   protected JCheckBox showConsensHistogram = new JCheckBox();
173
174   protected JCheckBox showConsensLogo = new JCheckBox();
175
176   protected JCheckBox showInformationHistogram = new JCheckBox();
177
178   protected JCheckBox showHMMLogo = new JCheckBox();
179   protected JCheckBox showDbRefTooltip = new JCheckBox();
180
181   protected JCheckBox showNpTooltip = new JCheckBox();
182
183   /*
184    * Structure tab and components
185    */
186   protected JPanel structureTab;
187
188   protected JCheckBox structFromPdb = new JCheckBox();
189
190   protected JCheckBox addSecondaryStructure = new JCheckBox();
191
192   protected JCheckBox addTempFactor = new JCheckBox();
193
194   protected JComboBox<String> structViewer = new JComboBox<>();
195
196   protected JLabel structureViewerPathLabel;
197
198   protected JTextField structureViewerPath = new JTextField();
199
200   protected ButtonGroup mappingMethod = new ButtonGroup();
201
202   protected JRadioButton siftsMapping = new JRadioButton();
203
204   protected JRadioButton nwMapping = new JRadioButton();
205
206   /*
207    * Colours tab components
208    */
209   protected JPanel minColour = new JPanel();
210
211   protected JPanel maxColour = new JPanel();
212
213   protected JComboBox<String> protColour = new JComboBox<>();
214
215   protected JComboBox<String> nucColour = new JComboBox<>();
216
217   /*
218    * Overview tab components
219    */
220   protected JPanel gapColour = new JPanel();
221
222   protected JPanel hiddenColour = new JPanel();
223
224   protected JCheckBox useLegacyGap;
225
226   protected JCheckBox showHiddenAtStart;
227
228   protected JLabel gapLabel;
229
230   /*
231    * Connections tab components
232    */
233   protected JPanel connectTab;
234
235   protected JTable linkUrlTable = new JTable();
236
237   protected JButton editLink = new JButton();
238
239   protected JButton deleteLink = new JButton();
240
241   protected JTextField filterTB = new JTextField();
242
243   protected JButton doReset = new JButton();
244
245   protected JButton userOnly = new JButton();
246
247   protected JLabel httpLabel = new JLabel();
248
249   protected JLabel httpsLabel = new JLabel();
250
251   protected JLabel portLabel = new JLabel();
252
253   protected JLabel serverLabel = new JLabel();
254
255   protected JLabel portLabel2 = new JLabel();
256
257   protected JLabel serverLabel2 = new JLabel();
258
259   protected JLabel proxyAuthUsernameLabel = new JLabel();
260
261   protected JLabel proxyAuthPasswordLabel = new JLabel();
262
263   protected JLabel passwordNotStoredLabel = new JLabel();
264
265   protected JTextField proxyServerHttpTB = new JTextField();
266
267   protected JTextField proxyPortHttpTB = new JTextField();
268
269   protected JTextField proxyServerHttpsTB = new JTextField();
270
271   protected JTextField proxyPortHttpsTB = new JTextField();
272
273   protected JCheckBox proxyAuth = new JCheckBox();
274
275   protected JTextField proxyAuthUsernameTB = new JTextField();
276
277   protected JPasswordField proxyAuthPasswordPB = new JPasswordField();
278
279   protected JTextField defaultBrowser = new JTextField();
280
281   protected ButtonGroup proxyType = new ButtonGroup();
282
283   protected JRadioButton noProxy = new JRadioButton();
284
285   protected JRadioButton systemProxy = new JRadioButton();
286
287   protected JRadioButton customProxy = new JRadioButton();
288
289   protected JButton applyProxyButton = new JButton();
290
291   protected JCheckBox usagestats = new JCheckBox();
292
293   protected JCheckBox questionnaire = new JCheckBox();
294
295   protected JCheckBox versioncheck = new JCheckBox();
296
297   /*
298    * Output tab components
299    */
300   protected JComboBox<Object> epsRendering = new JComboBox<>();
301
302   protected JComboBox<Object> htmlRendering = new JComboBox<>();
303
304   protected JComboBox<Object> svgRendering = new JComboBox<>();
305
306   protected JLabel userIdWidthlabel = new JLabel();
307
308   protected JCheckBox autoIdWidth = new JCheckBox();
309
310   protected JTextField userIdWidth = new JTextField();
311
312   protected JCheckBox blcjv = new JCheckBox();
313
314   protected JCheckBox pileupjv = new JCheckBox();
315
316   protected JCheckBox clustaljv = new JCheckBox();
317
318   protected JCheckBox msfjv = new JCheckBox();
319
320   protected JCheckBox fastajv = new JCheckBox();
321
322   protected JCheckBox pfamjv = new JCheckBox();
323
324   protected JCheckBox pirjv = new JCheckBox();
325
326   protected JCheckBox modellerOutput = new JCheckBox();
327
328   protected JCheckBox embbedBioJSON = new JCheckBox();
329
330   /*
331    * Editing tab components
332    */
333   protected JCheckBox autoCalculateConsCheck = new JCheckBox();
334
335   protected JCheckBox padGaps = new JCheckBox();
336
337   protected JCheckBox sortByTree = new JCheckBox();
338
339   /*
340    * hmmer tab and components
341    */
342   protected JPanel hmmerTab;
343
344   protected JCheckBox hmmrTrimTermini;
345
346   protected AbstractButton hmmerBackgroundUniprot;
347
348   protected AbstractButton hmmerBackgroundAlignment;
349
350   protected JTextField hmmerSequenceCount;
351
352   protected JTextField hmmerPath;
353
354   protected JTextField cygwinPath;
355
356   /*
357    * Web Services tab
358    */
359   protected JPanel wsTab = new JPanel();
360
361   protected JPanel slivkaTab = new JPanel();
362   /*
363    * Backups tab components
364    * a lot of these are member variables instead of local variables only so that they
365    * can be enabled/disabled easily in one go
366    */
367
368   protected JCheckBox enableBackupFiles = new JCheckBox();
369
370   protected JPanel presetsPanel = new JPanel();
371
372   protected JLabel presetsComboLabel = new JLabel();
373
374   protected JCheckBox customiseCheckbox = new JCheckBox();
375
376   protected JButton revertButton = new JButton();
377
378   protected JComboBox<Object> backupfilesPresetsCombo = new JComboBox<>();
379
380   private int backupfilesPresetsComboLastSelected = 0;
381
382   protected JPanel suffixPanel = new JPanel();
383
384   protected JPanel keepfilesPanel = new JPanel();
385
386   protected JPanel exampleFilesPanel = new JPanel();
387
388   protected JTextField suffixTemplate = new JTextField(null, 8);
389
390   protected JLabel suffixTemplateLabel = new JLabel();
391
392   protected JLabel suffixDigitsLabel = new JLabel();
393
394   protected JSpinner suffixDigitsSpinner = new JSpinner();
395
396   protected JalviewBooleanRadioButtons suffixReverse = new JalviewBooleanRadioButtons();
397
398   protected JalviewBooleanRadioButtons backupfilesKeepAll = new JalviewBooleanRadioButtons();
399
400   public JSpinner backupfilesRollMaxSpinner = new JSpinner();
401
402   protected JLabel oldBackupFilesLabel = new JLabel();
403
404   protected JalviewBooleanRadioButtons backupfilesConfirmDelete = new JalviewBooleanRadioButtons();
405
406   protected JTextArea backupfilesExampleLabel = new JTextArea();
407
408   private final JTabbedPane tabbedPane = new JTabbedPane();
409
410   private JLabel messageLabel = new JLabel("", JLabel.CENTER);
411
412   /*
413    * Startup tab components
414    */
415
416   protected JCheckBox customiseMemorySetting = new JCheckBox();
417
418   protected JLabel exampleMemoryLabel = new JLabel();
419
420   protected JTextArea exampleMemoryMessageTextArea = new JTextArea();
421
422   protected JLabel maxMemoryLabel = new JLabel();
423
424   protected JLabel jvmMemoryPercentLabel = new JLabel();
425
426   protected JSlider jvmMemoryPercentSlider = new JSlider();
427
428   protected JLabel jvmMemoryPercentDisplay = new JLabel();
429
430   protected JLabel jvmMemoryMaxLabel = new JLabel();
431
432   protected JTextField jvmMemoryMaxTextField = new JTextField(null, 8);
433
434   protected JComboBox<Object> lafCombo = new JComboBox<>();
435   /**
436    * Creates a new GPreferences object.
437    */
438   public GPreferences()
439   {
440     try
441     {
442       jbInit();
443     } catch (Exception ex)
444     {
445       ex.printStackTrace();
446     }
447   }
448
449   /**
450    * Construct the panel and its tabbed sub-panels.
451    * 
452    * @throws Exception
453    */
454   private void jbInit() throws Exception
455   {
456     // final JTabbedPane tabbedPane = new JTabbedPane();
457     this.setLayout(new BorderLayout());
458
459     // message label at top
460     this.add(messageLabel, BorderLayout.NORTH);
461
462     JPanel okCancelPanel = initOkCancelPanel();
463     this.add(tabbedPane, BorderLayout.CENTER);
464     this.add(okCancelPanel, BorderLayout.SOUTH);
465
466     tabbedPane.add(initVisualTab(),
467             MessageManager.getString("label.visual"));
468
469     tabbedPane.add(initColoursTab(),
470             MessageManager.getString("label.colours"));
471
472     tabbedPane.add(initOverviewTab(),
473             MessageManager.getString("label.overview"));
474
475     tabbedPane.add(initStructureTab(),
476             MessageManager.getString("label.structure"));
477
478     tabbedPane.add(initConnectionsTab(),
479             MessageManager.getString("label.connections"));
480
481     if (!Platform.isJS())
482     {
483       tabbedPane.add(initBackupsTab(),
484               MessageManager.getString("label.backups"));
485     }
486
487     tabbedPane.add(initLinksTab(),
488             MessageManager.getString("label.urllinks"));
489
490     tabbedPane.add(initOutputTab(),
491             MessageManager.getString("label.output"));
492
493     tabbedPane.add(initEditingTab(),
494             MessageManager.getString("label.editing"));
495
496     /*
497      * See WsPreferences for the real work of configuring this tab.
498      */
499     if (!Platform.isJS())
500     {
501       tabbedPane.add(initHMMERTab(), MessageManager.getString("label.hmmer"));
502       tabbedPane.add(initStartupTab(),
503               MessageManager.getString("label.startup"));
504       wsTab.setLayout(new BorderLayout());
505       tabbedPane.add(wsTab, MessageManager.getString("label.web_services"));
506     }
507     
508     slivkaTab.setLayout(new BorderLayout());
509     tabbedPane.add(slivkaTab, "Slivka Services");
510
511     /*
512      * Handler to validate a tab before leaving it - currently only for
513      * Structure.
514      * Adding a clearMessage() so messages are cleared when changing tabs.
515      */
516     tabbedPane.addChangeListener(new ChangeListener()
517     {
518       private Component lastTab;
519
520       @Override
521       public void stateChanged(ChangeEvent e)
522       {
523         if (lastTab == structureTab
524                 && tabbedPane.getSelectedComponent() != structureTab)
525         {
526           if (!validateStructure())
527           {
528             tabbedPane.setSelectedComponent(structureTab);
529             return;
530           }
531         }
532         lastTab = tabbedPane.getSelectedComponent();
533
534         clearMessage();
535       }
536
537     });
538   }
539
540   public void setMessage(String message)
541   {
542     if (message != null)
543     {
544       messageLabel.setText(message);
545       messageLabel.setFont(LABEL_FONT_BOLD);
546       messageLabel.setForeground(Color.RED.darker());
547       messageLabel.revalidate();
548       messageLabel.repaint();
549     }
550     // note message not cleared if message is null. call clearMessage()
551     // directly.
552     this.revalidate();
553     this.repaint();
554   }
555
556   public void clearMessage()
557   {
558     // only repaint if message exists
559     if (messageLabel.getText() != null
560             && messageLabel.getText().length() > 0)
561     {
562       messageLabel.setText("");
563       messageLabel.revalidate();
564       messageLabel.repaint();
565       this.revalidate();
566       this.repaint();
567     }
568   }
569
570   public static enum TabRef
571   {
572     CONNECTIONS_TAB, STRUCTURE_TAB
573   };
574
575   public void selectTab(TabRef selectTab)
576   {
577     // select a given tab - currently only for Connections
578     switch (selectTab)
579     {
580     case CONNECTIONS_TAB:
581       tabbedPane.setSelectedComponent(connectTab);
582       break;
583     case STRUCTURE_TAB:
584       tabbedPane.setSelectedComponent(structureTab);
585       break;
586     default:
587     }
588   }
589
590   /**
591    * Initialises the Editing tabbed panel.
592    * 
593    * @return
594    */
595   private JPanel initEditingTab()
596   {
597     JPanel editingTab = new JPanel();
598     editingTab.setLayout(null);
599     autoCalculateConsCheck.setFont(LABEL_FONT);
600     autoCalculateConsCheck.setText(
601             MessageManager.getString("label.autocalculate_consensus"));
602     autoCalculateConsCheck.setBounds(new Rectangle(21, 52, 209, 23));
603     padGaps.setFont(LABEL_FONT);
604     padGaps.setText(
605             MessageManager.getString("label.pad_gaps_when_editing"));
606     padGaps.setBounds(new Rectangle(22, 94, 168, 23));
607     sortByTree.setFont(LABEL_FONT);
608     sortByTree
609             .setText(MessageManager.getString("label.sort_with_new_tree"));
610     sortByTree.setToolTipText(MessageManager.getString(
611             "label.any_trees_calculated_or_loaded_alignment_automatically_sort"));
612     sortByTree.setBounds(new Rectangle(22, 136, 168, 23));
613     editingTab.add(autoCalculateConsCheck);
614     editingTab.add(padGaps);
615     editingTab.add(sortByTree);
616     return editingTab;
617   }
618
619   /**
620    * Initialises the hmmer tabbed panel
621    * 
622    * @return
623    */
624   private JPanel initHMMERTab()
625   {
626     hmmerTab = new JPanel();
627     hmmerTab.setLayout(new BoxLayout(hmmerTab, BoxLayout.Y_AXIS));
628     hmmerTab.setLayout(new MigLayout("flowy"));
629
630     /*
631      * path to hmmer binaries folder
632      */
633     JPanel installationPanel = new JPanel(new MigLayout("flowy"));
634     // new FlowLayout(FlowLayout.LEFT));
635     JvSwingUtils.createTitledBorder(installationPanel,
636             MessageManager.getString("label.installation"), true);
637     hmmerTab.add(installationPanel);
638     JLabel hmmerLocation = new JLabel(
639             MessageManager.getString("label.hmmer_location"));
640     hmmerLocation.setFont(LABEL_FONT);
641     final int pathFieldLength = 40;
642     hmmerPath = new JTextField(pathFieldLength);
643     hmmerPath.addMouseListener(new MouseAdapter()
644     {
645       @Override
646       public void mouseClicked(MouseEvent e)
647       {
648         if (e.getClickCount() == 2)
649         {
650           String chosen = openFileChooser(true);
651           if (chosen != null)
652           {
653             hmmerPath.setText(chosen);
654             validateHmmerPath();
655           }
656         }
657       }
658     });
659     installationPanel.add(hmmerLocation);
660     installationPanel.add(hmmerPath);
661
662     /*
663      * path to Cygwin binaries folder (for Windows)
664      */
665     if (Platform.isWindowsAndNotJS())
666     {
667       JLabel cygwinLocation = new JLabel(
668               MessageManager.getString("label.cygwin_location"));
669       cygwinLocation.setFont(LABEL_FONT);
670       cygwinPath = new JTextField(pathFieldLength);
671       cygwinPath.addMouseListener(new MouseAdapter()
672       {
673         @Override
674         public void mouseClicked(MouseEvent e)
675         {
676           if (e.getClickCount() == 2)
677           {
678             String chosen = openFileChooser(true);
679             if (chosen != null)
680             {
681               cygwinPath.setText(chosen);
682               validateCygwinPath();
683             }
684           }
685         }
686       });
687       installationPanel.add(cygwinLocation);
688       installationPanel.add(cygwinPath);
689     }
690
691     /*
692      * preferences for hmmalign
693      */
694     JPanel alignOptionsPanel = new JPanel(new MigLayout());
695     // new FlowLayout(FlowLayout.LEFT));
696     JvSwingUtils.createTitledBorder(alignOptionsPanel,
697             MessageManager.getString("label.hmmalign_options"), true);
698     hmmerTab.add(alignOptionsPanel);
699     hmmrTrimTermini = new JCheckBox();
700     hmmrTrimTermini.setFont(LABEL_FONT);
701     hmmrTrimTermini.setText(MessageManager.getString("label.trim_termini"));
702     alignOptionsPanel.add(hmmrTrimTermini);
703
704     /*
705      * preferences for hmmsearch
706      */
707     JPanel searchOptions = new JPanel(new MigLayout());
708     // FlowLayout(FlowLayout.LEFT));
709     JvSwingUtils.createTitledBorder(searchOptions,
710             MessageManager.getString("label.hmmsearch_options"), true);
711     hmmerTab.add(searchOptions);
712     JLabel sequencesToKeep = new JLabel(
713             MessageManager.getString("label.no_of_sequences"));
714     sequencesToKeep.setFont(LABEL_FONT);
715     searchOptions.add(sequencesToKeep);
716     hmmerSequenceCount = new JTextField(5);
717     searchOptions.add(hmmerSequenceCount);
718
719     /*
720      * preferences for Information Content annotation
721      */
722     // JPanel dummy = new JPanel(new FlowLayout(FlowLayout.LEFT));
723     JPanel annotationOptions = new JPanel(new MigLayout("left"));
724     JvSwingUtils.createTitledBorder(annotationOptions,
725             MessageManager.getString("label.information_annotation"), true);
726     // dummy.add(annotationOptions);
727     hmmerTab.add(annotationOptions);
728     ButtonGroup backgroundOptions = new ButtonGroup();
729     hmmerBackgroundUniprot = new JRadioButton(
730             MessageManager.getString("label.freq_uniprot"));
731     hmmerBackgroundUniprot.setFont(LABEL_FONT);
732     hmmerBackgroundAlignment = new JRadioButton(
733             MessageManager.getString("label.freq_alignment"));
734     hmmerBackgroundAlignment.setFont(LABEL_FONT);
735     backgroundOptions.add(hmmerBackgroundUniprot);
736     backgroundOptions.add(hmmerBackgroundAlignment);
737     backgroundOptions.setSelected(hmmerBackgroundUniprot.getModel(), true);
738     // disable buttons for now as annotation only uses Uniprot background
739     hmmerBackgroundAlignment.setEnabled(false);
740     hmmerBackgroundUniprot.setEnabled(false);
741     annotationOptions.add(hmmerBackgroundUniprot, "wrap");
742     annotationOptions.add(hmmerBackgroundAlignment);
743
744     return hmmerTab;
745   }
746
747   /**
748    * Initialises the Output tabbed panel.
749    * 
750    * @return
751    */
752   private JPanel initOutputTab()
753   {
754     JPanel outputTab = new JPanel();
755     outputTab.setLayout(null);
756
757     JLabel epsLabel = new JLabel(
758             MessageManager.formatMessage("label.rendering_style", "EPS"));
759     epsLabel.setFont(LABEL_FONT);
760     epsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
761     epsLabel.setBounds(new Rectangle(9, 31, 160, 24));
762     epsRendering.setFont(LABEL_FONT);
763     epsRendering.setBounds(new Rectangle(174, 34, 187, 21));
764     JLabel htmlLabel = new JLabel(
765             MessageManager.formatMessage("label.rendering_style", "HTML"));
766     htmlLabel.setFont(LABEL_FONT);
767     htmlLabel.setHorizontalAlignment(SwingConstants.RIGHT);
768     htmlLabel.setBounds(new Rectangle(9, 55, 160, 24));
769     htmlRendering.setFont(LABEL_FONT);
770     htmlRendering.setBounds(new Rectangle(174, 58, 187, 21));
771     JLabel svgLabel = new JLabel(
772             MessageManager.formatMessage("label.rendering_style", "SVG"));
773     svgLabel.setFont(LABEL_FONT);
774     svgLabel.setHorizontalAlignment(SwingConstants.RIGHT);
775     svgLabel.setBounds(new Rectangle(9, 79, 160, 24));
776     svgRendering.setFont(LABEL_FONT);
777     svgRendering.setBounds(new Rectangle(174, 82, 187, 21));
778
779     JLabel jLabel1 = new JLabel();
780     jLabel1.setFont(LABEL_FONT);
781     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
782     jLabel1.setText(MessageManager.getString("label.append_start_end"));
783     jLabel1.setFont(LABEL_FONT);
784
785     fastajv.setFont(LABEL_FONT);
786     fastajv.setHorizontalAlignment(SwingConstants.LEFT);
787     clustaljv.setText(MessageManager.getString("label.clustal") + "     ");
788     blcjv.setText(MessageManager.getString("label.blc") + "     ");
789     fastajv.setText(MessageManager.getString("label.fasta") + "     ");
790     msfjv.setText(MessageManager.getString("label.msf") + "     ");
791     pfamjv.setText(MessageManager.getString("label.pfam") + "     ");
792     pileupjv.setText(MessageManager.getString("label.pileup") + "     ");
793     msfjv.setFont(LABEL_FONT);
794     msfjv.setHorizontalAlignment(SwingConstants.LEFT);
795     pirjv.setText(MessageManager.getString("label.pir") + "     ");
796     JPanel jPanel11 = new JPanel();
797     jPanel11.setFont(LABEL_FONT);
798     TitledBorder titledBorder2 = new TitledBorder(
799             MessageManager.getString("label.file_output"));
800     jPanel11.setBorder(titledBorder2);
801     jPanel11.setBounds(new Rectangle(30, 120, 196, 182));
802     GridLayout gridLayout3 = new GridLayout();
803     jPanel11.setLayout(gridLayout3);
804     gridLayout3.setRows(8);
805     blcjv.setFont(LABEL_FONT);
806     blcjv.setHorizontalAlignment(SwingConstants.LEFT);
807     clustaljv.setFont(LABEL_FONT);
808     clustaljv.setHorizontalAlignment(SwingConstants.LEFT);
809     pfamjv.setFont(LABEL_FONT);
810     pfamjv.setHorizontalAlignment(SwingConstants.LEFT);
811     pileupjv.setFont(LABEL_FONT);
812     pileupjv.setHorizontalAlignment(SwingConstants.LEFT);
813     pirjv.setFont(LABEL_FONT);
814     pirjv.setHorizontalAlignment(SwingConstants.LEFT);
815     autoIdWidth.setFont(LABEL_FONT);
816     autoIdWidth.setText(
817             MessageManager.getString("label.automatically_set_id_width"));
818     autoIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
819             .getString("label.adjusts_width_generated_eps_png")));
820     autoIdWidth.setBounds(new Rectangle(228, 144, 320, 23));
821     autoIdWidth.addActionListener(new ActionListener()
822     {
823
824       @Override
825       public void actionPerformed(ActionEvent e)
826       {
827         autoIdWidth_actionPerformed();
828       }
829     });
830     userIdWidthlabel.setFont(LABEL_FONT);
831     userIdWidthlabel.setText(
832             MessageManager.getString("label.figure_id_column_width"));
833     userIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
834             .getString("label.manually_specify_width_left_column")));
835     userIdWidthlabel.setToolTipText(
836             JvSwingUtils.wrapTooltip(true, MessageManager.getString(
837                     "label.manually_specify_width_left_column")));
838     userIdWidthlabel.setBounds(new Rectangle(236, 168, 320, 23));
839     userIdWidth.setFont(JvSwingUtils.getTextAreaFont());
840     userIdWidth.setText("");
841     userIdWidth.setBounds(new Rectangle(232, 192, 84, 23));
842     userIdWidth.addActionListener(new ActionListener()
843     {
844
845       @Override
846       public void actionPerformed(ActionEvent e)
847       {
848         userIdWidth_actionPerformed();
849       }
850     });
851     modellerOutput.setFont(LABEL_FONT);
852     modellerOutput
853             .setText(MessageManager.getString("label.use_modeller_output"));
854     modellerOutput.setBounds(new Rectangle(228, 274, 320, 23));
855     embbedBioJSON.setFont(LABEL_FONT);
856     embbedBioJSON.setText(MessageManager.getString("label.embbed_biojson"));
857     embbedBioJSON.setBounds(new Rectangle(228, 248, 250, 23));
858
859     jPanel11.add(jLabel1);
860     jPanel11.add(blcjv);
861     jPanel11.add(clustaljv);
862     jPanel11.add(fastajv);
863     jPanel11.add(msfjv);
864     jPanel11.add(pfamjv);
865     jPanel11.add(pileupjv);
866     jPanel11.add(pirjv);
867     outputTab.add(autoIdWidth);
868     outputTab.add(userIdWidth);
869     outputTab.add(userIdWidthlabel);
870     outputTab.add(modellerOutput);
871     if (!Platform.isJS())
872     {
873       /*
874        * JalviewJS doesn't support Lineart option or SVG output
875        */
876       outputTab.add(embbedBioJSON);
877       outputTab.add(epsLabel);
878       outputTab.add(epsRendering);
879       outputTab.add(htmlLabel);
880       outputTab.add(htmlRendering);
881       outputTab.add(svgLabel);
882       outputTab.add(svgRendering);
883     }
884     outputTab.add(jPanel11);
885     return outputTab;
886   }
887
888   /**
889    * Initialises the Connections tabbed panel.
890    * 
891    * @return
892    */
893   private JPanel initConnectionsTab()
894   {
895     connectTab = new JPanel();
896     connectTab.setLayout(new GridBagLayout());
897
898
899     JPanel proxyPanel = initConnTabProxyPanel();
900     initConnTabCheckboxes();
901
902     // Add proxy server panel
903     connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0,
904             GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
905             new Insets(10, 0, 5, 12), 4, 10));
906
907     // Add usage stats, version check and questionnaire checkboxes
908     connectTab.add(usagestats,
909             new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
910                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
911                     new Insets(0, 2, 5, 5), 70, 1));
912     connectTab.add(questionnaire,
913             new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
914                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
915                     new Insets(0, 2, 5, 10), 70, 1));
916     connectTab.add(versioncheck,
917             new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0,
918                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
919                     new Insets(0, 2, 5, 5), 70, 1));
920
921     versioncheck.setVisible(false);
922
923     // Add padding so the panel doesn't look ridiculous
924     JPanel spacePanel = new JPanel();
925     connectTab.add(spacePanel,
926             new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
927                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
928                     new Insets(0, 0, 0, 5), 70, 1));
929
930     return connectTab;
931   }
932
933   /**
934    * Initialises the Links tabbed panel.
935    * 
936    * @return
937    */
938   private JPanel initLinksTab()
939   {
940     JPanel linkTab = new JPanel();
941     linkTab.setLayout(new GridBagLayout());
942
943     // Set up table for Url links
944     linkUrlTable.getTableHeader().setReorderingAllowed(false);
945     linkUrlTable.setFillsViewportHeight(true);
946     linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
947     linkUrlTable.setAutoCreateRowSorter(true);
948     linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
949
950     // adjust row height so radio buttons actually fit
951     // don't do this in the renderer, it causes the awt thread to activate
952     // constantly
953     JRadioButton temp = new JRadioButton();
954     linkUrlTable.setRowHeight(temp.getMinimumSize().height);
955
956     // Table in scrollpane so that the table is given a scrollbar
957     JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
958     linkScrollPane.setBorder(null);
959
960     // Panel for links functionality
961     JPanel linkPanel = new JPanel(new GridBagLayout());
962     linkPanel.setBorder(new TitledBorder(
963             MessageManager.getString("label.url_linkfrom_sequence_id")));
964
965     // Put the Url links panel together
966
967     // Buttons go at top right, resizing only resizes the blank space vertically
968     JPanel buttonPanel = initLinkTabUrlButtons();
969     GridBagConstraints linkConstraints1 = new GridBagConstraints();
970     linkConstraints1.insets = new Insets(0, 0, 5, 0);
971     linkConstraints1.gridx = 0;
972     linkConstraints1.gridy = 0;
973     linkConstraints1.weightx = 1.0;
974     linkConstraints1.fill = GridBagConstraints.HORIZONTAL;
975     linkTab.add(buttonPanel, linkConstraints1);
976
977     // Links table goes at top left, resizing resizes the table
978     GridBagConstraints linkConstraints2 = new GridBagConstraints();
979     linkConstraints2.insets = new Insets(0, 0, 5, 5);
980     linkConstraints2.gridx = 0;
981     linkConstraints2.gridy = 1;
982     linkConstraints2.weightx = 1.0;
983     linkConstraints2.weighty = 1.0;
984     linkConstraints2.fill = GridBagConstraints.BOTH;
985     linkTab.add(linkScrollPane, linkConstraints2);
986
987     // Filter box and buttons goes at bottom left, resizing resizes the text box
988     JPanel filterPanel = initLinkTabFilterPanel();
989     GridBagConstraints linkConstraints3 = new GridBagConstraints();
990     linkConstraints3.insets = new Insets(0, 0, 0, 5);
991     linkConstraints3.gridx = 0;
992     linkConstraints3.gridy = 2;
993     linkConstraints3.weightx = 1.0;
994     linkConstraints3.fill = GridBagConstraints.HORIZONTAL;
995     linkTab.add(filterPanel, linkConstraints3);
996
997     return linkTab;
998   }
999
1000   private JPanel initLinkTabFilterPanel()
1001   {
1002     // Filter textbox and reset button
1003     JLabel filterLabel = new JLabel(
1004             MessageManager.getString("label.filter"));
1005     filterLabel.setFont(LABEL_FONT);
1006     filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1007     filterLabel.setHorizontalTextPosition(SwingConstants.LEADING);
1008
1009     filterTB.setFont(LABEL_FONT);
1010     filterTB.setText("");
1011
1012     doReset.setText(MessageManager.getString("action.showall"));
1013     userOnly.setText(MessageManager.getString("action.customfilter"));
1014
1015     // Panel for filter functionality
1016     JPanel filterPanel = new JPanel(new GridBagLayout());
1017     filterPanel.setBorder(new TitledBorder("Filter"));
1018     GridBagConstraints gbc = new GridBagConstraints();
1019     gbc.gridx = 0;
1020     gbc.gridy = 0;
1021     gbc.fill = GridBagConstraints.NONE;
1022     gbc.anchor = GridBagConstraints.WEST;
1023
1024     filterPanel.add(filterLabel, gbc);
1025
1026     GridBagConstraints gbc1 = new GridBagConstraints();
1027     gbc1.gridx = 1;
1028     gbc1.gridwidth = 2;
1029     gbc1.fill = GridBagConstraints.HORIZONTAL;
1030     gbc1.anchor = GridBagConstraints.WEST;
1031     gbc1.weightx = 1.0;
1032     filterPanel.add(filterTB, gbc1);
1033
1034     GridBagConstraints gbc2 = new GridBagConstraints();
1035     gbc2.gridx = 3;
1036     gbc2.fill = GridBagConstraints.NONE;
1037     gbc2.anchor = GridBagConstraints.WEST;
1038     filterPanel.add(doReset, gbc2);
1039
1040     GridBagConstraints gbc3 = new GridBagConstraints();
1041     gbc3.gridx = 4;
1042     gbc3.fill = GridBagConstraints.NONE;
1043     gbc3.anchor = GridBagConstraints.WEST;
1044     filterPanel.add(userOnly, gbc3);
1045
1046     return filterPanel;
1047   }
1048
1049   private JPanel initLinkTabUrlButtons()
1050   {
1051     // Buttons for new / edit / delete Url links
1052     JButton newLink = new JButton();
1053     newLink.setText(MessageManager.getString("action.new"));
1054
1055     editLink.setText(MessageManager.getString("action.edit"));
1056
1057     deleteLink.setText(MessageManager.getString("action.delete"));
1058
1059     // no current selection, so initially disable delete/edit buttons
1060     editLink.setEnabled(false);
1061     deleteLink.setEnabled(false);
1062
1063     newLink.addActionListener(new java.awt.event.ActionListener()
1064     {
1065       @Override
1066       public void actionPerformed(ActionEvent e)
1067       {
1068         newLink_actionPerformed(e);
1069       }
1070     });
1071
1072     editLink.setText(MessageManager.getString("action.edit"));
1073     editLink.addActionListener(new java.awt.event.ActionListener()
1074     {
1075       @Override
1076       public void actionPerformed(ActionEvent e)
1077       {
1078         editLink_actionPerformed(e);
1079       }
1080     });
1081
1082     deleteLink.setText(MessageManager.getString("action.delete"));
1083     deleteLink.addActionListener(new java.awt.event.ActionListener()
1084     {
1085       @Override
1086       public void actionPerformed(ActionEvent e)
1087       {
1088         deleteLink_actionPerformed(e);
1089       }
1090     });
1091
1092     JPanel buttonPanel = new JPanel(new GridBagLayout());
1093     buttonPanel.setBorder(new TitledBorder("Edit links"));
1094     GridBagConstraints gbc = new GridBagConstraints();
1095     gbc.gridx = 0;
1096     gbc.gridy = 0;
1097     gbc.fill = GridBagConstraints.NONE;
1098     buttonPanel.add(newLink, gbc);
1099
1100     GridBagConstraints gbc1 = new GridBagConstraints();
1101     gbc1.gridx = 1;
1102     gbc1.gridy = 0;
1103     gbc1.fill = GridBagConstraints.NONE;
1104     buttonPanel.add(editLink, gbc1);
1105
1106     GridBagConstraints gbc2 = new GridBagConstraints();
1107     gbc2.gridx = 2;
1108     gbc2.gridy = 0;
1109     gbc2.fill = GridBagConstraints.NONE;
1110     buttonPanel.add(deleteLink, gbc2);
1111
1112     GridBagConstraints gbc3 = new GridBagConstraints();
1113     gbc3.gridx = 3;
1114     gbc3.gridy = 0;
1115     gbc3.fill = GridBagConstraints.HORIZONTAL;
1116     gbc3.weightx = 1.0;
1117     JPanel spacePanel = new JPanel();
1118     spacePanel.setBorder(null);
1119     buttonPanel.add(spacePanel, gbc3);
1120
1121     return buttonPanel;
1122   }
1123
1124   /**
1125    * Initialises the proxy server panel in the Connections tab
1126    * 
1127    * @return the proxy server panel
1128    */
1129   private JPanel initConnTabProxyPanel()
1130   {
1131     // Label for server text box
1132     serverLabel.setText(MessageManager.getString("label.host") + ": ");
1133     serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1134     serverLabel.setFont(LABEL_FONT);
1135     serverLabel2.setText(MessageManager.getString("label.host") + ": ");
1136     serverLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
1137     serverLabel2.setFont(LABEL_FONT);
1138
1139     // Proxy server and port text boxes
1140     proxyServerHttpTB.setFont(LABEL_FONT);
1141     proxyServerHttpTB.setColumns(40);
1142     proxyPortHttpTB.setFont(LABEL_FONT);
1143     proxyPortHttpTB.setColumns(4);
1144     proxyServerHttpsTB.setFont(LABEL_FONT);
1145     proxyServerHttpsTB.setColumns(40);
1146     proxyPortHttpsTB.setFont(LABEL_FONT);
1147     proxyPortHttpsTB.setColumns(4);
1148     proxyAuthUsernameTB.setFont(LABEL_FONT);
1149     proxyAuthUsernameTB.setColumns(30);
1150
1151     // check for any change to enable applyProxyButton
1152     DocumentListener d = new DocumentListener()
1153     {
1154       @Override
1155       public void changedUpdate(DocumentEvent e)
1156       {
1157         applyProxyButtonEnabled(true);
1158       }
1159
1160       @Override
1161       public void insertUpdate(DocumentEvent e)
1162       {
1163         applyProxyButtonEnabled(true);
1164       }
1165
1166       @Override
1167       public void removeUpdate(DocumentEvent e)
1168       {
1169         applyProxyButtonEnabled(true);
1170       }
1171     };
1172     proxyServerHttpTB.getDocument().addDocumentListener(d);
1173     proxyPortHttpTB.getDocument().addDocumentListener(d);
1174     proxyServerHttpsTB.getDocument().addDocumentListener(d);
1175     proxyPortHttpsTB.getDocument().addDocumentListener(d);
1176     proxyAuthUsernameTB.getDocument().addDocumentListener(d);
1177     proxyAuthPasswordPB.setFont(LABEL_FONT);
1178     proxyAuthPasswordPB.setColumns(30);
1179     proxyAuthPasswordPB.getDocument()
1180             .addDocumentListener(new DocumentListener()
1181             {
1182               @Override
1183               public void changedUpdate(DocumentEvent e)
1184               {
1185                 proxyAuthPasswordCheckHighlight(true);
1186                 applyProxyButtonEnabled(true);
1187               }
1188
1189               @Override
1190               public void insertUpdate(DocumentEvent e)
1191               {
1192                 proxyAuthPasswordCheckHighlight(true);
1193                 applyProxyButtonEnabled(true);
1194               }
1195
1196               @Override
1197               public void removeUpdate(DocumentEvent e)
1198               {
1199                 proxyAuthPasswordCheckHighlight(true);
1200                 applyProxyButtonEnabled(true);
1201               }
1202
1203             });
1204
1205     // Label for Port text box
1206     portLabel.setFont(LABEL_FONT);
1207     portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1208     portLabel.setText(MessageManager.getString("label.port") + ": ");
1209     portLabel2.setFont(LABEL_FONT);
1210     portLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
1211     portLabel2.setText(MessageManager.getString("label.port") + ": ");
1212
1213     httpLabel.setText("HTTP");
1214     httpLabel.setFont(LABEL_FONT_BOLD);
1215     httpLabel.setHorizontalAlignment(SwingConstants.LEFT);
1216     httpsLabel.setText("HTTPS");
1217     httpsLabel.setFont(LABEL_FONT_BOLD);
1218     httpsLabel.setHorizontalAlignment(SwingConstants.LEFT);
1219
1220     proxyAuthUsernameLabel
1221             .setText(MessageManager.getString("label.username") + ": ");
1222     proxyAuthUsernameLabel.setFont(LABEL_FONT);
1223     proxyAuthUsernameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1224     proxyAuthPasswordLabel
1225             .setText(MessageManager.getString("label.password") + ": ");
1226     proxyAuthPasswordLabel.setFont(LABEL_FONT);
1227     proxyAuthPasswordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1228     passwordNotStoredLabel.setText(
1229             "(" + MessageManager.getString("label.not_stored") + ")");
1230     passwordNotStoredLabel.setFont(LABEL_FONT_ITALIC);
1231     passwordNotStoredLabel.setHorizontalAlignment(SwingConstants.LEFT);
1232
1233     // Proxy type radio buttons
1234     noProxy.setFont(LABEL_FONT);
1235     noProxy.setHorizontalAlignment(SwingConstants.LEFT);
1236     noProxy.setText(MessageManager.getString("label.no_proxy"));
1237     systemProxy.setFont(LABEL_FONT);
1238     systemProxy.setHorizontalAlignment(SwingConstants.LEFT);
1239     systemProxy.setText(MessageManager.formatMessage("label.system_proxy",
1240             displayUserHostPort(Cache.startupProxyProperties[4],
1241                     Cache.startupProxyProperties[0],
1242                     Cache.startupProxyProperties[1]),
1243             displayUserHostPort(Cache.startupProxyProperties[6],
1244                     Cache.startupProxyProperties[2],
1245                     Cache.startupProxyProperties[3])));
1246     customProxy.setFont(LABEL_FONT);
1247     customProxy.setHorizontalAlignment(SwingConstants.LEFT);
1248     customProxy.setText(
1249             MessageManager.getString("label.use_proxy_server") + ":");
1250     ActionListener al = new ActionListener()
1251     {
1252       @Override
1253       public void actionPerformed(ActionEvent e)
1254       {
1255         proxyType_actionPerformed();
1256       }
1257     };
1258     noProxy.addActionListener(al);
1259     systemProxy.addActionListener(al);
1260     customProxy.addActionListener(al);
1261     proxyType.add(noProxy);
1262     proxyType.add(systemProxy);
1263     proxyType.add(customProxy);
1264
1265     proxyAuth.setFont(LABEL_FONT);
1266     proxyAuth.setHorizontalAlignment(SwingConstants.LEFT);
1267     proxyAuth.setText(MessageManager.getString("label.auth_required"));
1268     proxyAuth.addActionListener(new ActionListener()
1269     {
1270       @Override
1271       public void actionPerformed(ActionEvent e)
1272       {
1273         proxyAuth_actionPerformed();
1274       }
1275     });
1276
1277     setCustomProxyEnabled();
1278
1279     // Make proxy server panel
1280     JPanel proxyPanel = new JPanel();
1281     TitledBorder titledBorder1 = new TitledBorder(
1282             MessageManager.getString("label.proxy_servers"));
1283     proxyPanel.setBorder(titledBorder1);
1284     proxyPanel.setLayout(new GridBagLayout());
1285     GridBagConstraints gbc = new GridBagConstraints();
1286     gbc.fill = GridBagConstraints.HORIZONTAL;
1287     gbc.weightx = 1.0;
1288
1289     GridBagConstraints c = new GridBagConstraints();
1290     // Proxy type radio buttons (3)
1291     JPanel ptPanel = new JPanel();
1292     ptPanel.setLayout(new GridBagLayout());
1293     c.weightx = 1.0;
1294     c.gridy = 0;
1295     c.gridx = 0;
1296     c.gridwidth = 1;
1297     c.fill = GridBagConstraints.HORIZONTAL;
1298     ptPanel.add(noProxy, c);
1299     c.gridy++;
1300     ptPanel.add(systemProxy, c);
1301     c.gridy++;
1302     ptPanel.add(customProxy, c);
1303
1304     gbc.gridy = 0;
1305     proxyPanel.add(ptPanel, gbc);
1306
1307     // host and port text boxes
1308     JPanel hpPanel = new JPanel();
1309     hpPanel.setLayout(new GridBagLayout());
1310     // HTTP host port row
1311     c.gridy = 0;
1312     c.gridx = 0;
1313
1314     c.weightx = 0.1;
1315     c.anchor = GridBagConstraints.LINE_START;
1316     hpPanel.add(httpLabel, c);
1317
1318     c.gridx++;
1319     c.weightx = 0.1;
1320     c.anchor = GridBagConstraints.LINE_END;
1321     hpPanel.add(serverLabel, c);
1322
1323     c.gridx++;
1324     c.weightx = 1.0;
1325     c.anchor = GridBagConstraints.LINE_START;
1326     hpPanel.add(proxyServerHttpTB, c);
1327
1328     c.gridx++;
1329     c.weightx = 0.1;
1330     c.anchor = GridBagConstraints.LINE_END;
1331     hpPanel.add(portLabel, c);
1332
1333     c.gridx++;
1334     c.weightx = 0.2;
1335     c.anchor = GridBagConstraints.LINE_START;
1336     hpPanel.add(proxyPortHttpTB, c);
1337
1338     // HTTPS host port row
1339     c.gridy++;
1340     c.gridx = 0;
1341     c.gridwidth = 1;
1342
1343     c.anchor = GridBagConstraints.LINE_START;
1344     hpPanel.add(httpsLabel, c);
1345
1346     c.gridx++;
1347     c.anchor = GridBagConstraints.LINE_END;
1348     hpPanel.add(serverLabel2, c);
1349
1350     c.gridx++;
1351     c.anchor = GridBagConstraints.LINE_START;
1352     hpPanel.add(proxyServerHttpsTB, c);
1353
1354     c.gridx++;
1355     c.anchor = GridBagConstraints.LINE_END;
1356     hpPanel.add(portLabel2, c);
1357
1358     c.gridx++;
1359     c.anchor = GridBagConstraints.LINE_START;
1360     hpPanel.add(proxyPortHttpsTB, c);
1361
1362     gbc.gridy++;
1363     proxyPanel.add(hpPanel, gbc);
1364
1365     if (!Platform.isJS())
1366     /**
1367      * java.net.Authenticator is not implemented in SwingJS. Not displaying the
1368      * Authentication options in Preferences.
1369      * 
1370      * @j2sIgnore
1371      * 
1372      */
1373     {
1374       // Require authentication checkbox
1375       gbc.gridy++;
1376       proxyPanel.add(proxyAuth, gbc);
1377
1378       // username and password
1379       JPanel upPanel = new JPanel();
1380       upPanel.setLayout(new GridBagLayout());
1381       // username row
1382       c.gridy = 0;
1383       c.gridx = 0;
1384       c.gridwidth = 1;
1385       c.weightx = 0.4;
1386       c.anchor = GridBagConstraints.LINE_END;
1387       upPanel.add(proxyAuthUsernameLabel, c);
1388
1389       c.gridx++;
1390       c.weightx = 1.0;
1391       c.anchor = GridBagConstraints.LINE_START;
1392       upPanel.add(proxyAuthUsernameTB, c);
1393
1394       // password row
1395       c.gridy++;
1396       c.gridx = 0;
1397       c.weightx = 0.4;
1398       c.anchor = GridBagConstraints.LINE_END;
1399       upPanel.add(proxyAuthPasswordLabel, c);
1400
1401       c.gridx++;
1402       c.weightx = 1.0;
1403       c.anchor = GridBagConstraints.LINE_START;
1404       upPanel.add(proxyAuthPasswordPB, c);
1405
1406       c.gridx++;
1407       c.weightx = 0.4;
1408       c.anchor = GridBagConstraints.LINE_START;
1409       upPanel.add(passwordNotStoredLabel, c);
1410
1411       gbc.gridy++;
1412       proxyPanel.add(upPanel, gbc);
1413
1414     } // end j2sIgnore
1415
1416     applyProxyButton.setText(MessageManager.getString("action.apply"));
1417     applyProxyButton.addActionListener(new ActionListener()
1418     {
1419       @Override
1420       public void actionPerformed(ActionEvent e)
1421       {
1422         saveProxySettings();
1423         applyProxyButton.setEnabled(false);
1424       }
1425     });
1426     gbc.gridy++;
1427     gbc.fill = GridBagConstraints.NONE;
1428     gbc.anchor = GridBagConstraints.LINE_END;
1429     proxyPanel.add(applyProxyButton, gbc);
1430
1431     return proxyPanel;
1432   }
1433
1434   public void proxyAuthPasswordCheckHighlight(boolean enabled)
1435   {
1436     proxyAuthPasswordCheckHighlight(enabled, false);
1437   }
1438
1439   public void proxyAuthPasswordCheckHighlight(boolean enabled,
1440           boolean grabFocus)
1441   {
1442     if (enabled && proxyType.isSelected(customProxy.getModel())
1443             && proxyAuth.isSelected()
1444             && !proxyAuthUsernameTB.getText().isEmpty()
1445             && proxyAuthPasswordPB.getDocument().getLength() == 0)
1446     {
1447       if (grabFocus)
1448         proxyAuthPasswordPB.grabFocus();
1449       proxyAuthPasswordPB.setBackground(Color.PINK);
1450     }
1451     else
1452     {
1453       proxyAuthPasswordPB.setBackground(Color.WHITE);
1454     }
1455   }
1456
1457   public void applyProxyButtonEnabled(boolean enabled)
1458   {
1459     applyProxyButton.setEnabled(enabled);
1460   }
1461
1462   public void saveProxySettings()
1463   {
1464     // overridden in Preferences
1465   }
1466
1467   private String displayUserHostPort(String user, String host, String port)
1468   {
1469     boolean hostBlank = (host == null || host.isEmpty());
1470     boolean portBlank = (port == null || port.isEmpty());
1471     if (hostBlank && portBlank)
1472     {
1473       return MessageManager.getString("label.none");
1474     }
1475
1476     StringBuilder sb = new StringBuilder();
1477     if (user != null)
1478     {
1479       sb.append(user.isEmpty() || user.indexOf(" ") > -1 ? '"' + user + '"'
1480               : user);
1481       sb.append("@");
1482     }
1483     sb.append(hostBlank ? "" : host);
1484     if (!portBlank)
1485     {
1486       sb.append(":");
1487       sb.append(port);
1488     }
1489     return sb.toString();
1490   }
1491
1492   /**
1493    * Initialises the checkboxes in the Connections tab
1494    */
1495   private void initConnTabCheckboxes()
1496   {
1497     // Usage stats checkbox label
1498     usagestats.setText(
1499             MessageManager.getString("label.send_usage_statistics"));
1500     usagestats.setFont(LABEL_FONT);
1501     usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
1502     usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
1503
1504     // Questionnaire checkbox label
1505     questionnaire.setText(
1506             MessageManager.getString("label.check_for_questionnaires"));
1507     questionnaire.setFont(LABEL_FONT);
1508     questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
1509     questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
1510
1511     // Check for latest version checkbox label
1512     versioncheck.setText(
1513             MessageManager.getString("label.check_for_latest_version"));
1514     versioncheck.setFont(LABEL_FONT);
1515     versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
1516     versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
1517   }
1518
1519   /**
1520    * Initialises the parent panel which contains the tabbed sections.
1521    * 
1522    * @return
1523    */
1524   private JPanel initOkCancelPanel()
1525   {
1526     JButton ok = new JButton();
1527     ok.setText(MessageManager.getString("action.ok"));
1528     ok.addActionListener(new ActionListener()
1529     {
1530       @Override
1531       public void actionPerformed(ActionEvent e)
1532       {
1533         ok_actionPerformed(e);
1534       }
1535     });
1536     JButton cancel = new JButton();
1537     cancel.setText(MessageManager.getString("action.cancel"));
1538     cancel.addActionListener(new ActionListener()
1539     {
1540       @Override
1541       public void actionPerformed(ActionEvent e)
1542       {
1543         cancel_actionPerformed(e);
1544       }
1545     });
1546     JPanel okCancelPanel = new JPanel();
1547     okCancelPanel.add(ok);
1548     okCancelPanel.add(cancel);
1549     return okCancelPanel;
1550   }
1551
1552   /**
1553    * Initialises the Colours tabbed panel.
1554    * 
1555    * @return
1556    */
1557   private JPanel initColoursTab()
1558   {
1559     JPanel coloursTab = new JPanel();
1560     coloursTab.setBorder(new TitledBorder(
1561             MessageManager.getString("action.open_new_alignment")));
1562     coloursTab.setLayout(new FlowLayout());
1563     JLabel mincolourLabel = new JLabel();
1564     mincolourLabel.setFont(LABEL_FONT);
1565     mincolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1566     mincolourLabel.setText(MessageManager.getString("label.min_colour"));
1567     minColour.setFont(LABEL_FONT);
1568     minColour.setBorder(BorderFactory.createEtchedBorder());
1569     minColour.setPreferredSize(new Dimension(40, 20));
1570     minColour.addMouseListener(new MouseAdapter()
1571     {
1572       @Override
1573       public void mousePressed(MouseEvent e)
1574       {
1575         minColour_actionPerformed(minColour);
1576       }
1577     });
1578     JLabel maxcolourLabel = new JLabel();
1579     maxcolourLabel.setFont(LABEL_FONT);
1580     maxcolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1581     maxcolourLabel.setText(MessageManager.getString("label.max_colour"));
1582     maxColour.setFont(LABEL_FONT);
1583     maxColour.setBorder(BorderFactory.createEtchedBorder());
1584     maxColour.setPreferredSize(new Dimension(40, 20));
1585     maxColour.addMouseListener(new MouseAdapter()
1586     {
1587       @Override
1588       public void mousePressed(MouseEvent e)
1589       {
1590         maxColour_actionPerformed(maxColour);
1591       }
1592     });
1593
1594     protColour.setFont(LABEL_FONT);
1595     protColour.setBounds(new Rectangle(172, 225, 155, 21));
1596     JLabel protColourLabel = new JLabel();
1597     protColourLabel.setFont(LABEL_FONT);
1598     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1599     protColourLabel.setText(
1600             MessageManager.getString("label.prot_alignment_colour") + " ");
1601     GPreferences.addtoLayout(coloursTab,
1602             MessageManager
1603                     .getString("label.default_colour_scheme_for_alignment"),
1604             protColourLabel, protColour);
1605
1606     nucColour.setFont(LABEL_FONT);
1607     nucColour.setBounds(new Rectangle(172, 240, 155, 21));
1608     JLabel nucColourLabel = new JLabel();
1609     nucColourLabel.setFont(LABEL_FONT);
1610     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1611     nucColourLabel.setText(
1612             MessageManager.getString("label.nuc_alignment_colour") + " ");
1613     GPreferences.addtoLayout(coloursTab,
1614             MessageManager
1615                     .getString("label.default_colour_scheme_for_alignment"),
1616             nucColourLabel, nucColour);
1617
1618     JPanel annotationShding = new JPanel();
1619     annotationShding.setBorder(new TitledBorder(
1620             MessageManager.getString("label.annotation_shading_default")));
1621     annotationShding.setLayout(new GridLayout(1, 2));
1622     GPreferences.addtoLayout(annotationShding,
1623             MessageManager.getString(
1624                     "label.default_minimum_colour_annotation_shading"),
1625             mincolourLabel, minColour);
1626     GPreferences.addtoLayout(annotationShding,
1627             MessageManager.getString(
1628                     "label.default_maximum_colour_annotation_shading"),
1629             maxcolourLabel, maxColour);
1630     coloursTab.add(annotationShding); // , FlowLayout.LEFT);
1631     return coloursTab;
1632   }
1633
1634   /**
1635    * Initialises the Overview tabbed panel.
1636    * 
1637    * @return
1638    */
1639   private JPanel initOverviewTab()
1640   {
1641     JPanel overviewPanel = new JPanel();
1642     overviewPanel.setBorder(new TitledBorder(
1643             MessageManager.getString("label.overview_settings")));
1644
1645     gapColour.setFont(LABEL_FONT);
1646     // fixing the border colours stops apparent colour bleed from the panel
1647     gapColour.setBorder(
1648             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1649     gapColour.setPreferredSize(new Dimension(40, 20));
1650     gapColour.addMouseListener(new MouseAdapter()
1651     {
1652       @Override
1653       public void mousePressed(MouseEvent e)
1654       {
1655         gapColour_actionPerformed(gapColour);
1656       }
1657     });
1658
1659     hiddenColour.setFont(LABEL_FONT);
1660     // fixing the border colours stops apparent colour bleed from the panel
1661     hiddenColour.setBorder(
1662             BorderFactory.createEtchedBorder(Color.white, Color.lightGray));
1663     hiddenColour.setPreferredSize(new Dimension(40, 20));
1664     hiddenColour.addMouseListener(new MouseAdapter()
1665     {
1666       @Override
1667       public void mousePressed(MouseEvent e)
1668       {
1669         hiddenColour_actionPerformed(hiddenColour);
1670       }
1671     });
1672
1673     useLegacyGap = new JCheckBox(
1674             MessageManager.getString("label.ov_legacy_gap"));
1675     useLegacyGap.setFont(LABEL_FONT);
1676     useLegacyGap.setHorizontalAlignment(SwingConstants.LEFT);
1677     useLegacyGap.setVerticalTextPosition(SwingConstants.TOP);
1678     gapLabel = new JLabel(MessageManager.getString("label.gap_colour"));
1679     gapLabel.setFont(LABEL_FONT);
1680     gapLabel.setHorizontalAlignment(SwingConstants.LEFT);
1681     gapLabel.setVerticalTextPosition(SwingConstants.TOP);
1682     showHiddenAtStart = new JCheckBox(
1683             MessageManager.getString("label.ov_show_hide_default"));
1684     showHiddenAtStart.setFont(LABEL_FONT);
1685     showHiddenAtStart.setHorizontalAlignment(SwingConstants.LEFT);
1686     showHiddenAtStart.setVerticalTextPosition(SwingConstants.TOP);
1687     JLabel hiddenLabel = new JLabel(
1688             MessageManager.getString("label.hidden_colour"));
1689     hiddenLabel.setFont(LABEL_FONT);
1690     hiddenLabel.setHorizontalAlignment(SwingConstants.LEFT);
1691     hiddenLabel.setVerticalTextPosition(SwingConstants.TOP);
1692
1693     useLegacyGap.addActionListener(new ActionListener()
1694     {
1695       @Override
1696       public void actionPerformed(ActionEvent e)
1697       {
1698         useLegacyGaps_actionPerformed(e);
1699       }
1700     });
1701
1702     overviewPanel.setLayout(new GridBagLayout());
1703     GridBagConstraints c1 = new GridBagConstraints();
1704
1705     c1.fill = GridBagConstraints.HORIZONTAL;
1706     c1.gridx = 0;
1707     c1.gridy = 0;
1708     c1.weightx = 1;
1709     c1.ipady = 20;
1710     c1.anchor = GridBagConstraints.FIRST_LINE_START;
1711     overviewPanel.add(useLegacyGap, c1);
1712
1713     GridBagConstraints c2 = new GridBagConstraints();
1714     c2.fill = GridBagConstraints.HORIZONTAL;
1715     c2.gridx = 1;
1716     c2.gridy = 0;
1717     c2.insets = new Insets(0, 15, 0, 10);
1718     overviewPanel.add(gapLabel, c2);
1719
1720     GridBagConstraints c3 = new GridBagConstraints();
1721     c3.fill = GridBagConstraints.HORIZONTAL;
1722     c3.gridx = 2;
1723     c3.gridy = 0;
1724     c3.insets = new Insets(0, 0, 0, 15);
1725     overviewPanel.add(gapColour, c3);
1726
1727     GridBagConstraints c4 = new GridBagConstraints();
1728     c4.fill = GridBagConstraints.HORIZONTAL;
1729     c4.gridx = 0;
1730     c4.gridy = 1;
1731     c4.weightx = 1;
1732     overviewPanel.add(showHiddenAtStart, c4);
1733
1734     GridBagConstraints c5 = new GridBagConstraints();
1735     c5.fill = GridBagConstraints.HORIZONTAL;
1736     c5.gridx = 1;
1737     c5.gridy = 1;
1738     c5.insets = new Insets(0, 15, 0, 10);
1739     overviewPanel.add(hiddenLabel, c5);
1740
1741     GridBagConstraints c6 = new GridBagConstraints();
1742     c6.fill = GridBagConstraints.HORIZONTAL;
1743     c6.gridx = 2;
1744     c6.gridy = 1;
1745     c6.insets = new Insets(0, 0, 0, 15);
1746     overviewPanel.add(hiddenColour, c6);
1747
1748     JButton resetButton = new JButton(
1749             MessageManager.getString("label.reset_to_defaults"));
1750
1751     resetButton.addActionListener(new ActionListener()
1752     {
1753       @Override
1754       public void actionPerformed(ActionEvent e)
1755       {
1756         resetOvDefaults_actionPerformed(e);
1757       }
1758     });
1759
1760     GridBagConstraints c7 = new GridBagConstraints();
1761     c7.fill = GridBagConstraints.NONE;
1762     c7.gridx = 0;
1763     c7.gridy = 2;
1764     c7.insets = new Insets(10, 0, 0, 0);
1765     c7.anchor = GridBagConstraints.WEST;
1766     overviewPanel.add(resetButton, c7);
1767
1768     // Add padding so the panel doesn't look ridiculous
1769     JPanel spacePanel = new JPanel();
1770     overviewPanel.add(spacePanel,
1771             new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0,
1772                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
1773                     new Insets(0, 0, 0, 5), 0, 0));
1774
1775     return overviewPanel;
1776   }
1777
1778   /**
1779    * Initialises the Structure tabbed panel.
1780    * 
1781    * @return
1782    */
1783   private JPanel initStructureTab()
1784   {
1785     structureTab = new JPanel();
1786
1787     structureTab.setBorder(new TitledBorder(
1788             MessageManager.getString("label.structure_options")));
1789     structureTab.setLayout(null);
1790     final int width = 420;
1791     final int height = 22;
1792     final int lineSpacing = 25;
1793     int ypos = 15;
1794
1795     structFromPdb.setFont(LABEL_FONT);
1796     structFromPdb
1797             .setText(MessageManager.getString("label.struct_from_pdb"));
1798     structFromPdb.setBounds(new Rectangle(5, ypos, width, height));
1799     structFromPdb.addActionListener(new ActionListener()
1800     {
1801       @Override
1802       public void actionPerformed(ActionEvent e)
1803       {
1804         boolean selected = structFromPdb.isSelected();
1805         // enable other options only when the first is checked
1806         addSecondaryStructure.setEnabled(selected);
1807         addTempFactor.setEnabled(selected);
1808       }
1809     });
1810     structureTab.add(structFromPdb);
1811
1812     // indent checkboxes that are conditional on the first one
1813     ypos += lineSpacing;
1814     addSecondaryStructure.setFont(LABEL_FONT);
1815     addSecondaryStructure
1816             .setText(MessageManager.getString("label.autoadd_secstr"));
1817     addSecondaryStructure.setBounds(new Rectangle(25, ypos, width, height));
1818     structureTab.add(addSecondaryStructure);
1819
1820     ypos += lineSpacing;
1821     addTempFactor.setFont(LABEL_FONT);
1822     addTempFactor.setText(MessageManager.getString("label.autoadd_temp"));
1823     addTempFactor.setBounds(new Rectangle(25, ypos, width, height));
1824     structureTab.add(addTempFactor);
1825
1826     ypos += lineSpacing;
1827     JLabel viewerLabel = new JLabel();
1828     viewerLabel.setFont(LABEL_FONT);
1829     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
1830     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
1831     viewerLabel.setBounds(new Rectangle(10, ypos, 220, height));
1832     structureTab.add(viewerLabel);
1833
1834     /*
1835      * add all external viewers as options here - check 
1836      * when selected whether the program is installed
1837      */
1838     structViewer.setFont(LABEL_FONT);
1839     structViewer.setBounds(new Rectangle(190, ypos, 120, height));
1840     structViewer.addItem(ViewerType.JMOL.name());
1841     structViewer.addItem(ViewerType.CHIMERA.name());
1842     structViewer.addItem(ViewerType.CHIMERAX.name());
1843     structViewer.addItem(ViewerType.PYMOL.name());
1844     structViewer.addActionListener(new ActionListener()
1845     {
1846       @Override
1847       public void actionPerformed(ActionEvent e)
1848       {
1849         structureViewer_actionPerformed(
1850                 (String) structViewer.getSelectedItem());
1851       }
1852     });
1853     structureTab.add(structViewer);
1854
1855     ypos += lineSpacing;
1856     structureViewerPathLabel = new JLabel();
1857     structureViewerPathLabel.setFont(LABEL_FONT);// new Font("SansSerif", 0,
1858                                                  // 11));
1859     structureViewerPathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1860     structureViewerPathLabel.setText(MessageManager
1861             .formatMessage("label.viewer_path", "Chimera(X)"));
1862     structureViewerPathLabel
1863             .setBounds(new Rectangle(10, ypos, 170, height));
1864     structureViewerPathLabel.setEnabled(false);
1865     structureTab.add(structureViewerPathLabel);
1866
1867     structureViewerPath.setFont(LABEL_FONT);
1868     structureViewerPath.setText("");
1869     structureViewerPath.setEnabled(false);
1870     final String tooltip = JvSwingUtils.wrapTooltip(true,
1871             MessageManager.getString("label.viewer_path_tip"));
1872     structureViewerPath.setToolTipText(tooltip);
1873     structureViewerPath.setBounds(new Rectangle(190, ypos, 290, height));
1874     structureViewerPath.addMouseListener(new MouseAdapter()
1875     {
1876       @Override
1877       public void mouseClicked(MouseEvent e)
1878       {
1879         if (structureViewerPath.isEnabled() && e.getClickCount() == 2)
1880         {
1881           String chosen = openFileChooser(false);
1882           if (chosen != null)
1883           {
1884             structureViewerPath.setText(chosen);
1885           }
1886         }
1887       }
1888     });
1889     structureTab.add(structureViewerPath);
1890
1891     ypos += lineSpacing;
1892     nwMapping.setFont(LABEL_FONT);
1893     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1894     siftsMapping.setFont(LABEL_FONT);
1895     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1896     mappingMethod.add(nwMapping);
1897     mappingMethod.add(siftsMapping);
1898     JPanel mappingPanel = new JPanel();
1899     mappingPanel.setFont(LABEL_FONT);
1900     TitledBorder mmTitledBorder = new TitledBorder(
1901             MessageManager.getString("label.mapping_method"));
1902     mmTitledBorder.setTitleFont(LABEL_FONT);
1903     mappingPanel.setBorder(mmTitledBorder);
1904     mappingPanel.setBounds(new Rectangle(10, ypos, 472, 45));
1905     // GridLayout mappingLayout = new GridLayout();
1906     mappingPanel.setLayout(new GridLayout());
1907     mappingPanel.add(nwMapping);
1908     mappingPanel.add(siftsMapping);
1909     structureTab.add(mappingPanel);
1910
1911     ypos += lineSpacing;
1912     ypos += lineSpacing;
1913     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1914             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1915     docFieldPref.setBounds(new Rectangle(10, ypos, 470, 120));
1916     structureTab.add(docFieldPref);
1917
1918     /*
1919      * hide Chimera options in JalviewJS
1920      */
1921     if (Platform.isJS())
1922     {
1923       structureViewerPathLabel.setVisible(false);
1924       structureViewerPath.setVisible(false);
1925       viewerLabel.setVisible(false);
1926       structViewer.setVisible(false);
1927     }
1928
1929     return structureTab;
1930   }
1931
1932   /**
1933    * Action on choosing a structure viewer from combobox options.
1934    * 
1935    * @param selectedItem
1936    */
1937   protected void structureViewer_actionPerformed(String selectedItem)
1938   {
1939   }
1940
1941   /**
1942    * Show a dialog for the user to choose a file. Returns the chosen path, or null
1943    * on Cancel.
1944    * 
1945    * @return
1946    */
1947   protected String openFileChooser(boolean forFolder)
1948   {
1949     String choice = null;
1950     JFileChooser chooser = new JFileChooser();
1951
1952     // Enable appBundleIsTraversable in macOS FileChooser to allow selecting
1953     // hidden executables within .app dirs
1954     if (Platform.isMac())
1955     {
1956       chooser.putClientProperty("JFileChooser.appBundleIsTraversable",
1957               true);
1958     }
1959
1960     if (forFolder)
1961     {
1962       chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1963     }
1964     // chooser.setFileView(new JalviewFileView());
1965     chooser.setDialogTitle(
1966             MessageManager.getString("label.open_local_file"));
1967     chooser.setToolTipText(MessageManager.getString("action.open"));
1968
1969     int value = chooser.showOpenDialog(this);
1970
1971     if (value == JFileChooser.APPROVE_OPTION)
1972     {
1973       choice = chooser.getSelectedFile().getPath();
1974     }
1975     return choice;
1976   }
1977
1978   /**
1979    * Validate the structure tab preferences; if invalid, set focus on this tab.
1980    * 
1981    * @param e
1982    */
1983   protected boolean validateStructure(FocusEvent e)
1984   {
1985     if (!validateStructure())
1986     {
1987       e.getComponent().requestFocusInWindow();
1988       return false;
1989     }
1990     return true;
1991   }
1992
1993   protected boolean validateStructure()
1994   {
1995     return false;
1996   }
1997
1998   /**
1999    * Initialises the Visual tabbed panel.
2000    * 
2001    * @return
2002    */
2003   private JPanel initVisualTab()
2004   {
2005     JPanel visualTab = new JPanel();
2006     visualTab.setBorder(new TitledBorder(
2007             MessageManager.getString("action.open_new_alignment")));
2008     visualTab.setLayout(null);
2009     fullScreen.setFont(LABEL_FONT);
2010     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
2011     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
2012     fullScreen.setText(MessageManager.getString("label.maximize_window"));
2013     quality.setEnabled(false);
2014     quality.setFont(LABEL_FONT);
2015     quality.setHorizontalAlignment(SwingConstants.RIGHT);
2016     quality.setHorizontalTextPosition(SwingConstants.LEFT);
2017     quality.setSelected(true);
2018     quality.setText(MessageManager.getString("label.quality"));
2019     conservation.setEnabled(false);
2020     conservation.setFont(LABEL_FONT);
2021     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
2022     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
2023     conservation.setSelected(true);
2024     conservation.setText(MessageManager.getString("label.conservation"));
2025     identity.setEnabled(false);
2026     identity.setFont(LABEL_FONT);
2027     identity.setHorizontalAlignment(SwingConstants.RIGHT);
2028     identity.setHorizontalTextPosition(SwingConstants.LEFT);
2029     identity.setSelected(true);
2030     identity.setText(MessageManager.getString("label.consensus"));
2031     showOccupancy.setFont(LABEL_FONT);
2032     showOccupancy.setEnabled(false);
2033     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
2034     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
2035     showOccupancy.setSelected(true);
2036     showOccupancy.setText(MessageManager.getString("label.occupancy"));
2037
2038     JLabel showGroupbits = new JLabel();
2039     showGroupbits.setFont(LABEL_FONT);
2040     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
2041     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
2042     showGroupbits
2043             .setText(MessageManager.getString("action.show_group") + ":");
2044     JLabel showConsensbits = new JLabel();
2045     showConsensbits.setFont(LABEL_FONT);
2046     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
2047     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
2048     showConsensbits
2049             .setText(MessageManager.getString("label.consensus") + ":");
2050     showConsensHistogram.setEnabled(false);
2051     showConsensHistogram.setFont(LABEL_FONT);
2052     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
2053     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
2054     showConsensHistogram.setSelected(true);
2055     showConsensHistogram
2056             .setText(MessageManager.getString("label.histogram"));
2057     showConsensLogo.setEnabled(false);
2058     showConsensLogo.setFont(LABEL_FONT);
2059     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
2060     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
2061     showConsensLogo.setSelected(true);
2062     showConsensLogo.setText(MessageManager.getString("label.logo"));
2063     showGroupConsensus.setEnabled(false);
2064     showGroupConsensus.setFont(LABEL_FONT);
2065     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
2066     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
2067     showGroupConsensus.setSelected(true);
2068     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
2069     showGroupConservation.setEnabled(false);
2070     showGroupConservation.setFont(LABEL_FONT);
2071     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
2072     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
2073     showGroupConservation.setSelected(true);
2074     showGroupConservation
2075             .setText(MessageManager.getString("label.conservation"));
2076     showNpTooltip.setEnabled(true);
2077     showNpTooltip.setFont(LABEL_FONT);
2078     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
2079     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
2080     showNpTooltip.setSelected(true);
2081     showNpTooltip.setText(
2082             MessageManager.getString("label.non_positional_features"));
2083     showDbRefTooltip.setEnabled(true);
2084     showDbRefTooltip.setFont(LABEL_FONT);
2085     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
2086     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
2087     showDbRefTooltip.setSelected(true);
2088     showDbRefTooltip
2089             .setText(MessageManager.getString("label.database_references"));
2090     annotations.setFont(LABEL_FONT);
2091     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
2092     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
2093     annotations.setSelected(true);
2094     annotations.setText(MessageManager.getString("label.show_annotations"));
2095     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
2096     annotations.addActionListener(new ActionListener()
2097     {
2098       @Override
2099       public void actionPerformed(ActionEvent e)
2100       {
2101         annotations_actionPerformed(e);
2102       }
2103     });
2104     identity.addActionListener(new ActionListener()
2105     {
2106       @Override
2107       public void actionPerformed(ActionEvent e)
2108       {
2109         annotations_actionPerformed(e);
2110       }
2111     });
2112     showGroupConsensus.addActionListener(new ActionListener()
2113     {
2114       @Override
2115       public void actionPerformed(ActionEvent e)
2116       {
2117         annotations_actionPerformed(e);
2118       }
2119     });
2120     showUnconserved.setFont(LABEL_FONT);
2121     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
2122     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
2123     showUnconserved.setSelected(true);
2124     showUnconserved
2125             .setText(MessageManager.getString("action.show_unconserved"));
2126     showUnconserved.addActionListener(new ActionListener()
2127     {
2128       @Override
2129       public void actionPerformed(ActionEvent e)
2130       {
2131         showunconserved_actionPerformed(e);
2132       }
2133     });
2134
2135     // TODO these are not yet added to / action from Preferences
2136     // JCheckBox shareSelections = new JCheckBox();
2137     // shareSelections.setFont(verdana11);
2138     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
2139     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
2140     // shareSelections.setSelected(true);
2141     // shareSelections.setText(MessageManager
2142     // .getString("label.share_selection_across_views"));
2143     // JCheckBox followHighlight = new JCheckBox();
2144     // followHighlight.setFont(verdana11);
2145     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
2146     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
2147     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
2148     // followHighlight.setSelected(true);
2149     // followHighlight.setText(MessageManager
2150     // .getString("label.scroll_highlighted_regions"));
2151
2152     seqLimit.setFont(LABEL_FONT);
2153     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
2154     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
2155     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
2156     smoothFont.setFont(LABEL_FONT);
2157     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
2158     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
2159     smoothFont.setText(MessageManager.getString("label.smooth_font"));
2160     scaleProteinToCdna.setFont(LABEL_FONT);
2161     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
2162     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
2163     scaleProteinToCdna.setText(
2164             MessageManager.getString("label.scale_protein_to_cdna"));
2165     scaleProteinToCdna.setToolTipText(
2166             MessageManager.getString("label.scale_protein_to_cdna_tip"));
2167     JLabel gapLabel = new JLabel();
2168     gapLabel.setFont(LABEL_FONT);
2169     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
2170     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
2171     JLabel fontLabel = new JLabel();
2172     fontLabel.setFont(LABEL_FONT);
2173     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
2174     fontLabel.setText(MessageManager.getString("label.font"));
2175     fontSizeCB.setFont(LABEL_FONT);
2176     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
2177     fontStyleCB.setFont(LABEL_FONT);
2178     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
2179     fontNameCB.setFont(LABEL_FONT);
2180     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
2181     gapSymbolCB.setFont(LABEL_FONT);
2182     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
2183     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
2184     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
2185     gapSymbolCB.setRenderer(dlcr);
2186
2187     startupCheckbox.setText(MessageManager.getString("action.open_file"));
2188     startupCheckbox.setFont(LABEL_FONT);
2189     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
2190     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
2191     startupCheckbox.setSelected(true);
2192     startupFileTextfield.setFont(LABEL_FONT);
2193     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
2194     final String tooltip = JvSwingUtils.wrapTooltip(true,
2195             MessageManager.getString("label.double_click_to_browse"));
2196     startupFileTextfield.setToolTipText(tooltip);
2197     startupFileTextfield.addMouseListener(new MouseAdapter()
2198     {
2199       @Override
2200       public void mouseClicked(MouseEvent e)
2201       {
2202         if (e.getClickCount() > 1)
2203         {
2204           startupFileTextfield_mouseClicked();
2205         }
2206       }
2207     });
2208
2209     sortby.setFont(LABEL_FONT);
2210     sortby.setBounds(new Rectangle(172, 260, 155, 21));
2211     JLabel sortLabel = new JLabel();
2212     sortLabel.setFont(LABEL_FONT);
2213     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
2214     sortLabel.setText(MessageManager.getString("label.sort_by"));
2215     sortAnnBy.setFont(LABEL_FONT);
2216     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
2217     JLabel sortAnnLabel = new JLabel();
2218     sortAnnLabel.setFont(LABEL_FONT);
2219     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
2220     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
2221     sortAutocalc.setFont(LABEL_FONT);
2222     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
2223
2224     JPanel annsettingsPanel = new JPanel();
2225     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
2226     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
2227     annsettingsPanel.setBorder(new EtchedBorder());
2228     visualTab.add(annsettingsPanel);
2229     Border jb = new EmptyBorder(1, 1, 4, 5);
2230     annotations.setBorder(jb);
2231     showOccupancy.setBorder(jb);
2232     quality.setBorder(jb);
2233     conservation.setBorder(jb);
2234     identity.setBorder(jb);
2235     showConsensbits.setBorder(jb);
2236     showGroupbits.setBorder(jb);
2237     showGroupConsensus.setBorder(jb);
2238     showGroupConservation.setBorder(jb);
2239     showConsensHistogram.setBorder(jb);
2240     showConsensLogo.setBorder(jb);
2241
2242     JPanel autoAnnotSettings = new JPanel();
2243     annsettingsPanel.add(autoAnnotSettings);
2244     autoAnnotSettings.setLayout(new GridLayout(0, 2));
2245     autoAnnotSettings.add(annotations);
2246     autoAnnotSettings.add(quality);
2247     // second row of autoannotation box
2248     autoAnnotSettings = new JPanel();
2249     annsettingsPanel.add(autoAnnotSettings);
2250
2251     autoAnnotSettings.setLayout(new GridLayout(0, 3));
2252     autoAnnotSettings.add(conservation);
2253     autoAnnotSettings.add(identity);
2254     autoAnnotSettings.add(showOccupancy);
2255     autoAnnotSettings.add(showGroupbits);
2256     autoAnnotSettings.add(showGroupConservation);
2257     autoAnnotSettings.add(showGroupConsensus);
2258     autoAnnotSettings.add(showConsensbits);
2259     autoAnnotSettings.add(showConsensHistogram);
2260     autoAnnotSettings.add(showConsensLogo);
2261
2262     JPanel tooltipSettings = new JPanel();
2263     tooltipSettings.setBorder(new TitledBorder(
2264             MessageManager.getString("label.sequence_id_tooltip")));
2265     tooltipSettings.setBounds(173, 140, 220, 62);
2266     tooltipSettings.setLayout(new GridLayout(2, 1));
2267     tooltipSettings.add(showDbRefTooltip);
2268     tooltipSettings.add(showNpTooltip);
2269     visualTab.add(tooltipSettings);
2270
2271     wrap.setFont(LABEL_FONT);
2272     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
2273     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
2274     wrap.setText(MessageManager.getString("label.wrap_alignment"));
2275     rightAlign.setFont(LABEL_FONT);
2276     rightAlign.setForeground(Color.black);
2277     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
2278     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
2279     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
2280     idItalics.setFont(LABEL_FONT_ITALIC);
2281     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
2282     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
2283     idItalics.setText(
2284             MessageManager.getString("label.sequence_name_italics"));
2285     openoverv.setFont(LABEL_FONT);
2286     openoverv.setActionCommand(
2287             MessageManager.getString("label.open_overview"));
2288     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
2289     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
2290     openoverv.setText(MessageManager.getString("label.open_overview"));
2291     JPanel jPanel2 = new JPanel();
2292     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
2293     jPanel2.setLayout(new GridLayout(14, 1));
2294     jPanel2.add(fullScreen);
2295     jPanel2.add(openoverv);
2296     jPanel2.add(seqLimit);
2297     jPanel2.add(rightAlign);
2298     jPanel2.add(fontLabel);
2299     jPanel2.add(showUnconserved);
2300     jPanel2.add(idItalics);
2301     jPanel2.add(smoothFont);
2302     jPanel2.add(scaleProteinToCdna);
2303     jPanel2.add(gapLabel);
2304     jPanel2.add(wrap);
2305     jPanel2.add(sortLabel);
2306     jPanel2.add(sortAnnLabel);
2307     jPanel2.add(startupCheckbox);
2308     visualTab.add(jPanel2);
2309     visualTab.add(startupFileTextfield);
2310     visualTab.add(sortby);
2311     visualTab.add(sortAnnBy);
2312     visualTab.add(sortAutocalc);
2313     visualTab.add(gapSymbolCB);
2314     visualTab.add(fontNameCB);
2315     visualTab.add(fontSizeCB);
2316     visualTab.add(fontStyleCB);
2317
2318     
2319     if (Platform.isJS())
2320     {
2321       startupCheckbox.setVisible(false);
2322       startupFileTextfield.setVisible(false);
2323     }
2324
2325     
2326     return visualTab;
2327   }
2328
2329   /**
2330    * Load the saved Backups options EXCEPT "Enabled" and "Scheme"
2331    */
2332
2333   protected void loadLastSavedBackupsOptions()
2334   {
2335     BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
2336             .getSavedBackupEntry();
2337     enableBackupFiles
2338             .setSelected(Cache.getDefault(BackupFiles.ENABLED, !Platform.isJS()));
2339
2340     BackupFilesPresetEntry backupfilesCustomEntry = BackupFilesPresetEntry
2341             .createBackupFilesPresetEntry(Cache
2342                     .getDefault(BackupFilesPresetEntry.CUSTOMCONFIG, null));
2343     if (backupfilesCustomEntry == null)
2344     {
2345       backupfilesCustomEntry = BackupFilesPresetEntry.backupfilesPresetEntriesValues
2346               .get(BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT);
2347     }
2348     BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
2349             BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM,
2350             backupfilesCustomEntry);
2351
2352     setComboIntStringKey(backupfilesPresetsCombo,
2353             Cache.getDefault(BackupFiles.NS + "_PRESET",
2354                     BackupFilesPresetEntry.BACKUPFILESSCHEMEDEFAULT));
2355
2356     backupsSetOptions(savedPreset);
2357
2358     backupsOptionsSetEnabled();
2359     updateBackupFilesExampleLabel();
2360   }
2361
2362   /*
2363    * Load the saved Memory settings
2364    */
2365   protected void loadLastSavedMemorySettings()
2366   {
2367     customiseMemorySetting.setSelected(
2368             Cache.getDefault(MemorySetting.CUSTOMISED_SETTINGS, false));
2369     jvmMemoryPercentSlider
2370             .setValue(Cache.getDefault(MemorySetting.MEMORY_JVMMEMPC, 90));
2371     jvmMemoryMaxTextField.setText(
2372             Cache.getDefault(MemorySetting.MEMORY_JVMMEMMAX, "32g"));
2373   }
2374   private boolean warnAboutSuffixReverseChange()
2375   {
2376     BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
2377             .getSavedBackupEntry();
2378     boolean savedSuffixReverse = bfpe.reverse;
2379     int savedSuffixDigits = bfpe.digits;
2380     String savedSuffixTemplate = bfpe.suffix;
2381
2382     boolean nowSuffixReverse = suffixReverse.isSelected();
2383     int nowSuffixDigits = getSpinnerInt(suffixDigitsSpinner, 3);
2384     String nowSuffixTemplate = suffixTemplate.getText();
2385     return nowSuffixReverse != savedSuffixReverse
2386             && nowSuffixDigits == savedSuffixDigits
2387             && nowSuffixTemplate != null
2388             && nowSuffixTemplate.equals(savedSuffixTemplate);
2389   }
2390
2391   /* Initialises the Startup tabbed panel.
2392    * 
2393    * @return
2394    * */
2395
2396   private JPanel initStartupTab()
2397   {
2398     JPanel startupTab = new JPanel();
2399     startupTab.setBorder(
2400             new TitledBorder(MessageManager.getString("label.memory")));
2401     startupTab.setLayout(new GridBagLayout());
2402
2403     GridBagConstraints gbc = new GridBagConstraints();
2404     gbc.weightx = 0.0;
2405     gbc.weighty = 0.0;
2406     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2407     gbc.fill = GridBagConstraints.NONE;
2408
2409     initMemoryPanel();
2410
2411     gbc.gridheight = 1;
2412     gbc.gridwidth = 3;
2413
2414     gbc.gridy = 0; // row 1
2415     gbc.gridx = 0;
2416     JLabel memoryText = new JLabel();
2417     memoryText.setFont(LABEL_FONT_ITALIC);
2418     memoryText
2419             .setText(MessageManager.getString("label.memory_setting_text"));
2420     startupTab.add(memoryText, gbc);
2421
2422     gbc.gridy++; // row 2
2423     gbc.gridx = 0;
2424     JPanel exampleMemoryPanel = new JPanel();
2425     exampleMemoryPanel
2426             .setLayout(new BoxLayout(exampleMemoryPanel, BoxLayout.Y_AXIS));
2427     exampleMemoryPanel.setToolTipText(JvSwingUtils.wrapTooltip(true,
2428             MessageManager.getString("label.memory_example_tooltip")));
2429     JLabel exampleTextLabel = new JLabel();
2430     exampleTextLabel
2431             .setText(MessageManager.getString("label.memory_example_text"));
2432     exampleTextLabel.setForeground(Color.GRAY);
2433     exampleTextLabel.setFont(LABEL_FONT);
2434     exampleMemoryPanel.add(exampleTextLabel);
2435     exampleMemoryPanel.add(exampleMemoryLabel);
2436     exampleMemoryPanel.setBackground(Color.WHITE);
2437     exampleMemoryPanel.setBorder(BorderFactory.createEtchedBorder());
2438     startupTab.add(exampleMemoryPanel, gbc);
2439
2440     gbc.gridy++; // row 3
2441     gbc.gridx = 0;
2442     startupTab.add(customiseMemorySetting, gbc);
2443
2444     gbc.gridy += 2; // row 4 with a gap
2445     gbc.gridx = 0;
2446     startupTab.add(maxMemoryLabel, gbc);
2447
2448     gbc.gridy += 2; // row 5
2449     gbc.gridx = 0;
2450     gbc.gridwidth = 1;
2451     startupTab.add(jvmMemoryPercentLabel, gbc);
2452     gbc.gridx++;
2453     startupTab.add(jvmMemoryPercentSlider, gbc);
2454     gbc.gridx++;
2455     // gbc.weightx = 0.1;
2456     startupTab.add(jvmMemoryPercentDisplay, gbc);
2457     // gbc.weightx = 1.0;
2458     gbc.gridwidth = 3;
2459
2460     gbc.gridy++; // row 6
2461     gbc.gridx = 0;
2462     startupTab.add(jvmMemoryMaxLabel, gbc);
2463     gbc.gridx++;
2464     startupTab.add(jvmMemoryMaxTextField, gbc);
2465
2466     gbc.gridy++; // row 7
2467     gbc.gridx = 0;
2468     gbc.gridwidth = 4;
2469     exampleMemoryMessageTextArea.setBackground(startupTab.getBackground());
2470     JScrollPane sp = new JScrollPane(exampleMemoryMessageTextArea);
2471     sp.setBorder(BorderFactory.createEmptyBorder());
2472     sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
2473     sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
2474     startupTab.add(sp, gbc);
2475
2476     // fill empty space to push widget to top left
2477     gbc.gridy++;
2478     gbc.weighty = 1.0;
2479     gbc.gridx = 100;
2480     gbc.gridwidth = 1;
2481     gbc.weightx = 1.0;
2482     startupTab.add(new JPanel(), gbc);
2483
2484     setMemoryPercentDisplay();
2485     memoryOptionsSetEnabled();
2486     return startupTab;
2487   }
2488
2489   private void initMemoryPanel()
2490   {
2491     // Enable memory settings checkbox
2492     customiseMemorySetting.setFont(LABEL_FONT_BOLD);
2493     customiseMemorySetting.setText(
2494             MessageManager.getString("label.customise_memory_settings"));
2495     customiseMemorySetting.addActionListener(new ActionListener()
2496     {
2497       @Override
2498       public void actionPerformed(ActionEvent e)
2499       {
2500         memoryOptionsSetEnabled();
2501       }
2502     });
2503
2504     loadLastSavedMemorySettings();
2505
2506     exampleMemoryLabel.setFont(LABEL_FONT_BOLD);
2507     exampleMemoryLabel.setBackground(Color.WHITE);
2508
2509     maxMemoryLabel = new JLabel(
2510             MessageManager.getString("label.maximum_memory_used"));
2511     maxMemoryLabel.setFont(LABEL_FONT_BOLD);
2512
2513     // Maximum memory percentage slider
2514     jvmMemoryPercentLabel.setFont(LABEL_FONT);
2515     jvmMemoryPercentLabel.setText(
2516             MessageManager.getString("label.percent_of_physical_memory"));
2517     jvmMemoryPercentSlider.setPaintLabels(true);
2518     jvmMemoryPercentSlider.setPaintTicks(true);
2519     jvmMemoryPercentSlider.setPaintTrack(true);
2520     jvmMemoryPercentSlider.setMajorTickSpacing(50);
2521     jvmMemoryPercentSlider.setMinorTickSpacing(10);
2522     jvmMemoryPercentSlider.addChangeListener(new ChangeListener()
2523     {
2524       @Override
2525       public void stateChanged(ChangeEvent e)
2526       {
2527         setMemoryPercentDisplay();
2528       }
2529     });
2530     jvmMemoryPercentDisplay.setFont(LABEL_FONT);
2531     setMemoryPercentDisplay();
2532
2533     // Maximum memory cap textbox
2534     jvmMemoryMaxLabel.setFont(LABEL_FONT);
2535     jvmMemoryMaxLabel
2536             .setText(MessageManager.getString("label.maximum_memory"));
2537     initMemoryMaxTextField();
2538
2539     exampleMemoryMessageTextArea.setFont(LABEL_FONT_ITALIC);
2540     exampleMemoryMessageTextArea.setForeground(Color.GRAY);
2541     exampleMemoryMessageTextArea.setEditable(false);
2542     exampleMemoryMessageTextArea.setLineWrap(true);
2543     exampleMemoryMessageTextArea.setWrapStyleWord(true);
2544     exampleMemoryMessageTextArea.setText(" ");
2545     exampleMemoryMessageTextArea.setRows(2);
2546     exampleMemoryMessageTextArea.setColumns(40);
2547
2548     setExampleMemoryLabel();
2549   }
2550
2551   private void initMemoryMaxTextField()
2552   {
2553     jvmMemoryMaxTextField.setToolTipText(
2554             MessageManager.getString("label.maximum_memory_tooltip"));
2555     jvmMemoryMaxTextField.addActionListener(new ActionListener()
2556     {
2557       @Override
2558       public void actionPerformed(ActionEvent arg0)
2559       {
2560         validateMemoryMaxTextField();
2561         setExampleMemoryLabel();
2562       }
2563     });
2564
2565     jvmMemoryMaxTextField.addKeyListener(new KeyListener()
2566     {
2567       @Override
2568       public void keyReleased(KeyEvent e)
2569       {
2570         validateMemoryMaxTextField();
2571         setExampleMemoryLabel();
2572       }
2573
2574       @Override
2575       public void keyPressed(KeyEvent e)
2576       {
2577       }
2578
2579       // try and stop invalid typing
2580       @Override
2581       public void keyTyped(KeyEvent e)
2582       {
2583         char c = Character.toLowerCase(e.getKeyChar());
2584         String text = jvmMemoryMaxTextField.getText();
2585         String suffixes = "tgmkb";
2586         int pos = jvmMemoryMaxTextField.getCaretPosition();
2587         int suffixPos = StringUtils.firstCharPosIgnoreCase(text, suffixes);
2588         if (!((('0' <= c && c <= '9')
2589                 && (suffixPos == -1 || pos <= suffixPos)) // digits only allowed
2590                 // before suffix
2591                 || (suffixes.indexOf(Character.toLowerCase(c)) >= 0 // valid
2592                                                                     // suffix
2593                         && pos == text.length() // at end of text and
2594                         && suffixPos == -1) // there isn't already one
2595         ))
2596         {
2597           // don't process
2598           e.consume();
2599         }
2600       }
2601     });
2602   }
2603
2604   private boolean isMemoryMaxTextFieldValid()
2605   {
2606     return MemorySetting
2607             .isValidMemoryString(jvmMemoryMaxTextField.getText());
2608   }
2609
2610   private void validateMemoryMaxTextField()
2611   {
2612     if (isMemoryMaxTextFieldValid())
2613     {
2614       jvmMemoryMaxTextField.setBackground(Color.WHITE);
2615     }
2616     else
2617     {
2618       jvmMemoryMaxTextField.setBackground(Color.PINK);
2619     }
2620   }
2621
2622   private void setMemoryPercentDisplay()
2623   {
2624     jvmMemoryPercentDisplay
2625             .setText(jvmMemoryPercentSlider.getValue() + "%");
2626     setExampleMemoryLabel();
2627   }
2628
2629   private void setExampleMemoryLabel()
2630   {
2631     boolean selected = customiseMemorySetting.isSelected();
2632     int jvmmempc = jvmMemoryPercentSlider.getValue();
2633     String jvmmemmax = jvmMemoryMaxTextField.getText();
2634
2635     long mem;
2636     if (selected && (0 <= jvmmempc && jvmmempc <= 100)
2637             && MemorySetting.isValidMemoryString(jvmmemmax))
2638     {
2639       mem = MemorySetting.getMemorySetting(jvmmemmax,
2640               String.valueOf(jvmmempc), false, true);
2641     }
2642     else
2643     {
2644       mem = MemorySetting.getMemorySetting(null, null, false, true);
2645     }
2646     exampleMemoryLabel.setText(MemorySetting.memoryLongToString(mem));
2647     String message = MemorySetting.getAdjustmentMessage();
2648     exampleMemoryMessageTextArea.setText(
2649             MessageManager.getString("label.adjustments_for_this_computer")
2650                     + ": "
2651                     + (message == null
2652                             ? MessageManager.getString("label.none")
2653                             : message));
2654   }
2655
2656   private void memoryOptionsSetEnabled()
2657   {
2658     boolean enabled = customiseMemorySetting.isSelected();
2659     // leave exampleMemoryLabel enabled always
2660     maxMemoryLabel.setEnabled(enabled);
2661     jvmMemoryPercentLabel.setEnabled(enabled);
2662     jvmMemoryPercentSlider.setEnabled(enabled);
2663     jvmMemoryPercentDisplay.setEnabled(enabled);
2664     jvmMemoryMaxLabel.setEnabled(enabled);
2665     jvmMemoryMaxTextField.setEnabled(enabled);
2666     exampleMemoryMessageTextArea.setEnabled(enabled);
2667     setExampleMemoryLabel();
2668   }
2669
2670   /**
2671    * Initialises the Backups tabbed panel.
2672    * 
2673    * @return
2674    */
2675   private JPanel initBackupsTab()
2676   {
2677     JPanel backupsTab = new JPanel();
2678     backupsTab.setBorder(new TitledBorder(
2679             MessageManager.getString("label.backup_files")));
2680     backupsTab.setLayout(new GridBagLayout());
2681
2682     GridBagConstraints gbc = new GridBagConstraints();
2683     gbc.weightx = 0.0;
2684     gbc.weighty = 0.0;
2685     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2686     gbc.fill = GridBagConstraints.NONE;
2687
2688     initBackupsTabPresetsPanel();
2689     initBackupsTabSuffixPanel();
2690     initBackupsTabKeepFilesPanel();
2691     initBackupsTabFilenameExamplesPanel();
2692
2693     enableBackupFiles.setFont(LABEL_FONT_BOLD);
2694     enableBackupFiles
2695             .setText(MessageManager.getString("label.enable_backupfiles"));
2696     enableBackupFiles.addActionListener(new ActionListener()
2697     {
2698       @Override
2699       public void actionPerformed(ActionEvent e)
2700       {
2701         // enable other options only when the first is checked
2702         backupsOptionsSetEnabled();
2703       }
2704     });
2705
2706     // enable checkbox 1 col
2707     gbc.gridwidth = 1;
2708     gbc.gridheight = 1;
2709     gbc.gridx = 0;
2710     gbc.gridy = 0; // row 0
2711     backupsTab.add(enableBackupFiles, gbc);
2712
2713     // summary of scheme box (over two rows)
2714     gbc.gridx = 1;
2715     gbc.weightx = 0.0;
2716     gbc.gridheight = 2;
2717     gbc.anchor = GridBagConstraints.FIRST_LINE_END;
2718     gbc.fill = GridBagConstraints.BOTH;
2719     backupsTab.add(exampleFilesPanel, gbc);
2720     gbc.gridheight = 1;
2721     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2722     gbc.fill = GridBagConstraints.NONE;
2723
2724     // fill empty space on right
2725     gbc.gridx++;
2726     gbc.weightx = 1.0;
2727     backupsTab.add(new JPanel(), gbc);
2728
2729     // schemes box
2730     gbc.weightx = 0.0;
2731     gbc.gridx = 0;
2732     gbc.gridy++; // row 1
2733     backupsTab.add(presetsPanel, gbc);
2734
2735     // now using whole row
2736     gbc.gridwidth = 2;
2737     gbc.gridheight = 1;
2738     // keep files box
2739     gbc.gridx = 0;
2740     gbc.gridy++; // row 2
2741     backupsTab.add(keepfilesPanel, gbc);
2742
2743     // filename strategy box
2744     gbc.gridy++; // row 3
2745     backupsTab.add(suffixPanel, gbc);
2746
2747     // fill empty space
2748     gbc.gridy++; // row 4
2749     gbc.weighty = 1.0;
2750     backupsTab.add(new JPanel(), gbc);
2751
2752     backupsOptionsSetEnabled();
2753     return backupsTab;
2754   }
2755
2756   private JPanel initBackupsTabPresetsPanel()
2757   {
2758
2759     String title = MessageManager.getString("label.schemes");
2760
2761     presetsPanel.setLayout(new GridBagLayout());
2762
2763     GridBagConstraints gbc = new GridBagConstraints();
2764     gbc.weightx = 0.0;
2765     gbc.weighty = 0.0;
2766     gbc.anchor = GridBagConstraints.BASELINE_LEADING;
2767     gbc.fill = GridBagConstraints.NONE;
2768     gbc.gridwidth = 1;
2769     gbc.gridheight = 1;
2770
2771     // "Scheme: "
2772     gbc.gridx = 0;
2773     gbc.gridy = 0;
2774
2775     presetsComboLabel = new JLabel(title + ":");
2776     presetsPanel.add(presetsComboLabel, gbc);
2777
2778     List<Object> entries = Arrays
2779             .asList((Object[]) BackupFilesPresetEntry.backupfilesPresetEntries);
2780     List<String> tooltips = Arrays.asList(
2781             BackupFilesPresetEntry.backupfilesPresetEntryDescriptions);
2782     backupfilesPresetsCombo = JvSwingUtils.buildComboWithTooltips(entries,
2783             tooltips);
2784     /*
2785     for (int i = 0; i < BackupFilesPresetEntry.backupfilesPresetEntries.length; i++)
2786     {
2787       backupfilesPresetsCombo
2788               .addItem(BackupFilesPresetEntry.backupfilesPresetEntries[i]);
2789     }
2790     */
2791
2792     backupfilesPresetsCombo.addActionListener(new ActionListener()
2793     {
2794       @Override
2795       public void actionPerformed(ActionEvent e)
2796       {
2797         int key = getComboIntStringKey(backupfilesPresetsCombo);
2798         if (!customiseCheckbox.isSelected())
2799         {
2800           backupfilesPresetsComboLastSelected = key;
2801         }
2802         if (key == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
2803         {
2804           if (customiseCheckbox.isSelected())
2805           {
2806             // got here by clicking on customiseCheckbox so don't change the values
2807             backupfilesCustomOptionsSetEnabled();
2808           }
2809           else
2810           {
2811             backupsTabUpdatePresets();
2812             backupfilesCustomOptionsSetEnabled();
2813           }
2814         }
2815         else
2816         {
2817           customiseCheckbox.setSelected(false);
2818           backupsTabUpdatePresets();
2819           backupfilesCustomOptionsSetEnabled();
2820         }
2821       }
2822     });
2823
2824     // dropdown list of preset schemes
2825     gbc.gridx = 1;
2826     presetsPanel.add(backupfilesPresetsCombo, gbc);
2827
2828     revertButton.setText(MessageManager.getString("label.cancel_changes"));
2829     revertButton.setToolTipText(
2830             MessageManager.getString("label.cancel_changes_description"));
2831     revertButton.addActionListener(new ActionListener()
2832     {
2833       @Override
2834       public void actionPerformed(ActionEvent e)
2835       {
2836         backupsSetOptions(
2837                 BackupFilesPresetEntry.backupfilesPresetEntriesValues.get(
2838                         BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM));
2839         backupfilesCustomOptionsSetEnabled();
2840       }
2841
2842     });
2843     revertButton.setFont(LABEL_FONT);
2844
2845     customiseCheckbox.setFont(LABEL_FONT);
2846     customiseCheckbox.setText(MessageManager.getString("label.customise"));
2847     customiseCheckbox.addActionListener(new ActionListener()
2848     {
2849       @Override
2850       public void actionPerformed(ActionEvent e)
2851       {
2852         int currently = getComboIntStringKey(backupfilesPresetsCombo);
2853         if (customiseCheckbox.isSelected())
2854         {
2855           backupfilesPresetsComboLastSelected = currently;
2856           setComboIntStringKey(backupfilesPresetsCombo,
2857                   BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
2858         }
2859         else
2860         {
2861           setComboIntStringKey(backupfilesPresetsCombo,
2862                   backupfilesPresetsComboLastSelected);
2863
2864         }
2865         backupfilesCustomOptionsSetEnabled();
2866       }
2867     });
2868     customiseCheckbox.setToolTipText(
2869             MessageManager.getString("label.customise_description"));
2870
2871     // customise checkbox
2872     gbc.gridx = 0;
2873     gbc.gridy++;
2874     presetsPanel.add(customiseCheckbox, gbc);
2875
2876     // "Cancel changes" button (aligned with combo box above)
2877     gbc.gridx = 1;
2878     presetsPanel.add(revertButton, gbc);
2879
2880     return presetsPanel;
2881   }
2882
2883   private JPanel initBackupsTabFilenameExamplesPanel()
2884   {
2885     String title = MessageManager
2886             .getString("label.scheme_examples");
2887     TitledBorder tb = new TitledBorder(title);
2888     exampleFilesPanel.setBorder(tb);
2889     exampleFilesPanel.setLayout(new GridBagLayout());
2890
2891     backupfilesExampleLabel.setEditable(false);
2892     backupfilesExampleLabel
2893             .setBackground(exampleFilesPanel.getBackground());
2894
2895     updateBackupFilesExampleLabel();
2896
2897     GridBagConstraints gbc = new GridBagConstraints();
2898     gbc.weightx = 1.0;
2899     gbc.weighty = 1.0;
2900     gbc.fill = GridBagConstraints.NONE;
2901     gbc.anchor = GridBagConstraints.FIRST_LINE_START;
2902
2903     exampleFilesPanel.add(backupfilesExampleLabel, gbc);
2904     return exampleFilesPanel;
2905   }
2906
2907   private void backupsTabUpdatePresets()
2908   {
2909     IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo
2910             .getSelectedItem();
2911     int key = entry.k;
2912     String value = entry.v;
2913
2914     if (BackupFilesPresetEntry.backupfilesPresetEntriesValues
2915             .containsKey(key))
2916     {
2917       backupsSetOptions(
2918               BackupFilesPresetEntry.backupfilesPresetEntriesValues
2919                       .get(key));
2920     }
2921     else
2922     {
2923       Console.error(
2924               "Preset '" + value + "' [key:" + key + "] not implemented");
2925     }
2926
2927     // Custom options will now be enabled when the customiseCheckbox is checked
2928     // (performed above)
2929     // backupfilesCustomOptionsSetEnabled();
2930     updateBackupFilesExampleLabel();
2931   }
2932
2933   protected int getComboIntStringKey(
2934           JComboBox<Object> backupfilesPresetsCombo2)
2935   {
2936     IntKeyStringValueEntry e;
2937     try
2938     {
2939       e = (IntKeyStringValueEntry) backupfilesPresetsCombo2
2940               .getSelectedItem();
2941     } catch (Exception ex)
2942     {
2943       Console.error(
2944               "Problem casting Combo entry to IntKeyStringValueEntry.");
2945       e = null;
2946     }
2947     return e != null ? e.k : 0;
2948   }
2949
2950   protected void setComboIntStringKey(
2951           JComboBox<Object> backupfilesPresetsCombo2,
2952           int key)
2953   {
2954     for (int i = 0; i < backupfilesPresetsCombo2.getItemCount(); i++)
2955     {
2956       IntKeyStringValueEntry e;
2957       try
2958       {
2959         e = (IntKeyStringValueEntry) backupfilesPresetsCombo2.getItemAt(i);
2960       } catch (Exception ex)
2961       {
2962         Console.error(
2963                 "Problem casting Combo entry to IntKeyStringValueEntry. Skipping item. ");
2964         continue;
2965       }
2966       if (e.k == key)
2967       {
2968         backupfilesPresetsCombo2.setSelectedIndex(i);
2969         break;
2970       }
2971     }
2972     // backupsTabUpdatePresets();
2973   }
2974
2975   private JPanel initBackupsTabSuffixPanel()
2976   {
2977     suffixPanel.setBorder(new TitledBorder(
2978             MessageManager.getString("label.backup_filename_strategy")));
2979     suffixPanel.setLayout(new GridBagLayout());
2980
2981     suffixTemplateLabel
2982             .setText(MessageManager.getString("label.append_to_filename"));
2983     suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
2984     suffixTemplateLabel.setFont(LABEL_FONT);
2985
2986     final String tooltip = JvSwingUtils.wrapTooltip(true,
2987             MessageManager.getString("label.append_to_filename_tooltip"));
2988     suffixTemplate.setToolTipText(tooltip);
2989     suffixTemplate.addActionListener(new ActionListener()
2990     {
2991       @Override
2992       public void actionPerformed(ActionEvent e)
2993       {
2994         updateBackupFilesExampleLabel();
2995         backupfilesCustomOptionsSetEnabled();
2996         backupfilesRevertButtonSetEnabled(true);
2997       }
2998
2999     });
3000     suffixTemplate.addKeyListener(new KeyListener()
3001     {
3002       @Override
3003       public void keyReleased(KeyEvent e)
3004       {
3005         updateBackupFilesExampleLabel();
3006         backupfilesCustomOptionsSetEnabled();
3007         backupfilesRevertButtonSetEnabled(true);
3008       }
3009
3010       @Override
3011       public void keyPressed(KeyEvent e)
3012       {
3013       }
3014
3015       // disable use of ':' or '/' or '\'
3016       @Override
3017       public void keyTyped(KeyEvent e)
3018       {
3019         char c = e.getKeyChar();
3020         if (c == ':' || c == '/' || c == '\\')
3021         {
3022           // don't process ':' or '/' or '\'
3023           e.consume();
3024         }
3025       }
3026
3027     });
3028
3029     // digits spinner
3030     suffixDigitsLabel
3031             .setText(MessageManager.getString("label.index_digits"));
3032     suffixDigitsLabel.setHorizontalAlignment(SwingConstants.LEFT);
3033     suffixDigitsLabel.setFont(LABEL_FONT);
3034     ChangeListener c = new ChangeListener()
3035     {
3036       @Override
3037       public void stateChanged(ChangeEvent e)
3038       {
3039         backupfilesRevertButtonSetEnabled(true);
3040         updateBackupFilesExampleLabel();
3041       }
3042
3043     };
3044     setIntegerSpinner(suffixDigitsSpinner, BackupFilesPresetEntry.DIGITSMIN,
3045             BackupFilesPresetEntry.DIGITSMAX, 3, c);
3046
3047     suffixReverse.setLabels(MessageManager.getString("label.reverse_roll"),
3048             MessageManager.getString("label.increment_index"));
3049     suffixReverse.addActionListener(new ActionListener()
3050     {
3051       @Override
3052       public void actionPerformed(ActionEvent e)
3053       {
3054         boolean okay = true;
3055         if (warnAboutSuffixReverseChange())
3056         {
3057           // Warning popup
3058           okay = confirmSuffixReverseChange();
3059         }
3060         if (okay)
3061         {
3062           backupfilesRevertButtonSetEnabled(true);
3063           updateBackupFilesExampleLabel();
3064         }
3065         else
3066         {
3067           boolean savedSuffixReverse = BackupFilesPresetEntry
3068                   .getSavedBackupEntry().reverse;
3069           suffixReverse.setSelected(savedSuffixReverse);
3070         }
3071       }
3072     });
3073
3074     GridBagConstraints sgbc = new GridBagConstraints();
3075
3076     // first row (template text box)
3077     sgbc.anchor = GridBagConstraints.WEST;
3078     sgbc.gridx = 0;
3079     sgbc.gridy = 0;
3080     sgbc.gridwidth = 1;
3081     sgbc.gridheight = 1;
3082     sgbc.weightx = 1.0;
3083     sgbc.weighty = 0.0;
3084     sgbc.fill = GridBagConstraints.NONE;
3085     suffixPanel.add(suffixTemplateLabel, sgbc);
3086
3087     sgbc.gridx = 1;
3088     sgbc.fill = GridBagConstraints.HORIZONTAL;
3089     suffixPanel.add(suffixTemplate, sgbc);
3090
3091     // second row (number of digits spinner)
3092     sgbc.gridy = 1;
3093
3094     sgbc.gridx = 0;
3095     sgbc.fill = GridBagConstraints.NONE;
3096     suffixPanel.add(suffixDigitsLabel, sgbc);
3097
3098     sgbc.gridx = 1;
3099     sgbc.fill = GridBagConstraints.HORIZONTAL;
3100     suffixPanel.add(suffixDigitsSpinner, sgbc);
3101
3102     // third row (forward order radio selection)
3103     sgbc.gridx = 0;
3104     sgbc.gridy = 2;
3105     sgbc.gridwidth = GridBagConstraints.REMAINDER;
3106     sgbc.fill = GridBagConstraints.HORIZONTAL;
3107     suffixPanel.add(suffixReverse.getFalseButton(), sgbc);
3108
3109     // fourth row (reverse order radio selection)
3110     sgbc.gridy = 3;
3111     suffixPanel.add(suffixReverse.getTrueButton(), sgbc);
3112     return suffixPanel;
3113   }
3114
3115   private boolean confirmSuffixReverseChange()
3116   {
3117     boolean ret = false;
3118     String warningMessage = MessageManager
3119             .getString("label.warning_confirm_change_reverse");
3120     int confirm = JvOptionPane.showConfirmDialog(Desktop.getDesktopPane(),
3121             warningMessage,
3122             MessageManager.getString("label.change_increment_decrement"),
3123             JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE);
3124
3125     ret = (confirm == JvOptionPane.YES_OPTION);
3126     return ret;
3127   }
3128
3129   private JPanel initBackupsTabKeepFilesPanel()
3130   {
3131     keepfilesPanel.setBorder(
3132             new TitledBorder(MessageManager.getString("label.keep_files")));
3133     keepfilesPanel.setLayout(new GridBagLayout());
3134
3135     backupfilesKeepAll.setLabels(
3136             MessageManager.getString("label.keep_all_backup_files"),
3137             MessageManager.getString(
3138                     "label.keep_only_this_number_of_backup_files"));
3139     backupfilesKeepAll.addTrueActionListener(new ActionListener()
3140     {
3141       @Override
3142       public void actionPerformed(ActionEvent e)
3143       {
3144         backupfilesRevertButtonSetEnabled(true);
3145         updateBackupFilesExampleLabel();
3146       }
3147     });
3148     backupfilesKeepAll.addActionListener(new ActionListener()
3149     {
3150       @Override
3151       public void actionPerformed(ActionEvent e)
3152       {
3153         backupfilesRevertButtonSetEnabled(true);
3154         keepRollMaxOptionsEnabled();
3155         updateBackupFilesExampleLabel();
3156       }
3157     });
3158
3159     ChangeListener c = new ChangeListener()
3160     {
3161       @Override
3162       public void stateChanged(ChangeEvent e)
3163       {
3164         backupfilesRevertButtonSetEnabled(true);
3165         updateBackupFilesExampleLabel();
3166       }
3167
3168     };
3169     setIntegerSpinner(backupfilesRollMaxSpinner,
3170             BackupFilesPresetEntry.ROLLMAXMIN,
3171             BackupFilesPresetEntry.ROLLMAXMAX, 4, true, c);
3172
3173     backupfilesConfirmDelete.setLabels(
3174             MessageManager.getString("label.always_ask"),
3175             MessageManager.getString("label.auto_delete"));
3176     backupfilesConfirmDelete.addActionListener(new ActionListener()
3177     {
3178       @Override
3179       public void actionPerformed(ActionEvent e)
3180       {
3181         backupfilesRevertButtonSetEnabled(true);
3182       }
3183     });
3184     // update the enabled section
3185     keepRollMaxOptionsEnabled();
3186
3187     GridBagConstraints kgbc = new GridBagConstraints();
3188
3189     // first row (template text box)
3190     kgbc.anchor = GridBagConstraints.WEST;
3191     kgbc.gridx = 0;
3192     kgbc.gridy = 0;
3193     kgbc.gridwidth = GridBagConstraints.REMAINDER;
3194     kgbc.gridheight = 1;
3195     kgbc.weightx = 1.0;
3196     kgbc.weighty = 0.0;
3197     kgbc.fill = GridBagConstraints.HORIZONTAL;
3198     keepfilesPanel.add(backupfilesKeepAll.getTrueButton(), kgbc);
3199
3200     // second row
3201     kgbc.gridy = 1;
3202
3203     kgbc.gridx = 0;
3204     kgbc.gridwidth = GridBagConstraints.RELATIVE;
3205     keepfilesPanel.add(backupfilesKeepAll.getFalseButton(), kgbc);
3206
3207     kgbc.gridx = 1;
3208     kgbc.gridwidth = GridBagConstraints.REMAINDER;
3209     keepfilesPanel.add(backupfilesRollMaxSpinner, kgbc);
3210
3211     // third row (indented)
3212     kgbc.gridy = 2;
3213     kgbc.insets = new Insets(0, 20, 0, 0);
3214
3215     kgbc.gridx = 0;
3216     kgbc.gridwidth = GridBagConstraints.REMAINDER;
3217     kgbc.fill = GridBagConstraints.HORIZONTAL;
3218     kgbc.weightx = 1.0;
3219
3220     JPanel jp = new JPanel();
3221     jp.setLayout(new FlowLayout());
3222     oldBackupFilesLabel
3223             .setText(MessageManager
3224                     .getString("label.autodelete_old_backup_files"));
3225     oldBackupFilesLabel.setFont(LABEL_FONT);
3226     oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
3227     jp.add(oldBackupFilesLabel);
3228     jp.add(backupfilesConfirmDelete.getTrueButton());
3229     jp.add(backupfilesConfirmDelete.getFalseButton());
3230     keepfilesPanel.add(jp, kgbc);
3231
3232     return keepfilesPanel;
3233   }
3234
3235   protected void updateBackupFilesExampleLabel()
3236   {
3237     int exampleindex = 12;
3238     String base = MessageManager.getString("label.filename") + ".fa";
3239     if (base == null || base.length() == 0)
3240     {
3241       base = "file_name.fa";
3242     }
3243
3244     boolean reverse = suffixReverse.isSelected();
3245     boolean keepAll = backupfilesKeepAll.isSelected();
3246     int rollMax = 4;
3247     String suffix = suffixTemplate.getText();
3248     int digits = 3;
3249
3250     backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
3251     if (suffix == null || suffix.length() == 0)
3252     {
3253       backupfilesExampleLabel
3254               .setText(MessageManager.getString("label.no_backup_files"));
3255       backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
3256       return;
3257     }
3258
3259     rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 4);
3260     rollMax = rollMax < 1 ? 1 : rollMax;
3261
3262     if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
3263     {
3264       rollMax = 1;
3265     }
3266
3267     digits = getSpinnerInt(suffixDigitsSpinner, 3);
3268     digits = digits < 1 ? 1 : digits;
3269
3270     int lowersurround = 2;
3271     int uppersurround = 0;
3272     StringBuilder exampleSB = new StringBuilder();
3273     boolean firstLine = true;
3274     int lineNumber = 0;
3275     if (reverse)
3276     {
3277
3278       int min = 1;
3279       int max = keepAll ? exampleindex : rollMax;
3280       for (int index = min; index <= max; index++)
3281       {
3282         if (index == min + lowersurround && index < max - uppersurround - 1)
3283         {
3284           exampleSB.append("\n...");
3285           lineNumber++;
3286         }
3287         else if (index > min + lowersurround && index < max - uppersurround)
3288         {
3289           // nothing
3290         }
3291         else
3292         {
3293           if (firstLine)
3294           {
3295             firstLine = false;
3296           }
3297           else
3298           {
3299             exampleSB.append("\n");
3300             lineNumber++;
3301           }
3302           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
3303                   base, suffix, digits));
3304           if (min == max)
3305           {
3306             // no extra text needed
3307           }
3308           else if (index == min)
3309           {
3310             String newest = MessageManager.getString("label.braced_newest");
3311             if (newest != null && newest.length() > 0)
3312             {
3313               exampleSB.append(" " + newest);
3314             }
3315           }
3316           else if (index == max)
3317           {
3318             String oldest = MessageManager.getString("label.braced_oldest");
3319             if (oldest != null && oldest.length() > 0)
3320             {
3321               exampleSB.append(" " + oldest);
3322             }
3323           }
3324         }
3325       }
3326     }
3327     else
3328     {
3329
3330       int min = (keepAll || exampleindex - rollMax < 0) ? 1
3331               : exampleindex - rollMax + 1;
3332       int max = exampleindex;
3333
3334       for (int index = min; index <= max; index++)
3335       {
3336
3337         if (index == min + lowersurround && index < max - uppersurround - 1)
3338         {
3339           exampleSB.append("\n...");
3340           lineNumber++;
3341         }
3342         else if (index > min + lowersurround && index < max - uppersurround)
3343         {
3344           // nothing
3345         }
3346         else
3347         {
3348           if (firstLine)
3349           {
3350             firstLine = false;
3351           }
3352           else
3353           {
3354             exampleSB.append("\n");
3355             lineNumber++;
3356           }
3357           exampleSB.append(BackupFilenameParts.getBackupFilename(index,
3358                   base, suffix, digits));
3359           if (min == max)
3360           {
3361             // no extra text needed
3362           }
3363           else if (index == min)
3364           {
3365             String oldest = MessageManager.getString("label.braced_oldest");
3366             if (oldest != null && oldest.length() > 0)
3367             {
3368               exampleSB.append(" " + oldest);
3369             }
3370           }
3371           else if (index == max)
3372           {
3373             String newest = MessageManager.getString("label.braced_newest");
3374             if (newest != null && newest.length() > 0)
3375             {
3376               exampleSB.append(" " + newest);
3377             }
3378           }
3379         }
3380       }
3381
3382     }
3383
3384     // add some extra empty lines to pad out the example files box. ugh, please tell
3385     // me how to do this better
3386     int remainingLines = lowersurround + uppersurround + 1 - lineNumber;
3387     if (remainingLines > 0)
3388     {
3389       for (int i = 0; i < remainingLines; i++)
3390       {
3391         exampleSB.append("\n ");
3392         lineNumber++;
3393       }
3394     }
3395
3396     backupfilesExampleLabel.setText(exampleSB.toString());
3397   }
3398
3399   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
3400           boolean useExistingVal, ChangeListener c)
3401   {
3402     int i = def;
3403     if (useExistingVal)
3404     {
3405       try
3406       {
3407         i = ((Integer) s.getValue()).intValue();
3408       } catch (Exception e)
3409       {
3410         Console.error(
3411                 "Exception casting the initial value of s.getValue()");
3412       }
3413     }
3414
3415     setIntegerSpinner(s, min, max, i, c);
3416   }
3417
3418   protected void setIntegerSpinner(JSpinner s, int min, int max, int def,
3419           ChangeListener c)
3420   {
3421     // integer spinner for number of digits
3422     if (def > max)
3423     {
3424       max = def;
3425     }
3426     if (def < min)
3427     {
3428       def = min;
3429     }
3430     SpinnerModel sModel = new SpinnerNumberModel(def, min, max, 1);
3431     s.setModel(sModel);
3432
3433     s.addChangeListener(c);
3434
3435   }
3436
3437   protected static int getSpinnerInt(JSpinner s, int def)
3438   {
3439     int i = def;
3440     try
3441     {
3442       s.commitEdit();
3443       i = (Integer) s.getValue();
3444     } catch (Exception e)
3445     {
3446       Console.error("Failed casting (Integer) JSpinner s.getValue()");
3447     }
3448     return i;
3449   }
3450
3451   private void keepRollMaxOptionsEnabled()
3452   {
3453     boolean enabled = backupfilesKeepAll.isEnabled()
3454             && !backupfilesKeepAll.isSelected();
3455     oldBackupFilesLabel.setEnabled(enabled);
3456     backupfilesRollMaxSpinner.setEnabled(enabled);
3457     backupfilesConfirmDelete.setEnabled(enabled);
3458   }
3459
3460   private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
3461   {
3462     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
3463             && customiseCheckbox.isSelected()
3464             && suffixTemplate.getText()
3465                     .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
3466     keepfilesPanel.setEnabled(enabled);
3467     backupfilesKeepAll.setEnabled(enabled);
3468     oldBackupFilesLabel.setEnabled(enabled);
3469     keepRollMaxOptionsEnabled();
3470   }
3471
3472   private void backupfilesSuffixTemplateDigitsSetEnabled()
3473   {
3474     boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
3475             .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
3476     suffixDigitsLabel.setEnabled(enabled);
3477     suffixDigitsSpinner.setEnabled(enabled);
3478     suffixReverse.setEnabled(enabled);
3479   }
3480
3481   private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
3482   {
3483     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
3484             && customiseCheckbox.isSelected();
3485     suffixPanel.setEnabled(enabled);
3486     suffixTemplateLabel.setEnabled(enabled);
3487     suffixTemplate.setEnabled(enabled);
3488     backupfilesSuffixTemplateDigitsSetEnabled();
3489   }
3490
3491   private void backupfilesRevertButtonSetEnabled(boolean tryEnabled)
3492   {
3493     boolean enabled = tryEnabled && enableBackupFiles.isSelected()
3494             && customiseCheckbox.isSelected() && backupfilesCustomChanged();
3495     revertButton.setEnabled(enabled);
3496   }
3497
3498   private boolean backupfilesCustomChanged()
3499   {
3500     BackupFilesPresetEntry custom = BackupFilesPresetEntry.backupfilesPresetEntriesValues
3501             .get(BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM);
3502     BackupFilesPresetEntry current = getBackupfilesCurrentEntry();
3503     return !custom.equals(current);
3504   }
3505
3506   protected BackupFilesPresetEntry getBackupfilesCurrentEntry()
3507   {
3508     String suffix = suffixTemplate.getText();
3509     int digits = getSpinnerInt(suffixDigitsSpinner, 3);
3510     boolean reverse = suffixReverse.isSelected();
3511     boolean keepAll = backupfilesKeepAll.isSelected();
3512     int rollMax = getSpinnerInt(backupfilesRollMaxSpinner, 3);
3513     boolean confirmDelete = backupfilesConfirmDelete.isSelected();
3514
3515     BackupFilesPresetEntry bfpe = new BackupFilesPresetEntry(suffix, digits,
3516             reverse, keepAll, rollMax, confirmDelete);
3517
3518     return bfpe;
3519   }
3520
3521   protected void backupfilesCustomOptionsSetEnabled()
3522   {
3523     boolean enabled = customiseCheckbox.isSelected();
3524
3525     backupfilesRevertButtonSetEnabled(enabled);
3526     backupfilesSuffixTemplateSetEnabled(enabled);
3527     backupfilesKeepAllSetEnabled(enabled);
3528   }
3529
3530   private void backupfilesSummarySetEnabled()
3531   {
3532     boolean enabled = enableBackupFiles.isSelected();
3533     backupfilesExampleLabel.setEnabled(enabled);
3534     exampleFilesPanel.setEnabled(enabled);
3535   }
3536
3537   private void backupfilesPresetsSetEnabled()
3538   {
3539     boolean enabled = enableBackupFiles.isSelected();
3540     presetsPanel.setEnabled(enabled);
3541     presetsComboLabel.setEnabled(enabled);
3542     backupfilesPresetsCombo.setEnabled(enabled);
3543     customiseCheckbox.setEnabled(enabled);
3544     revertButton.setEnabled(enabled);
3545   }
3546
3547   protected void backupsOptionsSetEnabled()
3548   {
3549     backupfilesPresetsSetEnabled();
3550     backupfilesSummarySetEnabled();
3551     backupfilesCustomOptionsSetEnabled();
3552   }
3553
3554   protected void backupsSetOptions(String suffix, int digits,
3555           boolean reverse, boolean keepAll, int rollMax,
3556           boolean confirmDelete)
3557   {
3558     suffixTemplate.setText(suffix);
3559     suffixDigitsSpinner.setValue(digits);
3560     suffixReverse.setSelected(reverse);
3561     backupfilesKeepAll.setSelected(keepAll);
3562     backupfilesRollMaxSpinner.setValue(rollMax);
3563     backupfilesConfirmDelete.setSelected(confirmDelete);
3564   }
3565
3566   protected void backupsSetOptions(BackupFilesPresetEntry p)
3567   {
3568     backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax,
3569             p.confirmDelete);
3570   }
3571
3572   protected void autoIdWidth_actionPerformed()
3573   {
3574     // TODO Auto-generated method stub
3575
3576   }
3577
3578   protected void userIdWidth_actionPerformed()
3579   {
3580     // TODO Auto-generated method stub
3581
3582   }
3583
3584   protected void maxColour_actionPerformed(JPanel panel)
3585   {
3586   }
3587
3588   protected void minColour_actionPerformed(JPanel panel)
3589   {
3590   }
3591
3592   protected void gapColour_actionPerformed(JPanel panel)
3593   {
3594   }
3595
3596   protected void hiddenColour_actionPerformed(JPanel panel)
3597   {
3598   }
3599
3600   protected void showunconserved_actionPerformed(ActionEvent e)
3601   {
3602     // TODO Auto-generated method stub
3603
3604   }
3605
3606   protected void useLegacyGaps_actionPerformed(ActionEvent e)
3607   {
3608   }
3609
3610   protected void resetOvDefaults_actionPerformed(ActionEvent e)
3611   {
3612   }
3613
3614   /**
3615    * DOCUMENT ME!
3616    * 
3617    * @param e
3618    *          DOCUMENT ME!
3619    */
3620   public void ok_actionPerformed(ActionEvent e)
3621   {
3622   }
3623
3624   /**
3625    * DOCUMENT ME!
3626    * 
3627    * @param e
3628    *          DOCUMENT ME!
3629    */
3630   public void cancel_actionPerformed(ActionEvent e)
3631   {
3632   }
3633
3634   /**
3635    * DOCUMENT ME!
3636    * 
3637    * @param e
3638    *          DOCUMENT ME!
3639    */
3640   public void annotations_actionPerformed(ActionEvent e)
3641   {
3642   }
3643
3644   /**
3645    * DOCUMENT ME!
3646    */
3647   public void startupFileTextfield_mouseClicked()
3648   {
3649   }
3650
3651   public void newLink_actionPerformed(ActionEvent e)
3652   {
3653
3654   }
3655
3656   public void editLink_actionPerformed(ActionEvent e)
3657   {
3658
3659   }
3660
3661   public void deleteLink_actionPerformed(ActionEvent e)
3662   {
3663
3664   }
3665
3666   public void defaultBrowser_mouseClicked(MouseEvent e)
3667   {
3668
3669   }
3670
3671   public void linkURLList_keyTyped(KeyEvent e)
3672   {
3673
3674   }
3675
3676   public void setProxyAuthEnabled()
3677   {
3678     boolean enabled = proxyAuth.isSelected() && proxyAuth.isEnabled();
3679     proxyAuthUsernameLabel.setEnabled(enabled);
3680     proxyAuthPasswordLabel.setEnabled(enabled);
3681     passwordNotStoredLabel.setEnabled(enabled);
3682     proxyAuthUsernameTB.setEnabled(enabled);
3683     proxyAuthPasswordPB.setEnabled(enabled);
3684   }
3685
3686   public void setCustomProxyEnabled()
3687   {
3688     boolean enabled = customProxy.isSelected();
3689     portLabel.setEnabled(enabled);
3690     serverLabel.setEnabled(enabled);
3691     portLabel2.setEnabled(enabled);
3692     serverLabel2.setEnabled(enabled);
3693     httpLabel.setEnabled(enabled);
3694     httpsLabel.setEnabled(enabled);
3695     proxyServerHttpTB.setEnabled(enabled);
3696     proxyPortHttpTB.setEnabled(enabled);
3697     proxyServerHttpsTB.setEnabled(enabled);
3698     proxyPortHttpsTB.setEnabled(enabled);
3699     proxyAuth.setEnabled(enabled);
3700     setProxyAuthEnabled();
3701   }
3702
3703   public void proxyType_actionPerformed()
3704   {
3705     setCustomProxyEnabled();
3706     proxyAuthPasswordCheckHighlight(true);
3707     applyProxyButtonEnabled(true);
3708   }
3709
3710   public void proxyAuth_actionPerformed()
3711   {
3712     setProxyAuthEnabled();
3713     proxyAuthPasswordCheckHighlight(true);
3714     applyProxyButtonEnabled(true);
3715   }
3716
3717   /**
3718    * Customer renderer for JTable: supports column of radio buttons
3719    */
3720   public class RadioButtonRenderer extends JRadioButton
3721           implements TableCellRenderer
3722   {
3723     public RadioButtonRenderer()
3724     {
3725       setHorizontalAlignment(CENTER);
3726       setToolTipText(MessageManager.getString("label.urltooltip"));
3727     }
3728
3729     @Override
3730     public Component getTableCellRendererComponent(JTable table,
3731             Object value, boolean isSelected, boolean hasFocus, int row,
3732             int column)
3733     {
3734       setSelected((boolean) value);
3735
3736       // set colours to match rest of table
3737       if (isSelected)
3738       {
3739         setBackground(table.getSelectionBackground());
3740         setForeground(table.getSelectionForeground());
3741       }
3742       else
3743       {
3744         setBackground(table.getBackground());
3745         setForeground(table.getForeground());
3746       }
3747       return this;
3748     }
3749   }
3750
3751   /**
3752    * Customer cell editor for JTable: supports column of radio buttons in
3753    * conjunction with renderer
3754    */
3755   public class RadioButtonEditor extends AbstractCellEditor
3756           implements TableCellEditor
3757   {
3758     private JRadioButton button = new JRadioButton();
3759
3760     public RadioButtonEditor()
3761     {
3762       button.setHorizontalAlignment(SwingConstants.CENTER);
3763       this.button.addActionListener(new ActionListener()
3764       {
3765         @Override
3766         public void actionPerformed(ActionEvent e)
3767         {
3768           fireEditingStopped();
3769         }
3770       });
3771     }
3772
3773     @Override
3774     public Component getTableCellEditorComponent(JTable table, Object value,
3775             boolean isSelected, int row, int column)
3776     {
3777       button.setSelected((boolean) value);
3778       return button;
3779     }
3780
3781     @Override
3782     public Object getCellEditorValue()
3783     {
3784       return button.isSelected();
3785     }
3786
3787   }
3788
3789   protected void validateHmmerPath()
3790   {
3791   }
3792
3793   protected void validateCygwinPath()
3794   {
3795   }
3796
3797   /**
3798    * A helper method to add a panel containing a label and a component to a
3799    * panel
3800    * 
3801    * @param panel
3802    * @param tooltip
3803    * @param label
3804    * @param valBox
3805    */
3806   protected static void addtoLayout(JPanel panel, String tooltip,
3807           JComponent label, JComponent valBox)
3808   {
3809     JPanel laypanel = new JPanel(new GridLayout(1, 2));
3810     JPanel labPanel = new JPanel(new BorderLayout());
3811     JPanel valPanel = new JPanel();
3812     labPanel.setBounds(new Rectangle(7, 7, 158, 23));
3813     valPanel.setBounds(new Rectangle(172, 7, 270, 23));
3814     labPanel.add(label, BorderLayout.WEST);
3815     valPanel.add(valBox);
3816     laypanel.add(labPanel);
3817     laypanel.add(valPanel);
3818     valPanel.setToolTipText(tooltip);
3819     labPanel.setToolTipText(tooltip);
3820     valBox.setToolTipText(tooltip);
3821     panel.add(laypanel);
3822     panel.validate();
3823   }
3824 }