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