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