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