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