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