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