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