more simple
[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             addClickToOption( Configuration.get_ext_desc_data,
1393                               _configuration.getClickToTitle( Configuration.get_ext_desc_data ) );
1394             if ( !ForesterUtil.isEmpty( getConfiguration().getLabelForGetExtDescendentsData() ) ) {
1395                 fixme
1396                 getConfiguration().getLabelForGetExtDescendentsData();
1397             }
1398             
1399             if ( default_option == Configuration.get_ext_desc_data ) {
1400                 selected_index = cb_index;
1401             }
1402             cb_index++;
1403         }
1404         if ( getOptions().isEditable() ) {
1405             if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) {
1406                 _cut_subtree_item = cb_index;
1407                 addClickToOption( Configuration.cut_subtree, _configuration.getClickToTitle( Configuration.cut_subtree ) );
1408                 if ( default_option == Configuration.cut_subtree ) {
1409                     selected_index = cb_index;
1410                 }
1411                 cb_index++;
1412             }
1413             if ( _configuration.doDisplayClickToOption( Configuration.copy_subtree ) ) {
1414                 _copy_subtree_item = cb_index;
1415                 addClickToOption( Configuration.copy_subtree,
1416                                   _configuration.getClickToTitle( Configuration.copy_subtree ) );
1417                 if ( default_option == Configuration.copy_subtree ) {
1418                     selected_index = cb_index;
1419                 }
1420                 cb_index++;
1421             }
1422             if ( _configuration.doDisplayClickToOption( Configuration.paste_subtree ) ) {
1423                 _paste_subtree_item = cb_index;
1424                 addClickToOption( Configuration.paste_subtree,
1425                                   _configuration.getClickToTitle( Configuration.paste_subtree ) );
1426                 if ( default_option == Configuration.paste_subtree ) {
1427                     selected_index = cb_index;
1428                 }
1429                 cb_index++;
1430             }
1431             if ( _configuration.doDisplayClickToOption( Configuration.delete_subtree_or_node ) ) {
1432                 _delete_node_or_subtree_item = cb_index;
1433                 addClickToOption( Configuration.delete_subtree_or_node,
1434                                   _configuration.getClickToTitle( Configuration.delete_subtree_or_node ) );
1435                 if ( default_option == Configuration.delete_subtree_or_node ) {
1436                     selected_index = cb_index;
1437                 }
1438                 cb_index++;
1439             }
1440             if ( _configuration.doDisplayClickToOption( Configuration.add_new_node ) ) {
1441                 _add_new_node_item = cb_index;
1442                 addClickToOption( Configuration.add_new_node,
1443                                   _configuration.getClickToTitle( Configuration.add_new_node ) );
1444                 if ( default_option == Configuration.add_new_node ) {
1445                     selected_index = cb_index;
1446                 }
1447                 cb_index++;
1448             }
1449             if ( _configuration.doDisplayClickToOption( Configuration.edit_node_data ) ) {
1450                 _edit_node_data_item = cb_index;
1451                 addClickToOption( Configuration.edit_node_data,
1452                                   _configuration.getClickToTitle( Configuration.edit_node_data ) );
1453                 if ( default_option == Configuration.edit_node_data ) {
1454                     selected_index = cb_index;
1455                 }
1456                 cb_index++;
1457             }
1458         }
1459         // Set default selection and its action
1460         _click_to_combobox.setSelectedIndex( selected_index );
1461         setClickToAction( selected_index );
1462     }
1463
1464     /* GUILHEM_END */
1465     /*
1466      * Set up the controls from the config settings. 11/26/05
1467      */
1468     void setupControls() {
1469         // The tree display options:
1470         setupDisplayCheckboxes();
1471         /* GUILHEM_BEG */
1472         // The sequence relation query selection combo-box
1473         if ( _configuration.displaySequenceRelations() ) {
1474             addSequenceRelationBlock();
1475         }
1476         /* GUILHEM_END */
1477         // Click-to options
1478         startClickToOptions();
1479         setupClickToOptions();
1480         endClickToOptions();
1481         // Zoom and quick edit buttons
1482         addButtons();
1483         setupSearchTools();
1484     }
1485
1486     void setUpControlsForDomainStrucures() {
1487         _domain_display_label = new JLabel( "Domain Display:" );
1488         add( customizeLabel( _domain_display_label, getConfiguration() ) );
1489         add( _domain_display_label );
1490         _zoom_in_domain_structure = new JButton( "d+" );
1491         _zoom_out_domain_structure = new JButton( "d-" );
1492         _decr_domain_structure_evalue_thr = new JButton( "-" );
1493         _incr_domain_structure_evalue_thr = new JButton( "+" );
1494         _zoom_in_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1495         _zoom_out_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1496         _decr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1497         _incr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1498         _incr_domain_structure_evalue_thr.setToolTipText( "Increase the E-value threshold by a factor of 10" );
1499         _decr_domain_structure_evalue_thr.setToolTipText( "Decrease the E-value threshold by a factor of 10" );
1500         _domain_structure_evalue_thr_tf = new JTextField( 3 );
1501         _domain_structure_evalue_thr_tf.setEditable( false );
1502         if ( !getConfiguration().isUseNativeUI() ) {
1503             _domain_structure_evalue_thr_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1504             _domain_structure_evalue_thr_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1505             _domain_structure_evalue_thr_tf.setBorder( null );
1506         }
1507         final JPanel d1_panel = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1508         final JPanel d2_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
1509         if ( !_configuration.isUseNativeUI() ) {
1510             d1_panel.setBackground( getBackground() );
1511             d2_panel.setBackground( getBackground() );
1512         }
1513         add( d1_panel );
1514         add( d2_panel );
1515         addJButton( _zoom_out_domain_structure, d1_panel );
1516         addJButton( _zoom_in_domain_structure, d1_panel );
1517         addJButton( _decr_domain_structure_evalue_thr, d2_panel );
1518         addJTextField( _domain_structure_evalue_thr_tf, d2_panel );
1519         addJButton( _incr_domain_structure_evalue_thr, d2_panel );
1520     }
1521
1522     private void setupDisplayCheckboxes() {
1523         if ( _configuration.doDisplayOption( Configuration.display_as_phylogram ) ) {
1524             addCheckbox( Configuration.display_as_phylogram,
1525                          _configuration.getDisplayTitle( Configuration.display_as_phylogram ) );
1526             setCheckbox( Configuration.display_as_phylogram,
1527                          _configuration.doCheckOption( Configuration.display_as_phylogram ) );
1528         }
1529         if ( _configuration.doDisplayOption( Configuration.dynamically_hide_data ) ) {
1530             addCheckbox( Configuration.dynamically_hide_data,
1531                          _configuration.getDisplayTitle( Configuration.dynamically_hide_data ) );
1532             setCheckbox( Configuration.dynamically_hide_data,
1533                          _configuration.doCheckOption( Configuration.dynamically_hide_data ) );
1534         }
1535         if ( _configuration.doDisplayOption( Configuration.node_data_popup ) ) {
1536             addCheckbox( Configuration.node_data_popup, _configuration.getDisplayTitle( Configuration.node_data_popup ) );
1537             setCheckbox( Configuration.node_data_popup, _configuration.doCheckOption( Configuration.node_data_popup ) );
1538         }
1539         if ( _configuration.doDisplayOption( Configuration.display_internal_data ) ) {
1540             addCheckbox( Configuration.display_internal_data,
1541                          _configuration.getDisplayTitle( Configuration.display_internal_data ) );
1542             setCheckbox( Configuration.display_internal_data,
1543                          _configuration.doCheckOption( Configuration.display_internal_data ) );
1544         }
1545         if ( _configuration.doDisplayOption( Configuration.color_according_to_species ) ) {
1546             addCheckbox( Configuration.color_according_to_species,
1547                          _configuration.getDisplayTitle( Configuration.color_according_to_species ) );
1548             setCheckbox( Configuration.color_according_to_species,
1549                          _configuration.doCheckOption( Configuration.color_according_to_species ) );
1550         }
1551         if ( _configuration.doDisplayOption( Configuration.color_according_to_annotation ) ) {
1552             addCheckbox( Configuration.color_according_to_annotation,
1553                          _configuration.getDisplayTitle( Configuration.color_according_to_annotation ) );
1554             setCheckbox( Configuration.color_according_to_annotation,
1555                          _configuration.doCheckOption( Configuration.color_according_to_annotation ) );
1556         }
1557         if ( _configuration.doDisplayOption( Configuration.color_branches ) ) {
1558             addCheckbox( Configuration.color_branches, _configuration.getDisplayTitle( Configuration.color_branches ) );
1559             setCheckbox( Configuration.color_branches, _configuration.doCheckOption( Configuration.color_branches ) );
1560         }
1561         if ( _configuration.doDisplayOption( Configuration.width_branches ) ) {
1562             addCheckbox( Configuration.width_branches, _configuration.getDisplayTitle( Configuration.width_branches ) );
1563             setCheckbox( Configuration.width_branches, _configuration.doCheckOption( Configuration.width_branches ) );
1564         }
1565         final JLabel label = new JLabel( "Display Data:" );
1566         label.setFont( ControlPanel.jcb_bold_font );
1567         if ( !getConfiguration().isUseNativeUI() ) {
1568             label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1569         }
1570         add( label );
1571         if ( _configuration.doDisplayOption( Configuration.show_node_names ) ) {
1572             addCheckbox( Configuration.show_node_names, _configuration.getDisplayTitle( Configuration.show_node_names ) );
1573             setCheckbox( Configuration.show_node_names, _configuration.doCheckOption( Configuration.show_node_names ) );
1574         }
1575         if ( _configuration.doDisplayOption( Configuration.show_tax_code ) ) {
1576             addCheckbox( Configuration.show_tax_code, _configuration.getDisplayTitle( Configuration.show_tax_code ) );
1577             setCheckbox( Configuration.show_tax_code, _configuration.doCheckOption( Configuration.show_tax_code ) );
1578         }
1579         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_scientific_names ) ) {
1580             addCheckbox( Configuration.show_taxonomy_scientific_names,
1581                          _configuration.getDisplayTitle( Configuration.show_taxonomy_scientific_names ) );
1582             setCheckbox( Configuration.show_taxonomy_scientific_names,
1583                          _configuration.doCheckOption( Configuration.show_taxonomy_scientific_names ) );
1584         }
1585         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_common_names ) ) {
1586             addCheckbox( Configuration.show_taxonomy_common_names,
1587                          _configuration.getDisplayTitle( Configuration.show_taxonomy_common_names ) );
1588             setCheckbox( Configuration.show_taxonomy_common_names,
1589                          _configuration.doCheckOption( Configuration.show_taxonomy_common_names ) );
1590         }
1591         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_images ) ) {
1592             addCheckbox( Configuration.show_taxonomy_images,
1593                          _configuration.getDisplayTitle( Configuration.show_taxonomy_images ) );
1594             setCheckbox( Configuration.show_taxonomy_images,
1595                          _configuration.doCheckOption( Configuration.show_taxonomy_images ) );
1596         }
1597         if ( _configuration.doDisplayOption( Configuration.show_gene_symbols ) ) {
1598             addCheckbox( Configuration.show_gene_symbols,
1599                          _configuration.getDisplayTitle( Configuration.show_gene_symbols ) );
1600             setCheckbox( Configuration.show_gene_symbols,
1601                          _configuration.doCheckOption( Configuration.show_gene_symbols ) );
1602         }
1603         if ( _configuration.doDisplayOption( Configuration.show_gene_names ) ) {
1604             addCheckbox( Configuration.show_gene_names, _configuration.getDisplayTitle( Configuration.show_gene_names ) );
1605             setCheckbox( Configuration.show_gene_names, _configuration.doCheckOption( Configuration.show_gene_names ) );
1606         }
1607         if ( _configuration.doDisplayOption( Configuration.show_sequence_acc ) ) {
1608             addCheckbox( Configuration.show_sequence_acc,
1609                          _configuration.getDisplayTitle( Configuration.show_sequence_acc ) );
1610             setCheckbox( Configuration.show_sequence_acc,
1611                          _configuration.doCheckOption( Configuration.show_sequence_acc ) );
1612         }
1613         if ( _configuration.doDisplayOption( Configuration.show_annotation ) ) {
1614             addCheckbox( Configuration.show_annotation, _configuration.getDisplayTitle( Configuration.show_annotation ) );
1615             setCheckbox( Configuration.show_annotation, _configuration.doCheckOption( Configuration.show_annotation ) );
1616         }
1617         if ( _configuration.doDisplayOption( Configuration.show_binary_characters ) ) {
1618             addCheckbox( Configuration.show_binary_characters,
1619                          _configuration.getDisplayTitle( Configuration.show_binary_characters ) );
1620             setCheckbox( Configuration.show_binary_characters,
1621                          _configuration.doCheckOption( Configuration.show_binary_characters ) );
1622         }
1623         if ( _configuration.doDisplayOption( Configuration.show_binary_character_counts ) ) {
1624             addCheckbox( Configuration.show_binary_character_counts,
1625                          _configuration.getDisplayTitle( Configuration.show_binary_character_counts ) );
1626             setCheckbox( Configuration.show_binary_character_counts,
1627                          _configuration.doCheckOption( Configuration.show_binary_character_counts ) );
1628         }
1629         if ( _configuration.doDisplayOption( Configuration.show_domain_architectures ) ) {
1630             addCheckbox( Configuration.show_domain_architectures,
1631                          _configuration.getDisplayTitle( Configuration.show_domain_architectures ) );
1632             setCheckbox( Configuration.show_domain_architectures,
1633                          _configuration.doCheckOption( Configuration.show_domain_architectures ) );
1634         }
1635         if ( _configuration.doDisplayOption( Configuration.write_confidence_values ) ) {
1636             addCheckbox( Configuration.write_confidence_values,
1637                          _configuration.getDisplayTitle( Configuration.write_confidence_values ) );
1638             setCheckbox( Configuration.write_confidence_values,
1639                          _configuration.doCheckOption( Configuration.write_confidence_values ) );
1640         }
1641         if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
1642             addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
1643             setCheckbox( Configuration.write_events, _configuration.doCheckOption( Configuration.write_events ) );
1644         }
1645         if ( _configuration.doDisplayOption( Configuration.show_vector_data ) ) {
1646             addCheckbox( Configuration.show_vector_data,
1647                          _configuration.getDisplayTitle( Configuration.show_vector_data ) );
1648             setCheckbox( Configuration.show_vector_data, _configuration.doCheckOption( Configuration.show_vector_data ) );
1649         }
1650         if ( _configuration.doDisplayOption( Configuration.show_properties ) ) {
1651             addCheckbox( Configuration.show_properties, _configuration.getDisplayTitle( Configuration.show_properties ) );
1652             setCheckbox( Configuration.show_properties, _configuration.doCheckOption( Configuration.show_properties ) );
1653         }
1654     }
1655
1656     void setupSearchTools() {
1657         final String tip = "Enter text to search for. Use ',' for multiple searches (logical OR) and '+' for logical AND.";
1658         final JLabel search_label = new JLabel( "Search:" );
1659         search_label.setFont( ControlPanel.jcb_bold_font );
1660         if ( !getConfiguration().isUseNativeUI() ) {
1661             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1662         }
1663         add( search_label );
1664         search_label.setToolTipText( tip );
1665         _search_found_label = new JLabel();
1666         getSearchFoundCountsLabel().setVisible( false );
1667         _search_found_label.setFont( ControlPanel.jcb_bold_font );
1668         if ( !getConfiguration().isUseNativeUI() ) {
1669             _search_found_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1670         }
1671         _search_tf = new JTextField( 3 );
1672         _search_tf.setToolTipText( tip );
1673         _search_tf.setEditable( true );
1674         if ( !getConfiguration().isUseNativeUI() ) {
1675             _search_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1676             _search_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1677             _search_tf.setBorder( null );
1678         }
1679         _search_reset_button = new JButton();
1680         getSearchResetButton().setText( "Reset" );
1681         getSearchResetButton().setEnabled( false );
1682         getSearchResetButton().setVisible( false );
1683         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
1684         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1685         s_panel_1.setBackground( getBackground() );
1686         add( s_panel_1 );
1687         s_panel_2.setBackground( getBackground() );
1688         add( s_panel_2 );
1689         final KeyAdapter key_adapter = new KeyAdapter() {
1690
1691             @Override
1692             public void keyReleased( final KeyEvent key_event ) {
1693                 search();
1694                 displayedPhylogenyMightHaveChanged( true );
1695             }
1696         };
1697         final ActionListener action_listener = new ActionListener() {
1698
1699             @Override
1700             public void actionPerformed( final ActionEvent e ) {
1701                 searchReset();
1702                 setSearchFoundCountsOnLabel( 0 );
1703                 getSearchFoundCountsLabel().setVisible( false );
1704                 getSearchTextField().setText( "" );
1705                 getSearchResetButton().setEnabled( false );
1706                 getSearchResetButton().setVisible( false );
1707                 displayedPhylogenyMightHaveChanged( true );
1708             }
1709         };
1710         _search_reset_button.addActionListener( action_listener );
1711         _search_tf.addKeyListener( key_adapter );
1712         addJTextField( _search_tf, s_panel_1 );
1713         s_panel_2.add( _search_found_label );
1714         addJButton( _search_reset_button, s_panel_2 );
1715     }
1716
1717     private void setVisibilityOfDomainStrucureControls() {
1718         if ( _zoom_in_domain_structure != null ) {
1719             if ( isShowDomainArchitectures() ) {
1720                 _domain_display_label.setVisible( true );
1721                 _zoom_in_domain_structure.setVisible( true );
1722                 _zoom_out_domain_structure.setVisible( true );
1723                 _decr_domain_structure_evalue_thr.setVisible( true );
1724                 _incr_domain_structure_evalue_thr.setVisible( true );
1725                 _domain_structure_evalue_thr_tf.setVisible( true );
1726             }
1727             else {
1728                 _domain_display_label.setVisible( false );
1729                 _zoom_in_domain_structure.setVisible( false );
1730                 _zoom_out_domain_structure.setVisible( false );
1731                 _decr_domain_structure_evalue_thr.setVisible( false );
1732                 _incr_domain_structure_evalue_thr.setVisible( false );
1733                 _domain_structure_evalue_thr_tf.setVisible( false );
1734             }
1735         }
1736     }
1737
1738     /**
1739      * Fit entire tree into window.
1740      */
1741     void showWhole() {
1742         if ( ( _mainpanel.getCurrentScrollPane() == null ) || _mainpanel.getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1743             return;
1744         }
1745         getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1746         displayedPhylogenyMightHaveChanged( true );
1747         _mainpanel.getCurrentTreePanel().updateOvSettings();
1748         _mainpanel.getCurrentTreePanel().validate();
1749         _mainpanel.validate();
1750         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1751                                                                    _mainpanel.getSizeOfViewport().height,
1752                                                                    true );
1753         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1754         _mainpanel.adjustJScrollPane();
1755         _mainpanel.getCurrentTreePanel().repaint();
1756         _mainpanel.getCurrentTreePanel().validate();
1757         _mainpanel.validate();
1758         _mainpanel.getCurrentTreePanel().setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1759                                                                    _mainpanel.getSizeOfViewport().height,
1760                                                                    true );
1761         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1762         _mainpanel.adjustJScrollPane();
1763         _mainpanel.getCurrentTreePanel().repaint();
1764         _mainpanel.getCurrentTreePanel().updateOvSizes();
1765     }
1766
1767     void showWholeAll() {
1768         for( final TreePanel tree_panel : _mainpanel.getTreePanels() ) {
1769             if ( tree_panel != null ) {
1770                 tree_panel.validate();
1771                 tree_panel.setParametersForPainting( _mainpanel.getSizeOfViewport().width,
1772                                                      _mainpanel.getSizeOfViewport().height,
1773                                                      true );
1774                 tree_panel.resetPreferredSize();
1775                 tree_panel.repaint();
1776             }
1777         }
1778     }
1779
1780     // Create header for click-to combo box.
1781     void startClickToOptions() {
1782         final JLabel spacer = new JLabel( "" );
1783         spacer.setFont( ControlPanel.jcb_font );
1784         add( spacer );
1785         _click_to_label = new JLabel( "Click on Node to:" );
1786         add( customizeLabel( _click_to_label, getConfiguration() ) );
1787         _click_to_combobox = new JComboBox();
1788         _click_to_combobox.setFocusable( false );
1789         _click_to_combobox.setMaximumRowCount( 14 );
1790         _click_to_combobox.setFont( ControlPanel.js_font );
1791         if ( !_configuration.isUseNativeUI() ) {
1792             _click_to_combobox.setBackground( getConfiguration().getGuiBackgroundColor() );
1793         }
1794         // don't add listener until all items are set (or each one will trigger
1795         // an event)
1796         // click_to_list.addActionListener(this);
1797         add( _click_to_combobox );
1798         // Correlates option names to titles
1799         _all_click_to_names = new HashMap<Integer, String>();
1800         _click_to_names = new ArrayList<String>();
1801     }
1802
1803     void tabChanged() {
1804         if ( getMainPanel().getTabbedPane().getTabCount() > 0 ) {
1805             if ( getCurrentTreePanel().isPhyHasBranchLengths()
1806                     && ( getCurrentTreePanel().getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1807                 setDrawPhylogramEnabled( true );
1808                 setDrawPhylogram( isDrawPhylogram() );
1809             }
1810             else {
1811                 setDrawPhylogramEnabled( false );
1812                 setDrawPhylogram( false );
1813             }
1814             if ( getMainPanel().getMainFrame() == null ) {
1815                 // Must be "E" applet version.
1816                 final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1817                 e.setSelectedTypeInTypeMenu( e.getCurrentTreePanel().getPhylogenyGraphicsType() );
1818             }
1819             else {
1820                 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel()
1821                         .getPhylogenyGraphicsType() );
1822             }
1823             getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton();
1824             getMainPanel().getControlPanel().search();
1825             getSequenceRelationTypeBox().removeAllItems();
1826             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
1827                     .getRelevantSequenceRelationTypes() ) {
1828                 _sequence_relation_type_box.addItem( type );
1829             }
1830             //setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
1831             // according to GUILHEM the line above can be removed.
1832         }
1833     }
1834
1835     /**
1836      * Uncollapse all nodes.
1837      */
1838     void uncollapseAll( final TreePanel tp ) {
1839         final Phylogeny t = tp.getPhylogeny();
1840         if ( ( t != null ) && !t.isEmpty() ) {
1841             for( final PhylogenyNodeIterator iter = t.iteratorPreorder(); iter.hasNext(); ) {
1842                 final PhylogenyNode node = iter.next();
1843                 node.setCollapse( false );
1844             }
1845             tp.resetNodeIdToDistToLeafMap();
1846             tp.updateSetOfCollapsedExternalNodes();
1847             t.recalculateNumberOfExternalDescendants( false );
1848             tp.setNodeInPreorderToNull();
1849             t.clearHashIdToNodeMap();
1850             showWhole();
1851         }
1852     }
1853
1854     void updateDomainStructureEvaluethresholdDisplay() {
1855         if ( _domain_structure_evalue_thr_tf != null ) {
1856             _domain_structure_evalue_thr_tf.setText( "10^"
1857                     + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThreshold() );
1858         }
1859     }
1860
1861     void zoomInX( final float factor, final float x_correction_factor ) {
1862         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1863         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1864         treepanel.multiplyUrtFactor( 1f );
1865         if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1866                 || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1867                 || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1868                 || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1869             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1870             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1871             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1872             getMainPanel().adjustJScrollPane();
1873             treepanel.resetPreferredSize();
1874             getMainPanel().getCurrentScrollPane().getViewport().validate();
1875             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1876                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1877         }
1878         else {
1879             final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1880             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1881             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1882             getMainPanel().adjustJScrollPane();
1883             treepanel.resetPreferredSize();
1884             getMainPanel().getCurrentScrollPane().getViewport().validate();
1885             sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1886         }
1887         treepanel.resetPreferredSize();
1888         treepanel.updateOvSizes();
1889     }
1890
1891     void zoomInY( final float factor ) {
1892         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1893         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1894         treepanel.multiplyUrtFactor( 1.1f );
1895         final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1896         treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1897         getMainPanel().adjustJScrollPane();
1898         treepanel.resetPreferredSize();
1899         getMainPanel().getCurrentScrollPane().getViewport().validate();
1900         sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1901                 - ( sb.getVisibleAmount() / 2.0 ) ) );
1902         treepanel.resetPreferredSize();
1903         treepanel.updateOvSizes();
1904     }
1905
1906     void zoomOutX( final float factor, final float x_correction_factor ) {
1907         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1908         treepanel.multiplyUrtFactor( 1f );
1909         if ( ( treepanel.getXdistance() * factor ) > 0.0 ) {
1910             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1911             if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1912                     || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1913                     || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1914                     || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1915                 getMainPanel().adjustJScrollPane();
1916                 treepanel.resetPreferredSize();
1917                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1918                 final double x = ( sb.getMaximum() - sb.getMinimum() )
1919                         / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1920                 treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1921                 treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1922                 getMainPanel().adjustJScrollPane();
1923                 treepanel.resetPreferredSize();
1924                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1925                 sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1926                         - ( sb.getVisibleAmount() / 2.0 ) ) );
1927             }
1928             else {
1929                 final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1930                 treepanel.setXdistance( treepanel.getXdistance() * factor );
1931                 treepanel.setXcorrectionFactor( treepanel.getXcorrectionFactor() * x_correction_factor );
1932                 if ( x > 0 ) {
1933                     getMainPanel().adjustJScrollPane();
1934                     treepanel.resetPreferredSize();
1935                     getMainPanel().getCurrentScrollPane().getViewport().validate();
1936                     sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1937                 }
1938             }
1939             treepanel.resetPreferredSize();
1940             treepanel.updateOvSizes();
1941         }
1942     }
1943
1944     void zoomOutY( final float factor ) {
1945         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1946         treepanel.multiplyUrtFactor( 0.9f );
1947         if ( ( treepanel.getYdistance() * factor ) > 0.0 ) {
1948             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1949             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1950             treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1951             getMainPanel().adjustJScrollPane();
1952             treepanel.resetPreferredSize();
1953             getMainPanel().getCurrentScrollPane().getViewport().validate();
1954             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1955                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1956             treepanel.resetPreferredSize();
1957             treepanel.updateOvSizes();
1958         }
1959     }
1960
1961     static JLabel customizeLabel( final JLabel label, final Configuration configuration ) {
1962         label.setFont( ControlPanel.jcb_bold_font );
1963         if ( !configuration.isUseNativeUI() ) {
1964             label.setForeground( configuration.getGuiCheckboxTextColor() );
1965             label.setBackground( configuration.getGuiBackgroundColor() );
1966         }
1967         return label;
1968     }
1969
1970     enum NodeClickAction {
1971         SHOW_DATA,
1972         COLLAPSE,
1973         REROOT,
1974         SUBTREE,
1975         SWAP,
1976         COLOR_SUBTREE,
1977         OPEN_TAX_WEB,
1978         OPEN_SEQ_WEB,
1979         CUT_SUBTREE,
1980         COPY_SUBTREE,
1981         DELETE_NODE_OR_SUBTREE,
1982         PASTE_SUBTREE,
1983         ADD_NEW_NODE,
1984         EDIT_NODE_DATA,
1985         SORT_DESCENDENTS,
1986         GET_EXT_DESC_DATA,
1987         BLAST;
1988     }
1989 }