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