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