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