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