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