Merge remote-tracking branch 'origin/releases/Release_2_10_2_Branch' into features...
[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
86           .getLabelFont(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(
408             MessageManager.getString("label.autocalculate_consensus"));
409     autoCalculateConsCheck.setBounds(new Rectangle(21, 52, 209, 23));
410     padGaps.setFont(LABEL_FONT);
411     padGaps.setText(
412             MessageManager.getString("label.pad_gaps_when_editing"));
413     padGaps.setBounds(new Rectangle(22, 94, 168, 23));
414     sortByTree.setFont(LABEL_FONT);
415     sortByTree
416             .setText(MessageManager.getString("label.sort_with_new_tree"));
417     sortByTree.setToolTipText(MessageManager.getString(
418             "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(
568             MessageManager.getString("label.automatically_set_id_width"));
569     autoIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
570             .getString("label.adjusts_width_generated_eps_png")));
571     autoIdWidth.setBounds(new Rectangle(228, 96, 188, 23));
572     autoIdWidth.addActionListener(new ActionListener()
573     {
574
575       @Override
576       public void actionPerformed(ActionEvent e)
577       {
578         autoIdWidth_actionPerformed();
579       }
580     });
581     userIdWidthlabel.setFont(LABEL_FONT);
582     userIdWidthlabel.setText(
583             MessageManager.getString("label.figure_id_column_width"));
584     userIdWidth.setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
585             .getString("label.manually_specify_width_left_column")));
586     userIdWidthlabel.setToolTipText(
587             JvSwingUtils.wrapTooltip(true, MessageManager.getString(
588                     "label.manually_specify_width_left_column")));
589     userIdWidthlabel.setBounds(new Rectangle(236, 120, 168, 23));
590     userIdWidth.setFont(JvSwingUtils.getTextAreaFont());
591     userIdWidth.setText("");
592     userIdWidth.setBounds(new Rectangle(232, 144, 84, 23));
593     userIdWidth.addActionListener(new ActionListener()
594     {
595
596       @Override
597       public void actionPerformed(ActionEvent e)
598       {
599         userIdWidth_actionPerformed();
600       }
601     });
602     modellerOutput.setFont(LABEL_FONT);
603     modellerOutput
604             .setText(MessageManager.getString("label.use_modeller_output"));
605     modellerOutput.setBounds(new Rectangle(228, 226, 168, 23));
606     embbedBioJSON.setFont(LABEL_FONT);
607     embbedBioJSON.setText(MessageManager.getString("label.embbed_biojson"));
608     embbedBioJSON.setBounds(new Rectangle(228, 200, 250, 23));
609
610     jPanel11.add(jLabel1);
611     jPanel11.add(blcjv);
612     jPanel11.add(clustaljv);
613     jPanel11.add(fastajv);
614     jPanel11.add(msfjv);
615     jPanel11.add(pfamjv);
616     jPanel11.add(pileupjv);
617     jPanel11.add(pirjv);
618     outputTab.add(autoIdWidth);
619     outputTab.add(userIdWidth);
620     outputTab.add(userIdWidthlabel);
621     outputTab.add(modellerOutput);
622     outputTab.add(embbedBioJSON);
623     outputTab.add(epsLabel);
624     outputTab.add(epsRendering);
625     outputTab.add(jPanel11);
626     return outputTab;
627   }
628
629   /**
630    * Initialises the Connections tabbed panel.
631    * 
632    * @return
633    */
634   private JPanel initConnectionsTab()
635   {
636     JPanel connectTab = new JPanel();
637     connectTab.setLayout(new GridBagLayout());
638
639     // Label for browser text box
640     JLabel browserLabel = new JLabel();
641     browserLabel.setFont(LABEL_FONT);
642     browserLabel.setHorizontalAlignment(SwingConstants.TRAILING);
643     browserLabel.setText(
644             MessageManager.getString("label.default_browser_unix"));
645     defaultBrowser.setFont(LABEL_FONT);
646     defaultBrowser.setText("");
647
648     defaultBrowser.addMouseListener(new MouseAdapter()
649     {
650       @Override
651       public void mouseClicked(MouseEvent e)
652       {
653         if (e.getClickCount() > 1)
654         {
655           defaultBrowser_mouseClicked(e);
656         }
657       }
658     });
659
660     JPanel proxyPanel = initConnTabProxyPanel();
661     initConnTabCheckboxes();
662
663     // Add default Browser text box
664     connectTab.add(browserLabel,
665             new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
666                     GridBagConstraints.WEST, GridBagConstraints.NONE,
667                     new Insets(10, 0, 5, 5), 5, 1));
668     defaultBrowser.setFont(LABEL_FONT);
669     defaultBrowser.setText("");
670
671     connectTab.add(defaultBrowser, new GridBagConstraints(1, 0, 1, 1, 1.0,
672             0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
673             new Insets(10, 0, 5, 10), 30, 1));
674
675     // Add proxy server panel
676     connectTab.add(proxyPanel, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0,
677             GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
678             new Insets(10, 0, 5, 12), 4, 10));
679
680     // Add usage stats, version check and questionnaire checkboxes
681     connectTab.add(usagestats,
682             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,
686             new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
687                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
688                     new Insets(0, 2, 5, 10), 70, 1));
689     connectTab.add(versioncheck,
690             new GridBagConstraints(0, 3, 1, 1, 1.0, 0.0,
691                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
692                     new Insets(0, 2, 5, 5), 70, 1));
693
694     // Add padding so the panel doesn't look ridiculous
695     JPanel spacePanel = new JPanel();
696     connectTab.add(spacePanel,
697             new GridBagConstraints(0, 4, 1, 1, 1.0, 1.0,
698                     GridBagConstraints.WEST, GridBagConstraints.BOTH,
699                     new Insets(0, 0, 0, 5), 70, 1));
700
701     return connectTab;
702   }
703
704   /**
705    * Initialises the Links tabbed panel.
706    * 
707    * @return
708    */
709   private JPanel initLinksTab()
710   {
711     JPanel linkTab = new JPanel();
712     linkTab.setLayout(new GridBagLayout());
713
714     // Set up table for Url links
715     linkUrlTable.setFillsViewportHeight(true);
716     linkUrlTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
717     linkUrlTable.setAutoCreateRowSorter(true);
718     linkUrlTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
719
720     // adjust row height so radio buttons actually fit
721     // don't do this in the renderer, it causes the awt thread to activate
722     // constantly
723     JRadioButton temp = new JRadioButton();
724     linkUrlTable.setRowHeight(temp.getMinimumSize().height);
725
726     // Table in scrollpane so that the table is given a scrollbar
727     JScrollPane linkScrollPane = new JScrollPane(linkUrlTable);
728     linkScrollPane.setBorder(null);
729
730     // Panel for links functionality
731     JPanel linkPanel = new JPanel(new GridBagLayout());
732     linkPanel.setBorder(new TitledBorder(
733             MessageManager.getString("label.url_linkfrom_sequence_id")));
734
735     // Put the Url links panel together
736
737     // Buttons go at top right, resizing only resizes the blank space vertically
738     JPanel buttonPanel = initLinkTabUrlButtons();
739     GridBagConstraints linkConstraints1 = new GridBagConstraints();
740     linkConstraints1.insets = new Insets(0, 0, 5, 0);
741     linkConstraints1.gridx = 0;
742     linkConstraints1.gridy = 0;
743     linkConstraints1.weightx = 1.0;
744     linkConstraints1.fill = GridBagConstraints.HORIZONTAL;
745     linkTab.add(buttonPanel, linkConstraints1);
746
747     // Links table goes at top left, resizing resizes the table
748     GridBagConstraints linkConstraints2 = new GridBagConstraints();
749     linkConstraints2.insets = new Insets(0, 0, 5, 5);
750     linkConstraints2.gridx = 0;
751     linkConstraints2.gridy = 1;
752     linkConstraints2.weightx = 1.0;
753     linkConstraints2.weighty = 1.0;
754     linkConstraints2.fill = GridBagConstraints.BOTH;
755     linkTab.add(linkScrollPane, linkConstraints2);
756
757     // Filter box and buttons goes at bottom left, resizing resizes the text box
758     JPanel filterPanel = initLinkTabFilterPanel();
759     GridBagConstraints linkConstraints3 = new GridBagConstraints();
760     linkConstraints3.insets = new Insets(0, 0, 0, 5);
761     linkConstraints3.gridx = 0;
762     linkConstraints3.gridy = 2;
763     linkConstraints3.weightx = 1.0;
764     linkConstraints3.fill = GridBagConstraints.HORIZONTAL;
765     linkTab.add(filterPanel, linkConstraints3);
766
767     return linkTab;
768   }
769
770   private JPanel initLinkTabFilterPanel()
771   {
772     // Filter textbox and reset button
773     JLabel filterLabel = new JLabel(
774             MessageManager.getString("label.filter"));
775     filterLabel.setFont(LABEL_FONT);
776     filterLabel.setHorizontalAlignment(SwingConstants.RIGHT);
777     filterLabel.setHorizontalTextPosition(SwingConstants.LEADING);
778
779     filterTB.setFont(LABEL_FONT);
780     filterTB.setText("");
781
782     doReset.setText(MessageManager.getString("action.showall"));
783     userOnly.setText(MessageManager.getString("action.customfilter"));
784
785     // Panel for filter functionality
786     JPanel filterPanel = new JPanel(new GridBagLayout());
787     filterPanel.setBorder(new TitledBorder("Filter"));
788     GridBagConstraints gbc = new GridBagConstraints();
789     gbc.gridx = 0;
790     gbc.gridy = 0;
791     gbc.fill = GridBagConstraints.NONE;
792     gbc.anchor = GridBagConstraints.WEST;
793
794     filterPanel.add(filterLabel, gbc);
795
796     GridBagConstraints gbc1 = new GridBagConstraints();
797     gbc1.gridx = 1;
798     gbc1.gridwidth = 2;
799     gbc1.fill = GridBagConstraints.HORIZONTAL;
800     gbc1.anchor = GridBagConstraints.WEST;
801     gbc1.weightx = 1.0;
802     filterPanel.add(filterTB, gbc1);
803
804     GridBagConstraints gbc2 = new GridBagConstraints();
805     gbc2.gridx = 3;
806     gbc2.fill = GridBagConstraints.NONE;
807     gbc2.anchor = GridBagConstraints.WEST;
808     filterPanel.add(doReset, gbc2);
809
810     GridBagConstraints gbc3 = new GridBagConstraints();
811     gbc3.gridx = 4;
812     gbc3.fill = GridBagConstraints.NONE;
813     gbc3.anchor = GridBagConstraints.WEST;
814     filterPanel.add(userOnly, gbc3);
815
816     return filterPanel;
817   }
818
819   private JPanel initLinkTabUrlButtons()
820   {
821     // Buttons for new / edit / delete Url links
822     JButton newLink = new JButton();
823     newLink.setText(MessageManager.getString("action.new"));
824
825     editLink.setText(MessageManager.getString("action.edit"));
826
827     deleteLink.setText(MessageManager.getString("action.delete"));
828
829     // no current selection, so initially disable delete/edit buttons
830     editLink.setEnabled(false);
831     deleteLink.setEnabled(false);
832
833     newLink.addActionListener(new java.awt.event.ActionListener()
834     {
835       @Override
836       public void actionPerformed(ActionEvent e)
837       {
838         newLink_actionPerformed(e);
839       }
840     });
841
842     editLink.setText(MessageManager.getString("action.edit"));
843     editLink.addActionListener(new java.awt.event.ActionListener()
844     {
845       @Override
846       public void actionPerformed(ActionEvent e)
847       {
848         editLink_actionPerformed(e);
849       }
850     });
851
852     deleteLink.setText(MessageManager.getString("action.delete"));
853     deleteLink.addActionListener(new java.awt.event.ActionListener()
854     {
855       @Override
856       public void actionPerformed(ActionEvent e)
857       {
858         deleteLink_actionPerformed(e);
859       }
860     });
861
862     JPanel buttonPanel = new JPanel(new GridBagLayout());
863     buttonPanel.setBorder(new TitledBorder("Edit links"));
864     GridBagConstraints gbc = new GridBagConstraints();
865     gbc.gridx = 0;
866     gbc.gridy = 0;
867     gbc.fill = GridBagConstraints.NONE;
868     buttonPanel.add(newLink, gbc);
869
870     GridBagConstraints gbc1 = new GridBagConstraints();
871     gbc1.gridx = 1;
872     gbc1.gridy = 0;
873     gbc1.fill = GridBagConstraints.NONE;
874     buttonPanel.add(editLink, gbc1);
875
876     GridBagConstraints gbc2 = new GridBagConstraints();
877     gbc2.gridx = 2;
878     gbc2.gridy = 0;
879     gbc2.fill = GridBagConstraints.NONE;
880     buttonPanel.add(deleteLink, gbc2);
881
882     GridBagConstraints gbc3 = new GridBagConstraints();
883     gbc3.gridx = 3;
884     gbc3.gridy = 0;
885     gbc3.fill = GridBagConstraints.HORIZONTAL;
886     gbc3.weightx = 1.0;
887     JPanel spacePanel = new JPanel();
888     spacePanel.setBorder(null);
889     buttonPanel.add(spacePanel, gbc3);
890
891     return buttonPanel;
892   }
893
894   /**
895    * Initialises the proxy server panel in the Connections tab
896    * 
897    * @return the proxy server panel
898    */
899   private JPanel initConnTabProxyPanel()
900   {
901     // Label for server text box
902     serverLabel.setText(MessageManager.getString("label.address"));
903     serverLabel.setHorizontalAlignment(SwingConstants.RIGHT);
904     serverLabel.setFont(LABEL_FONT);
905
906     // Proxy server and port text boxes
907     proxyServerTB.setFont(LABEL_FONT);
908     proxyPortTB.setFont(LABEL_FONT);
909
910     // Label for Port text box
911     portLabel.setFont(LABEL_FONT);
912     portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
913     portLabel.setText(MessageManager.getString("label.port"));
914
915     // Use proxy server checkbox
916     useProxy.setFont(LABEL_FONT);
917     useProxy.setHorizontalAlignment(SwingConstants.RIGHT);
918     useProxy.setHorizontalTextPosition(SwingConstants.LEADING);
919     useProxy.setText(MessageManager.getString("label.use_proxy_server"));
920     useProxy.addActionListener(new ActionListener()
921     {
922       @Override
923       public void actionPerformed(ActionEvent e)
924       {
925         useProxy_actionPerformed();
926       }
927     });
928
929     // Make proxy server panel
930     JPanel proxyPanel = new JPanel();
931     TitledBorder titledBorder1 = new TitledBorder(
932             MessageManager.getString("label.proxy_server"));
933     proxyPanel.setBorder(titledBorder1);
934     proxyPanel.setLayout(new GridBagLayout());
935     proxyPanel.add(serverLabel,
936             new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
937                     GridBagConstraints.WEST, GridBagConstraints.NONE,
938                     new Insets(0, 2, 2, 0), 5, 0));
939     proxyPanel.add(portLabel,
940             new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0,
941                     GridBagConstraints.WEST, GridBagConstraints.NONE,
942                     new Insets(0, 0, 2, 0), 11, 0));
943     proxyPanel.add(useProxy,
944             new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0,
945                     GridBagConstraints.WEST, GridBagConstraints.NONE,
946                     new Insets(0, 2, 5, 185), 2, -4));
947     proxyPanel.add(proxyPortTB,
948             new GridBagConstraints(3, 1, 1, 1, 1.0, 0.0,
949                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
950                     new Insets(0, 2, 2, 2), 54, 1));
951     proxyPanel.add(proxyServerTB,
952             new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0,
953                     GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
954                     new Insets(0, 2, 2, 0), 263, 1));
955
956     return proxyPanel;
957   }
958
959   /**
960    * Initialises the checkboxes in the Connections tab
961    */
962   private void initConnTabCheckboxes()
963   {
964     // Usage stats checkbox label
965     usagestats.setText(
966             MessageManager.getString("label.send_usage_statistics"));
967     usagestats.setFont(LABEL_FONT);
968     usagestats.setHorizontalAlignment(SwingConstants.RIGHT);
969     usagestats.setHorizontalTextPosition(SwingConstants.LEADING);
970
971     // Questionnaire checkbox label
972     questionnaire.setText(
973             MessageManager.getString("label.check_for_questionnaires"));
974     questionnaire.setFont(LABEL_FONT);
975     questionnaire.setHorizontalAlignment(SwingConstants.RIGHT);
976     questionnaire.setHorizontalTextPosition(SwingConstants.LEADING);
977
978     // Check for latest version checkbox label
979     versioncheck.setText(
980             MessageManager.getString("label.check_for_latest_version"));
981     versioncheck.setFont(LABEL_FONT);
982     versioncheck.setHorizontalAlignment(SwingConstants.RIGHT);
983     versioncheck.setHorizontalTextPosition(SwingConstants.LEADING);
984   }
985
986   /**
987    * Initialises the parent panel which contains the tabbed sections.
988    * 
989    * @return
990    */
991   private JPanel initOkCancelPanel()
992   {
993     JButton ok = new JButton();
994     ok.setText(MessageManager.getString("action.ok"));
995     ok.addActionListener(new ActionListener()
996     {
997       @Override
998       public void actionPerformed(ActionEvent e)
999       {
1000         ok_actionPerformed(e);
1001       }
1002     });
1003     JButton cancel = new JButton();
1004     cancel.setText(MessageManager.getString("action.cancel"));
1005     cancel.addActionListener(new ActionListener()
1006     {
1007       @Override
1008       public void actionPerformed(ActionEvent e)
1009       {
1010         cancel_actionPerformed(e);
1011       }
1012     });
1013     JPanel okCancelPanel = new JPanel();
1014     okCancelPanel.add(ok);
1015     okCancelPanel.add(cancel);
1016     return okCancelPanel;
1017   }
1018
1019   /**
1020    * Initialises the Colours tabbed panel.
1021    * 
1022    * @return
1023    */
1024   private JPanel initColoursTab()
1025   {
1026     JPanel coloursTab = new JPanel();
1027     coloursTab.setBorder(new TitledBorder(
1028             MessageManager.getString("action.open_new_alignment")));
1029     coloursTab.setLayout(new FlowLayout());
1030     JLabel mincolourLabel = new JLabel();
1031     mincolourLabel.setFont(LABEL_FONT);
1032     mincolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1033     mincolourLabel.setText(MessageManager.getString("label.min_colour"));
1034     minColour.setFont(LABEL_FONT);
1035     minColour.setBorder(BorderFactory.createEtchedBorder());
1036     minColour.setPreferredSize(new Dimension(40, 20));
1037     minColour.addMouseListener(new MouseAdapter()
1038     {
1039       @Override
1040       public void mousePressed(MouseEvent e)
1041       {
1042         minColour_actionPerformed(minColour);
1043       }
1044     });
1045     JLabel maxcolourLabel = new JLabel();
1046     maxcolourLabel.setFont(LABEL_FONT);
1047     maxcolourLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1048     maxcolourLabel.setText(MessageManager.getString("label.max_colour"));
1049     maxColour.setFont(LABEL_FONT);
1050     maxColour.setBorder(BorderFactory.createEtchedBorder());
1051     maxColour.setPreferredSize(new Dimension(40, 20));
1052     maxColour.addMouseListener(new MouseAdapter()
1053     {
1054       @Override
1055       public void mousePressed(MouseEvent e)
1056       {
1057         maxColour_actionPerformed(maxColour);
1058       }
1059     });
1060
1061     protColour.setFont(LABEL_FONT);
1062     protColour.setBounds(new Rectangle(172, 225, 155, 21));
1063     JLabel protColourLabel = new JLabel();
1064     protColourLabel.setFont(LABEL_FONT);
1065     protColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1066     protColourLabel.setText(
1067             MessageManager.getString("label.prot_alignment_colour") + " ");
1068     JvSwingUtils.addtoLayout(coloursTab,
1069             MessageManager
1070                     .getString("label.default_colour_scheme_for_alignment"),
1071             protColourLabel, protColour);
1072
1073     nucColour.setFont(LABEL_FONT);
1074     nucColour.setBounds(new Rectangle(172, 240, 155, 21));
1075     JLabel nucColourLabel = new JLabel();
1076     nucColourLabel.setFont(LABEL_FONT);
1077     nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT);
1078     nucColourLabel.setText(
1079             MessageManager.getString("label.nuc_alignment_colour") + " ");
1080     JvSwingUtils.addtoLayout(coloursTab,
1081             MessageManager
1082                     .getString("label.default_colour_scheme_for_alignment"),
1083             nucColourLabel, nucColour);
1084
1085     JPanel annotationShding = new JPanel();
1086     annotationShding.setBorder(new TitledBorder(
1087             MessageManager.getString("label.annotation_shading_default")));
1088     annotationShding.setLayout(new GridLayout(1, 2));
1089     JvSwingUtils.addtoLayout(annotationShding,
1090             MessageManager.getString(
1091                     "label.default_minimum_colour_annotation_shading"),
1092             mincolourLabel, minColour);
1093     JvSwingUtils.addtoLayout(annotationShding,
1094             MessageManager.getString(
1095                     "label.default_maximum_colour_annotation_shading"),
1096             maxcolourLabel, maxColour);
1097     coloursTab.add(annotationShding); // , FlowLayout.LEFT);
1098     return coloursTab;
1099   }
1100
1101   /**
1102    * Initialises the Structure tabbed panel.
1103    * 
1104    * @return
1105    */
1106   private JPanel initStructureTab()
1107   {
1108     structureTab = new JPanel();
1109
1110     structureTab.setBorder(new TitledBorder(
1111             MessageManager.getString("label.structure_options")));
1112     structureTab.setLayout(null);
1113     final int width = 400;
1114     final int height = 22;
1115     final int lineSpacing = 25;
1116     int ypos = 15;
1117
1118     structFromPdb.setFont(LABEL_FONT);
1119     structFromPdb
1120             .setText(MessageManager.getString("label.struct_from_pdb"));
1121     structFromPdb.setBounds(new Rectangle(5, ypos, width, height));
1122     structFromPdb.addActionListener(new ActionListener()
1123     {
1124       @Override
1125       public void actionPerformed(ActionEvent e)
1126       {
1127         boolean selected = structFromPdb.isSelected();
1128         // enable other options only when the first is checked
1129         useRnaView.setEnabled(selected);
1130         addSecondaryStructure.setEnabled(selected);
1131         addTempFactor.setEnabled(selected);
1132       }
1133     });
1134     structureTab.add(structFromPdb);
1135
1136     // indent checkboxes that are conditional on the first one
1137     ypos += lineSpacing;
1138     useRnaView.setFont(LABEL_FONT);
1139     useRnaView.setText(MessageManager.getString("label.use_rnaview"));
1140     useRnaView.setBounds(new Rectangle(25, ypos, width, height));
1141     structureTab.add(useRnaView);
1142
1143     ypos += lineSpacing;
1144     addSecondaryStructure.setFont(LABEL_FONT);
1145     addSecondaryStructure
1146             .setText(MessageManager.getString("label.autoadd_secstr"));
1147     addSecondaryStructure.setBounds(new Rectangle(25, ypos, width, height));
1148     structureTab.add(addSecondaryStructure);
1149
1150     ypos += lineSpacing;
1151     addTempFactor.setFont(LABEL_FONT);
1152     addTempFactor.setText(MessageManager.getString("label.autoadd_temp"));
1153     addTempFactor.setBounds(new Rectangle(25, ypos, width, height));
1154     structureTab.add(addTempFactor);
1155
1156     ypos += lineSpacing;
1157     JLabel viewerLabel = new JLabel();
1158     viewerLabel.setFont(LABEL_FONT);
1159     viewerLabel.setHorizontalAlignment(SwingConstants.LEFT);
1160     viewerLabel.setText(MessageManager.getString("label.structure_viewer"));
1161     viewerLabel.setBounds(new Rectangle(10, ypos, 200, height));
1162     structureTab.add(viewerLabel);
1163
1164     structViewer.setFont(LABEL_FONT);
1165     structViewer.setBounds(new Rectangle(160, ypos, 120, height));
1166     structViewer.addItem(ViewerType.JMOL.name());
1167     structViewer.addItem(ViewerType.CHIMERA.name());
1168     structViewer.addActionListener(new ActionListener()
1169     {
1170       @Override
1171       public void actionPerformed(ActionEvent e)
1172       {
1173         structureViewer_actionPerformed(
1174                 (String) structViewer.getSelectedItem());
1175       }
1176     });
1177     structureTab.add(structViewer);
1178
1179     ypos += lineSpacing;
1180     JLabel pathLabel = new JLabel();
1181     pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11));
1182     pathLabel.setHorizontalAlignment(SwingConstants.LEFT);
1183     pathLabel.setText(MessageManager.getString("label.chimera_path"));
1184     final String tooltip = JvSwingUtils.wrapTooltip(true,
1185             MessageManager.getString("label.chimera_path_tip"));
1186     pathLabel.setToolTipText(tooltip);
1187     pathLabel.setBounds(new Rectangle(10, ypos, 140, height));
1188     structureTab.add(pathLabel);
1189
1190     chimeraPath.setFont(LABEL_FONT);
1191     chimeraPath.setText("");
1192     chimeraPath.setBounds(new Rectangle(160, ypos, 300, height));
1193     chimeraPath.addMouseListener(new MouseAdapter()
1194     {
1195       @Override
1196       public void mouseClicked(MouseEvent e)
1197       {
1198         if (e.getClickCount() == 2)
1199         {
1200           String chosen = openFileChooser(false);
1201           if (chosen != null)
1202           {
1203             chimeraPath.setText(chosen);
1204           }
1205         }
1206       }
1207     });
1208     structureTab.add(chimeraPath);
1209
1210     ypos += lineSpacing;
1211     nwMapping.setFont(LABEL_FONT);
1212     nwMapping.setText(MessageManager.getString("label.nw_mapping"));
1213     siftsMapping.setFont(LABEL_FONT);
1214     siftsMapping.setText(MessageManager.getString("label.sifts_mapping"));
1215     mappingMethod.add(nwMapping);
1216     mappingMethod.add(siftsMapping);
1217     JPanel mappingPanel = new JPanel();
1218     mappingPanel.setFont(LABEL_FONT);
1219     TitledBorder mmTitledBorder = new TitledBorder(
1220             MessageManager.getString("label.mapping_method"));
1221     mmTitledBorder.setTitleFont(LABEL_FONT);
1222     mappingPanel.setBorder(mmTitledBorder);
1223     mappingPanel.setBounds(new Rectangle(10, ypos, 452, 45));
1224     // GridLayout mappingLayout = new GridLayout();
1225     mappingPanel.setLayout(new GridLayout());
1226     mappingPanel.add(nwMapping);
1227     mappingPanel.add(siftsMapping);
1228     structureTab.add(mappingPanel);
1229
1230     ypos += lineSpacing;
1231     ypos += lineSpacing;
1232     FTSDataColumnPreferences docFieldPref = new FTSDataColumnPreferences(
1233             PreferenceSource.PREFERENCES, PDBFTSRestClient.getInstance());
1234     docFieldPref.setBounds(new Rectangle(10, ypos, 450, 120));
1235     structureTab.add(docFieldPref);
1236
1237     return structureTab;
1238   }
1239
1240   /**
1241    * Action on choosing a structure viewer from combobox options.
1242    * 
1243    * @param selectedItem
1244    */
1245   protected void structureViewer_actionPerformed(String selectedItem)
1246   {
1247   }
1248
1249   /**
1250    * Show a dialog for the user to choose a file. Returns the chosen path, or
1251    * null on Cancel.
1252    * 
1253    * @return
1254    */
1255   protected String openFileChooser(boolean forFolder)
1256   {
1257     String choice = null;
1258     JFileChooser chooser = new JFileChooser();
1259     if (forFolder)
1260     {
1261       chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
1262     }
1263
1264     // chooser.setFileView(new JalviewFileView());
1265     chooser.setDialogTitle(
1266             MessageManager.getString("label.open_local_file"));
1267     chooser.setToolTipText(MessageManager.getString("action.open"));
1268
1269     int value = chooser.showOpenDialog(this);
1270
1271     if (value == JFileChooser.APPROVE_OPTION)
1272     {
1273       choice = chooser.getSelectedFile().getPath();
1274     }
1275     return choice;
1276   }
1277
1278   /**
1279    * Validate the structure tab preferences; if invalid, set focus on this tab.
1280    * 
1281    * @param e
1282    */
1283   protected boolean validateStructure(FocusEvent e)
1284   {
1285     if (!validateStructure())
1286     {
1287       e.getComponent().requestFocusInWindow();
1288       return false;
1289     }
1290     return true;
1291   }
1292
1293   /**
1294    * Validate the hmmer tab preferences; if invalid, set focus on this tab.
1295    * 
1296    * @param e
1297    */
1298   protected boolean validateHMMER(FocusEvent e)
1299   {
1300     if (!validateHMMER())
1301     {
1302       e.getComponent().requestFocusInWindow();
1303       return false;
1304     }
1305     return true;
1306   }
1307
1308   protected boolean validateStructure()
1309   {
1310     return false;
1311   }
1312
1313   protected boolean validateHMMER()
1314   {
1315     return false;
1316   }
1317
1318   /**
1319    * Initialises the Visual tabbed panel.
1320    * 
1321    * @return
1322    */
1323   private JPanel initVisualTab()
1324   {
1325     JPanel visualTab = new JPanel();
1326     visualTab.setBorder(new TitledBorder(
1327             MessageManager.getString("action.open_new_alignment")));
1328     visualTab.setLayout(null);
1329     fullScreen.setFont(LABEL_FONT);
1330     fullScreen.setHorizontalAlignment(SwingConstants.RIGHT);
1331     fullScreen.setHorizontalTextPosition(SwingConstants.LEFT);
1332     fullScreen.setText(MessageManager.getString("label.maximize_window"));
1333     quality.setEnabled(false);
1334     quality.setFont(LABEL_FONT);
1335     quality.setHorizontalAlignment(SwingConstants.RIGHT);
1336     quality.setHorizontalTextPosition(SwingConstants.LEFT);
1337     quality.setSelected(true);
1338     quality.setText(MessageManager.getString("label.quality"));
1339     conservation.setEnabled(false);
1340     conservation.setFont(LABEL_FONT);
1341     conservation.setHorizontalAlignment(SwingConstants.RIGHT);
1342     conservation.setHorizontalTextPosition(SwingConstants.LEFT);
1343     conservation.setSelected(true);
1344     conservation.setText(MessageManager.getString("label.conservation"));
1345     identity.setEnabled(false);
1346     identity.setFont(LABEL_FONT);
1347     identity.setHorizontalAlignment(SwingConstants.RIGHT);
1348     identity.setHorizontalTextPosition(SwingConstants.LEFT);
1349     identity.setSelected(true);
1350     identity.setText(MessageManager.getString("label.consensus"));
1351     showOccupancy.setFont(LABEL_FONT);
1352     showOccupancy.setEnabled(false);
1353     showOccupancy.setHorizontalAlignment(SwingConstants.RIGHT);
1354     showOccupancy.setHorizontalTextPosition(SwingConstants.LEFT);
1355     showOccupancy.setSelected(true);
1356     showOccupancy.setText(MessageManager.getString("label.occupancy"));
1357
1358     JLabel showGroupbits = new JLabel();
1359     showGroupbits.setFont(LABEL_FONT);
1360     showGroupbits.setHorizontalAlignment(SwingConstants.RIGHT);
1361     showGroupbits.setHorizontalTextPosition(SwingConstants.LEFT);
1362     showGroupbits
1363             .setText(MessageManager.getString("action.show_group") + ":");
1364     JLabel showConsensbits = new JLabel();
1365     showConsensbits.setFont(LABEL_FONT);
1366     showConsensbits.setHorizontalAlignment(SwingConstants.RIGHT);
1367     showConsensbits.setHorizontalTextPosition(SwingConstants.LEFT);
1368     showConsensbits
1369             .setText(MessageManager.getString("label.consensus") + ":");
1370     showConsensHistogram.setEnabled(false);
1371     showConsensHistogram.setFont(LABEL_FONT);
1372     showConsensHistogram.setHorizontalAlignment(SwingConstants.RIGHT);
1373     showConsensHistogram.setHorizontalTextPosition(SwingConstants.LEFT);
1374     showConsensHistogram.setSelected(true);
1375     showConsensHistogram
1376             .setText(MessageManager.getString("label.histogram"));
1377     showConsensLogo.setEnabled(false);
1378     showConsensLogo.setFont(LABEL_FONT);
1379     showConsensLogo.setHorizontalAlignment(SwingConstants.RIGHT);
1380     showConsensLogo.setHorizontalTextPosition(SwingConstants.LEFT);
1381     showConsensLogo.setSelected(true);
1382     showConsensLogo.setText(MessageManager.getString("label.logo"));
1383     showGroupConsensus.setEnabled(false);
1384     showGroupConsensus.setFont(LABEL_FONT);
1385     showGroupConsensus.setHorizontalAlignment(SwingConstants.RIGHT);
1386     showGroupConsensus.setHorizontalTextPosition(SwingConstants.LEFT);
1387     showGroupConsensus.setSelected(true);
1388     showGroupConsensus.setText(MessageManager.getString("label.consensus"));
1389     showGroupConservation.setEnabled(false);
1390     showGroupConservation.setFont(LABEL_FONT);
1391     showGroupConservation.setHorizontalAlignment(SwingConstants.RIGHT);
1392     showGroupConservation.setHorizontalTextPosition(SwingConstants.LEFT);
1393     showGroupConservation.setSelected(true);
1394     showGroupConservation
1395             .setText(MessageManager.getString("label.conservation"));
1396     showNpTooltip.setEnabled(true);
1397     showNpTooltip.setFont(LABEL_FONT);
1398     showNpTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1399     showNpTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1400     showNpTooltip.setSelected(true);
1401     showNpTooltip.setText(
1402             MessageManager.getString("label.non_positional_features"));
1403     showDbRefTooltip.setEnabled(true);
1404     showDbRefTooltip.setFont(LABEL_FONT);
1405     showDbRefTooltip.setHorizontalAlignment(SwingConstants.RIGHT);
1406     showDbRefTooltip.setHorizontalTextPosition(SwingConstants.LEFT);
1407     showDbRefTooltip.setSelected(true);
1408     showDbRefTooltip
1409             .setText(MessageManager.getString("label.database_references"));
1410     annotations.setFont(LABEL_FONT);
1411     annotations.setHorizontalAlignment(SwingConstants.RIGHT);
1412     annotations.setHorizontalTextPosition(SwingConstants.LEFT);
1413     annotations.setSelected(true);
1414     annotations.setText(MessageManager.getString("label.show_annotations"));
1415     // annotations.setBounds(new Rectangle(169, 12, 200, 23));
1416     annotations.addActionListener(new ActionListener()
1417     {
1418       @Override
1419       public void actionPerformed(ActionEvent e)
1420       {
1421         annotations_actionPerformed(e);
1422       }
1423     });
1424     identity.addActionListener(new ActionListener()
1425     {
1426       @Override
1427       public void actionPerformed(ActionEvent e)
1428       {
1429         annotations_actionPerformed(e);
1430       }
1431     });
1432     showGroupConsensus.addActionListener(new ActionListener()
1433     {
1434       @Override
1435       public void actionPerformed(ActionEvent e)
1436       {
1437         annotations_actionPerformed(e);
1438       }
1439     });
1440     showUnconserved.setFont(LABEL_FONT);
1441     showUnconserved.setHorizontalAlignment(SwingConstants.RIGHT);
1442     showUnconserved.setHorizontalTextPosition(SwingConstants.LEFT);
1443     showUnconserved.setSelected(true);
1444     showUnconserved
1445             .setText(MessageManager.getString("action.show_unconserved"));
1446     showUnconserved.addActionListener(new ActionListener()
1447     {
1448       @Override
1449       public void actionPerformed(ActionEvent e)
1450       {
1451         showunconserved_actionPerformed(e);
1452       }
1453     });
1454
1455     // TODO these are not yet added to / action from Preferences
1456     // JCheckBox shareSelections = new JCheckBox();
1457     // shareSelections.setFont(verdana11);
1458     // shareSelections.setHorizontalAlignment(SwingConstants.RIGHT);
1459     // shareSelections.setHorizontalTextPosition(SwingConstants.LEFT);
1460     // shareSelections.setSelected(true);
1461     // shareSelections.setText(MessageManager
1462     // .getString("label.share_selection_across_views"));
1463     // JCheckBox followHighlight = new JCheckBox();
1464     // followHighlight.setFont(verdana11);
1465     // followHighlight.setHorizontalAlignment(SwingConstants.RIGHT);
1466     // followHighlight.setHorizontalTextPosition(SwingConstants.LEFT);
1467     // // showUnconserved.setBounds(new Rectangle(169, 40, 200, 23));
1468     // followHighlight.setSelected(true);
1469     // followHighlight.setText(MessageManager
1470     // .getString("label.scroll_highlighted_regions"));
1471
1472     seqLimit.setFont(LABEL_FONT);
1473     seqLimit.setHorizontalAlignment(SwingConstants.RIGHT);
1474     seqLimit.setHorizontalTextPosition(SwingConstants.LEFT);
1475     seqLimit.setText(MessageManager.getString("label.full_sequence_id"));
1476     smoothFont.setFont(LABEL_FONT);
1477     smoothFont.setHorizontalAlignment(SwingConstants.RIGHT);
1478     smoothFont.setHorizontalTextPosition(SwingConstants.LEADING);
1479     smoothFont.setText(MessageManager.getString("label.smooth_font"));
1480     scaleProteinToCdna.setFont(LABEL_FONT);
1481     scaleProteinToCdna.setHorizontalAlignment(SwingConstants.RIGHT);
1482     scaleProteinToCdna.setHorizontalTextPosition(SwingConstants.LEADING);
1483     scaleProteinToCdna.setText(
1484             MessageManager.getString("label.scale_protein_to_cdna"));
1485     scaleProteinToCdna.setToolTipText(
1486             MessageManager.getString("label.scale_protein_to_cdna_tip"));
1487     JLabel gapLabel = new JLabel();
1488     gapLabel.setFont(LABEL_FONT);
1489     gapLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1490     gapLabel.setText(MessageManager.getString("label.gap_symbol") + " ");
1491     JLabel fontLabel = new JLabel();
1492     fontLabel.setFont(LABEL_FONT);
1493     fontLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1494     fontLabel.setText(MessageManager.getString("label.font"));
1495     fontSizeCB.setFont(LABEL_FONT);
1496     fontSizeCB.setBounds(new Rectangle(320, 112, 65, 23));
1497     fontStyleCB.setFont(LABEL_FONT);
1498     fontStyleCB.setBounds(new Rectangle(382, 112, 80, 23));
1499     fontNameCB.setFont(LABEL_FONT);
1500     fontNameCB.setBounds(new Rectangle(172, 112, 147, 23));
1501     gapSymbolCB.setFont(LABEL_FONT);
1502     gapSymbolCB.setBounds(new Rectangle(172, 215, 69, 23));
1503     DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
1504     dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
1505     gapSymbolCB.setRenderer(dlcr);
1506
1507     startupCheckbox.setText(MessageManager.getString("action.open_file"));
1508     startupCheckbox.setFont(LABEL_FONT);
1509     startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT);
1510     startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT);
1511     startupCheckbox.setSelected(true);
1512     startupFileTextfield.setFont(LABEL_FONT);
1513     startupFileTextfield.setBounds(new Rectangle(172, 310, 330, 20));
1514     startupFileTextfield.addMouseListener(new MouseAdapter()
1515     {
1516       @Override
1517       public void mouseClicked(MouseEvent e)
1518       {
1519         if (e.getClickCount() > 1)
1520         {
1521           startupFileTextfield_mouseClicked();
1522         }
1523       }
1524     });
1525
1526     sortby.setFont(LABEL_FONT);
1527     sortby.setBounds(new Rectangle(172, 260, 155, 21));
1528     JLabel sortLabel = new JLabel();
1529     sortLabel.setFont(LABEL_FONT);
1530     sortLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1531     sortLabel.setText(MessageManager.getString("label.sort_by"));
1532     sortAnnBy.setFont(LABEL_FONT);
1533     sortAnnBy.setBounds(new Rectangle(172, 285, 110, 21));
1534     JLabel sortAnnLabel = new JLabel();
1535     sortAnnLabel.setFont(LABEL_FONT);
1536     sortAnnLabel.setHorizontalAlignment(SwingConstants.RIGHT);
1537     sortAnnLabel.setText(MessageManager.getString("label.sort_ann_by"));
1538     sortAutocalc.setFont(LABEL_FONT);
1539     sortAutocalc.setBounds(new Rectangle(290, 285, 165, 21));
1540
1541     JPanel annsettingsPanel = new JPanel();
1542     annsettingsPanel.setBounds(new Rectangle(173, 13, 320, 96));
1543     annsettingsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
1544     annsettingsPanel.setBorder(new EtchedBorder());
1545     visualTab.add(annsettingsPanel);
1546     Border jb = new EmptyBorder(1, 1, 4, 5);
1547     annotations.setBorder(jb);
1548     showOccupancy.setBorder(jb);
1549     quality.setBorder(jb);
1550     conservation.setBorder(jb);
1551     identity.setBorder(jb);
1552     showConsensbits.setBorder(jb);
1553     showGroupbits.setBorder(jb);
1554     showGroupConsensus.setBorder(jb);
1555     showGroupConservation.setBorder(jb);
1556     showConsensHistogram.setBorder(jb);
1557     showConsensLogo.setBorder(jb);
1558
1559     JPanel autoAnnotSettings = new JPanel();
1560     annsettingsPanel.add(autoAnnotSettings);
1561     autoAnnotSettings.setLayout(new GridLayout(0, 2));
1562     autoAnnotSettings.add(annotations);
1563     autoAnnotSettings.add(quality);
1564     // second row of autoannotation box
1565     autoAnnotSettings = new JPanel();
1566     annsettingsPanel.add(autoAnnotSettings);
1567
1568     autoAnnotSettings.setLayout(new GridLayout(0, 3));
1569     autoAnnotSettings.add(conservation);
1570     autoAnnotSettings.add(identity);
1571     autoAnnotSettings.add(showOccupancy);
1572     autoAnnotSettings.add(showGroupbits);
1573     autoAnnotSettings.add(showGroupConservation);
1574     autoAnnotSettings.add(showGroupConsensus);
1575     autoAnnotSettings.add(showConsensbits);
1576     autoAnnotSettings.add(showConsensHistogram);
1577     autoAnnotSettings.add(showConsensLogo);
1578
1579     JPanel tooltipSettings = new JPanel();
1580     tooltipSettings.setBorder(new TitledBorder(
1581             MessageManager.getString("label.sequence_id_tooltip")));
1582     tooltipSettings.setBounds(173, 140, 220, 62);
1583     tooltipSettings.setLayout(new GridLayout(2, 1));
1584     tooltipSettings.add(showDbRefTooltip);
1585     tooltipSettings.add(showNpTooltip);
1586     visualTab.add(tooltipSettings);
1587
1588     wrap.setFont(LABEL_FONT);
1589     wrap.setHorizontalAlignment(SwingConstants.TRAILING);
1590     wrap.setHorizontalTextPosition(SwingConstants.LEADING);
1591     wrap.setText(MessageManager.getString("label.wrap_alignment"));
1592     rightAlign.setFont(LABEL_FONT);
1593     rightAlign.setForeground(Color.black);
1594     rightAlign.setHorizontalAlignment(SwingConstants.RIGHT);
1595     rightAlign.setHorizontalTextPosition(SwingConstants.LEFT);
1596     rightAlign.setText(MessageManager.getString("label.right_align_ids"));
1597     idItalics.setFont(LABEL_FONT_ITALIC);
1598     idItalics.setHorizontalAlignment(SwingConstants.RIGHT);
1599     idItalics.setHorizontalTextPosition(SwingConstants.LEADING);
1600     idItalics.setText(
1601             MessageManager.getString("label.sequence_name_italics"));
1602     openoverv.setFont(LABEL_FONT);
1603     openoverv.setActionCommand(
1604             MessageManager.getString("label.open_overview"));
1605     openoverv.setHorizontalAlignment(SwingConstants.RIGHT);
1606     openoverv.setHorizontalTextPosition(SwingConstants.LEFT);
1607     openoverv.setText(MessageManager.getString("label.open_overview"));
1608     JPanel jPanel2 = new JPanel();
1609     jPanel2.setBounds(new Rectangle(7, 17, 158, 310));
1610     jPanel2.setLayout(new GridLayout(14, 1));
1611     jPanel2.add(fullScreen);
1612     jPanel2.add(openoverv);
1613     jPanel2.add(seqLimit);
1614     jPanel2.add(rightAlign);
1615     jPanel2.add(fontLabel);
1616     jPanel2.add(showUnconserved);
1617     jPanel2.add(idItalics);
1618     jPanel2.add(smoothFont);
1619     jPanel2.add(scaleProteinToCdna);
1620     jPanel2.add(gapLabel);
1621     jPanel2.add(wrap);
1622     jPanel2.add(sortLabel);
1623     jPanel2.add(sortAnnLabel);
1624     jPanel2.add(startupCheckbox);
1625     visualTab.add(jPanel2);
1626     visualTab.add(startupFileTextfield);
1627     visualTab.add(sortby);
1628     visualTab.add(sortAnnBy);
1629     visualTab.add(sortAutocalc);
1630     visualTab.add(gapSymbolCB);
1631     visualTab.add(fontNameCB);
1632     visualTab.add(fontSizeCB);
1633     visualTab.add(fontStyleCB);
1634     return visualTab;
1635   }
1636
1637   protected void autoIdWidth_actionPerformed()
1638   {
1639     // TODO Auto-generated method stub
1640
1641   }
1642
1643   protected void userIdWidth_actionPerformed()
1644   {
1645     // TODO Auto-generated method stub
1646
1647   }
1648
1649   protected void maxColour_actionPerformed(JPanel panel)
1650   {
1651   }
1652
1653   protected void minColour_actionPerformed(JPanel panel)
1654   {
1655   }
1656
1657   protected void showunconserved_actionPerformed(ActionEvent e)
1658   {
1659     // TODO Auto-generated method stub
1660
1661   }
1662
1663   /**
1664    * DOCUMENT ME!
1665    * 
1666    * @param e
1667    *          DOCUMENT ME!
1668    */
1669   public void ok_actionPerformed(ActionEvent e)
1670   {
1671   }
1672
1673   /**
1674    * DOCUMENT ME!
1675    * 
1676    * @param e
1677    *          DOCUMENT ME!
1678    */
1679   public void cancel_actionPerformed(ActionEvent e)
1680   {
1681   }
1682
1683   /**
1684    * DOCUMENT ME!
1685    * 
1686    * @param e
1687    *          DOCUMENT ME!
1688    */
1689   public void annotations_actionPerformed(ActionEvent e)
1690   {
1691   }
1692
1693   /**
1694    * DOCUMENT ME!
1695    */
1696   public void startupFileTextfield_mouseClicked()
1697   {
1698   }
1699
1700   public void newLink_actionPerformed(ActionEvent e)
1701   {
1702
1703   }
1704
1705   public void editLink_actionPerformed(ActionEvent e)
1706   {
1707
1708   }
1709
1710   public void deleteLink_actionPerformed(ActionEvent e)
1711   {
1712
1713   }
1714
1715   public void defaultBrowser_mouseClicked(MouseEvent e)
1716   {
1717
1718   }
1719
1720   public void linkURLList_keyTyped(KeyEvent e)
1721   {
1722
1723   }
1724
1725   public void useProxy_actionPerformed()
1726   {
1727     boolean enabled = useProxy.isSelected();
1728     portLabel.setEnabled(enabled);
1729     serverLabel.setEnabled(enabled);
1730     proxyServerTB.setEnabled(enabled);
1731     proxyPortTB.setEnabled(enabled);
1732   }
1733
1734   /**
1735    * Customer renderer for JTable: supports column of radio buttons
1736    */
1737   public class RadioButtonRenderer extends JRadioButton
1738           implements TableCellRenderer
1739   {
1740     public RadioButtonRenderer()
1741     {
1742       setHorizontalAlignment(CENTER);
1743       setToolTipText(MessageManager.getString("label.urltooltip"));
1744     }
1745
1746     @Override
1747     public Component getTableCellRendererComponent(JTable table,
1748             Object value, boolean isSelected, boolean hasFocus, int row,
1749             int column)
1750     {
1751       setSelected((boolean) value);
1752
1753       // set colours to match rest of table
1754       if (isSelected)
1755       {
1756         setBackground(table.getSelectionBackground());
1757         setForeground(table.getSelectionForeground());
1758       }
1759       else
1760       {
1761         setBackground(table.getBackground());
1762         setForeground(table.getForeground());
1763       }
1764       return this;
1765     }
1766   }
1767
1768   /**
1769    * Customer cell editor for JTable: supports column of radio buttons in
1770    * conjunction with renderer
1771    */
1772   public class RadioButtonEditor extends AbstractCellEditor
1773           implements TableCellEditor
1774   {
1775     private JRadioButton button = new JRadioButton();
1776
1777     public RadioButtonEditor()
1778     {
1779       button.setHorizontalAlignment(SwingConstants.CENTER);
1780       this.button.addActionListener(new ActionListener()
1781       {
1782         @Override
1783         public void actionPerformed(ActionEvent e)
1784         {
1785           fireEditingStopped();
1786         }
1787       });
1788     }
1789
1790     @Override
1791     public Component getTableCellEditorComponent(JTable table, Object value,
1792             boolean isSelected, int row, int column)
1793     {
1794       button.setSelected((boolean) value);
1795       return button;
1796     }
1797
1798     @Override
1799     public Object getCellEditorValue()
1800     {
1801       return button.isSelected();
1802     }
1803
1804   }
1805
1806   public void hmmerPath_actionPerformed(ActionEvent e)
1807   {
1808
1809   }
1810 }