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