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