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