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