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