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