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