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