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