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