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