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