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