JAL-2668 add tests for HMMER commands, annotation and io
[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 jalview.fts.core.FTSDataColumnPreferences;
24 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
25 import jalview.fts.service.pdb.PDBFTSRestClient;
26 import jalview.gui.JvSwingUtils;
27 import jalview.gui.StructureViewer.ViewerType;
28 import jalview.util.MessageManager;
29
30 import java.awt.BorderLayout;
31 import java.awt.Color;
32 import java.awt.Component;
33 import java.awt.Dimension;
34 import java.awt.FlowLayout;
35 import java.awt.Font;
36 import java.awt.GridBagConstraints;
37 import java.awt.GridBagLayout;
38 import java.awt.GridLayout;
39 import java.awt.Insets;
40 import java.awt.Rectangle;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.FocusEvent;
44 import java.awt.event.KeyEvent;
45 import java.awt.event.MouseAdapter;
46 import java.awt.event.MouseEvent;
47
48 import javax.swing.AbstractButton;
49 import javax.swing.AbstractCellEditor;
50 import javax.swing.BorderFactory;
51 import javax.swing.ButtonGroup;
52 import javax.swing.DefaultListCellRenderer;
53 import javax.swing.JButton;
54 import javax.swing.JCheckBox;
55 import javax.swing.JComboBox;
56 import javax.swing.JFileChooser;
57 import javax.swing.JLabel;
58 import javax.swing.JPanel;
59 import javax.swing.JRadioButton;
60 import javax.swing.JScrollPane;
61 import javax.swing.JTabbedPane;
62 import javax.swing.JTable;
63 import javax.swing.JTextField;
64 import javax.swing.ListSelectionModel;
65 import javax.swing.SwingConstants;
66 import javax.swing.border.Border;
67 import javax.swing.border.EmptyBorder;
68 import javax.swing.border.EtchedBorder;
69 import javax.swing.border.TitledBorder;
70 import javax.swing.event.ChangeEvent;
71 import javax.swing.event.ChangeListener;
72 import javax.swing.table.TableCellEditor;
73 import javax.swing.table.TableCellRenderer;
74
75 /**
76  * Base class for the Preferences panel.
77  * 
78  * @author $author$
79  * @version $Revision$
80  */
81 public class GPreferences extends JPanel
82 {
83   private static final Font LABEL_FONT = JvSwingUtils.getLabelFont();
84
85   private static final Font LABEL_FONT_ITALIC = JvSwingUtils.getLabelFont(
86           false, true);
87
88   /*
89    * Visual tab components
90    */
91   protected JCheckBox fullScreen = new JCheckBox();
92
93   protected JCheckBox openoverv = new JCheckBox();
94
95   protected JCheckBox seqLimit = new JCheckBox();
96
97   protected JCheckBox rightAlign = new JCheckBox();
98
99   protected JComboBox<String> fontSizeCB = new JComboBox<>();
100
101   protected JComboBox<String> fontStyleCB = new JComboBox<>();
102
103   protected JComboBox<String> fontNameCB = new JComboBox<>();
104
105   protected JCheckBox showOccupancy = new JCheckBox();
106
107   protected JCheckBox showUnconserved = new JCheckBox();
108
109   protected JCheckBox idItalics = new JCheckBox();
110
111   protected JCheckBox smoothFont = new JCheckBox();
112
113   protected JCheckBox scaleProteinToCdna = new JCheckBox();
114
115   protected JComboBox<String> gapSymbolCB = new JComboBox<>();
116
117   protected JCheckBox wrap = new JCheckBox();
118
119   protected JComboBox<String> sortby = new JComboBox<>();
120
121   protected JComboBox<String> sortAnnBy = new JComboBox<>();
122
123   protected JComboBox<String> sortAutocalc = new JComboBox<>();
124
125   protected JCheckBox startupCheckbox = new JCheckBox();
126
127   protected JTextField startupFileTextfield = new JTextField();
128
129   // below are in the 'second column'
130   protected JCheckBox annotations = new JCheckBox();
131
132   protected JCheckBox quality = new JCheckBox();
133
134   protected JCheckBox conservation = new JCheckBox();
135
136   protected JCheckBox identity = new JCheckBox();
137
138   protected JCheckBox showGroupConsensus = new JCheckBox();
139
140   protected JCheckBox showGroupConservation = new JCheckBox();
141
142   protected JCheckBox showConsensHistogram = new JCheckBox();
143
144   protected JCheckBox showConsensLogo = new JCheckBox();
145
146   protected JCheckBox showInformationHistogram = new JCheckBox();
147
148   protected JCheckBox showHMMLogo = new JCheckBox();
149
150   protected JCheckBox showDbRefTooltip = new JCheckBox();
151
152   protected JCheckBox showNpTooltip = new JCheckBox();
153
154
155   /*
156    * Structure tab and components
157    */
158   protected JPanel structureTab;
159
160   protected JCheckBox structFromPdb = new JCheckBox();
161
162   protected JCheckBox useRnaView = new JCheckBox();
163
164   protected JCheckBox addSecondaryStructure = new JCheckBox();
165
166   protected JCheckBox addTempFactor = new JCheckBox();
167
168   protected JComboBox<String> structViewer = new JComboBox<>();
169
170   protected JTextField chimeraPath = new JTextField();
171
172   protected ButtonGroup mappingMethod = new ButtonGroup();
173
174   protected JRadioButton siftsMapping = new JRadioButton();
175
176   protected JRadioButton nwMapping = new JRadioButton();
177
178   /*
179    * Colours tab components
180    */
181   protected JPanel minColour = new JPanel();
182
183   protected JPanel maxColour = new JPanel();
184
185   protected JComboBox<String> protColour = new JComboBox<>();
186
187   protected JComboBox<String> nucColour = new JComboBox<>();
188
189   /*
190    * Connections tab components
191    */
192   protected JTable linkUrlTable = new JTable();
193
194   protected JButton editLink = new JButton();
195
196   protected JButton deleteLink = new JButton();
197
198   protected JTextField filterTB = new JTextField();
199
200   protected JButton doReset = new JButton();
201
202   protected JButton userOnly = new JButton();
203
204   protected JLabel portLabel = new JLabel();
205
206   protected JLabel serverLabel = new JLabel();
207
208   protected JTextField proxyServerTB = new JTextField();
209
210   protected JTextField proxyPortTB = new JTextField();
211
212   protected JTextField defaultBrowser = new JTextField();
213
214   protected JCheckBox useProxy = new JCheckBox();
215
216   protected JCheckBox usagestats = new JCheckBox();
217
218   protected JCheckBox questionnaire = new JCheckBox();
219
220   protected JCheckBox versioncheck = new JCheckBox();
221
222   /*
223    * Output tab components
224    */
225   protected JComboBox<Object> epsRendering = new JComboBox<>();
226
227   protected JLabel userIdWidthlabel = new JLabel();
228
229   protected JCheckBox autoIdWidth = new JCheckBox();
230
231   protected JTextField userIdWidth = new JTextField();
232
233   protected JCheckBox blcjv = new JCheckBox();
234
235   protected JCheckBox pileupjv = new JCheckBox();
236
237   protected JCheckBox clustaljv = new JCheckBox();
238
239   protected JCheckBox msfjv = new JCheckBox();
240
241   protected JCheckBox fastajv = new JCheckBox();
242
243   protected JCheckBox pfamjv = new JCheckBox();
244
245   protected JCheckBox pirjv = new JCheckBox();
246
247   protected JCheckBox modellerOutput = new JCheckBox();
248
249   protected JCheckBox embbedBioJSON = new JCheckBox();
250
251   /*
252    * Editing tab components
253    */
254   protected JCheckBox autoCalculateConsCheck = new JCheckBox();
255
256   protected JCheckBox padGaps = new JCheckBox();
257
258   protected JCheckBox sortByTree = new JCheckBox();
259
260   /*
261    * hmmer tab and components
262    */
263   protected JPanel hmmerTab = new JPanel();
264
265   protected JCheckBox trimTermini = new JCheckBox();
266
267   protected ButtonGroup backgroundFreqSource = new ButtonGroup();
268
269   protected AbstractButton uniprot = new JCheckBox();
270
271   protected AbstractButton alignment = new JCheckBox();
272
273   protected JLabel sequencesToKeep = new JLabel();
274
275   protected JTextField numberOfSequencesToKeepField = new JTextField();
276
277   protected JLabel installationLocation = new JLabel();
278
279   protected JCheckBox isHMMERInstalled = new JCheckBox();
280
281   protected JTextField hmmerPath = new JTextField();
282
283   protected JLabel hmmsearch = new JLabel();
284
285   protected JLabel hmmalign = new JLabel();
286
287   /*
288    * DAS Settings tab
289    */
290   protected JPanel dasTab = new JPanel();
291
292   /*
293    * Web Services tab
294    */
295   protected JPanel wsTab = new JPanel();
296
297
298
299   /**
300    * Creates a new GPreferences object.
301    */
302   public GPreferences()
303   {
304     try
305     {
306       jbInit();
307     } catch (Exception ex)
308     {
309       ex.printStackTrace();
310     }
311   }
312
313   /**
314    * Construct the panel and its tabbed sub-panels.
315    * 
316    * @throws Exception
317    */
318   private void jbInit() throws Exception
319   {
320     final JTabbedPane tabbedPane = new JTabbedPane();
321     this.setLayout(new BorderLayout());
322     JPanel okCancelPanel = initOkCancelPanel();
323     this.add(tabbedPane, BorderLayout.CENTER);
324     this.add(okCancelPanel, BorderLayout.SOUTH);
325
326     tabbedPane.add(initVisualTab(),
327             MessageManager.getString("label.visual"));
328
329     tabbedPane.add(initColoursTab(),
330             MessageManager.getString("label.colours"));
331
332     tabbedPane.add(initStructureTab(),
333             MessageManager.getString("label.structure"));
334
335     tabbedPane.add(initConnectionsTab(),
336             MessageManager.getString("label.connections"));
337
338     tabbedPane.add(initLinksTab(),
339             MessageManager.getString("label.urllinks"));
340
341     tabbedPane.add(initOutputTab(),
342             MessageManager.getString("label.output"));
343
344     tabbedPane.add(initEditingTab(),
345             MessageManager.getString("label.editing"));
346
347     tabbedPane.add(initHMMERTab(), MessageManager.getString("label.hmmer"));
348
349     /*
350      * See DasSourceBrowser for the real work of configuring this tab.
351      */
352     dasTab.setLayout(new BorderLayout());
353     tabbedPane.add(dasTab, MessageManager.getString("label.das_settings"));
354
355     /*
356      * See WsPreferences for the real work of configuring this tab.
357      */
358     wsTab.setLayout(new BorderLayout());
359     tabbedPane.add(wsTab, MessageManager.getString("label.web_services"));
360
361     /*
362      * Handler to validate a tab before leaving it - currently only for
363      * Structure.
364      */
365     tabbedPane.addChangeListener(new ChangeListener()
366     {
367       private Component lastTab;
368
369       @Override
370       public void stateChanged(ChangeEvent e)
371       {
372         if (lastTab == structureTab
373                 && tabbedPane.getSelectedComponent() != structureTab)
374         {
375           if (!validateStructure())
376           {
377             tabbedPane.setSelectedComponent(structureTab);
378             return;
379           }
380         }
381         else if (lastTab == hmmerTab
382                 && tabbedPane.getSelectedComponent() != hmmerTab
383                 && isHMMERInstalled.isSelected())
384         {
385           if (!validateHMMER())
386           {
387             tabbedPane.setSelectedComponent(hmmerTab);
388           }
389           return;
390         }
391         lastTab = tabbedPane.getSelectedComponent();
392       }
393
394     });
395   }
396
397   /**
398    * Initialises the Editing tabbed panel.
399    * 
400    * @return
401    */
402   private JPanel initEditingTab()
403   {
404     JPanel editingTab = new JPanel();
405     editingTab.setLayout(null);
406     autoCalculateConsCheck.setFont(LABEL_FONT);
407     autoCalculateConsCheck.setText(MessageManager
408             .getString("label.autocalculate_consensus"));
409     autoCalculateConsCheck.setBounds(new Rectangle(21, 52, 209, 23));
410     padGaps.setFont(LABEL_FONT);
411     padGaps.setText(MessageManager.getString("label.pad_gaps_when_editing"));
412     padGaps.setBounds(new Rectangle(22, 94, 168, 23));
413     sortByTree.setFont(LABEL_FONT);
414     sortByTree
415             .setText(MessageManager.getString("label.sort_with_new_tree"));
416     sortByTree
417             .setToolTipText(MessageManager
418                     .getString("label.any_trees_calculated_or_loaded_alignment_automatically_sort"));
419     sortByTree.setBounds(new Rectangle(22, 136, 168, 23));
420     editingTab.add(autoCalculateConsCheck);
421     editingTab.add(padGaps);
422     editingTab.add(sortByTree);
423     return editingTab;
424   }
425
426   /**
427    * Initialises the hmmer tabbed panel.
428    * 
429    * @return
430    */
431   private JPanel initHMMERTab()
432   {
433     hmmerTab.setLayout(null);
434
435     hmmalign.setFont(LABEL_FONT);
436     hmmalign.setText(MessageManager.getString("label.hmmalign_label"));
437     hmmalign.setBounds(new Rectangle(22, 10, 200, 23));
438
439     trimTermini.setFont(LABEL_FONT);
440     trimTermini.setText(MessageManager.getString("label.trim_termini"));
441     trimTermini.setBounds(new Rectangle(22, 30, 200, 23));
442
443     hmmsearch.setFont(LABEL_FONT);
444     hmmsearch.setText(MessageManager.getString("label.hmmsearch_label"));
445     hmmsearch.setBounds(new Rectangle(250, 10, 200, 23));
446
447     sequencesToKeep.setFont(LABEL_FONT);
448     sequencesToKeep
449             .setText(MessageManager.getString("label.no_of_sequences"));
450     sequencesToKeep.setBounds(new Rectangle(250, 30, 125, 23));
451     numberOfSequencesToKeepField.setBounds(new Rectangle(375, 30, 40, 23));
452
453     isHMMERInstalled.setFont(LABEL_FONT);
454     isHMMERInstalled.setText(
455             MessageManager.getString("label.hmmer_installed"));
456     isHMMERInstalled.setBounds(new Rectangle(22, 180, 200, 23));
457     isHMMERInstalled.addActionListener(new ActionListener()
458     {
459       @Override
460       public void actionPerformed(ActionEvent e)
461       {
462         boolean status = isHMMERInstalled.isSelected();
463         installationLocation.setEnabled(status);
464         hmmerPath.setEnabled(status);
465       }
466     });
467     installationLocation.setFont(LABEL_FONT);
468     installationLocation.setText(
469             MessageManager.getString("label.change_hmmer_location"));
470     installationLocation.setBounds(new Rectangle(22, 200, 200, 23));
471     hmmerPath.setBounds(new Rectangle(22, 220, 200, 23));
472     hmmerPath.addMouseListener(new MouseAdapter()
473     {
474       @Override
475       public void mouseClicked(MouseEvent e)
476       {
477         if (e.getClickCount() == 2)
478         {
479           String chosen = openFileChooser(true);
480           if (chosen != null)
481           {
482             hmmerPath.setText(chosen);
483           }
484         }
485       }
486     });
487
488     backgroundFreqSource.add(uniprot);
489     backgroundFreqSource.add(alignment);
490     backgroundFreqSource.setSelected(uniprot.getModel(), true);
491
492     uniprot.setText(MessageManager.getString("label.freq_uniprot"));
493     uniprot.setFont(LABEL_FONT);
494     uniprot.setBounds(new Rectangle(22, 260, 255, 23));
495
496     alignment.setText(MessageManager.getString("label.freq_alignment"));
497     alignment.setFont(LABEL_FONT);
498     alignment.setBounds(new Rectangle(22, 280, 255, 23));
499
500     hmmerTab.add(uniprot);
501     hmmerTab.add(alignment);
502     hmmerTab.add(hmmalign);
503     hmmerTab.add(hmmsearch);
504     hmmerTab.add(installationLocation);
505     hmmerTab.add(hmmerPath);
506     hmmerTab.add(trimTermini);
507     hmmerTab.add(sequencesToKeep);
508     hmmerTab.add(sequencesToKeep);
509     hmmerTab.add(numberOfSequencesToKeepField);
510     hmmerTab.add(isHMMERInstalled);
511
512     return hmmerTab;
513   }
514
515   /**
516    * Initialises the Output tabbed panel.
517    * 
518    * @return
519    */
520   private JPanel initOutputTab()
521   {
522     JPanel outputTab = new JPanel();
523     outputTab.setLayout(null);
524     JLabel epsLabel = new JLabel();
525     epsLabel.setFont(LABEL_FONT);
526     epsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
527     epsLabel.setText(MessageManager.getString("label.eps_rendering_style"));
528     epsLabel.setBounds(new Rectangle(9, 31, 140, 24));
529     epsRendering.setFont(LABEL_FONT);
530     epsRendering.setBounds(new Rectangle(154, 34, 187, 21));
531     JLabel jLabel1 = new JLabel();
532     jLabel1.setFont(LABEL_FONT);
533     jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
534     jLabel1.setText(MessageManager.getString("label.append_start_end"));
535     jLabel1.setFont(LABEL_FONT);
536     fastajv.setFont(LABEL_FONT);
537     fastajv.setHorizontalAlignment(SwingConstants.LEFT);
538     clustaljv.setText(MessageManager.getString("label.clustal") + "     ");
539     blcjv.setText(MessageManager.getString("label.blc") + "     ");
540     fastajv.setText(MessageManager.getString("label.fasta") + "     ");
541     msfjv.setText(MessageManager.getString("label.msf") + "     ");
542     pfamjv.setText(MessageManager.getString("label.pfam") + "     ");
543     pileupjv.setText(MessageManager.getString("label.pileup") + "     ");
544     msfjv.setFont(LABEL_FONT);
545     msfjv.setHorizontalAlignment(SwingConstants.LEFT);
546     pirjv.setText(MessageManager.getString("label.pir") + "     ");
547     JPanel jPanel11 = new JPanel();
548     jPanel11.setFont(LABEL_FONT);
549     TitledBorder titledBorder2 = new TitledBorder(
550             MessageManager.getString("label.file_output"));
551     jPanel11.setBorder(titledBorder2);
552     jPanel11.setBounds(new Rectangle(30, 72, 196, 182));
553     GridLayout gridLayout3 = new GridLayout();
554     jPanel11.setLayout(gridLayout3);
555     gridLayout3.setRows(8);
556     blcjv.setFont(LABEL_FONT);
557     blcjv.setHorizontalAlignment(SwingConstants.LEFT);
558     clustaljv.setFont(LABEL_FONT);
559     clustaljv.setHorizontalAlignment(SwingConstants.LEFT);
560     pfamjv.setFont(LABEL_FONT);
561     pfamjv.setHorizontalAlignment(SwingConstants.LEFT);
562     pileupjv.setFont(LABEL_FONT);
563     pileupjv.setHorizontalAlignment(SwingConstants.LEFT);
564     pirjv.setFont(LABEL_FONT);
565     pirjv.setHorizontalAlignment(SwingConstants.LEFT);
566     autoIdWidth.setFont(LABEL_FONT);
567     autoIdWidth.setText(MessageManager
568             .getString("label.automatically_set_id_width"));
569     autoIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true,
570             MessageManager
571                     .getString("label.adjusts_width_generated_eps_png")));
572     autoIdWidth.setBounds(new Rectangle(228, 96, 188, 23));
573     autoIdWidth.addActionListener(new ActionListener()
574     {
575
576       @Override
577       public void actionPerformed(ActionEvent e)
578       {
579         autoIdWidth_actionPerformed();
580       }
581     });
582     userIdWidthlabel.setFont(LABEL_FONT);
583     userIdWidthlabel.setText(MessageManager
584             .getString("label.figure_id_column_width"));
585     userIdWidth
586             .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
587                     .getString("label.manually_specify_width_left_column")));
588     userIdWidthlabel
589             .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
590                     .getString("label.manually_specify_width_left_column")));
591     userIdWidthlabel.setBounds(new Rectangle(236, 120, 168, 23));
592     userIdWidth.setFont(JvSwingUtils.getTextAreaFont());
593     userIdWidth.setText("");
594     userIdWidth.setBounds(new Rectangle(232, 144, 84, 23));
595     userIdWidth.addActionListener(new ActionListener()
596     {
597
598       @Override
599       public void actionPerformed(ActionEvent e)
600       {
601         userIdWidth_actionPerformed();
602       }
603     });
604     modellerOutput.setFont(LABEL_FONT);
605     modellerOutput.setText(MessageManager
606             .getString("label.use_modeller_output"));
607     modellerOutput.setBounds(new Rectangle(228, 226, 168, 23));
608     embbedBioJSON.setFont(LABEL_FONT);
609     embbedBioJSON.setText(MessageManager.getString("label.embbed_biojson"));
610     embbedBioJSON.setBounds(new Rectangle(228, 200, 250, 23));
611
612     jPanel11.add(jLabel1);
613     jPanel11.add(blcjv);
614     jPanel11.add(clustaljv);
615     jPanel11.add(fastajv);
616     jPanel11.add(msfjv);
617     jPanel11.add(pfamjv);
618     jPanel11.add(pileupjv);
619     jPanel11.add(pirjv);
620     outputTab.add(autoIdWidth);
621     outputTab.add(userIdWidth);
622     outputTab.add(userIdWidthlabel);
623     outputTab.add(modellerOutput);
624     outputTab.add(embbedBioJSON);
625     outputTab.add(epsLabel);
626     outputTab.add(epsRendering);
627     outputTab.add(jPanel11);
628     return outputTab;
629   }
630
631   /**
632    * Initialises the Connections tabbed panel.
633    * 
634    * @return
635    */
636   private JPanel initConnectionsTab()
637   {
638     JPanel connectTab = new JPanel();
639     connectTab.setLayout(new GridBagLayout());
640
641     // Label for browser text box
642     JLabel browserLabel = new JLabel();
643     browserLabel.setFont(LABEL_FONT);
644     browserLabel.setHorizontalAlignment(SwingConstants.TRAILING);
645     browserLabel.setText(MessageManager
646             .getString("label.default_browser_unix"));
647     defaultBrowser.setFont(LABEL_FONT);
648     defaultBrowser.setText("");
649
650     defaultBrowser.addMouseListener(new MouseAdapter()
651     {
652       @Override
653       public void mouseClicked(MouseEvent e)
654       {
655         if (e.getClickCount() > 1)
656         {
657           defaultBrowser_mouseClicked(e);
658         }
659       }
660     });
661
662     JPanel proxyPanel = initConnTabProxyPanel();
663     initConnTabCheckboxes();
664
665     // Add default Browser text box
666     connectTab.add(browserLabel, new GridBagConstraints(0, 0, 1, 1, 0.0,
667             0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
668             new Insets(10, 0, 5, 5), 5, 1));
669     defaultBrowser.setFont(LABEL_FONT);
670     defaultBrowser.setText("");
671
672     connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0,
673             0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
674             new Insets(10, 0, 5, 10), 30, 1));
675
676     // Add proxy server panel
677     connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0,
678             GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
679             new Insets(10, 0, 5, 12), 4, 10));
680
681     // Add usage stats, version check and questionnaire checkboxes
682     connectTab.add(usagestats, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,
683             GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
684             new Insets(0, 2, 5, 5), 70, 1));
685     connectTab.add(questionnaire, new GridBagConstraints(1, 2, 1, 1, 1.0,
686             0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
687             new Insets(0, 2, 5, 10), 70, 1));
688     connectTab.add(versioncheck, new GridBagConstraints(0, 3, 1, 1, 1.0,
689             0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
690             new Insets(0, 2, 5, 5), 70, 1));
691
692     // Add padding so the panel doesn't look ridiculous
693     JPanel spacePanel = new JPanel();
694     connectTab.add(spacePanel, new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
695             GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
696                     0, 0, 5), 70, 1));
697
698     return connectTab;
699   }
700
701   /**
702    * Initialises the Links tabbed panel.
703    * 
704    * @return
705    */
706   private JPanel initLinksTab()
707   {
708     JPanel linkTab = new JPanel();
709     linkTab.setLayout(new GridBagLayout());
710
711     // Set up table for Url links
712     linkUrlTable.setFillsViewportHeight(true);
713     linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
714     linkUrlTable.setAutoCreateRowSorter(true);
715     linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
716
717     // adjust row height so radio buttons actually fit
718     // don't do this in the renderer, it causes the awt thread to activate
719     // constantly
720     JRadioButton temp = new JRadioButton();
721     linkUrlTable.setRowHeight(temp.getMinimumSize().height);
722
723     // Table in scrollpane so that the table is given a scrollbar
724     JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
725     linkScrollPane.setBorder(null);
726
727     // Panel for links functionality
728     JPanel linkPanel = new JPanel(new GridBagLayout());
729     linkPanel.setBorder(new TitledBorder(MessageManager
730             .getString("label.url_linkfrom_sequence_id")));
731
732     // Put the Url links panel together
733
734     // Buttons go at top right, resizing only resizes the blank space vertically
735     JPanel buttonPanel = initLinkTabUrlButtons();
736     GridBagConstraints linkConstraints1 = new GridBagConstraints();
737     linkConstraints1.insets = new Insets(0, 0, 5, 0);
738     linkConstraints1.gridx = 0;
739     linkConstraints1.gridy = 0;
740     linkConstraints1.weightx = 1.0;
741     linkConstraints1.fill = GridBagConstraints.HORIZONTAL;
742     linkTab.add(buttonPanel, linkConstraints1);
743
744     // Links table goes at top left, resizing resizes the table
745     GridBagConstraints linkConstraints2 = new GridBagConstraints();
746     linkConstraints2.insets = new Insets(0, 0, 5, 5);
747     linkConstraints2.gridx = 0;
748     linkConstraints2.gridy = 1;
749     linkConstraints2.weightx = 1.0;
750     linkConstraints2.weighty = 1.0;
751     linkConstraints2.fill = GridBagConstraints.BOTH;
752     linkTab.add(linkScrollPane, linkConstraints2);
753
754     // Filter box and buttons goes at bottom left, resizing resizes the text box
755     JPanel filterPanel = initLinkTabFilterPanel();
756     GridBagConstraints linkConstraints3 = new GridBagConstraints();
757     linkConstraints3.insets = new Insets(0, 0, 0, 5);
758     linkConstraints3.gridx = 0;
759     linkConstraints3.gridy = 2;
760     linkConstraints3.weightx = 1.0;
761     linkConstraints3.fill = GridBagConstraints.HORIZONTAL;
762     linkTab.add(filterPanel, linkConstraints3);
763
764     return linkTab;
765   }
766
767   private JPanel initLinkTabFilterPanel()
768   {
769     // Filter textbox and reset button
770     JLabel filterLabel = new JLabel(
771             MessageManager.getString("label.filter"));
772     filterLabel.setFont(LABEL_FONT);
773     filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);
774     filterLabel.setHorizontalTextPosition(SwingConstants.LEADING);
775
776     filterTB.setFont(LABEL_FONT);
777     filterTB.setText("");
778
779     doReset.setText(MessageManager.getString("action.showall"));
780     userOnly.setText(MessageManager.getString("action.customfilter"));
781
782     // Panel for filter functionality
783     JPanel filterPanel = new JPanel(new GridBagLayout());
784     filterPanel.setBorder(new TitledBorder("Filter"));
785     GridBagConstraints gbc = new GridBagConstraints();
786     gbc.gridx = 0;
787     gbc.gridy = 0;
788     gbc.fill = GridBagConstraints.NONE;
789     gbc.anchor = GridBagConstraints.WEST;
790
791     filterPanel.add(filterLabel, gbc);
792
793     GridBagConstraints gbc1 = new GridBagConstraints();
794     gbc1.gridx = 1;
795     gbc1.gridwidth = 2;
796     gbc1.fill = GridBagConstraints.HORIZONTAL;
797     gbc1.anchor = GridBagConstraints.WEST;
798     gbc1.weightx = 1.0;
799     filterPanel.add(filterTB, gbc1);
800
801     GridBagConstraints gbc2 = new GridBagConstraints();
802     gbc2.gridx = 3;
803     gbc2.fill = GridBagConstraints.NONE;
804     gbc2.anchor = GridBagConstraints.WEST;
805     filterPanel.add(doReset, gbc2);
806
807     GridBagConstraints gbc3 = new GridBagConstraints();
808     gbc3.gridx = 4;
809     gbc3.fill = GridBagConstraints.NONE;
810     gbc3.anchor = GridBagConstraints.WEST;
811     filterPanel.add(userOnly, gbc3);
812
813     return filterPanel;
814   }
815
816   private JPanel initLinkTabUrlButtons()
817   {
818     // Buttons for new / edit / delete Url links
819     JButton newLink = new JButton();
820     newLink.setText(MessageManager.getString("action.new"));
821
822     editLink.setText(MessageManager.getString("action.edit"));
823
824     deleteLink.setText(MessageManager.getString("action.delete"));
825
826     // no current selection, so initially disable delete/edit buttons
827     editLink.setEnabled(false);
828     deleteLink.setEnabled(false);
829     
830     newLink.addActionListener(new java.awt.event.ActionListener()
831     {
832       @Override
833       public void actionPerformed(ActionEvent e)
834       {
835         newLink_actionPerformed(e);
836       }
837     });
838
839     editLink.setText(MessageManager.getString("action.edit"));
840     editLink.addActionListener(new java.awt.event.ActionListener()
841     {
842       @Override
843       public void actionPerformed(ActionEvent e)
844       {
845         editLink_actionPerformed(e);
846       }
847     });
848
849     deleteLink.setText(MessageManager.getString("action.delete"));
850     deleteLink.addActionListener(new java.awt.event.ActionListener()
851     {
852       @Override
853       public void actionPerformed(ActionEvent e)
854       {
855         deleteLink_actionPerformed(e);
856       }
857     });
858
859     JPanel buttonPanel = new JPanel(new GridBagLayout());
860     buttonPanel.setBorder(new TitledBorder("Edit links"));
861     GridBagConstraints gbc = new GridBagConstraints();
862     gbc.gridx = 0;
863     gbc.gridy = 0;
864     gbc.fill = GridBagConstraints.NONE;
865     buttonPanel.add(newLink, gbc);
866
867     GridBagConstraints gbc1 = new GridBagConstraints();
868     gbc1.gridx = 1;
869     gbc1.gridy = 0;
870     gbc1.fill = GridBagConstraints.NONE;
871     buttonPanel.add(editLink, gbc1);
872
873     GridBagConstraints gbc2 = new GridBagConstraints();
874     gbc2.gridx = 2;
875     gbc2.gridy = 0;
876     gbc2.fill = GridBagConstraints.NONE;
877     buttonPanel.add(deleteLink, gbc2);
878
879     GridBagConstraints gbc3 = new GridBagConstraints();
880     gbc3.gridx = 3;
881     gbc3.gridy = 0;
882     gbc3.fill = GridBagConstraints.HORIZONTAL;
883     gbc3.weightx = 1.0;
884     JPanel spacePanel = new JPanel();
885     spacePanel.setBorder(null);
886     buttonPanel.add(spacePanel, gbc3);
887
888     return buttonPanel;
889   }
890
891   /**
892    * Initialises the proxy server panel in the Connections tab
893    * 
894    * @return the proxy server panel
895    */
896   private JPanel initConnTabProxyPanel()
897   {
898     // Label for server text box
899     serverLabel.setText(MessageManager.getString("label.address"));
900     serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
901     serverLabel.setFont(LABEL_FONT);
902
903     // Proxy server and port text boxes
904     proxyServerTB.setFont(LABEL_FONT);
905     proxyPortTB.setFont(LABEL_FONT);
906
907     // Label for Port text box
908     portLabel.setFont(LABEL_FONT);
909     portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
910     portLabel.setText(MessageManager.getString("label.port"));
911
912     // Use proxy server checkbox
913     useProxy.setFont(LABEL_FONT);
914     useProxy.setHorizontalAlignment(SwingConstants.RIGHT);
915     useProxy.setHorizontalTextPosition(SwingConstants.LEADING);
916     useProxy.setText(MessageManager.getString("label.use_proxy_server"));
917     useProxy.addActionListener(new ActionListener()
918     {
919       @Override
920       public void actionPerformed(ActionEvent e)
921       {
922         useProxy_actionPerformed();
923       }
924     });
925
926     // Make proxy server panel
927     JPanel proxyPanel = new JPanel();
928     TitledBorder titledBorder1 = new TitledBorder(
929             MessageManager.getString("label.proxy_server"));
930     proxyPanel.setBorder(titledBorder1);
931     proxyPanel.setLayout(new GridBagLayout());
932     proxyPanel.add(serverLabel, new GridBagConstraints(0, 1, 1, 1, 0.0,
933             0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
934             new Insets(0, 2, 2, 0), 5, 0));
935     proxyPanel.add(portLabel, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
936             GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
937                     0, 2, 0), 11, 0));
938     proxyPanel.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
939             GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,
940                     2, 5, 185), 2, -4));
941     proxyPanel.add(proxyPortTB, new GridBagConstraints(3, 1, 1, 1, 1.0,
942             0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
943             new Insets(0, 2, 2, 2), 54, 1));
944     proxyPanel.add(proxyServerTB, new GridBagConstraints(1, 1, 1, 1, 1.0,
945             0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
946             new Insets(0, 2, 2, 0), 263, 1));
947
948     return proxyPanel;
949   }
950
951   /**
952    * Initialises the checkboxes in the Connections tab
953    */
954   private void initConnTabCheckboxes()
955   {
956     // Usage stats checkbox label
957     usagestats.setText(MessageManager
958             .getString("label.send_usage_statistics"));
959     usagestats.setFont(LABEL_FONT);
960     usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
961     usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
962
963     // Questionnaire checkbox label
964     questionnaire.setText(MessageManager
965             .getString("label.check_for_questionnaires"));
966     questionnaire.setFont(LABEL_FONT);
967     questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
968     questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
969
970     // Check for latest version checkbox label
971     versioncheck.setText(MessageManager
972             .getString("label.check_for_latest_version"));
973     versioncheck.setFont(LABEL_FONT);
974     versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
975     versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
976   }
977
978   /**
979    * Initialises the parent panel which contains the tabbed sections.
980    * 
981    * @return
982    */
983   private JPanel initOkCancelPanel()
984   {
985     JButton ok = new JButton();
986     ok.setText(MessageManager.getString("action.ok"));
987     ok.addActionListener(new ActionListener()
988     {
989       @Override
990       public void actionPerformed(ActionEvent e)
991       {
992         ok_actionPerformed(e);
993       }
994     });
995     JButton cancel = new JButton();
996     cancel.setText(MessageManager.getString("action.cancel"));
997     cancel.addActionListener(new ActionListener()
998     {
999       @Override
1000       public void actionPerformed(ActionEvent e)
1001       {
1002         cancel_actionPerformed(e);
1003       }
1004     });
1005     JPanel okCancelPanel = new JPanel();
1006     okCancelPanel.add(ok);
1007     okCancelPanel.add(cancel);
1008     return okCancelPanel;
1009   }
1010
1011   /**
1012    * Initialises the Colours tabbed panel.
1013    * 
1014    * @return
1015    */
1016   private JPanel initColoursTab()
1017   {
1018     JPanel coloursTab = new JPanel();
1019     coloursTab.setBorder(new TitledBorder(MessageManager
1020             .getString("action.open_new_alignment")));
1021     coloursTab.setLayout(new FlowLayout());
1022     JLabel mincolourLabel = new JLabel();
1023     mincolourLabel.setFont(LABEL_FONT);
1024     mincolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1025     mincolourLabel.setText(MessageManager.getString("label.min_colour"));
1026     minColour.setFont(LABEL_FONT);
1027     minColour.setBorder(BorderFactory.createEtchedBorder());
1028     minColour.setPreferredSize(new Dimension(40, 20));
1029     minColour.addMouseListener(new MouseAdapter()
1030     {
1031       @Override
1032       public void mousePressed(MouseEvent e)
1033       {
1034         minColour_actionPerformed(minColour);
1035       }
1036     });
1037     JLabel maxcolourLabel = new JLabel();
1038     maxcolourLabel.setFont(LABEL_FONT);
1039     maxcolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1040     maxcolourLabel.setText(MessageManager.getString("label.max_colour"));
1041     maxColour.setFont(LABEL_FONT);
1042     maxColour.setBorder(BorderFactory.createEtchedBorder());
1043     maxColour.setPreferredSize(new Dimension(40, 20));
1044     maxColour.addMouseListener(new MouseAdapter()
1045     {
1046       @Override
1047       public void mousePressed(MouseEvent e)
1048       {
1049         maxColour_actionPerformed(maxColour);
1050       }
1051     });
1052
1053     protColour.setFont(LABEL_FONT);
1054     protColour.setBounds(new Rectangle(172, 225, 155, 21));
1055     JLabel protColourLabel = new JLabel();
1056     protColourLabel.setFont(LABEL_FONT);
1057     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1058     protColourLabel.setText(MessageManager
1059             .getString("label.prot_alignment_colour") + " ");
1060     JvSwingUtils.addtoLayout(coloursTab, MessageManager
1061             .getString("label.default_colour_scheme_for_alignment"),
1062             protColourLabel, protColour);
1063
1064     nucColour.setFont(LABEL_FONT);
1065     nucColour.setBounds(new Rectangle(172, 240, 155, 21));
1066     JLabel nucColourLabel = new JLabel();
1067     nucColourLabel.setFont(LABEL_FONT);
1068     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1069     nucColourLabel.setText(MessageManager
1070             .getString("label.nuc_alignment_colour") + " ");
1071     JvSwingUtils.addtoLayout(coloursTab, MessageManager
1072             .getString("label.default_colour_scheme_for_alignment"),
1073             nucColourLabel, nucColour);
1074
1075     JPanel annotationShding = new JPanel();
1076     annotationShding.setBorder(new TitledBorder(MessageManager
1077             .getString("label.annotation_shading_default")));
1078     annotationShding.setLayout(new GridLayout(1, 2));
1079     JvSwingUtils.addtoLayout(annotationShding, MessageManager
1080             .getString("label.default_minimum_colour_annotation_shading"),
1081             mincolourLabel, minColour);
1082     JvSwingUtils.addtoLayout(annotationShding, MessageManager
1083             .getString("label.default_maximum_colour_annotation_shading"),
1084             maxcolourLabel, maxColour);
1085     coloursTab.add(annotationShding); // , FlowLayout.LEFT);
1086     return coloursTab;
1087   }
1088
1089   /**
1090    * Initialises the Structure tabbed panel.
1091    * 
1092    * @return
1093    */
1094   private JPanel initStructureTab()
1095   {
1096     structureTab = new JPanel();
1097
1098     structureTab.setBorder(new TitledBorder(MessageManager
1099             .getString("label.structure_options")));
1100     structureTab.setLayout(null);
1101     final int width = 400;
1102     final int height = 22;
1103     final int lineSpacing = 25;
1104     int ypos = 15;
1105
1106     structFromPdb.setFont(LABEL_FONT);
1107     structFromPdb
1108             .setText(MessageManager.getString("label.struct_from_pdb"));
1109     structFromPdb.setBounds(new Rectangle(5, ypos, width, height));
1110     structFromPdb.addActionListener(new ActionListener()
1111     {
1112       @Override
1113       public void actionPerformed(ActionEvent e)
1114       {
1115         boolean selected = structFromPdb.isSelected();
1116         // enable other options only when the first is checked
1117         useRnaView.setEnabled(selected);
1118         addSecondaryStructure.setEnabled(selected);
1119         addTempFactor.setEnabled(selected);
1120       }
1121     });
1122     structureTab.add(structFromPdb);
1123
1124     // indent checkboxes that are conditional on the first one
1125     ypos += lineSpacing;
1126     useRnaView.setFont(LABEL_FONT);
1127     useRnaView.setText(MessageManager.getString("label.use_rnaview"));
1128     useRnaView.setBounds(new Rectangle(25, ypos, width, height));
1129     structureTab.add(useRnaView);
1130
1131     ypos += lineSpacing;
1132     addSecondaryStructure.setFont(LABEL_FONT);
1133     addSecondaryStructure.setText(MessageManager
1134             .getString("label.autoadd_secstr"));
1135     addSecondaryStructure.setBounds(new Rectangle(25, ypos, width, height));
1136     structureTab.add(addSecondaryStructure);
1137
1138     ypos += lineSpacing;
1139     addTempFactor.setFont(LABEL_FONT);
1140     addTempFactor.setText(MessageManager.getString("label.autoadd_temp"));
1141     addTempFactor.setBounds(new Rectangle(25, ypos, width, height));
1142     structureTab.add(addTempFactor);
1143
1144     ypos += lineSpacing;
1145     JLabel viewerLabel = new JLabel();
1146     viewerLabel.setFont(LABEL_FONT);
1147     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
1148     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
1149     viewerLabel.setBounds(new Rectangle(10, ypos, 200, height));
1150     structureTab.add(viewerLabel);
1151
1152     structViewer.setFont(LABEL_FONT);
1153     structViewer.setBounds(new Rectangle(160, ypos, 120, height));
1154     structViewer.addItem(ViewerType.JMOL.name());
1155     structViewer.addItem(ViewerType.CHIMERA.name());
1156     structViewer.addActionListener(new ActionListener()
1157     {
1158       @Override
1159       public void actionPerformed(ActionEvent e)
1160       {
1161         structureViewer_actionPerformed((String) structViewer
1162                 .getSelectedItem());
1163       }
1164     });
1165     structureTab.add(structViewer);
1166
1167     ypos += lineSpacing;
1168     JLabel pathLabel = new JLabel();
1169     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
1170     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1171     pathLabel.setText(MessageManager.getString("label.chimera_path"));
1172     final String tooltip = JvSwingUtils.wrapTooltip(true,
1173             MessageManager.getString("label.chimera_path_tip"));
1174     pathLabel.setToolTipText(tooltip);
1175     pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
1176     structureTab.add(pathLabel);
1177
1178     chimeraPath.setFont(LABEL_FONT);
1179     chimeraPath.setText("");
1180     chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
1181     chimeraPath.addMouseListener(new MouseAdapter()
1182     {
1183       @Override
1184       public void mouseClicked(MouseEvent e)
1185       {
1186         if (e.getClickCount() == 2)
1187         {
1188           String chosen = openFileChooser(false);
1189           if (chosen != null)
1190           {
1191             chimeraPath.setText(chosen);
1192           }
1193         }
1194       }
1195     });
1196     structureTab.add(chimeraPath);
1197
1198     ypos += lineSpacing;
1199     nwMapping.setFont(LABEL_FONT);
1200     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1201     siftsMapping.setFont(LABEL_FONT);
1202     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1203     mappingMethod.add(nwMapping);
1204     mappingMethod.add(siftsMapping);
1205     JPanel mappingPanel = new JPanel();
1206     mappingPanel.setFont(LABEL_FONT);
1207     TitledBorder mmTitledBorder = new TitledBorder(
1208             MessageManager.getString("label.mapping_method"));
1209     mmTitledBorder.setTitleFont(LABEL_FONT);
1210     mappingPanel.setBorder(mmTitledBorder);
1211     mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
1212     // GridLayout mappingLayout = new GridLayout();
1213     mappingPanel.setLayout(new GridLayout());
1214     mappingPanel.add(nwMapping);
1215     mappingPanel.add(siftsMapping);
1216     structureTab.add(mappingPanel);
1217
1218     ypos += lineSpacing;
1219     ypos += lineSpacing;
1220     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1221             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1222     docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
1223     structureTab.add(docFieldPref);
1224
1225     return structureTab;
1226   }
1227
1228   /**
1229    * Action on choosing a structure viewer from combobox options.
1230    * 
1231    * @param selectedItem
1232    */
1233   protected void structureViewer_actionPerformed(String selectedItem)
1234   {
1235   }
1236
1237   /**
1238    * Show a dialog for the user to choose a file. Returns the chosen path, or
1239    * null on Cancel.
1240    * 
1241    * @return
1242    */
1243   protected String openFileChooser(boolean forFolder)
1244   {
1245     String choice = null;
1246     JFileChooser chooser = new JFileChooser();
1247     if (forFolder)
1248     {
1249       chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1250     }
1251
1252     // chooser.setFileView(new JalviewFileView());
1253     chooser.setDialogTitle(MessageManager
1254             .getString("label.open_local_file"));
1255     chooser.setToolTipText(MessageManager.getString("action.open"));
1256
1257     int value = chooser.showOpenDialog(this);
1258
1259     if (value == JFileChooser.APPROVE_OPTION)
1260     {
1261       choice = chooser.getSelectedFile().getPath();
1262     }
1263     return choice;
1264   }
1265
1266   /**
1267    * Validate the structure tab preferences; if invalid, set focus on this tab.
1268    * 
1269    * @param e
1270    */
1271   protected boolean validateStructure(FocusEvent e)
1272   {
1273     if (!validateStructure())
1274     {
1275       e.getComponent().requestFocusInWindow();
1276       return false;
1277     }
1278     return true;
1279   }
1280
1281   /**
1282    * Validate the hmmer tab preferences; if invalid, set focus on this tab.
1283    * 
1284    * @param e
1285    */
1286   protected boolean validateHMMER(FocusEvent e)
1287   {
1288     if (!validateHMMER())
1289     {
1290       e.getComponent().requestFocusInWindow();
1291       return false;
1292     }
1293     return true;
1294   }
1295
1296   protected boolean validateStructure()
1297   {
1298     return false;
1299   }
1300
1301   protected boolean validateHMMER()
1302   {
1303     return false;
1304   }
1305
1306   /**
1307    * Initialises the Visual tabbed panel.
1308    * 
1309    * @return
1310    */
1311   private JPanel initVisualTab()
1312   {
1313     JPanel visualTab = new JPanel();
1314     visualTab.setBorder(new TitledBorder(MessageManager
1315             .getString("action.open_new_alignment")));
1316     visualTab.setLayout(null);
1317     fullScreen.setFont(LABEL_FONT);
1318     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
1319     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
1320     fullScreen.setText(MessageManager.getString("label.maximize_window"));
1321     quality.setEnabled(false);
1322     quality.setFont(LABEL_FONT);
1323     quality.setHorizontalAlignment(SwingConstants.RIGHT);
1324     quality.setHorizontalTextPosition(SwingConstants.LEFT);
1325     quality.setSelected(true);
1326     quality.setText(MessageManager.getString("label.quality"));
1327     conservation.setEnabled(false);
1328     conservation.setFont(LABEL_FONT);
1329     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
1330     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
1331     conservation.setSelected(true);
1332     conservation.setText(MessageManager.getString("label.conservation"));
1333     identity.setEnabled(false);
1334     identity.setFont(LABEL_FONT);
1335     identity.setHorizontalAlignment(SwingConstants.RIGHT);
1336     identity.setHorizontalTextPosition(SwingConstants.LEFT);
1337     identity.setSelected(true);
1338     identity.setText(MessageManager.getString("label.consensus"));
1339     showOccupancy.setFont(LABEL_FONT);
1340     showOccupancy.setEnabled(false);
1341     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
1342     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
1343     showOccupancy.setSelected(true);
1344     showOccupancy.setText(MessageManager.getString("label.occupancy"));
1345
1346     JLabel showGroupbits = new JLabel();
1347     showGroupbits.setFont(LABEL_FONT);
1348     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
1349     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
1350     showGroupbits.setText(MessageManager.getString("action.show_group")
1351             + ":");
1352     JLabel showConsensbits = new JLabel();
1353     showConsensbits.setFont(LABEL_FONT);
1354     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
1355     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
1356     showConsensbits.setText(MessageManager.getString("label.consensus")
1357             + ":");
1358     showConsensHistogram.setEnabled(false);
1359     showConsensHistogram.setFont(LABEL_FONT);
1360     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
1361     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
1362     showConsensHistogram.setSelected(true);
1363     showConsensHistogram.setText(MessageManager
1364             .getString("label.histogram"));
1365     showConsensLogo.setEnabled(false);
1366     showConsensLogo.setFont(LABEL_FONT);
1367     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
1368     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
1369     showConsensLogo.setSelected(true);
1370     showConsensLogo.setText(MessageManager.getString("label.logo"));
1371     showGroupConsensus.setEnabled(false);
1372     showGroupConsensus.setFont(LABEL_FONT);
1373     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
1374     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
1375     showGroupConsensus.setSelected(true);
1376     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
1377     showGroupConservation.setEnabled(false);
1378     showGroupConservation.setFont(LABEL_FONT);
1379     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
1380     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
1381     showGroupConservation.setSelected(true);
1382     showGroupConservation.setText(MessageManager
1383             .getString("label.conservation"));
1384     showNpTooltip.setEnabled(true);
1385     showNpTooltip.setFont(LABEL_FONT);
1386     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1387     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1388     showNpTooltip.setSelected(true);
1389     showNpTooltip.setText(MessageManager
1390             .getString("label.non_positional_features"));
1391     showDbRefTooltip.setEnabled(true);
1392     showDbRefTooltip.setFont(LABEL_FONT);
1393     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1394     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1395     showDbRefTooltip.setSelected(true);
1396     showDbRefTooltip.setText(MessageManager
1397             .getString("label.database_references"));
1398     annotations.setFont(LABEL_FONT);
1399     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
1400     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
1401     annotations.setSelected(true);
1402     annotations.setText(MessageManager.getString("label.show_annotations"));
1403     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
1404     annotations.addActionListener(new ActionListener()
1405     {
1406       @Override
1407       public void actionPerformed(ActionEvent e)
1408       {
1409         annotations_actionPerformed(e);
1410       }
1411     });
1412     identity.addActionListener(new ActionListener()
1413     {
1414       @Override
1415       public void actionPerformed(ActionEvent e)
1416       {
1417         annotations_actionPerformed(e);
1418       }
1419     });
1420     showGroupConsensus.addActionListener(new ActionListener()
1421     {
1422       @Override
1423       public void actionPerformed(ActionEvent e)
1424       {
1425         annotations_actionPerformed(e);
1426       }
1427     });
1428     showUnconserved.setFont(LABEL_FONT);
1429     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
1430     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
1431     showUnconserved.setSelected(true);
1432     showUnconserved.setText(MessageManager
1433             .getString("action.show_unconserved"));
1434     showUnconserved.addActionListener(new ActionListener()
1435     {
1436       @Override
1437       public void actionPerformed(ActionEvent e)
1438       {
1439         showunconserved_actionPerformed(e);
1440       }
1441     });
1442
1443     // TODO these are not yet added to / action from Preferences
1444     // JCheckBox shareSelections = new JCheckBox();
1445     // shareSelections.setFont(verdana11);
1446     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
1447     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
1448     // shareSelections.setSelected(true);
1449     // shareSelections.setText(MessageManager
1450     // .getString("label.share_selection_across_views"));
1451     // JCheckBox followHighlight = new JCheckBox();
1452     // followHighlight.setFont(verdana11);
1453     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
1454     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
1455     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
1456     // followHighlight.setSelected(true);
1457     // followHighlight.setText(MessageManager
1458     // .getString("label.scroll_highlighted_regions"));
1459
1460     seqLimit.setFont(LABEL_FONT);
1461     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
1462     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
1463     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
1464     smoothFont.setFont(LABEL_FONT);
1465     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
1466     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
1467     smoothFont.setText(MessageManager.getString("label.smooth_font"));
1468     scaleProteinToCdna.setFont(LABEL_FONT);
1469     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
1470     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
1471     scaleProteinToCdna.setText(MessageManager
1472             .getString("label.scale_protein_to_cdna"));
1473     scaleProteinToCdna.setToolTipText(MessageManager
1474             .getString("label.scale_protein_to_cdna_tip"));
1475     JLabel gapLabel = new JLabel();
1476     gapLabel.setFont(LABEL_FONT);
1477     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1478     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
1479     JLabel fontLabel = new JLabel();
1480     fontLabel.setFont(LABEL_FONT);
1481     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1482     fontLabel.setText(MessageManager.getString("label.font"));
1483     fontSizeCB.setFont(LABEL_FONT);
1484     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
1485     fontStyleCB.setFont(LABEL_FONT);
1486     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
1487     fontNameCB.setFont(LABEL_FONT);
1488     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
1489     gapSymbolCB.setFont(LABEL_FONT);
1490     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
1491     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
1492     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
1493     gapSymbolCB.setRenderer(dlcr);
1494
1495     startupCheckbox.setText(MessageManager.getString("action.open_file"));
1496     startupCheckbox.setFont(LABEL_FONT);
1497     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
1498     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
1499     startupCheckbox.setSelected(true);
1500     startupFileTextfield.setFont(LABEL_FONT);
1501     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
1502     startupFileTextfield.addMouseListener(new MouseAdapter()
1503     {
1504       @Override
1505       public void mouseClicked(MouseEvent e)
1506       {
1507         if (e.getClickCount() > 1)
1508         {
1509           startupFileTextfield_mouseClicked();
1510         }
1511       }
1512     });
1513
1514     sortby.setFont(LABEL_FONT);
1515     sortby.setBounds(new Rectangle(172, 260, 155, 21));
1516     JLabel sortLabel = new JLabel();
1517     sortLabel.setFont(LABEL_FONT);
1518     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1519     sortLabel.setText(MessageManager.getString("label.sort_by"));
1520     sortAnnBy.setFont(LABEL_FONT);
1521     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
1522     JLabel sortAnnLabel = new JLabel();
1523     sortAnnLabel.setFont(LABEL_FONT);
1524     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1525     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
1526     sortAutocalc.setFont(LABEL_FONT);
1527     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
1528
1529     JPanel annsettingsPanel = new JPanel();
1530     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
1531     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
1532     annsettingsPanel.setBorder(new EtchedBorder());
1533     visualTab.add(annsettingsPanel);
1534     Border jb = new EmptyBorder(1, 1, 4, 5);
1535     annotations.setBorder(jb);
1536     showOccupancy.setBorder(jb);
1537     quality.setBorder(jb);
1538     conservation.setBorder(jb);
1539     identity.setBorder(jb);
1540     showConsensbits.setBorder(jb);
1541     showGroupbits.setBorder(jb);
1542     showGroupConsensus.setBorder(jb);
1543     showGroupConservation.setBorder(jb);
1544     showConsensHistogram.setBorder(jb);
1545     showConsensLogo.setBorder(jb);
1546
1547     JPanel autoAnnotSettings = new JPanel();
1548     annsettingsPanel.add(autoAnnotSettings);
1549     autoAnnotSettings.setLayout(new GridLayout(0, 2));
1550     autoAnnotSettings.add(annotations);
1551     autoAnnotSettings.add(quality);
1552     // second row of autoannotation box
1553     autoAnnotSettings = new JPanel();
1554     annsettingsPanel.add(autoAnnotSettings);
1555
1556     autoAnnotSettings.setLayout(new GridLayout(0, 3));
1557     autoAnnotSettings.add(conservation);
1558     autoAnnotSettings.add(identity);
1559     autoAnnotSettings.add(showOccupancy);
1560     autoAnnotSettings.add(showGroupbits);
1561     autoAnnotSettings.add(showGroupConservation);
1562     autoAnnotSettings.add(showGroupConsensus);
1563     autoAnnotSettings.add(showConsensbits);
1564     autoAnnotSettings.add(showConsensHistogram);
1565     autoAnnotSettings.add(showConsensLogo);
1566     
1567     
1568
1569     JPanel tooltipSettings = new JPanel();
1570     tooltipSettings.setBorder(new TitledBorder(MessageManager
1571             .getString("label.sequence_id_tooltip")));
1572     tooltipSettings.setBounds(173, 140, 220, 62);
1573     tooltipSettings.setLayout(new GridLayout(2, 1));
1574     tooltipSettings.add(showDbRefTooltip);
1575     tooltipSettings.add(showNpTooltip);
1576     visualTab.add(tooltipSettings);
1577
1578     wrap.setFont(LABEL_FONT);
1579     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
1580     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
1581     wrap.setText(MessageManager.getString("label.wrap_alignment"));
1582     rightAlign.setFont(LABEL_FONT);
1583     rightAlign.setForeground(Color.black);
1584     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
1585     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
1586     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
1587     idItalics.setFont(LABEL_FONT_ITALIC);
1588     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
1589     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
1590     idItalics.setText(MessageManager
1591             .getString("label.sequence_name_italics"));
1592     openoverv.setFont(LABEL_FONT);
1593     openoverv.setActionCommand(MessageManager
1594             .getString("label.open_overview"));
1595     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
1596     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
1597     openoverv.setText(MessageManager.getString("label.open_overview"));
1598     JPanel jPanel2 = new JPanel();
1599     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
1600     jPanel2.setLayout(new GridLayout(14, 1));
1601     jPanel2.add(fullScreen);
1602     jPanel2.add(openoverv);
1603     jPanel2.add(seqLimit);
1604     jPanel2.add(rightAlign);
1605     jPanel2.add(fontLabel);
1606     jPanel2.add(showUnconserved);
1607     jPanel2.add(idItalics);
1608     jPanel2.add(smoothFont);
1609     jPanel2.add(scaleProteinToCdna);
1610     jPanel2.add(gapLabel);
1611     jPanel2.add(wrap);
1612     jPanel2.add(sortLabel);
1613     jPanel2.add(sortAnnLabel);
1614     jPanel2.add(startupCheckbox);
1615     visualTab.add(jPanel2);
1616     visualTab.add(startupFileTextfield);
1617     visualTab.add(sortby);
1618     visualTab.add(sortAnnBy);
1619     visualTab.add(sortAutocalc);
1620     visualTab.add(gapSymbolCB);
1621     visualTab.add(fontNameCB);
1622     visualTab.add(fontSizeCB);
1623     visualTab.add(fontStyleCB);
1624     return visualTab;
1625   }
1626
1627   protected void autoIdWidth_actionPerformed()
1628   {
1629     // TODO Auto-generated method stub
1630
1631   }
1632
1633   protected void userIdWidth_actionPerformed()
1634   {
1635     // TODO Auto-generated method stub
1636
1637   }
1638
1639   protected void maxColour_actionPerformed(JPanel panel)
1640   {
1641   }
1642
1643   protected void minColour_actionPerformed(JPanel panel)
1644   {
1645   }
1646
1647   protected void showunconserved_actionPerformed(ActionEvent e)
1648   {
1649     // TODO Auto-generated method stub
1650
1651   }
1652
1653   /**
1654    * DOCUMENT ME!
1655    * 
1656    * @param e
1657    *          DOCUMENT ME!
1658    */
1659   public void ok_actionPerformed(ActionEvent e)
1660   {
1661   }
1662
1663   /**
1664    * DOCUMENT ME!
1665    * 
1666    * @param e
1667    *          DOCUMENT ME!
1668    */
1669   public void cancel_actionPerformed(ActionEvent e)
1670   {
1671   }
1672
1673   /**
1674    * DOCUMENT ME!
1675    * 
1676    * @param e
1677    *          DOCUMENT ME!
1678    */
1679   public void annotations_actionPerformed(ActionEvent e)
1680   {
1681   }
1682
1683   /**
1684    * DOCUMENT ME!
1685    */
1686   public void startupFileTextfield_mouseClicked()
1687   {
1688   }
1689
1690   public void newLink_actionPerformed(ActionEvent e)
1691   {
1692
1693   }
1694
1695   public void editLink_actionPerformed(ActionEvent e)
1696   {
1697
1698   }
1699
1700   public void deleteLink_actionPerformed(ActionEvent e)
1701   {
1702
1703   }
1704
1705   public void defaultBrowser_mouseClicked(MouseEvent e)
1706   {
1707
1708   }
1709
1710   public void linkURLList_keyTyped(KeyEvent e)
1711   {
1712
1713   }
1714
1715   public void useProxy_actionPerformed()
1716   {
1717     boolean enabled = useProxy.isSelected();
1718     portLabel.setEnabled(enabled);
1719     serverLabel.setEnabled(enabled);
1720     proxyServerTB.setEnabled(enabled);
1721     proxyPortTB.setEnabled(enabled);
1722   }
1723
1724   /**
1725    * Customer renderer for JTable: supports column of radio buttons
1726    */
1727   public class RadioButtonRenderer extends JRadioButton implements
1728           TableCellRenderer
1729   {
1730     public RadioButtonRenderer()
1731     {
1732       setHorizontalAlignment(CENTER);
1733       setToolTipText(MessageManager.getString("label.urltooltip"));
1734     }
1735
1736     @Override
1737     public Component getTableCellRendererComponent(JTable table,
1738             Object value, boolean isSelected, boolean hasFocus, int row,
1739             int column)
1740     {
1741       setSelected((boolean) value);
1742
1743       // set colours to match rest of table
1744       if (isSelected)
1745        {
1746          setBackground(table.getSelectionBackground());
1747          setForeground(table.getSelectionForeground());
1748        }
1749        else
1750        {
1751          setBackground(table.getBackground());
1752          setForeground(table.getForeground());
1753       }
1754       return this;
1755     }
1756   }
1757
1758   /**
1759    * Customer cell editor for JTable: supports column of radio buttons in
1760    * conjunction with renderer
1761    */
1762   public class RadioButtonEditor extends AbstractCellEditor implements
1763             TableCellEditor
1764     {
1765       private JRadioButton button = new JRadioButton();
1766
1767       public RadioButtonEditor()
1768       {
1769       button.setHorizontalAlignment(SwingConstants.CENTER);
1770       this.button.addActionListener(new ActionListener()
1771         {
1772           @Override
1773           public void actionPerformed(ActionEvent e)
1774           {
1775             fireEditingStopped();
1776           }
1777         });
1778       }
1779
1780       @Override
1781       public Component getTableCellEditorComponent(JTable table,
1782               Object value, boolean isSelected, int row, int column)
1783       {
1784       button.setSelected((boolean) value);
1785         return button;
1786       }
1787
1788       @Override
1789       public Object getCellEditorValue()
1790       {
1791       return button.isSelected();
1792       }
1793
1794   }
1795
1796   public void hmmerPath_actionPerformed(ActionEvent e)
1797   {
1798
1799   }
1800 }