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