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