changed order
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ControlPanel.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 //
22 // Contact: phylosoft @ gmail . com
23 // WWW: www.phylosoft.org/forester
24
25 package org.forester.archaeopteryx;
26
27 import java.awt.BorderLayout;
28 import java.awt.Color;
29 import java.awt.Component;
30 import java.awt.Dimension;
31 import java.awt.Font;
32 import java.awt.GridBagLayout;
33 import java.awt.GridLayout;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.awt.event.KeyAdapter;
39 import java.awt.event.KeyEvent;
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.HashMap;
44 import java.util.HashSet;
45 import java.util.List;
46 import java.util.Map;
47
48 import javax.swing.BorderFactory;
49 import javax.swing.DefaultListCellRenderer;
50 import javax.swing.JButton;
51 import javax.swing.JCheckBox;
52 import javax.swing.JComboBox;
53 import javax.swing.JLabel;
54 import javax.swing.JList;
55 import javax.swing.JPanel;
56 import javax.swing.JScrollBar;
57 import javax.swing.JTextField;
58 import javax.swing.ListCellRenderer;
59
60 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
61 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
62 import org.forester.phylogeny.Phylogeny;
63 import org.forester.phylogeny.PhylogenyMethods;
64 import org.forester.phylogeny.PhylogenyNode;
65 import org.forester.phylogeny.data.Sequence;
66 import org.forester.phylogeny.data.SequenceRelation;
67 import org.forester.util.ForesterUtil;
68
69 final class ControlPanel extends JPanel implements ActionListener {
70
71     private static final String  RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree";
72     final static Font            jcb_font                  = new Font( Configuration.getDefaultFontFamilyName(),
73                                                                        Font.PLAIN,
74                                                                        9 );
75     final static Font            js_font                   = new Font( Configuration.getDefaultFontFamilyName(),
76                                                                        Font.PLAIN,
77                                                                        9 );
78     final static Font            jcb_bold_font             = new Font( Configuration.getDefaultFontFamilyName(),
79                                                                        Font.BOLD,
80                                                                        9 );
81     private static final long    serialVersionUID          = -8463483932821545633L;
82     private final MainPanel      _mainpanel;
83     // The settings from the conf file
84     private final Configuration  _configuration;
85     // Tree checkboxes
86     private JCheckBox            _display_internal_data;
87     private JCheckBox            _show_node_names;
88     private JCheckBox            _show_taxo_code;
89     private JCheckBox            _write_confidence;
90     private JCheckBox            _show_events;
91     private JCheckBox            _color_acc_species;
92     private JCheckBox            _color_branches_cb;
93     private JCheckBox            _width_branches;
94     private JCheckBox            _show_domain_architectures;
95     private JCheckBox            _show_annotation;
96     private JCheckBox            _show_binary_characters;
97     private JCheckBox            _show_binary_character_counts;
98     private JCheckBox            _show_gene_names;
99     private JCheckBox            _show_gene_symbols;
100     private JCheckBox            _show_sequence_acc;
101     private JCheckBox            _node_desc_popup_cb;
102     private JCheckBox            _dynamically_hide_data;
103     private JCheckBox            _show_taxo_scientific_names;
104     private JCheckBox            _show_taxo_common_names;
105     private JCheckBox            _show_taxo_images_cb;
106     private JCheckBox            _color_according_to_annotation;
107     private JCheckBox            _display_as_phylogram_cb;
108     private JCheckBox            _seq_relation_confidence_switch;
109     private JComboBox            _show_sequence_relations;
110     private JComboBox            _sequence_relation_type_box;
111     private JCheckBox            _show_vector_data_cb;
112     private JLabel               _click_to_label;
113     private JLabel               _zoom_label;
114     private JLabel               _domain_display_label;
115     private JComboBox            _click_to_combobox;
116     private Map<Integer, String> _all_click_to_names;
117     private List<String>         _click_to_names;
118     // Indices for the click-to options in the combo box
119     private int                  _show_data_item;
120     private int                  _collapse_cb_item;
121     private int                  _reroot_cb_item;
122     private int                  _swap_cb_item;
123     private int                  _subtree_cb_item;
124     private int                  _color_subtree_cb_item;
125     private int                  _open_seq_web_item;
126     private int                  _open_tax_web_item;
127     private int                  _cut_subtree_item;
128     private int                  _copy_subtree_item;
129     private int                  _delete_node_or_subtree_item;
130     private int                  _paste_subtree_item;
131     private int                  _add_new_node_item;
132     private int                  _edit_node_data_item;
133     private int                  _blast_item;
134     // zooming and quick tree manipulation buttons:
135     private JButton              _zoom_in_x;
136     private JButton              _zoom_in_y;
137     private JButton              _zoom_out_x;
138     private JButton              _zoom_out_y;
139     private JButton              _show_whole;
140     private JButton              _order;
141     private JButton              _uncollapse_all;
142     private JButton              _zoom_in_domain_structure;
143     private JButton              _zoom_out_domain_structure;
144     private JButton              _decr_domain_structure_evalue_thr;
145     private JButton              _incr_domain_structure_evalue_thr;
146     private JButton              _return_to_super_tree;
147     private JTextField           _domain_structure_evalue_thr_tf;
148     private JTextField           _search_tf;
149     private boolean              _order_of_appearance;
150     private boolean              _color_branches;
151     private NodeClickAction      _action_when_node_clicked;
152     private List<Boolean>        _draw_phylogram;
153     private Map<String, Color>   _annotation_colors;
154     private Map<String, Color>   _species_colors;
155     private JButton              _search_reset_button;
156     private JLabel               _search_found_label;
157     private Sequence             _selected_query_seq;
158
159     ControlPanel( final MainPanel ap, final Configuration configuration ) {
160         init();
161         _mainpanel = ap;
162         _configuration = configuration;
163         if ( !_configuration.isUseNativeUI() ) {
164             setBackground( getConfiguration().getGuiBackgroundColor() );
165             setBorder( BorderFactory.createRaisedBevelBorder() );
166         }
167         setLayout( new GridLayout( 0, 1, 2, 2 ) );
168         _order_of_appearance = true;
169         setupControls();
170     }
171
172     /**
173      * Handle an action.
174      */
175     @Override
176     public void actionPerformed( final ActionEvent e ) {
177         try {
178             final TreePanel tp = getMainPanel().getCurrentTreePanel();
179             if ( tp == null ) {
180                 return;
181             }
182             if ( e.getSource() == _click_to_combobox ) {
183                 setClickToAction( _click_to_combobox.getSelectedIndex() );
184                 getCurrentTreePanel().repaint();
185             }
186             else if ( e.getSource() == _show_binary_characters ) {
187                 if ( ( _show_binary_character_counts != null ) && _show_binary_characters.isSelected() ) {
188                     _show_binary_character_counts.setSelected( false );
189                 }
190                 displayedPhylogenyMightHaveChanged( true );
191             }
192             else if ( e.getSource() == _show_binary_character_counts ) {
193                 if ( ( _show_binary_characters != null ) && _show_binary_character_counts.isSelected() ) {
194                     _show_binary_characters.setSelected( false );
195                 }
196                 displayedPhylogenyMightHaveChanged( true );
197             }
198             else if ( e.getSource() == _color_according_to_annotation ) {
199                 if ( ( _show_annotation != null ) && _color_according_to_annotation.isSelected() ) {
200                     _show_annotation.setSelected( true );
201                 }
202                 displayedPhylogenyMightHaveChanged( false );
203             }
204             else if ( e.getSource() == _show_annotation ) {
205                 if ( ( _color_according_to_annotation != null ) && !_show_annotation.isSelected() ) {
206                     _color_according_to_annotation.setSelected( false );
207                 }
208                 displayedPhylogenyMightHaveChanged( false );
209             }
210             else if ( ( tp != null ) && ( tp.getPhylogeny() != null ) ) {
211                 if ( e.getSource() == getDisplayAsPhylogramCb() ) {
212                     setDrawPhylogram( getDisplayAsPhylogramCb().isSelected() );
213                     showWhole();
214                 }
215                 // Zoom buttons
216                 else if ( e.getSource() == _zoom_in_x ) {
217                     zoomInX( Constants.BUTTON_ZOOM_IN_FACTOR, Constants.BUTTON_ZOOM_IN_X_CORRECTION_FACTOR );
218                     displayedPhylogenyMightHaveChanged( false );
219                 }
220                 else if ( e.getSource() == _zoom_in_y ) {
221                     zoomInY( Constants.BUTTON_ZOOM_IN_FACTOR );
222                     displayedPhylogenyMightHaveChanged( false );
223                 }
224                 else if ( e.getSource() == _zoom_out_x ) {
225                     zoomOutX( Constants.BUTTON_ZOOM_OUT_FACTOR, Constants.BUTTON_ZOOM_OUT_X_CORRECTION_FACTOR );
226                     displayedPhylogenyMightHaveChanged( false );
227                 }
228                 else if ( e.getSource() == _zoom_out_y ) {
229                     zoomOutY( Constants.BUTTON_ZOOM_OUT_FACTOR );
230                     displayedPhylogenyMightHaveChanged( false );
231                 }
232                 else if ( e.getSource() == _show_whole ) {
233                     showWhole();
234                 }
235                 else if ( e.getSource() == _return_to_super_tree ) {
236                     _mainpanel.getCurrentTreePanel().superTree();
237                     showWhole();
238                 }
239                 else if ( e.getSource() == _order ) {
240                     tp.getPhylogeny().orderAppearance( _order_of_appearance );
241                     _order_of_appearance = !_order_of_appearance;
242                     displayedPhylogenyMightHaveChanged( false );
243                 }
244                 else if ( e.getSource() == _uncollapse_all ) {
245                     uncollapseAll( tp );
246                     displayedPhylogenyMightHaveChanged( false );
247                 }
248                 else if ( e.getSource() == _zoom_in_domain_structure ) {
249                     _mainpanel.getCurrentTreePanel().zoomInDomainStructure();
250                     displayedPhylogenyMightHaveChanged( true );
251                 }
252                 else if ( e.getSource() == _zoom_out_domain_structure ) {
253                     _mainpanel.getCurrentTreePanel().zoomOutDomainStructure();
254                     displayedPhylogenyMightHaveChanged( true );
255                 }
256                 else if ( e.getSource() == _decr_domain_structure_evalue_thr ) {
257                     _mainpanel.getCurrentTreePanel().decreaseDomainStructureEvalueThreshold();
258                     displayedPhylogenyMightHaveChanged( true );
259                 }
260                 else if ( e.getSource() == _incr_domain_structure_evalue_thr ) {
261                     _mainpanel.getCurrentTreePanel().increaseDomainStructureEvalueThreshold();
262                     displayedPhylogenyMightHaveChanged( true );
263                 }
264                 else if ( e.getSource() == _search_tf ) {
265                     search();
266                     displayedPhylogenyMightHaveChanged( true );
267                 }
268                 else {
269                     displayedPhylogenyMightHaveChanged( true );
270                 }
271             }
272             tp.requestFocus();
273             tp.requestFocusInWindow();
274             tp.requestFocus();
275         }
276         catch ( final Exception ex ) {
277             Util.unexpectedException( ex );
278         }
279         catch ( final Error err ) {
280             Util.unexpectedError( err );
281         }
282     }
283
284     void activateButtonToReturnToSuperTree( int index ) {
285         --index;
286         if ( index > 0 ) {
287             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT + " " + index );
288         }
289         else {
290             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
291         }
292         _return_to_super_tree.setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
293         _return_to_super_tree.setEnabled( true );
294     }
295
296     /**
297      * Add zoom and quick edit buttons. (Last modified 8/9/04)
298      */
299     void addButtons() {
300         final JLabel spacer = new JLabel( "" );
301         spacer.setOpaque( false );
302         add( spacer );
303         final JPanel x_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
304         final JPanel y_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
305         final JPanel z_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
306         if ( !getConfiguration().isUseNativeUI() ) {
307             x_panel.setBackground( getBackground() );
308             y_panel.setBackground( getBackground() );
309             z_panel.setBackground( getBackground() );
310         }
311         add( _zoom_label = new JLabel( "Zoom:" ) );
312         customizeLabel( _zoom_label, getConfiguration() );
313         add( x_panel );
314         add( y_panel );
315         add( z_panel );
316         if ( getConfiguration().isUseNativeUI() ) {
317             _zoom_in_x = new JButton( "+" );
318             _zoom_out_x = new JButton( "-" );
319         }
320         else {
321             _zoom_in_x = new JButton( "X+" );
322             _zoom_out_x = new JButton( "X-" );
323         }
324         _zoom_in_y = new JButton( "Y+" );
325         _zoom_out_y = new JButton( "Y-" );
326         _show_whole = new JButton( "F" );
327         _show_whole.setToolTipText( "To fit the complete phylogeny to the current display size [Backspace]" );
328         _zoom_in_x.setToolTipText( "To zoom in horizontally [Shift+Right]" );
329         _zoom_in_y.setToolTipText( "To zoom in vertically [Shift+Up]" );
330         _zoom_out_x.setToolTipText( "To zoom out horizontally [Shift+Left]" );
331         _zoom_out_y.setToolTipText( "To zoom out vertically [Shift+Down]" );
332         if ( getConfiguration().isUseNativeUI() && Util.isMac() ) {
333             _zoom_out_x.setPreferredSize( new Dimension( 55, 10 ) );
334             _zoom_in_x.setPreferredSize( new Dimension( 55, 10 ) );
335         }
336         else {
337             _zoom_out_x.setPreferredSize( new Dimension( 10, 10 ) );
338             _zoom_in_x.setPreferredSize( new Dimension( 10, 10 ) );
339         }
340         _zoom_out_y.setPreferredSize( new Dimension( 10, 10 ) );
341         _zoom_in_y.setPreferredSize( new Dimension( 10, 10 ) );
342         _show_whole.setPreferredSize( new Dimension( 10, 10 ) );
343         _return_to_super_tree = new JButton( RETURN_TO_SUPER_TREE_TEXT );
344         _return_to_super_tree.setEnabled( false );
345         _order = new JButton( "Order Subtrees" );
346         _uncollapse_all = new JButton( "Uncollapse All" );
347         addJButton( _zoom_in_y, x_panel );
348         addJButton( _zoom_out_x, y_panel );
349         addJButton( _show_whole, y_panel );
350         addJButton( _zoom_in_x, y_panel );
351         addJButton( _zoom_out_y, z_panel );
352         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
353             setUpControlsForDomainStrucures();
354         }
355         final JLabel spacer2 = new JLabel( "" );
356         add( spacer2 );
357         addJButton( _return_to_super_tree, this );
358         addJButton( _order, this );
359         addJButton( _uncollapse_all, this );
360         final JLabel spacer3 = new JLabel( "" );
361         add( spacer3 );
362         setVisibilityOfDomainStrucureControls();
363     }
364
365     void addCheckbox( final int which, final String title ) {
366         final JPanel ch_panel = new JPanel( new BorderLayout( 0, 0 ) );
367         switch ( which ) {
368             case Configuration.display_as_phylogram:
369                 _display_as_phylogram_cb = new JCheckBox( title );
370                 getDisplayAsPhylogramCb().setToolTipText( "To switch between phylogram and cladogram display" );
371                 addJCheckBox( getDisplayAsPhylogramCb(), ch_panel );
372                 add( ch_panel );
373                 break;
374             case Configuration.display_internal_data:
375                 _display_internal_data = new JCheckBox( title );
376                 _display_internal_data.setToolTipText( "To allow or disallow display of internal labels" );
377                 addJCheckBox( _display_internal_data, ch_panel );
378                 add( ch_panel );
379                 break;
380             case Configuration.color_according_to_species:
381                 _color_acc_species = new JCheckBox( title );
382                 _color_acc_species
383                         .setToolTipText( "To colorize taxonomy and sequence labels as a function of taxonomy" );
384                 addJCheckBox( _color_acc_species, ch_panel );
385                 add( ch_panel );
386                 break;
387             case Configuration.color_according_to_annotation:
388                 _color_according_to_annotation = new JCheckBox( title );
389                 _color_according_to_annotation
390                         .setToolTipText( "To colorize sequence annotation labels as a function of sequence annotation" );
391                 addJCheckBox( _color_according_to_annotation, ch_panel );
392                 add( ch_panel );
393                 break;
394             case Configuration.show_node_names:
395                 _show_node_names = new JCheckBox( title );
396                 addJCheckBox( _show_node_names, ch_panel );
397                 add( ch_panel );
398                 break;
399             case Configuration.show_tax_code:
400                 _show_taxo_code = new JCheckBox( title );
401                 addJCheckBox( _show_taxo_code, ch_panel );
402                 add( ch_panel );
403                 break;
404             case Configuration.show_taxonomy_scientific_names:
405                 _show_taxo_scientific_names = new JCheckBox( title );
406                 addJCheckBox( _show_taxo_scientific_names, ch_panel );
407                 add( ch_panel );
408                 break;
409             case Configuration.show_taxonomy_common_names:
410                 _show_taxo_common_names = new JCheckBox( title );
411                 addJCheckBox( _show_taxo_common_names, ch_panel );
412                 add( ch_panel );
413                 break;
414             case Configuration.show_taxonomy_images:
415                 _show_taxo_images_cb = new JCheckBox( title );
416                 addJCheckBox( _show_taxo_images_cb, ch_panel );
417                 add( ch_panel );
418                 break;
419             case Configuration.show_binary_characters:
420                 _show_binary_characters = new JCheckBox( title );
421                 addJCheckBox( _show_binary_characters, ch_panel );
422                 add( ch_panel );
423                 break;
424             case Configuration.show_annotation:
425                 _show_annotation = new JCheckBox( title );
426                 addJCheckBox( _show_annotation, ch_panel );
427                 add( ch_panel );
428                 break;
429             case Configuration.show_binary_character_counts:
430                 _show_binary_character_counts = new JCheckBox( title );
431                 addJCheckBox( _show_binary_character_counts, ch_panel );
432                 add( ch_panel );
433                 break;
434             case Configuration.write_confidence_values:
435                 _write_confidence = new JCheckBox( title );
436                 addJCheckBox( getWriteConfidenceCb(), ch_panel );
437                 add( ch_panel );
438                 break;
439             case Configuration.write_events:
440                 _show_events = new JCheckBox( title );
441                 addJCheckBox( getShowEventsCb(), ch_panel );
442                 add( ch_panel );
443                 break;
444             case Configuration.color_branches:
445                 _color_branches_cb = new JCheckBox( title );
446                 getColorBranchesCb().setToolTipText( "To use branch color values, if present" );
447                 addJCheckBox( getColorBranchesCb(), ch_panel );
448                 add( ch_panel );
449                 break;
450             case Configuration.width_branches:
451                 _width_branches = new JCheckBox( title );
452                 _width_branches.setToolTipText( "To use branch width values, if present" );
453                 addJCheckBox( _width_branches, ch_panel );
454                 add( ch_panel );
455                 break;
456             case Configuration.show_domain_architectures:
457                 _show_domain_architectures = new JCheckBox( title );
458                 addJCheckBox( _show_domain_architectures, ch_panel );
459                 add( ch_panel );
460                 break;
461             case Configuration.show_gene_names:
462                 _show_gene_names = new JCheckBox( title );
463                 addJCheckBox( _show_gene_names, ch_panel );
464                 add( ch_panel );
465                 break;
466             case Configuration.show_gene_symbols:
467                 _show_gene_symbols = new JCheckBox( title );
468                 addJCheckBox( _show_gene_symbols, ch_panel );
469                 add( ch_panel );
470                 break;
471             case Configuration.show_sequence_acc:
472                 _show_sequence_acc = new JCheckBox( title );
473                 addJCheckBox( _show_sequence_acc, ch_panel );
474                 add( ch_panel );
475                 break;
476             case Configuration.dynamically_hide_data:
477                 _dynamically_hide_data = new JCheckBox( title );
478                 getDynamicallyHideData().setToolTipText( "To hide labels depending on likely visibility" );
479                 addJCheckBox( getDynamicallyHideData(), ch_panel );
480                 add( ch_panel );
481                 break;
482             case Configuration.node_data_popup:
483                 _node_desc_popup_cb = new JCheckBox( title );
484                 getNodeDescPopupCb().setToolTipText( "To enable mouse rollover display of basic node data" );
485                 addJCheckBox( getNodeDescPopupCb(), ch_panel );
486                 add( ch_panel );
487                 break;
488             case Configuration.show_relation_confidence:
489                 _seq_relation_confidence_switch = new JCheckBox( title );
490                 addJCheckBox( _seq_relation_confidence_switch, ch_panel );
491                 add( ch_panel );
492                 break;
493             case Configuration.show_vector_data:
494                 _show_vector_data_cb = new JCheckBox( title );
495                 addJCheckBox( _show_vector_data_cb, ch_panel );
496                 add( ch_panel );
497                 break;
498             default:
499                 throw new RuntimeException( "unknown checkbox: " + which );
500         }
501     }// addCheckbox
502
503     private void addClickToOption( final int which, final String title ) {
504         _click_to_combobox.addItem( title );
505         _click_to_names.add( title );
506         _all_click_to_names.put( new Integer( which ), title );
507         if ( !_configuration.isUseNativeUI() ) {
508             _click_to_combobox.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
509             _click_to_combobox.setForeground( getConfiguration().getGuiButtonTextColor() );
510         }
511     }
512
513     void addJButton( final JButton jb, final JPanel p ) {
514         jb.setFocusPainted( false );
515         jb.setFont( ControlPanel.jcb_font );
516         if ( !_configuration.isUseNativeUI() ) {
517             jb.setBorder( BorderFactory.createLineBorder( getConfiguration().getGuiButtonBorderColor() ) );
518             jb.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
519             jb.setForeground( getConfiguration().getGuiButtonTextColor() );
520         }
521         p.add( jb );
522         jb.addActionListener( this );
523     }
524
525     void addJCheckBox( final JCheckBox jcb, final JPanel p ) {
526         jcb.setFocusPainted( false );
527         jcb.setFont( ControlPanel.jcb_font );
528         if ( !_configuration.isUseNativeUI() ) {
529             jcb.setBackground( getConfiguration().getGuiBackgroundColor() );
530             jcb.setForeground( getConfiguration().getGuiCheckboxTextColor() );
531         }
532         p.add( jcb, "Center" );
533         jcb.addActionListener( this );
534     }
535
536     void addJTextField( final JTextField tf, final JPanel p ) {
537         if ( !_configuration.isUseNativeUI() ) {
538             tf.setForeground( getConfiguration().getGuiBackgroundColor() );
539             tf.setFont( ControlPanel.jcb_font );
540         }
541         p.add( tf );
542         tf.addActionListener( this );
543     }
544
545     /* GUILHEM_BEG */
546     private void addSequenceRelationBlock() {
547         final JLabel spacer = new JLabel( "" );
548         spacer.setSize( 1, 1 );
549         add( spacer );
550         final JLabel mainLabel = new JLabel( "Sequence relations to display" );
551         final JLabel typeLabel = customizeLabel( new JLabel( "(type) " ), getConfiguration() );
552         typeLabel.setFont( ControlPanel.js_font.deriveFont( 7 ) );
553         getSequenceRelationTypeBox().setFocusable( false );
554         _sequence_relation_type_box.setFont( ControlPanel.js_font );
555         if ( !_configuration.isUseNativeUI() ) {
556             _sequence_relation_type_box.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
557             _sequence_relation_type_box.setForeground( getConfiguration().getGuiButtonTextColor() );
558         }
559         _sequence_relation_type_box.setRenderer( new ListCellRenderer() {
560
561             @Override
562             public Component getListCellRendererComponent( final JList list,
563                                                            final Object value,
564                                                            final int index,
565                                                            final boolean isSelected,
566                                                            final boolean cellHasFocus ) {
567                 final Component component = new DefaultListCellRenderer().getListCellRendererComponent( list,
568                                                                                                         value,
569                                                                                                         index,
570                                                                                                         isSelected,
571                                                                                                         cellHasFocus );
572                 if ( ( value != null ) && ( value instanceof SequenceRelation.SEQUENCE_RELATION_TYPE ) ) {
573                     ( ( DefaultListCellRenderer ) component ).setText( SequenceRelation
574                             .getPrintableNameByType( ( SequenceRelation.SEQUENCE_RELATION_TYPE ) value ) );
575                 }
576                 return component;
577             }
578         } );
579         final GridBagLayout gbl = new GridBagLayout();
580         _sequence_relation_type_box.setMinimumSize( new Dimension( 115, 17 ) );
581         _sequence_relation_type_box.setPreferredSize( new Dimension( 115, 20 ) );
582         final JPanel horizGrid = new JPanel( gbl );
583         horizGrid.setBackground( getBackground() );
584         horizGrid.add( typeLabel );
585         horizGrid.add( _sequence_relation_type_box );
586         add( customizeLabel( mainLabel, getConfiguration() ) );
587         add( horizGrid );
588         add( getSequenceRelationBox() );
589         if ( _configuration.doDisplayOption( Configuration.show_relation_confidence ) ) {
590             addCheckbox( Configuration.show_relation_confidence,
591                          _configuration.getDisplayTitle( Configuration.show_relation_confidence ) );
592             setCheckbox( Configuration.show_relation_confidence,
593                          _configuration.doCheckOption( Configuration.show_relation_confidence ) );
594         }
595     }// addSequenceRelationBlock
596
597     void deactivateButtonToReturnToSuperTree() {
598         _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
599         _return_to_super_tree.setForeground( getConfiguration().getGuiButtonTextColor() );
600         _return_to_super_tree.setEnabled( false );
601     }
602
603     void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) {
604         if ( ( _mainpanel != null ) && ( _mainpanel.getCurrentPhylogeny() != null ) ) {
605             if ( getOptions().isShowOverview() ) {
606                 _mainpanel.getCurrentTreePanel().updateOvSizes();
607             }
608             _mainpanel.getCurrentTreePanel().recalculateMaxDistanceToRoot();
609             setVisibilityOfDomainStrucureControls();
610             updateDomainStructureEvaluethresholdDisplay();
611             _mainpanel.getCurrentTreePanel().calculateScaleDistance();
612             _mainpanel.getCurrentTreePanel().calcMaxDepth();
613             _mainpanel.adjustJScrollPane();
614             if ( recalc_longest_ext_node_info ) {
615                 _mainpanel.getCurrentTreePanel().initNodeData();
616                 _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo();
617             }
618             _mainpanel.getCurrentTreePanel().repaint();
619             // _mainpanel.getCurrentTreePanel().setUpUrtFactors();
620         }
621     }
622
623     void endClickToOptions() {
624         _click_to_combobox.addActionListener( this );
625     }
626
627     /**
628      * Indicates what action should be execute when a node is clicked
629      * 
630      * @return the click-on action
631      */
632     NodeClickAction getActionWhenNodeClicked() {
633         return _action_when_node_clicked;
634     }
635
636     Map<Integer, String> getAllClickToItems() {
637         return _all_click_to_names;
638     }
639
640     Map<String, Color> getAnnotationColors() {
641         return _annotation_colors;
642     }
643
644     public JCheckBox getColorBranchesCb() {
645         return _color_branches_cb;
646     }
647
648     Configuration getConfiguration() {
649         return _configuration;
650     }
651
652     TreePanel getCurrentTreePanel() {
653         return getMainPanel().getCurrentTreePanel();
654     }
655
656     public JCheckBox getDisplayAsPhylogramCb() {
657         return _display_as_phylogram_cb;
658     }
659
660     public JCheckBox getDynamicallyHideData() {
661         return _dynamically_hide_data;
662     }
663
664     /* GUILHEM_END */
665     private List<Boolean> getIsDrawPhylogramList() {
666         return _draw_phylogram;
667     }
668
669     MainPanel getMainPanel() {
670         return _mainpanel;
671     }
672
673     public JCheckBox getNodeDescPopupCb() {
674         return _node_desc_popup_cb;
675     }
676
677     Options getOptions() {
678         return getMainPanel().getOptions();
679     }
680
681     private JLabel getSearchFoundCountsLabel() {
682         return _search_found_label;
683     }
684
685     private JButton getSearchResetButton() {
686         return _search_reset_button;
687     }
688
689     JTextField getSearchTextField() {
690         return _search_tf;
691     }
692
693     public Sequence getSelectedQuerySequence() {
694         return _selected_query_seq;
695     }
696
697     public JComboBox getSequenceRelationBox() {
698         if ( _show_sequence_relations == null ) {
699             _show_sequence_relations = new JComboBox();
700             _show_sequence_relations.setFocusable( false );
701             _show_sequence_relations.setMaximumRowCount( 20 );
702             _show_sequence_relations.setFont( ControlPanel.js_font );
703             if ( !_configuration.isUseNativeUI() ) {
704                 _show_sequence_relations.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
705                 _show_sequence_relations.setForeground( getConfiguration().getGuiButtonTextColor() );
706             }
707             _show_sequence_relations.addItem( "-----" );
708             _show_sequence_relations.setToolTipText( "To display orthology information for selected query" );
709         }
710         return _show_sequence_relations;
711     }
712
713     /* GUILHEM_BEG */
714     public JComboBox getSequenceRelationTypeBox() {
715         if ( _sequence_relation_type_box == null ) {
716             _sequence_relation_type_box = new JComboBox();
717             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : SequenceRelation.SEQUENCE_RELATION_TYPE.values() ) {
718                 _sequence_relation_type_box.addItem( type );
719             }
720             _sequence_relation_type_box.addActionListener( new ActionListener() {
721
722                 @Override
723                 public void actionPerformed( final ActionEvent e ) {
724                     if ( _mainpanel.getCurrentPhylogeny() != null ) {
725                         setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
726                     }
727                 }
728             } );
729         }
730         return _sequence_relation_type_box;
731     }
732
733     public JCheckBox getShowEventsCb() {
734         return _show_events;
735     }
736
737     List<String> getSingleClickToNames() {
738         return _click_to_names;
739     }
740
741     Map<String, Color> getSpeciesColors() {
742         return _species_colors;
743     }
744
745     public JCheckBox getWriteConfidenceCb() {
746         return _write_confidence;
747     }
748
749     private void init() {
750         _draw_phylogram = new ArrayList<Boolean>();
751         setSpeciesColors( new HashMap<String, Color>() );
752         setAnnotationColors( new HashMap<String, Color>() );
753     }
754
755     boolean isAntialiasScreenText() {
756         return true;
757     }
758
759     boolean isColorAccordingToAnnotation() {
760         return ( ( _color_according_to_annotation != null ) && _color_according_to_annotation.isSelected() );
761     }
762
763     boolean isColorAccordingToTaxonomy() {
764         return ( ( _color_acc_species != null ) && _color_acc_species.isSelected() );
765     }
766
767     boolean isColorBranches() {
768         return ( ( ( getColorBranchesCb() != null ) && getColorBranchesCb().isSelected() ) || ( ( getColorBranchesCb() == null ) && _color_branches ) );
769     }
770
771     boolean isDrawPhylogram() {
772         return isDrawPhylogram( getMainPanel().getCurrentTabIndex() );
773     }
774
775     private boolean isDrawPhylogram( final int index ) {
776         return getIsDrawPhylogramList().get( index );
777     }
778
779     boolean isDynamicallyHideData() {
780         return ( ( getDynamicallyHideData() != null ) && getDynamicallyHideData().isSelected() );
781     }
782
783     boolean isEvents() {
784         return ( ( getShowEventsCb() != null ) && getShowEventsCb().isSelected() );
785     }
786
787     boolean isNodeDescPopup() {
788         return ( ( getNodeDescPopupCb() != null ) && getNodeDescPopupCb().isSelected() );
789     }
790
791     boolean isShowAnnotation() {
792         return ( ( _show_annotation != null ) && _show_annotation.isSelected() );
793     }
794
795     boolean isShowBinaryCharacterCounts() {
796         return ( ( _show_binary_character_counts != null ) && _show_binary_character_counts.isSelected() );
797     }
798
799     boolean isShowBinaryCharacters() {
800         return ( ( _show_binary_characters != null ) && _show_binary_characters.isSelected() );
801     }
802
803     boolean isShowBootstrapValues() {
804         return ( ( getWriteConfidenceCb() != null ) && getWriteConfidenceCb().isSelected() );
805     }
806
807     boolean isShowDomainArchitectures() {
808         return ( ( _show_domain_architectures != null ) && _show_domain_architectures.isSelected() );
809     }
810
811     boolean isShowGeneNames() {
812         return ( ( _show_gene_names != null ) && _show_gene_names.isSelected() );
813     }
814
815     public boolean isShowVectorData() {
816         return ( ( _show_vector_data_cb != null ) && _show_vector_data_cb.isSelected() );
817     }
818
819     boolean isShowGeneSymbols() {
820         return ( ( _show_gene_symbols != null ) && _show_gene_symbols.isSelected() );
821     }
822
823     boolean isShowInternalData() {
824         return ( ( _display_internal_data == null ) || _display_internal_data.isSelected() );
825     }
826
827     boolean isShowNodeNames() {
828         return ( ( _show_node_names != null ) && _show_node_names.isSelected() );
829     }
830
831     boolean isShowProperty() {
832         return ( ( _show_annotation != null ) && _show_annotation.isSelected() );
833     }
834
835     boolean isShowSequenceAcc() {
836         return ( ( _show_sequence_acc != null ) && _show_sequence_acc.isSelected() );
837     }
838
839     boolean isShowSequenceRelationConfidence() {
840         return ( ( _seq_relation_confidence_switch != null ) && ( _seq_relation_confidence_switch.isSelected() ) );
841     }
842
843     boolean isShowSequenceRelations() {
844         return ( ( _show_sequence_relations != null ) && ( _show_sequence_relations.getSelectedIndex() > 0 ) );
845     }
846
847     boolean isShowTaxonomyCode() {
848         return ( ( _show_taxo_code != null ) && _show_taxo_code.isSelected() );
849     }
850
851     public boolean isShowTaxonomyImages() {
852         return ( ( _show_taxo_images_cb != null ) && _show_taxo_images_cb.isSelected() );
853     }
854
855     boolean isShowTaxonomyCommonNames() {
856         return ( ( _show_taxo_common_names != null ) && _show_taxo_common_names.isSelected() );
857     }
858
859     boolean isShowTaxonomyScientificNames() {
860         return ( ( _show_taxo_scientific_names != null ) && _show_taxo_scientific_names.isSelected() );
861     }
862
863     boolean isWidthBranches() {
864         return ( ( _width_branches != null ) && _width_branches.isSelected() );
865     }
866
867     void phylogenyAdded( final Configuration configuration ) {
868         getIsDrawPhylogramList().add( configuration.isDrawAsPhylogram() );
869     }
870
871     void phylogenyRemoved( final int index ) {
872         getIsDrawPhylogramList().remove( index );
873     }
874
875     void search() {
876         final MainPanel main_panel = getMainPanel();
877         final Phylogeny tree = main_panel.getCurrentPhylogeny();
878         if ( ( tree == null ) || tree.isEmpty() ) {
879             return;
880         }
881         String query = getSearchTextField().getText();
882         if ( query != null ) {
883             query = query.trim();
884         }
885         else {
886             getSearchFoundCountsLabel().setVisible( false );
887             getSearchResetButton().setEnabled( false );
888             getSearchResetButton().setVisible( false );
889             searchReset();
890         }
891         if ( !ForesterUtil.isEmpty( query ) ) {
892             search( main_panel, tree, query );
893         }
894         else {
895             getSearchFoundCountsLabel().setVisible( false );
896             getSearchResetButton().setEnabled( false );
897             getSearchResetButton().setVisible( false );
898             searchReset();
899         }
900     }
901
902     private void search( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
903         getSearchFoundCountsLabel().setVisible( true );
904         getSearchResetButton().setEnabled( true );
905         getSearchResetButton().setVisible( true );
906         String[] queries = null;
907         List<PhylogenyNode> nodes = null;
908         if ( query_str.indexOf( ',' ) >= 0 ) {
909             queries = query_str.split( ",+" );
910         }
911         else {
912             queries = new String[ 1 ];
913             queries[ 0 ] = query_str.trim();
914         }
915         if ( ( queries != null ) && ( queries.length > 0 ) ) {
916             nodes = new ArrayList<PhylogenyNode>();
917             for( String query : queries ) {
918                 if ( ForesterUtil.isEmpty( query ) ) {
919                     continue;
920                 }
921                 query = query.trim();
922                 if ( query.indexOf( '+' ) >= 0 ) {
923                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ), tree, getOptions()
924                             .isSearchCaseSensitive(), !getOptions().isMatchWholeTermsOnly() ) );
925                 }
926                 else {
927                     nodes.addAll( PhylogenyMethods.searchData( query,
928                                                                tree,
929                                                                getOptions().isSearchCaseSensitive(),
930                                                                !getOptions().isMatchWholeTermsOnly() ) );
931                 }
932             }
933             if ( getOptions().isInverseSearchResult() ) {
934                 final List<PhylogenyNode> all = PhylogenyMethods.obtainAllNodesAsList( tree );
935                 all.removeAll( nodes );
936                 nodes = all;
937             }
938         }
939         if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
940             main_panel.getCurrentTreePanel().setFoundNodes( new HashSet<Integer>() );
941             for( final PhylogenyNode node : nodes ) {
942                 main_panel.getCurrentTreePanel().getFoundNodes().add( node.getId() );
943             }
944             setSearchFoundCountsOnLabel( nodes.size() );
945         }
946         else {
947             setSearchFoundCountsOnLabel( 0 );
948             searchReset();
949         }
950     }
951
952     private void searchReset() {
953         if ( getMainPanel().getCurrentTreePanel() != null ) {
954             getMainPanel().getCurrentTreePanel().setFoundNodes( null );
955         }
956     }
957
958     void setActionWhenNodeClicked( final NodeClickAction action ) {
959         _action_when_node_clicked = action;
960     }
961
962     void setAnnotationColors( final Map<String, Color> annotation_colors ) {
963         _annotation_colors = annotation_colors;
964     }
965
966     void setCheckbox( final int which, final boolean state ) {
967         switch ( which ) {
968             case Configuration.display_as_phylogram:
969                 if ( getDisplayAsPhylogramCb() != null ) {
970                     getDisplayAsPhylogramCb().setSelected( state );
971                 }
972                 break;
973             case Configuration.display_internal_data:
974                 if ( _display_internal_data != null ) {
975                     _display_internal_data.setSelected( state );
976                 }
977                 break;
978             case Configuration.color_according_to_species:
979                 if ( _color_acc_species != null ) {
980                     _color_acc_species.setSelected( state );
981                 }
982                 break;
983             case Configuration.color_according_to_annotation:
984                 if ( _color_according_to_annotation != null ) {
985                     _color_according_to_annotation.setSelected( state );
986                 }
987                 break;
988             case Configuration.show_node_names:
989                 if ( _show_node_names != null ) {
990                     _show_node_names.setSelected( state );
991                 }
992                 break;
993             case Configuration.show_tax_code:
994                 if ( _show_taxo_code != null ) {
995                     _show_taxo_code.setSelected( state );
996                 }
997                 break;
998             case Configuration.show_taxonomy_scientific_names:
999                 if ( _show_taxo_scientific_names != null ) {
1000                     _show_taxo_scientific_names.setSelected( state );
1001                 }
1002                 break;
1003             case Configuration.show_taxonomy_common_names:
1004                 if ( _show_taxo_common_names != null ) {
1005                     _show_taxo_common_names.setSelected( state );
1006                 }
1007                 break;
1008             case Configuration.show_taxonomy_images:
1009                 if ( _show_taxo_images_cb != null ) {
1010                     _show_taxo_images_cb.setSelected( state );
1011                 }
1012                 break;
1013             case Configuration.show_annotation:
1014                 if ( _show_annotation != null ) {
1015                     _show_annotation.setSelected( state );
1016                 }
1017                 break;
1018             case Configuration.show_binary_characters:
1019                 if ( _show_binary_characters != null ) {
1020                     _show_binary_characters.setSelected( state );
1021                 }
1022                 break;
1023             case Configuration.show_binary_character_counts:
1024                 if ( _show_binary_character_counts != null ) {
1025                     _show_binary_character_counts.setSelected( state );
1026                 }
1027                 break;
1028             case Configuration.write_confidence_values:
1029                 if ( getWriteConfidenceCb() != null ) {
1030                     getWriteConfidenceCb().setSelected( state );
1031                 }
1032                 break;
1033             case Configuration.write_events:
1034                 if ( getShowEventsCb() != null ) {
1035                     getShowEventsCb().setSelected( state );
1036                 }
1037                 break;
1038             case Configuration.color_branches:
1039                 if ( getColorBranchesCb() != null ) {
1040                     getColorBranchesCb().setSelected( state );
1041                 }
1042                 break;
1043             case Configuration.width_branches:
1044                 if ( _width_branches != null ) {
1045                     _width_branches.setSelected( state );
1046                 }
1047                 break;
1048             case Configuration.show_domain_architectures:
1049                 if ( _show_domain_architectures != null ) {
1050                     _show_domain_architectures.setSelected( state );
1051                 }
1052                 break;
1053             case Configuration.show_gene_names:
1054                 if ( _show_gene_names != null ) {
1055                     _show_gene_names.setSelected( state );
1056                 }
1057                 break;
1058             case Configuration.show_gene_symbols:
1059                 if ( _show_gene_symbols != null ) {
1060                     _show_gene_symbols.setSelected( state );
1061                 }
1062                 break;
1063             case Configuration.show_vector_data:
1064                 if ( _show_vector_data_cb != null ) {
1065                     _show_vector_data_cb.setSelected( state );
1066                 }
1067                 break;
1068             case Configuration.show_sequence_acc:
1069                 if ( _show_sequence_acc != null ) {
1070                     _show_sequence_acc.setSelected( state );
1071                 }
1072                 break;
1073             case Configuration.dynamically_hide_data:
1074                 if ( getDynamicallyHideData() != null ) {
1075                     getDynamicallyHideData().setSelected( state );
1076                 }
1077                 break;
1078             case Configuration.node_data_popup:
1079                 if ( getNodeDescPopupCb() != null ) {
1080                     getNodeDescPopupCb().setSelected( state );
1081                 }
1082                 break;
1083             /* GUILHEM_BEG */
1084             case Configuration.show_relation_confidence:
1085                 if ( _seq_relation_confidence_switch != null ) {
1086                     _seq_relation_confidence_switch.setSelected( state );
1087                 }
1088                 break;
1089             /* GUILHEM_END */
1090             default:
1091                 throw new AssertionError( "unknown checkbox: " + which );
1092         }
1093     }
1094
1095     /**
1096      * Set this checkbox state. Not all checkboxes have been instantiated
1097      * depending on the config.
1098      */
1099     void setCheckbox( final JCheckBox cb, final boolean state ) {
1100         if ( cb != null ) {
1101             cb.setSelected( state );
1102         }
1103     }
1104
1105     void setClickToAction( final int action ) {
1106         // Set click-to action
1107         if ( action == _show_data_item ) {
1108             setActionWhenNodeClicked( NodeClickAction.SHOW_DATA );
1109         }
1110         else if ( action == _collapse_cb_item ) {
1111             setActionWhenNodeClicked( NodeClickAction.COLLAPSE );
1112         }
1113         else if ( action == _reroot_cb_item ) {
1114             setActionWhenNodeClicked( NodeClickAction.REROOT );
1115         }
1116         else if ( action == _subtree_cb_item ) {
1117             setActionWhenNodeClicked( NodeClickAction.SUBTREE );
1118         }
1119         else if ( action == _swap_cb_item ) {
1120             setActionWhenNodeClicked( NodeClickAction.SWAP );
1121         }
1122         else if ( action == _color_subtree_cb_item ) {
1123             setActionWhenNodeClicked( NodeClickAction.COLOR_SUBTREE );
1124         }
1125         else if ( action == _open_seq_web_item ) {
1126             setActionWhenNodeClicked( NodeClickAction.OPEN_SEQ_WEB );
1127         }
1128         else if ( action == _blast_item ) {
1129             if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
1130                 setActionWhenNodeClicked( NodeClickAction.BLAST );
1131             }
1132         }
1133         else if ( action == _open_tax_web_item ) {
1134             setActionWhenNodeClicked( NodeClickAction.OPEN_TAX_WEB );
1135         }
1136         else if ( action == _cut_subtree_item ) {
1137             setActionWhenNodeClicked( NodeClickAction.CUT_SUBTREE );
1138         }
1139         else if ( action == _copy_subtree_item ) {
1140             setActionWhenNodeClicked( NodeClickAction.COPY_SUBTREE );
1141         }
1142         else if ( action == _delete_node_or_subtree_item ) {
1143             setActionWhenNodeClicked( NodeClickAction.DELETE_NODE_OR_SUBTREE );
1144         }
1145         else if ( action == _paste_subtree_item ) {
1146             setActionWhenNodeClicked( NodeClickAction.PASTE_SUBTREE );
1147         }
1148         else if ( action == _add_new_node_item ) {
1149             setActionWhenNodeClicked( NodeClickAction.ADD_NEW_NODE );
1150         }
1151         else if ( action == _edit_node_data_item ) {
1152             setActionWhenNodeClicked( NodeClickAction.EDIT_NODE_DATA );
1153         }
1154         else {
1155             throw new RuntimeException( "unknown action: " + action );
1156         }
1157         // make sure drop down is displaying the correct action
1158         // in case this was called from outside the class
1159         _click_to_combobox.setSelectedIndex( action );
1160     }
1161
1162     void setColorBranches( final boolean color_branches ) {
1163         _color_branches = color_branches;
1164     }
1165
1166     void setDrawPhylogram( final boolean b ) {
1167         getDisplayAsPhylogramCb().setSelected( b );
1168         setDrawPhylogram( getMainPanel().getCurrentTabIndex(), b );
1169     }
1170
1171     private void setDrawPhylogram( final int index, final boolean b ) {
1172         getIsDrawPhylogramList().set( index, b );
1173     }
1174
1175     void setDrawPhylogramEnabled( final boolean b ) {
1176         getDisplayAsPhylogramCb().setEnabled( b );
1177     }
1178
1179     void setDynamicHidingIsOn( final boolean is_on ) {
1180         //  if ( !_configuration.isUseNativeUI() ) {
1181         if ( is_on ) {
1182             getDynamicallyHideData().setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
1183         }
1184         else {
1185             if ( !_configuration.isUseNativeUI() ) {
1186                 getDynamicallyHideData().setForeground( getConfiguration().getGuiButtonTextColor() );
1187             }
1188             else {
1189                 getDynamicallyHideData().setForeground( Color.BLACK );
1190             }
1191         }
1192         // }
1193     }
1194
1195     private void setSearchFoundCountsOnLabel( final int counts ) {
1196         getSearchFoundCountsLabel().setText( "Found: " + counts );
1197     }
1198
1199     public void setSequenceRelationQueries( final Collection<Sequence> sequenceRelationQueries ) {
1200         final JComboBox box = getSequenceRelationBox();
1201         while ( box.getItemCount() > 1 ) {
1202             box.removeItemAt( 1 );
1203         }
1204         final HashMap<String, Sequence> sequencesByName = new HashMap<String, Sequence>();
1205         final SequenceRelation.SEQUENCE_RELATION_TYPE relationType = ( SequenceRelation.SEQUENCE_RELATION_TYPE ) _sequence_relation_type_box
1206                 .getSelectedItem();
1207         if ( relationType == null ) {
1208             return;
1209         }
1210         final ArrayList<String> sequenceNamesToAdd = new ArrayList<String>();
1211         for( final Sequence seq : sequenceRelationQueries ) {
1212             if ( seq.hasSequenceRelations() ) {
1213                 boolean fFoundForCurrentType = false;
1214                 for( final SequenceRelation sq : seq.getSequenceRelations() ) {
1215                     if ( sq.getType().equals( relationType ) ) {
1216                         fFoundForCurrentType = true;
1217                         break;
1218                     }
1219                 }
1220                 if ( fFoundForCurrentType ) {
1221                     sequenceNamesToAdd.add( seq.getName() );
1222                     sequencesByName.put( seq.getName(), seq );
1223                 }
1224             }
1225         }
1226         // sort sequences by name before adding them to the combo
1227         final String[] sequenceNameArray = sequenceNamesToAdd.toArray( new String[ sequenceNamesToAdd.size() ] );
1228         Arrays.sort( sequenceNameArray, String.CASE_INSENSITIVE_ORDER );
1229         for( final String seqName : sequenceNameArray ) {
1230             box.addItem( seqName );
1231         }
1232         for( final ItemListener oldItemListener : box.getItemListeners() ) {
1233             box.removeItemListener( oldItemListener );
1234         }
1235         box.addItemListener( new ItemListener() {
1236
1237             @Override
1238             public void itemStateChanged( final ItemEvent e ) {
1239                 _selected_query_seq = sequencesByName.get( e.getItem() );
1240                 _mainpanel.getCurrentTreePanel().repaint();
1241             }
1242         } );
1243     }
1244
1245     void setShowEvents( final boolean show_events ) {
1246         if ( getShowEventsCb() == null ) {
1247             _show_events = new JCheckBox( "" );
1248         }
1249         getShowEventsCb().setSelected( show_events );
1250     }
1251
1252     void setSpeciesColors( final Map<String, Color> species_colors ) {
1253         _species_colors = species_colors;
1254     }
1255
1256     private void setupClickToOptions() {
1257         final int default_option = _configuration.getDefaultDisplayClicktoOption();
1258         int selected_index = 0;
1259         int cb_index = 0;
1260         if ( _configuration.doDisplayClickToOption( Configuration.display_node_data ) ) {
1261             _show_data_item = cb_index;
1262             addClickToOption( Configuration.display_node_data,
1263                               _configuration.getClickToTitle( Configuration.display_node_data ) );
1264             if ( default_option == Configuration.display_node_data ) {
1265                 selected_index = cb_index;
1266             }
1267             cb_index++;
1268         }
1269         if ( _configuration.doDisplayClickToOption( Configuration.collapse_uncollapse ) ) {
1270             _collapse_cb_item = cb_index;
1271             addClickToOption( Configuration.collapse_uncollapse,
1272                               _configuration.getClickToTitle( Configuration.collapse_uncollapse ) );
1273             if ( default_option == Configuration.collapse_uncollapse ) {
1274                 selected_index = cb_index;
1275             }
1276             cb_index++;
1277         }
1278         if ( _configuration.doDisplayClickToOption( Configuration.reroot ) ) {
1279             _reroot_cb_item = cb_index;
1280             addClickToOption( Configuration.reroot, _configuration.getClickToTitle( Configuration.reroot ) );
1281             if ( default_option == Configuration.reroot ) {
1282                 selected_index = cb_index;
1283             }
1284             cb_index++;
1285         }
1286         if ( _configuration.doDisplayClickToOption( Configuration.subtree ) ) {
1287             _subtree_cb_item = cb_index;
1288             addClickToOption( Configuration.subtree, _configuration.getClickToTitle( Configuration.subtree ) );
1289             if ( default_option == Configuration.subtree ) {
1290                 selected_index = cb_index;
1291             }
1292             cb_index++;
1293         }
1294         if ( _configuration.doDisplayClickToOption( Configuration.swap ) ) {
1295             _swap_cb_item = cb_index;
1296             addClickToOption( Configuration.swap, _configuration.getClickToTitle( Configuration.swap ) );
1297             if ( default_option == Configuration.swap ) {
1298                 selected_index = cb_index;
1299             }
1300             cb_index++;
1301         }
1302         if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) {
1303             _color_subtree_cb_item = cb_index;
1304             addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) );
1305             if ( default_option == Configuration.color_subtree ) {
1306                 selected_index = cb_index;
1307             }
1308             cb_index++;
1309         }
1310         if ( _configuration.doDisplayClickToOption( Configuration.open_seq_web ) ) {
1311             _open_seq_web_item = cb_index;
1312             addClickToOption( Configuration.open_seq_web, _configuration.getClickToTitle( Configuration.open_seq_web ) );
1313             if ( default_option == Configuration.open_seq_web ) {
1314                 selected_index = cb_index;
1315             }
1316             cb_index++;
1317         }
1318         if ( _configuration.doDisplayClickToOption( Configuration.open_tax_web ) ) {
1319             _open_tax_web_item = cb_index;
1320             addClickToOption( Configuration.open_tax_web, _configuration.getClickToTitle( Configuration.open_tax_web ) );
1321             if ( default_option == Configuration.open_tax_web ) {
1322                 selected_index = cb_index;
1323             }
1324             cb_index++;
1325         }
1326         if ( getOptions().isEditable() ) {
1327             if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) {
1328                 _cut_subtree_item = cb_index;
1329                 addClickToOption( Configuration.cut_subtree, _configuration.getClickToTitle( Configuration.cut_subtree ) );
1330                 if ( default_option == Configuration.cut_subtree ) {
1331                     selected_index = cb_index;
1332                 }
1333                 cb_index++;
1334             }
1335             if ( _configuration.doDisplayClickToOption( Configuration.copy_subtree ) ) {
1336                 _copy_subtree_item = cb_index;
1337                 addClickToOption( Configuration.copy_subtree,
1338                                   _configuration.getClickToTitle( Configuration.copy_subtree ) );
1339                 if ( default_option == Configuration.copy_subtree ) {
1340                     selected_index = cb_index;
1341                 }
1342                 cb_index++;
1343             }
1344             if ( _configuration.doDisplayClickToOption( Configuration.paste_subtree ) ) {
1345                 _paste_subtree_item = cb_index;
1346                 addClickToOption( Configuration.paste_subtree,
1347                                   _configuration.getClickToTitle( Configuration.paste_subtree ) );
1348                 if ( default_option == Configuration.paste_subtree ) {
1349                     selected_index = cb_index;
1350                 }
1351                 cb_index++;
1352             }
1353             if ( _configuration.doDisplayClickToOption( Configuration.delete_subtree_or_node ) ) {
1354                 _delete_node_or_subtree_item = cb_index;
1355                 addClickToOption( Configuration.delete_subtree_or_node,
1356                                   _configuration.getClickToTitle( Configuration.delete_subtree_or_node ) );
1357                 if ( default_option == Configuration.delete_subtree_or_node ) {
1358                     selected_index = cb_index;
1359                 }
1360                 cb_index++;
1361             }
1362             if ( _configuration.doDisplayClickToOption( Configuration.add_new_node ) ) {
1363                 _add_new_node_item = cb_index;
1364                 addClickToOption( Configuration.add_new_node,
1365                                   _configuration.getClickToTitle( Configuration.add_new_node ) );
1366                 if ( default_option == Configuration.add_new_node ) {
1367                     selected_index = cb_index;
1368                 }
1369                 cb_index++;
1370             }
1371             if ( _configuration.doDisplayClickToOption( Configuration.edit_node_data ) ) {
1372                 _edit_node_data_item = cb_index;
1373                 addClickToOption( Configuration.edit_node_data,
1374                                   _configuration.getClickToTitle( Configuration.edit_node_data ) );
1375                 if ( default_option == Configuration.edit_node_data ) {
1376                     selected_index = cb_index;
1377                 }
1378                 cb_index++;
1379             }
1380             if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
1381                 if ( _configuration.doDisplayClickToOption( Configuration.blast ) ) {
1382                     _blast_item = cb_index;
1383                     addClickToOption( Configuration.blast, _configuration.getClickToTitle( Configuration.blast ) );
1384                     if ( default_option == Configuration.blast ) {
1385                         selected_index = cb_index;
1386                     }
1387                     cb_index++;
1388                 }
1389             }
1390         }
1391         // Set default selection and its action
1392         _click_to_combobox.setSelectedIndex( selected_index );
1393         setClickToAction( selected_index );
1394     }
1395
1396     /* GUILHEM_END */
1397     /*
1398      * Set up the controls from the config settings. 11/26/05
1399      */
1400     void setupControls() {
1401         // The tree display options:
1402         setupDisplayCheckboxes();
1403         /* GUILHEM_BEG */
1404         // The sequence relation query selection combo-box
1405         if ( _configuration.displaySequenceRelations() ) {
1406             addSequenceRelationBlock();
1407         }
1408         /* GUILHEM_END */
1409         // Click-to options
1410         startClickToOptions();
1411         setupClickToOptions();
1412         endClickToOptions();
1413         // Zoom and quick edit buttons
1414         addButtons();
1415         setupSearchTools();
1416     }
1417
1418     void setUpControlsForDomainStrucures() {
1419         _domain_display_label = new JLabel( "Domain Display:" );
1420         add( customizeLabel( _domain_display_label, getConfiguration() ) );
1421         add( _domain_display_label );
1422         _zoom_in_domain_structure = new JButton( "d+" );
1423         _zoom_out_domain_structure = new JButton( "d-" );
1424         _decr_domain_structure_evalue_thr = new JButton( "-" );
1425         _incr_domain_structure_evalue_thr = new JButton( "+" );
1426         _zoom_in_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1427         _zoom_out_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1428         _decr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1429         _incr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1430         _incr_domain_structure_evalue_thr.setToolTipText( "Increase the E-value threshold by a factor of 10" );
1431         _decr_domain_structure_evalue_thr.setToolTipText( "Decrease the E-value threshold by a factor of 10" );
1432         _domain_structure_evalue_thr_tf = new JTextField( 3 );
1433         _domain_structure_evalue_thr_tf.setEditable( false );
1434         if ( !getConfiguration().isUseNativeUI() ) {
1435             _domain_structure_evalue_thr_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1436             _domain_structure_evalue_thr_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1437             _domain_structure_evalue_thr_tf.setBorder( null );
1438         }
1439         final JPanel d1_panel = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1440         final JPanel d2_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
1441         if ( !_configuration.isUseNativeUI() ) {
1442             d1_panel.setBackground( getBackground() );
1443             d2_panel.setBackground( getBackground() );
1444         }
1445         add( d1_panel );
1446         add( d2_panel );
1447         addJButton( _zoom_out_domain_structure, d1_panel );
1448         addJButton( _zoom_in_domain_structure, d1_panel );
1449         addJButton( _decr_domain_structure_evalue_thr, d2_panel );
1450         addJTextField( _domain_structure_evalue_thr_tf, d2_panel );
1451         addJButton( _incr_domain_structure_evalue_thr, d2_panel );
1452     }
1453
1454     private void setupDisplayCheckboxes() {
1455         if ( _configuration.doDisplayOption( Configuration.display_as_phylogram ) ) {
1456             addCheckbox( Configuration.display_as_phylogram,
1457                          _configuration.getDisplayTitle( Configuration.display_as_phylogram ) );
1458             setCheckbox( Configuration.display_as_phylogram,
1459                          _configuration.doCheckOption( Configuration.display_as_phylogram ) );
1460         }
1461         if ( _configuration.doDisplayOption( Configuration.dynamically_hide_data ) ) {
1462             addCheckbox( Configuration.dynamically_hide_data,
1463                          _configuration.getDisplayTitle( Configuration.dynamically_hide_data ) );
1464             setCheckbox( Configuration.dynamically_hide_data,
1465                          _configuration.doCheckOption( Configuration.dynamically_hide_data ) );
1466         }
1467         if ( _configuration.doDisplayOption( Configuration.node_data_popup ) ) {
1468             addCheckbox( Configuration.node_data_popup, _configuration.getDisplayTitle( Configuration.node_data_popup ) );
1469             setCheckbox( Configuration.node_data_popup, _configuration.doCheckOption( Configuration.node_data_popup ) );
1470         }
1471         if ( _configuration.doDisplayOption( Configuration.display_internal_data ) ) {
1472             addCheckbox( Configuration.display_internal_data,
1473                          _configuration.getDisplayTitle( Configuration.display_internal_data ) );
1474             setCheckbox( Configuration.display_internal_data,
1475                          _configuration.doCheckOption( Configuration.display_internal_data ) );
1476         }
1477         if ( _configuration.doDisplayOption( Configuration.color_according_to_species ) ) {
1478             addCheckbox( Configuration.color_according_to_species,
1479                          _configuration.getDisplayTitle( Configuration.color_according_to_species ) );
1480             setCheckbox( Configuration.color_according_to_species,
1481                          _configuration.doCheckOption( Configuration.color_according_to_species ) );
1482         }
1483         if ( _configuration.doDisplayOption( Configuration.color_according_to_annotation ) ) {
1484             addCheckbox( Configuration.color_according_to_annotation,
1485                          _configuration.getDisplayTitle( Configuration.color_according_to_annotation ) );
1486             setCheckbox( Configuration.color_according_to_annotation,
1487                          _configuration.doCheckOption( Configuration.color_according_to_annotation ) );
1488         }
1489         if ( _configuration.doDisplayOption( Configuration.color_branches ) ) {
1490             addCheckbox( Configuration.color_branches, _configuration.getDisplayTitle( Configuration.color_branches ) );
1491             setCheckbox( Configuration.color_branches, _configuration.doCheckOption( Configuration.color_branches ) );
1492         }
1493         if ( _configuration.doDisplayOption( Configuration.width_branches ) ) {
1494             addCheckbox( Configuration.width_branches, _configuration.getDisplayTitle( Configuration.width_branches ) );
1495             setCheckbox( Configuration.width_branches, _configuration.doCheckOption( Configuration.width_branches ) );
1496         }
1497         final JLabel label = new JLabel( "Display Data:" );
1498         label.setFont( ControlPanel.jcb_bold_font );
1499         if ( !getConfiguration().isUseNativeUI() ) {
1500             label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1501         }
1502         add( label );
1503         if ( _configuration.doDisplayOption( Configuration.show_node_names ) ) {
1504             addCheckbox( Configuration.show_node_names, _configuration.getDisplayTitle( Configuration.show_node_names ) );
1505             setCheckbox( Configuration.show_node_names, _configuration.doCheckOption( Configuration.show_node_names ) );
1506         }
1507         if ( _configuration.doDisplayOption( Configuration.show_tax_code ) ) {
1508             addCheckbox( Configuration.show_tax_code, _configuration.getDisplayTitle( Configuration.show_tax_code ) );
1509             setCheckbox( Configuration.show_tax_code, _configuration.doCheckOption( Configuration.show_tax_code ) );
1510         }
1511         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_scientific_names ) ) {
1512             addCheckbox( Configuration.show_taxonomy_scientific_names,
1513                          _configuration.getDisplayTitle( Configuration.show_taxonomy_scientific_names ) );
1514             setCheckbox( Configuration.show_taxonomy_scientific_names,
1515                          _configuration.doCheckOption( Configuration.show_taxonomy_scientific_names ) );
1516         }
1517         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_common_names ) ) {
1518             addCheckbox( Configuration.show_taxonomy_common_names,
1519                          _configuration.getDisplayTitle( Configuration.show_taxonomy_common_names ) );
1520             setCheckbox( Configuration.show_taxonomy_common_names,
1521                          _configuration.doCheckOption( Configuration.show_taxonomy_common_names ) );
1522         }
1523         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_images ) ) {
1524             addCheckbox( Configuration.show_taxonomy_images,
1525                          _configuration.getDisplayTitle( Configuration.show_taxonomy_images ) );
1526             setCheckbox( Configuration.show_taxonomy_images,
1527                          _configuration.doCheckOption( Configuration.show_taxonomy_images ) );
1528         }
1529         if ( _configuration.doDisplayOption( Configuration.show_gene_symbols ) ) {
1530             addCheckbox( Configuration.show_gene_symbols,
1531                          _configuration.getDisplayTitle( Configuration.show_gene_symbols ) );
1532             setCheckbox( Configuration.show_gene_symbols,
1533                          _configuration.doCheckOption( Configuration.show_gene_symbols ) );
1534         }
1535         if ( _configuration.doDisplayOption( Configuration.show_gene_names ) ) {
1536             addCheckbox( Configuration.show_gene_names, _configuration.getDisplayTitle( Configuration.show_gene_names ) );
1537             setCheckbox( Configuration.show_gene_names, _configuration.doCheckOption( Configuration.show_gene_names ) );
1538         }
1539         if ( _configuration.doDisplayOption( Configuration.show_sequence_acc ) ) {
1540             addCheckbox( Configuration.show_sequence_acc,
1541                          _configuration.getDisplayTitle( Configuration.show_sequence_acc ) );
1542             setCheckbox( Configuration.show_sequence_acc,
1543                          _configuration.doCheckOption( Configuration.show_sequence_acc ) );
1544         }
1545         if ( _configuration.doDisplayOption( Configuration.show_annotation ) ) {
1546             addCheckbox( Configuration.show_annotation, _configuration.getDisplayTitle( Configuration.show_annotation ) );
1547             setCheckbox( Configuration.show_annotation, _configuration.doCheckOption( Configuration.show_annotation ) );
1548         }
1549         if ( _configuration.doDisplayOption( Configuration.show_binary_characters ) ) {
1550             addCheckbox( Configuration.show_binary_characters,
1551                          _configuration.getDisplayTitle( Configuration.show_binary_characters ) );
1552             setCheckbox( Configuration.show_binary_characters,
1553                          _configuration.doCheckOption( Configuration.show_binary_characters ) );
1554         }
1555         if ( _configuration.doDisplayOption( Configuration.show_binary_character_counts ) ) {
1556             addCheckbox( Configuration.show_binary_character_counts,
1557                          _configuration.getDisplayTitle( Configuration.show_binary_character_counts ) );
1558             setCheckbox( Configuration.show_binary_character_counts,
1559                          _configuration.doCheckOption( Configuration.show_binary_character_counts ) );
1560         }
1561         if ( _configuration.doDisplayOption( Configuration.show_domain_architectures ) ) {
1562             addCheckbox( Configuration.show_domain_architectures,
1563                          _configuration.getDisplayTitle( Configuration.show_domain_architectures ) );
1564             setCheckbox( Configuration.show_domain_architectures,
1565                          _configuration.doCheckOption( Configuration.show_domain_architectures ) );
1566         }
1567         if ( _configuration.doDisplayOption( Configuration.write_confidence_values ) ) {
1568             addCheckbox( Configuration.write_confidence_values,
1569                          _configuration.getDisplayTitle( Configuration.write_confidence_values ) );
1570             setCheckbox( Configuration.write_confidence_values,
1571                          _configuration.doCheckOption( Configuration.write_confidence_values ) );
1572         }
1573         if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
1574             addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
1575             setCheckbox( Configuration.write_events, _configuration.doCheckOption( Configuration.write_events ) );
1576         }
1577         if ( _configuration.doDisplayOption( Configuration.show_vector_data ) ) {
1578             addCheckbox( Configuration.show_vector_data,
1579                          _configuration.getDisplayTitle( Configuration.show_vector_data ) );
1580             setCheckbox( Configuration.show_vector_data, _configuration.doCheckOption( Configuration.show_vector_data ) );
1581         }
1582     }
1583
1584     void setupSearchTools() {
1585         final String tip = "Enter text to search for. Use ',' for multiple searches (logical OR) and '+' for logical AND.";
1586         final JLabel search_label = new JLabel( "Search:" );
1587         search_label.setFont( ControlPanel.jcb_bold_font );
1588         if ( !getConfiguration().isUseNativeUI() ) {
1589             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1590         }
1591         add( search_label );
1592         search_label.setToolTipText( tip );
1593         _search_found_label = new JLabel();
1594         getSearchFoundCountsLabel().setVisible( false );
1595         _search_found_label.setFont( ControlPanel.jcb_bold_font );
1596         if ( !getConfiguration().isUseNativeUI() ) {
1597             _search_found_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1598         }
1599         _search_tf = new JTextField( 3 );
1600         _search_tf.setToolTipText( tip );
1601         _search_tf.setEditable( true );
1602         if ( !getConfiguration().isUseNativeUI() ) {
1603             _search_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1604             _search_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1605             _search_tf.setBorder( null );
1606         }
1607         _search_reset_button = new JButton();
1608         getSearchResetButton().setText( "Reset" );
1609         getSearchResetButton().setEnabled( false );
1610         getSearchResetButton().setVisible( false );
1611         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
1612         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1613         s_panel_1.setBackground( getBackground() );
1614         add( s_panel_1 );
1615         s_panel_2.setBackground( getBackground() );
1616         add( s_panel_2 );
1617         final KeyAdapter key_adapter = new KeyAdapter() {
1618
1619             @Override
1620             public void keyReleased( final KeyEvent key_event ) {
1621                 search();
1622                 displayedPhylogenyMightHaveChanged( true );
1623             }
1624         };
1625         final ActionListener action_listener = new ActionListener() {
1626
1627             @Override
1628             public void actionPerformed( final ActionEvent e ) {
1629                 searchReset();
1630                 setSearchFoundCountsOnLabel( 0 );
1631                 getSearchFoundCountsLabel().setVisible( false );
1632                 getSearchTextField().setText( "" );
1633                 getSearchResetButton().setEnabled( false );
1634                 getSearchResetButton().setVisible( false );
1635                 displayedPhylogenyMightHaveChanged( true );
1636             }
1637         };
1638         _search_reset_button.addActionListener( action_listener );
1639         _search_tf.addKeyListener( key_adapter );
1640         addJTextField( _search_tf, s_panel_1 );
1641         s_panel_2.add( _search_found_label );
1642         addJButton( _search_reset_button, s_panel_2 );
1643     }
1644
1645     private void setVisibilityOfDomainStrucureControls() {
1646         if ( _zoom_in_domain_structure != null ) {
1647             if ( isShowDomainArchitectures() ) {
1648                 _domain_display_label.setVisible( true );
1649                 _zoom_in_domain_structure.setVisible( true );
1650                 _zoom_out_domain_structure.setVisible( true );
1651                 _decr_domain_structure_evalue_thr.setVisible( true );
1652                 _incr_domain_structure_evalue_thr.setVisible( true );
1653                 _domain_structure_evalue_thr_tf.setVisible( true );
1654             }
1655             else {
1656                 _domain_display_label.setVisible( false );
1657                 _zoom_in_domain_structure.setVisible( false );
1658                 _zoom_out_domain_structure.setVisible( false );
1659                 _decr_domain_structure_evalue_thr.setVisible( false );
1660                 _incr_domain_structure_evalue_thr.setVisible( false );
1661                 _domain_structure_evalue_thr_tf.setVisible( false );
1662             }
1663         }
1664     }
1665
1666     /**
1667      * Fit entire tree into window.
1668      */
1669     void showWhole() {
1670         if ( _mainpanel.getCurrentScrollPane() == null ) {
1671             return;
1672         }
1673         displayedPhylogenyMightHaveChanged( false );
1674         _mainpanel.getCurrentTreePanel().updateOvSettings();
1675         _mainpanel.getCurrentTreePanel().validate();
1676         _mainpanel.validate();
1677         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1678                                                                    _mainpanel.getSizeOfViewport().height,
1679                                                                    true );
1680         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1681         _mainpanel.adjustJScrollPane();
1682         _mainpanel.getCurrentTreePanel().repaint();
1683         _mainpanel.getCurrentTreePanel().validate();
1684         _mainpanel.validate();
1685         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1686                                                                    _mainpanel.getSizeOfViewport().height,
1687                                                                    true );
1688         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1689         _mainpanel.adjustJScrollPane();
1690         _mainpanel.getCurrentTreePanel().repaint();
1691         _mainpanel.getCurrentTreePanel().updateOvSizes();
1692     }
1693
1694     void showWholeAll() {
1695         for( final TreePanel tree_panel : _mainpanel.getTreePanels() ) {
1696             if ( tree_panel != null ) {
1697                 tree_panel.validate();
1698                 tree_panel.setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1699                                                      _mainpanel.getSizeOfViewport().height,
1700                                                      true );
1701                 tree_panel.resetPreferredSize();
1702                 tree_panel.repaint();
1703             }
1704         }
1705     }
1706
1707     // Create header for click-to combo box.
1708     void startClickToOptions() {
1709         final JLabel spacer = new JLabel( "" );
1710         spacer.setFont( ControlPanel.jcb_font );
1711         add( spacer );
1712         _click_to_label = new JLabel( "Click on Node to:" );
1713         add( customizeLabel( _click_to_label, getConfiguration() ) );
1714         _click_to_combobox = new JComboBox();
1715         _click_to_combobox.setFocusable( false );
1716         _click_to_combobox.setMaximumRowCount( 14 );
1717         _click_to_combobox.setFont( ControlPanel.js_font );
1718         if ( !_configuration.isUseNativeUI() ) {
1719             _click_to_combobox.setBackground( getConfiguration().getGuiBackgroundColor() );
1720         }
1721         // don't add listener until all items are set (or each one will trigger
1722         // an event)
1723         // click_to_list.addActionListener(this);
1724         add( _click_to_combobox );
1725         // Correlates option names to titles
1726         _all_click_to_names = new HashMap<Integer, String>();
1727         _click_to_names = new ArrayList<String>();
1728     }
1729
1730     void tabChanged() {
1731         if ( getMainPanel().getTabbedPane().getTabCount() > 0 ) {
1732             if ( getCurrentTreePanel().isPhyHasBranchLengths()
1733                     && ( getCurrentTreePanel().getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1734                 setDrawPhylogramEnabled( true );
1735                 setDrawPhylogram( isDrawPhylogram() );
1736             }
1737             else {
1738                 setDrawPhylogramEnabled( false );
1739                 setDrawPhylogram( false );
1740             }
1741             if ( getMainPanel().getMainFrame() == null ) {
1742                 // Must be "E" applet version.
1743                 final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1744                 e.setSelectedTypeInTypeMenu( e.getCurrentTreePanel().getPhylogenyGraphicsType() );
1745             }
1746             else {
1747                 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel()
1748                         .getPhylogenyGraphicsType() );
1749             }
1750             getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton();
1751             getMainPanel().getControlPanel().search();
1752             getSequenceRelationTypeBox().removeAllItems();
1753             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
1754                     .getRelevantSequenceRelationTypes() ) {
1755                 _sequence_relation_type_box.addItem( type );
1756             }
1757             //setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
1758             // according to GUILHEM the line above can be removed.
1759         }
1760     }
1761
1762     /**
1763      * Uncollapse all nodes.
1764      */
1765     void uncollapseAll( final TreePanel tp ) {
1766         final Phylogeny t = tp.getPhylogeny();
1767         if ( ( t != null ) && !t.isEmpty() ) {
1768             t.setAllNodesToNotCollapse();
1769             t.recalculateNumberOfExternalDescendants( false );
1770             showWhole();
1771         }
1772     }
1773
1774     void updateDomainStructureEvaluethresholdDisplay() {
1775         if ( _domain_structure_evalue_thr_tf != null ) {
1776             _domain_structure_evalue_thr_tf.setText( "10^"
1777                     + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThreshold() );
1778         }
1779     }
1780
1781     void zoomInX( final float factor, final float x_correction_factor ) {
1782         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1783         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1784         treepanel.multiplyUrtFactor( 1f );
1785         if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1786                 || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1787                 || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1788                 || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1789             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1790             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1791             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1792             getMainPanel().adjustJScrollPane();
1793             treepanel.resetPreferredSize();
1794             getMainPanel().getCurrentScrollPane().getViewport().validate();
1795             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1796                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1797         }
1798         else {
1799             final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1800             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1801             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1802             getMainPanel().adjustJScrollPane();
1803             treepanel.resetPreferredSize();
1804             getMainPanel().getCurrentScrollPane().getViewport().validate();
1805             sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1806         }
1807         treepanel.resetPreferredSize();
1808         treepanel.updateOvSizes();
1809     }
1810
1811     void zoomInY( final float factor ) {
1812         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1813         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1814         treepanel.multiplyUrtFactor( 1.1f );
1815         final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1816         treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1817         getMainPanel().adjustJScrollPane();
1818         treepanel.resetPreferredSize();
1819         getMainPanel().getCurrentScrollPane().getViewport().validate();
1820         sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1821                 - ( sb.getVisibleAmount() / 2.0 ) ) );
1822         treepanel.resetPreferredSize();
1823         treepanel.updateOvSizes();
1824     }
1825
1826     void zoomOutX( final float factor, final float x_correction_factor ) {
1827         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1828         treepanel.multiplyUrtFactor( 1f );
1829         if ( ( treepanel.getXdistance() * factor ) > 0.0 ) {
1830             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1831             if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1832                     || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1833                     || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1834                     || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1835                 getMainPanel().adjustJScrollPane();
1836                 treepanel.resetPreferredSize();
1837                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1838                 final double x = ( sb.getMaximum() - sb.getMinimum() )
1839                         / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1840                 treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1841                 treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1842                 getMainPanel().adjustJScrollPane();
1843                 treepanel.resetPreferredSize();
1844                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1845                 sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1846                         - ( sb.getVisibleAmount() / 2.0 ) ) );
1847             }
1848             else {
1849                 final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1850                 treepanel.setXdistance( treepanel.getXdistance() * factor );
1851                 treepanel.setXcorrectionFactor( treepanel.getXcorrectionFactor() * x_correction_factor );
1852                 if ( x > 0 ) {
1853                     getMainPanel().adjustJScrollPane();
1854                     treepanel.resetPreferredSize();
1855                     getMainPanel().getCurrentScrollPane().getViewport().validate();
1856                     sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1857                 }
1858             }
1859             treepanel.resetPreferredSize();
1860             treepanel.updateOvSizes();
1861         }
1862     }
1863
1864     void zoomOutY( final float factor ) {
1865         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1866         treepanel.multiplyUrtFactor( 0.9f );
1867         if ( ( treepanel.getYdistance() * factor ) > 0.0 ) {
1868             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1869             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1870             treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1871             getMainPanel().adjustJScrollPane();
1872             treepanel.resetPreferredSize();
1873             getMainPanel().getCurrentScrollPane().getViewport().validate();
1874             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1875                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1876             treepanel.resetPreferredSize();
1877             treepanel.updateOvSizes();
1878         }
1879     }
1880
1881     static JLabel customizeLabel( final JLabel label, final Configuration configuration ) {
1882         label.setFont( ControlPanel.jcb_bold_font );
1883         if ( !configuration.isUseNativeUI() ) {
1884             label.setForeground( configuration.getGuiCheckboxTextColor() );
1885             label.setBackground( configuration.getGuiBackgroundColor() );
1886         }
1887         return label;
1888     }
1889
1890     enum NodeClickAction {
1891         SHOW_DATA,
1892         COLLAPSE,
1893         REROOT,
1894         SUBTREE,
1895         SWAP,
1896         COLOR_SUBTREE,
1897         OPEN_TAX_WEB,
1898         OPEN_SEQ_WEB,
1899         CUT_SUBTREE,
1900         COPY_SUBTREE,
1901         DELETE_NODE_OR_SUBTREE,
1902         PASTE_SUBTREE,
1903         ADD_NEW_NODE,
1904         EDIT_NODE_DATA,
1905         BLAST;
1906     }
1907 }