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