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