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