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