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