domain + go output work begins
[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: https://sites.google.com/site/cmzmasek/home/software/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.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
65 import org.forester.phylogeny.PhylogenyNode;
66 import org.forester.phylogeny.data.Sequence;
67 import org.forester.phylogeny.data.SequenceRelation;
68 import org.forester.phylogeny.data.SequenceRelation.SEQUENCE_RELATION_TYPE;
69 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
70 import org.forester.util.ForesterUtil;
71
72 final class ControlPanel extends JPanel implements ActionListener {
73
74     final static Font                         jcb_bold_font             = new Font( Configuration.getDefaultFontFamilyName(),
75                                                                                     Font.BOLD,
76                                                                                     9 );
77     final static Font                         jcb_font                  = new Font( Configuration.getDefaultFontFamilyName(),
78                                                                                     Font.PLAIN,
79                                                                                     9 );
80     final static Font                         js_font                   = new Font( Configuration.getDefaultFontFamilyName(),
81                                                                                     Font.PLAIN,
82                                                                                     9 );
83     private static final String               RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree";
84     private static final String               SEARCH_TIP_TEXT           = "Enter text to search for. Use ',' for logical OR and '+' for logical AND (not used in this manner for regular expression searches).";
85     private static final long                 serialVersionUID          = -8463483932821545633L;
86     private NodeClickAction                   _action_when_node_clicked;
87     private int                               _add_new_node_item;
88     private Map<Integer, String>              _all_click_to_names;
89     private Map<String, Color>                _annotation_colors;
90     private int                               _blast_item;
91     private JComboBox<String>                 _click_to_combobox;
92     private JLabel                            _click_to_label;
93     private List<String>                      _click_to_names;
94     private int                               _collapse_cb_item;
95     private JCheckBox                         _color_acc_species;
96     private JCheckBox                         _color_acc_sequence;
97     private JCheckBox                         _color_according_to_annotation;
98     private boolean                           _color_branches;
99     private JCheckBox                         _use_visual_styles_cb;
100     private int                               _color_subtree_cb_item;
101     private int                               _change_node_font_item;
102     // The settings from the conf file
103     private final Configuration               _configuration;
104     private int                               _copy_subtree_item;
105     private int                               _cut_subtree_item;
106     private JButton                           _decr_domain_structure_evalue_thr;
107     private int                               _delete_node_or_subtree_item;
108     private JCheckBox                         _display_as_phylogram_cb;
109     // Tree checkboxes
110     private JCheckBox                         _display_internal_data;
111     private JLabel                            _domain_display_label;
112     private JTextField                        _domain_structure_evalue_thr_tf;
113     private List<Boolean>                     _draw_phylogram;
114     private JCheckBox                         _dynamically_hide_data;
115     private int                               _edit_node_data_item;
116     private int                               _get_ext_desc_data;
117     private JButton                           _incr_domain_structure_evalue_thr;
118     private final MainPanel                   _mainpanel;
119     private JCheckBox                         _node_desc_popup_cb;
120     private int                               _open_pdb_item;
121     private int                               _open_seq_web_item;
122     private int                               _open_tax_web_item;
123     private int                               _color_node_font_item;
124     private JButton                           _order;
125     private boolean                           _order_of_appearance;
126     private int                               _paste_subtree_item;
127     private int                               _reroot_cb_item;
128     private JButton                           _return_to_super_tree;
129     // Search
130     private JLabel                            _search_found_label_0;
131     private JLabel                            _search_found_label_1;
132     private JButton                           _search_reset_button_0;
133     private JButton                           _search_reset_button_1;
134     private JTextField                        _search_tf_0;
135     private JTextField                        _search_tf_1;
136     private int                               _select_nodes_item;
137     private Sequence                          _selected_query_seq;
138     private JCheckBox                         _seq_relation_confidence_switch;
139     private JComboBox<SEQUENCE_RELATION_TYPE> _sequence_relation_type_box;
140     private JCheckBox                         _show_annotation;
141     private JCheckBox                         _show_binary_character_counts;
142     private JCheckBox                         _show_binary_characters;
143     // Indices for the click-to options in the combo box
144     private int                               _show_data_item;
145     private JCheckBox                         _show_domain_architectures;
146     private JCheckBox                         _show_mol_seqs;
147     private JCheckBox                         _write_branch_length_values;
148     private JCheckBox                         _show_events;
149     private JCheckBox                         _show_gene_names;
150     private JCheckBox                         _show_node_names;
151     private JCheckBox                         _show_properties_cb;
152     private JCheckBox                         _show_seq_names;
153     private JCheckBox                         _show_seq_symbols;
154     private JCheckBox                         _show_sequence_acc;
155     private JComboBox<String>                 _show_sequence_relations;
156     private JCheckBox                         _show_taxo_code;
157     private JCheckBox                         _show_taxo_common_names;
158     private JCheckBox                         _show_taxo_images_cb;
159     private JCheckBox                         _show_taxo_scientific_names;
160     private JCheckBox                         _show_vector_data_cb;
161     private JButton                           _show_whole;
162     private int                               _sort_descendents_item;
163     private Map<String, Color>                _species_colors;
164     private Map<String, Color>                _sequence_colors;
165     private int                               _subtree_cb_item;
166     private int                               _swap_cb_item;
167     private JButton                           _uncollapse_all;
168     private JCheckBox                         _width_branches;
169     private JCheckBox                         _write_confidence;
170     private JButton                           _zoom_in_domain_structure;
171     private JButton                           _zoom_in_x;
172     private JButton                           _zoom_in_y;
173     private JLabel                            _zoom_label;
174     private JButton                           _zoom_out_domain_structure;
175     private JButton                           _zoom_out_x;
176     private JButton                           _zoom_out_y;
177
178     ControlPanel( final MainPanel ap, final Configuration configuration ) {
179         init();
180         _mainpanel = ap;
181         _configuration = configuration;
182         if ( !_configuration.isUseNativeUI() ) {
183             setBackground( getConfiguration().getGuiBackgroundColor() );
184             setBorder( BorderFactory.createRaisedBevelBorder() );
185         }
186         setLayout( new GridLayout( 0, 1, 2, 2 ) );
187         _order_of_appearance = true;
188         setupControls();
189     }
190
191     /**
192      * Handle an action.
193      */
194     @Override
195     public void actionPerformed( final ActionEvent e ) {
196         try {
197             if ( e.getSource() == _color_acc_sequence ) {
198                 if ( _color_acc_species != null ) {
199                     _color_acc_species.setSelected( false );
200                 }
201             }
202             else if ( e.getSource() == _color_acc_species ) {
203                 if ( _color_acc_sequence != null ) {
204                     _color_acc_sequence.setSelected( false );
205                 }
206             }
207             final TreePanel tp = getMainPanel().getCurrentTreePanel();
208             if ( tp == null ) {
209                 return;
210             }
211             if ( e.getSource() == _click_to_combobox ) {
212                 setClickToAction( _click_to_combobox.getSelectedIndex() );
213                 getCurrentTreePanel().repaint();
214             }
215             else if ( e.getSource() == _show_binary_characters ) {
216                 if ( ( _show_binary_character_counts != null ) && _show_binary_characters.isSelected() ) {
217                     _show_binary_character_counts.setSelected( false );
218                 }
219                 displayedPhylogenyMightHaveChanged( true );
220             }
221             else if ( e.getSource() == _show_binary_character_counts ) {
222                 if ( ( _show_binary_characters != null ) && _show_binary_character_counts.isSelected() ) {
223                     _show_binary_characters.setSelected( false );
224                 }
225                 displayedPhylogenyMightHaveChanged( true );
226             }
227             else if ( e.getSource() == _show_domain_architectures ) {
228                 search0();
229                 search1();
230                 displayedPhylogenyMightHaveChanged( true );
231             }
232             else if ( ( tp != null ) && ( tp.getPhylogeny() != null ) ) {
233                 if ( e.getSource() == getDisplayAsPhylogramCb() ) {
234                     setDrawPhylogram( getDisplayAsPhylogramCb().isSelected() );
235                     showWhole();
236                 }
237                 // Zoom buttons
238                 else if ( e.getSource() == _zoom_in_x ) {
239                     zoomInX( Constants.BUTTON_ZOOM_IN_FACTOR, Constants.BUTTON_ZOOM_IN_X_CORRECTION_FACTOR );
240                     displayedPhylogenyMightHaveChanged( false );
241                 }
242                 else if ( e.getSource() == _zoom_in_y ) {
243                     zoomInY( Constants.BUTTON_ZOOM_IN_FACTOR );
244                     displayedPhylogenyMightHaveChanged( false );
245                 }
246                 else if ( e.getSource() == _zoom_out_x ) {
247                     zoomOutX( Constants.BUTTON_ZOOM_OUT_FACTOR, Constants.BUTTON_ZOOM_OUT_X_CORRECTION_FACTOR );
248                     displayedPhylogenyMightHaveChanged( false );
249                 }
250                 else if ( e.getSource() == _zoom_out_y ) {
251                     zoomOutY( Constants.BUTTON_ZOOM_OUT_FACTOR );
252                     displayedPhylogenyMightHaveChanged( false );
253                 }
254                 else if ( e.getSource() == _show_whole ) {
255                     displayedPhylogenyMightHaveChanged( true );
256                     showWhole();
257                 }
258                 else if ( e.getSource() == _return_to_super_tree ) {
259                     _mainpanel.getCurrentTreePanel().superTree();
260                     showWhole();
261                 }
262                 else if ( e.getSource() == _order ) {
263                     DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
264                     if ( isShowTaxonomyScientificNames() || isShowTaxonomyCode() ) {
265                         pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
266                     }
267                     else if ( isShowSeqNames() || isShowSeqSymbols() || isShowGeneNames() ) {
268                         pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
269                     }
270                     PhylogenyMethods.orderAppearance( tp.getPhylogeny().getRoot(), _order_of_appearance, true, pri );
271                     _order_of_appearance = !_order_of_appearance;
272                     tp.setNodeInPreorderToNull();
273                     tp.getPhylogeny().externalNodesHaveChanged();
274                     tp.getPhylogeny().clearHashIdToNodeMap();
275                     tp.getPhylogeny().recalculateNumberOfExternalDescendants( true );
276                     tp.resetNodeIdToDistToLeafMap();
277                     tp.setEdited( true );
278                     displayedPhylogenyMightHaveChanged( true );
279                 }
280                 else if ( e.getSource() == _uncollapse_all ) {
281                     uncollapseAll( tp );
282                     displayedPhylogenyMightHaveChanged( false );
283                 }
284                 else if ( e.getSource() == _zoom_in_domain_structure ) {
285                     _mainpanel.getCurrentTreePanel().zoomInDomainStructure();
286                     displayedPhylogenyMightHaveChanged( true );
287                 }
288                 else if ( e.getSource() == _zoom_out_domain_structure ) {
289                     _mainpanel.getCurrentTreePanel().zoomOutDomainStructure();
290                     displayedPhylogenyMightHaveChanged( true );
291                 }
292                 else if ( e.getSource() == _decr_domain_structure_evalue_thr ) {
293                     _mainpanel.getCurrentTreePanel().decreaseDomainStructureEvalueThresholdExp();
294                     displayedPhylogenyMightHaveChanged( true );
295                 }
296                 else if ( e.getSource() == _incr_domain_structure_evalue_thr ) {
297                     _mainpanel.getCurrentTreePanel().increaseDomainStructureEvalueThresholdExp();
298                     displayedPhylogenyMightHaveChanged( true );
299                 }
300                 else if ( e.getSource() == _search_tf_0 ) {
301                     search0();
302                     displayedPhylogenyMightHaveChanged( true );
303                 }
304                 else if ( e.getSource() == _search_tf_1 ) {
305                     search1();
306                     displayedPhylogenyMightHaveChanged( true );
307                 }
308                 else if ( ( _dynamically_hide_data != null ) && ( e.getSource() == _dynamically_hide_data )
309                         && !_dynamically_hide_data.isSelected() ) {
310                     setDynamicHidingIsOn( false );
311                     displayedPhylogenyMightHaveChanged( true );
312                 }
313                 else {
314                     displayedPhylogenyMightHaveChanged( true );
315                 }
316             }
317             tp.requestFocus();
318             tp.requestFocusInWindow();
319             tp.requestFocus();
320         }
321         catch ( final Exception ex ) {
322             AptxUtil.unexpectedException( ex );
323         }
324         catch ( final Error err ) {
325             AptxUtil.unexpectedError( err );
326         }
327     }
328
329     public JCheckBox getColorAccSpeciesCb() {
330         return _color_acc_species;
331     }
332
333     public JCheckBox getColorAccSequenceCb() {
334         return _color_acc_sequence;
335     }
336
337     public JCheckBox getUseVisualStylesCb() {
338         return _use_visual_styles_cb;
339     }
340
341     public JCheckBox getDisplayAsPhylogramCb() {
342         return _display_as_phylogram_cb;
343     }
344
345     public JCheckBox getDynamicallyHideData() {
346         return _dynamically_hide_data;
347     }
348
349     public JCheckBox getNodeDescPopupCb() {
350         return _node_desc_popup_cb;
351     }
352
353     public Sequence getSelectedQuerySequence() {
354         return _selected_query_seq;
355     }
356
357     public JComboBox<String> getSequenceRelationBox() {
358         if ( _show_sequence_relations == null ) {
359             _show_sequence_relations = new JComboBox<String>();
360             _show_sequence_relations.setFocusable( false );
361             _show_sequence_relations.setMaximumRowCount( 20 );
362             _show_sequence_relations.setFont( ControlPanel.js_font );
363             if ( !_configuration.isUseNativeUI() ) {
364                 _show_sequence_relations.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
365                 _show_sequence_relations.setForeground( getConfiguration().getGuiButtonTextColor() );
366             }
367             _show_sequence_relations.addItem( "-----" );
368             _show_sequence_relations.setToolTipText( "To display orthology information for selected query" );
369         }
370         return _show_sequence_relations;
371     }
372
373     /* GUILHEM_BEG */
374     public JComboBox<SEQUENCE_RELATION_TYPE> getSequenceRelationTypeBox() {
375         if ( _sequence_relation_type_box == null ) {
376             _sequence_relation_type_box = new JComboBox<SEQUENCE_RELATION_TYPE>();
377             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : SequenceRelation.SEQUENCE_RELATION_TYPE.values() ) {
378                 _sequence_relation_type_box.addItem( type );
379             }
380             _sequence_relation_type_box.addActionListener( new ActionListener() {
381
382                 @Override
383                 public void actionPerformed( final ActionEvent e ) {
384                     if ( _mainpanel.getCurrentPhylogeny() != null ) {
385                         setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
386                     }
387                 }
388             } );
389         }
390         return _sequence_relation_type_box;
391     }
392
393     public JCheckBox getShowEventsCb() {
394         return _show_events;
395     }
396
397     public JCheckBox getWriteConfidenceCb() {
398         return _write_confidence;
399     }
400
401     public boolean isShowProperties() {
402         return ( ( _show_properties_cb != null ) && _show_properties_cb.isSelected() );
403     }
404
405     public boolean isShowTaxonomyImages() {
406         return ( ( _show_taxo_images_cb != null ) && _show_taxo_images_cb.isSelected() );
407     }
408
409     public boolean isShowVectorData() {
410         return ( ( _show_vector_data_cb != null ) && _show_vector_data_cb.isSelected() );
411     }
412
413     public void setSequenceRelationQueries( final Collection<Sequence> sequenceRelationQueries ) {
414         final JComboBox<String> box = getSequenceRelationBox();
415         while ( box.getItemCount() > 1 ) {
416             box.removeItemAt( 1 );
417         }
418         final HashMap<String, Sequence> sequencesByName = new HashMap<String, Sequence>();
419         final SequenceRelation.SEQUENCE_RELATION_TYPE relationType = ( SequenceRelation.SEQUENCE_RELATION_TYPE ) _sequence_relation_type_box
420                 .getSelectedItem();
421         if ( relationType == null ) {
422             return;
423         }
424         final ArrayList<String> sequenceNamesToAdd = new ArrayList<String>();
425         for( final Sequence seq : sequenceRelationQueries ) {
426             if ( seq.hasSequenceRelations() ) {
427                 boolean fFoundForCurrentType = false;
428                 for( final SequenceRelation sq : seq.getSequenceRelations() ) {
429                     if ( sq.getType().equals( relationType ) ) {
430                         fFoundForCurrentType = true;
431                         break;
432                     }
433                 }
434                 if ( fFoundForCurrentType ) {
435                     sequenceNamesToAdd.add( seq.getName() );
436                     sequencesByName.put( seq.getName(), seq );
437                 }
438             }
439         }
440         // sort sequences by name before adding them to the combo
441         final String[] sequenceNameArray = sequenceNamesToAdd.toArray( new String[ sequenceNamesToAdd.size() ] );
442         Arrays.sort( sequenceNameArray, String.CASE_INSENSITIVE_ORDER );
443         for( final String seqName : sequenceNameArray ) {
444             box.addItem( seqName );
445         }
446         for( final ItemListener oldItemListener : box.getItemListeners() ) {
447             box.removeItemListener( oldItemListener );
448         }
449         box.addItemListener( new ItemListener() {
450
451             @Override
452             public void itemStateChanged( final ItemEvent e ) {
453                 _selected_query_seq = sequencesByName.get( e.getItem() );
454                 _mainpanel.getCurrentTreePanel().repaint();
455             }
456         } );
457     }
458
459     void activateButtonToReturnToSuperTree( int index ) {
460         --index;
461         if ( index > 0 ) {
462             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT + " " + index );
463         }
464         else {
465             _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
466         }
467         _return_to_super_tree.setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
468         _return_to_super_tree.setEnabled( true );
469     }
470
471     /**
472      * Add zoom and quick edit buttons. (Last modified 8/9/04)
473      */
474     void addButtons() {
475         final JLabel spacer = new JLabel( "" );
476         spacer.setOpaque( false );
477         add( spacer );
478         final JPanel x_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
479         final JPanel y_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
480         final JPanel z_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
481         if ( !getConfiguration().isUseNativeUI() ) {
482             x_panel.setBackground( getBackground() );
483             y_panel.setBackground( getBackground() );
484             z_panel.setBackground( getBackground() );
485         }
486         add( _zoom_label = new JLabel( "Zoom:" ) );
487         customizeLabel( _zoom_label, getConfiguration() );
488         add( x_panel );
489         add( y_panel );
490         add( z_panel );
491         if ( getConfiguration().isUseNativeUI() ) {
492             _zoom_in_x = new JButton( "+" );
493             _zoom_out_x = new JButton( "-" );
494         }
495         else {
496             _zoom_in_x = new JButton( "X+" );
497             _zoom_out_x = new JButton( "X-" );
498         }
499         _zoom_in_y = new JButton( "Y+" );
500         _zoom_out_y = new JButton( "Y-" );
501         _show_whole = new JButton( "F" );
502         _show_whole.setToolTipText( "To fit the complete phylogeny to the current display size [F or Home]" );
503         _zoom_in_x.setToolTipText( "To zoom in horizontally [Shift+cursor-right]" );
504         _zoom_in_y.setToolTipText( "To zoom in vertically [Shift+cursor-up]" );
505         _zoom_out_x.setToolTipText( "To zoom out horizontally [Shift+cursor-left]" );
506         _zoom_out_y.setToolTipText( "To zoom out vertically [Shift+cursor-down]" );
507         if ( getConfiguration().isUseNativeUI() && ForesterUtil.isMac() ) {
508             _zoom_out_x.setPreferredSize( new Dimension( 55, 10 ) );
509             _zoom_in_x.setPreferredSize( new Dimension( 55, 10 ) );
510         }
511         else {
512             _zoom_out_x.setPreferredSize( new Dimension( 10, 10 ) );
513             _zoom_in_x.setPreferredSize( new Dimension( 10, 10 ) );
514         }
515         _zoom_out_y.setPreferredSize( new Dimension( 10, 10 ) );
516         _zoom_in_y.setPreferredSize( new Dimension( 10, 10 ) );
517         _show_whole.setPreferredSize( new Dimension( 10, 10 ) );
518         _return_to_super_tree = new JButton( RETURN_TO_SUPER_TREE_TEXT );
519         _return_to_super_tree.setEnabled( false );
520         _order = new JButton( "Order Subtrees" );
521         _uncollapse_all = new JButton( "Uncollapse All" );
522         addJButton( _zoom_in_y, x_panel );
523         addJButton( _zoom_out_x, y_panel );
524         addJButton( _show_whole, y_panel );
525         addJButton( _zoom_in_x, y_panel );
526         addJButton( _zoom_out_y, z_panel );
527         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
528             setUpControlsForDomainStrucures();
529         }
530         final JLabel spacer2 = new JLabel( "" );
531         add( spacer2 );
532         addJButton( _return_to_super_tree, this );
533         addJButton( _order, this );
534         addJButton( _uncollapse_all, this );
535         final JLabel spacer3 = new JLabel( "" );
536         add( spacer3 );
537         setVisibilityOfDomainStrucureControls();
538     }
539
540     void addCheckbox( final int which, final String title ) {
541         final JPanel ch_panel = new JPanel( new BorderLayout( 0, 0 ) );
542         switch ( which ) {
543             case Configuration.display_as_phylogram:
544                 _display_as_phylogram_cb = new JCheckBox( title );
545                 getDisplayAsPhylogramCb().setToolTipText( "To switch between phylogram and cladogram display" );
546                 addJCheckBox( getDisplayAsPhylogramCb(), ch_panel );
547                 add( ch_panel );
548                 break;
549             case Configuration.display_internal_data:
550                 _display_internal_data = new JCheckBox( title );
551                 _display_internal_data.setToolTipText( "To allow or disallow display of internal labels" );
552                 addJCheckBox( _display_internal_data, ch_panel );
553                 add( ch_panel );
554                 break;
555             case Configuration.color_according_to_species:
556                 _color_acc_species = new JCheckBox( title );
557                 _color_acc_species.setToolTipText( "To colorize node labels as a function of taxonomy" );
558                 addJCheckBox( _color_acc_species, ch_panel );
559                 add( ch_panel );
560                 break;
561             case Configuration.color_according_to_sequence:
562                 _color_acc_sequence = new JCheckBox( title );
563                 _color_acc_sequence.setToolTipText( "To colorize node labels as a function of sequence name" );
564                 addJCheckBox( _color_acc_sequence, ch_panel );
565                 add( ch_panel );
566                 break;
567             case Configuration.color_according_to_annotation:
568                 _color_according_to_annotation = new JCheckBox( title );
569                 _color_according_to_annotation
570                         .setToolTipText( "To colorize sequence annotation labels as a function of sequence annotation" );
571                 addJCheckBox( _color_according_to_annotation, ch_panel );
572                 add( ch_panel );
573                 break;
574             case Configuration.show_node_names:
575                 _show_node_names = new JCheckBox( title );
576                 addJCheckBox( _show_node_names, ch_panel );
577                 add( ch_panel );
578                 break;
579             case Configuration.show_taxonomy_scientific_names:
580                 _show_taxo_scientific_names = new JCheckBox( title );
581                 addJCheckBox( _show_taxo_scientific_names, ch_panel );
582                 add( ch_panel );
583                 break;
584             case Configuration.show_taxonomy_common_names:
585                 _show_taxo_common_names = new JCheckBox( title );
586                 addJCheckBox( _show_taxo_common_names, ch_panel );
587                 add( ch_panel );
588                 break;
589             case Configuration.show_tax_code:
590                 _show_taxo_code = new JCheckBox( title );
591                 addJCheckBox( _show_taxo_code, ch_panel );
592                 add( ch_panel );
593                 break;
594             case Configuration.show_taxonomy_images:
595                 _show_taxo_images_cb = new JCheckBox( title );
596                 addJCheckBox( _show_taxo_images_cb, ch_panel );
597                 add( ch_panel );
598                 break;
599             case Configuration.show_binary_characters:
600                 _show_binary_characters = new JCheckBox( title );
601                 addJCheckBox( _show_binary_characters, ch_panel );
602                 add( ch_panel );
603                 break;
604             case Configuration.show_annotation:
605                 _show_annotation = new JCheckBox( title );
606                 addJCheckBox( _show_annotation, ch_panel );
607                 add( ch_panel );
608                 break;
609             case Configuration.show_binary_character_counts:
610                 _show_binary_character_counts = new JCheckBox( title );
611                 addJCheckBox( _show_binary_character_counts, ch_panel );
612                 add( ch_panel );
613                 break;
614             case Configuration.write_confidence_values:
615                 _write_confidence = new JCheckBox( title );
616                 addJCheckBox( getWriteConfidenceCb(), ch_panel );
617                 add( ch_panel );
618                 break;
619             case Configuration.write_events:
620                 _show_events = new JCheckBox( title );
621                 addJCheckBox( getShowEventsCb(), ch_panel );
622                 add( ch_panel );
623                 break;
624             case Configuration.use_style:
625                 _use_visual_styles_cb = new JCheckBox( title );
626                 getUseVisualStylesCb()
627                         .setToolTipText( "To use visual styles (node colors, fonts) and branch colors, if present" );
628                 addJCheckBox( getUseVisualStylesCb(), ch_panel );
629                 add( ch_panel );
630                 break;
631             case Configuration.width_branches:
632                 _width_branches = new JCheckBox( title );
633                 _width_branches.setToolTipText( "To use branch width values, if present" );
634                 addJCheckBox( _width_branches, ch_panel );
635                 add( ch_panel );
636                 break;
637             case Configuration.write_branch_length_values:
638                 _write_branch_length_values = new JCheckBox( title );
639                 addJCheckBox( _write_branch_length_values, ch_panel );
640                 add( ch_panel );
641                 break;
642             case Configuration.show_domain_architectures:
643                 _show_domain_architectures = new JCheckBox( title );
644                 addJCheckBox( _show_domain_architectures, ch_panel );
645                 add( ch_panel );
646                 break;
647             case Configuration.show_mol_seqs:
648                 _show_mol_seqs = new JCheckBox( title );
649                 addJCheckBox( _show_mol_seqs, ch_panel );
650                 add( ch_panel );
651                 break;
652             case Configuration.show_seq_names:
653                 _show_seq_names = new JCheckBox( title );
654                 addJCheckBox( _show_seq_names, ch_panel );
655                 add( ch_panel );
656                 break;
657             case Configuration.show_gene_names:
658                 _show_gene_names = new JCheckBox( title );
659                 addJCheckBox( _show_gene_names, ch_panel );
660                 add( ch_panel );
661                 break;
662             case Configuration.show_seq_symbols:
663                 _show_seq_symbols = new JCheckBox( title );
664                 addJCheckBox( _show_seq_symbols, ch_panel );
665                 add( ch_panel );
666                 break;
667             case Configuration.show_sequence_acc:
668                 _show_sequence_acc = new JCheckBox( title );
669                 addJCheckBox( _show_sequence_acc, ch_panel );
670                 add( ch_panel );
671                 break;
672             case Configuration.dynamically_hide_data:
673                 _dynamically_hide_data = new JCheckBox( title );
674                 getDynamicallyHideData().setToolTipText( "To hide labels depending on expected visibility" );
675                 addJCheckBox( getDynamicallyHideData(), ch_panel );
676                 add( ch_panel );
677                 break;
678             case Configuration.node_data_popup:
679                 _node_desc_popup_cb = new JCheckBox( title );
680                 getNodeDescPopupCb().setToolTipText( "To enable mouse rollover display of basic node data" );
681                 addJCheckBox( getNodeDescPopupCb(), ch_panel );
682                 add( ch_panel );
683                 break;
684             case Configuration.show_relation_confidence:
685                 _seq_relation_confidence_switch = new JCheckBox( title );
686                 addJCheckBox( _seq_relation_confidence_switch, ch_panel );
687                 add( ch_panel );
688                 break;
689             case Configuration.show_vector_data:
690                 _show_vector_data_cb = new JCheckBox( title );
691                 addJCheckBox( _show_vector_data_cb, ch_panel );
692                 add( ch_panel );
693                 break;
694             case Configuration.show_properties:
695                 _show_properties_cb = new JCheckBox( title );
696                 addJCheckBox( _show_properties_cb, ch_panel );
697                 add( ch_panel );
698                 break;
699             default:
700                 throw new RuntimeException( "unknown checkbox: " + which );
701         }
702     }// addCheckbox
703
704     void addJButton( final JButton jb, final JPanel p ) {
705         jb.setFocusPainted( false );
706         jb.setFont( ControlPanel.jcb_font );
707         if ( !_configuration.isUseNativeUI() ) {
708             jb.setBorder( BorderFactory.createLineBorder( getConfiguration().getGuiButtonBorderColor() ) );
709             jb.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
710             jb.setForeground( getConfiguration().getGuiButtonTextColor() );
711         }
712         p.add( jb );
713         jb.addActionListener( this );
714     }
715
716     void addJCheckBox( final JCheckBox jcb, final JPanel p ) {
717         jcb.setFocusPainted( false );
718         jcb.setFont( ControlPanel.jcb_font );
719         if ( !_configuration.isUseNativeUI() ) {
720             jcb.setBackground( getConfiguration().getGuiBackgroundColor() );
721             jcb.setForeground( getConfiguration().getGuiCheckboxTextColor() );
722         }
723         p.add( jcb, "Center" );
724         jcb.addActionListener( this );
725     }
726
727     void addJTextField( final JTextField tf, final JPanel p ) {
728         if ( !_configuration.isUseNativeUI() ) {
729             tf.setForeground( getConfiguration().getGuiBackgroundColor() );
730             tf.setFont( ControlPanel.jcb_font );
731         }
732         p.add( tf );
733         tf.addActionListener( this );
734     }
735
736     void deactivateButtonToReturnToSuperTree() {
737         _return_to_super_tree.setText( RETURN_TO_SUPER_TREE_TEXT );
738         _return_to_super_tree.setForeground( getConfiguration().getGuiButtonTextColor() );
739         _return_to_super_tree.setEnabled( false );
740     }
741
742     void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) {
743         if ( ( _mainpanel != null )
744                 && ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
745             if ( getOptions().isShowOverview() ) {
746                 _mainpanel.getCurrentTreePanel().updateOvSizes();
747             }
748             _mainpanel.getCurrentTreePanel().recalculateMaxDistanceToRoot();
749             setVisibilityOfDomainStrucureControls();
750             updateDomainStructureEvaluethresholdDisplay();
751             _mainpanel.getCurrentTreePanel().calculateScaleDistance();
752             _mainpanel.getCurrentTreePanel().calcMaxDepth();
753             _mainpanel.adjustJScrollPane();
754             if ( recalc_longest_ext_node_info ) {
755                 _mainpanel.getCurrentTreePanel().initNodeData();
756                 _mainpanel.getCurrentTreePanel().calculateLongestExtNodeInfo();
757             }
758             _mainpanel.getCurrentTreePanel().repaint();
759             // _mainpanel.getCurrentTreePanel().setUpUrtFactors();
760         }
761     }
762
763     void endClickToOptions() {
764         _click_to_combobox.addActionListener( this );
765     }
766
767     /**
768      * Indicates what action should be execute when a node is clicked
769      *
770      * @return the click-on action
771      */
772     NodeClickAction getActionWhenNodeClicked() {
773         return _action_when_node_clicked;
774     }
775
776     Map<Integer, String> getAllClickToItems() {
777         return _all_click_to_names;
778     }
779
780     Map<String, Color> getAnnotationColors() {
781         return _annotation_colors;
782     }
783
784     Configuration getConfiguration() {
785         return _configuration;
786     }
787
788     TreePanel getCurrentTreePanel() {
789         return getMainPanel().getCurrentTreePanel();
790     }
791
792     MainPanel getMainPanel() {
793         return _mainpanel;
794     }
795
796     Options getOptions() {
797         return getMainPanel().getOptions();
798     }
799
800     JLabel getSearchFoundCountsLabel0() {
801         return _search_found_label_0;
802     }
803
804     JLabel getSearchFoundCountsLabel1() {
805         return _search_found_label_1;
806     }
807
808     JButton getSearchResetButton0() {
809         return _search_reset_button_0;
810     }
811
812     JButton getSearchResetButton1() {
813         return _search_reset_button_1;
814     }
815
816     JTextField getSearchTextField0() {
817         return _search_tf_0;
818     }
819
820     JTextField getSearchTextField1() {
821         return _search_tf_1;
822     }
823
824     List<String> getSingleClickToNames() {
825         return _click_to_names;
826     }
827
828     Map<String, Color> getSpeciesColors() {
829         return _species_colors;
830     }
831
832     Map<String, Color> getSequenceColors() {
833         return _sequence_colors;
834     }
835
836     boolean isAntialiasScreenText() {
837         return true;
838     }
839
840     boolean isColorAccordingToAnnotation() {
841         return ( ( _color_according_to_annotation != null ) && _color_according_to_annotation.isSelected() );
842     }
843
844     boolean isColorAccordingToTaxonomy() {
845         return ( ( _color_acc_species != null ) && _color_acc_species.isSelected() );
846     }
847
848     boolean isColorAccordingToSequence() {
849         return ( ( _color_acc_sequence != null ) && _color_acc_sequence.isSelected() );
850     }
851
852     boolean isUseVisualStyles() {
853         return ( ( ( getUseVisualStylesCb() != null ) && getUseVisualStylesCb().isSelected() ) || ( ( getUseVisualStylesCb() == null ) && _color_branches ) );
854     }
855
856     boolean isDrawPhylogram() {
857         return isDrawPhylogram( getMainPanel().getCurrentTabIndex() );
858     }
859
860     boolean isDynamicallyHideData() {
861         return ( ( getDynamicallyHideData() != null ) && getDynamicallyHideData().isSelected() );
862     }
863
864     boolean isEvents() {
865         return ( ( getShowEventsCb() != null ) && getShowEventsCb().isSelected() );
866     }
867
868     boolean isNodeDescPopup() {
869         return ( ( getNodeDescPopupCb() != null ) && getNodeDescPopupCb().isSelected() );
870     }
871
872     boolean isShowAnnotation() {
873         return ( ( _show_annotation != null ) && _show_annotation.isSelected() );
874     }
875
876     boolean isShowBinaryCharacterCounts() {
877         return ( ( _show_binary_character_counts != null ) && _show_binary_character_counts.isSelected() );
878     }
879
880     boolean isShowBinaryCharacters() {
881         return ( ( _show_binary_characters != null ) && _show_binary_characters.isSelected() );
882     }
883
884     boolean isShowConfidenceValues() {
885         return ( ( getWriteConfidenceCb() != null ) && getWriteConfidenceCb().isSelected() );
886     }
887
888     boolean isWriteBranchLengthValues() {
889         return ( ( _write_branch_length_values != null ) && _write_branch_length_values.isSelected() );
890     }
891
892     boolean isShowDomainArchitectures() {
893         return ( ( _show_domain_architectures != null ) && _show_domain_architectures.isSelected() );
894     }
895
896     public boolean isShowMolSequences() {
897         return ( ( _show_mol_seqs != null ) && _show_mol_seqs.isSelected() );
898     }
899
900     boolean isShowGeneNames() {
901         return ( ( _show_gene_names != null ) && _show_gene_names.isSelected() );
902     }
903
904     boolean isShowInternalData() {
905         return ( ( _display_internal_data == null ) || _display_internal_data.isSelected() );
906     }
907
908     boolean isShowNodeNames() {
909         return ( ( _show_node_names != null ) && _show_node_names.isSelected() );
910     }
911
912     boolean isShowSeqNames() {
913         return ( ( _show_seq_names != null ) && _show_seq_names.isSelected() );
914     }
915
916     boolean isShowSeqSymbols() {
917         return ( ( _show_seq_symbols != null ) && _show_seq_symbols.isSelected() );
918     }
919
920     boolean isShowSequenceAcc() {
921         return ( ( _show_sequence_acc != null ) && _show_sequence_acc.isSelected() );
922     }
923
924     boolean isShowSequenceRelationConfidence() {
925         return ( ( _seq_relation_confidence_switch != null ) && ( _seq_relation_confidence_switch.isSelected() ) );
926     }
927
928     boolean isShowSequenceRelations() {
929         return ( ( _show_sequence_relations != null ) && ( _show_sequence_relations.getSelectedIndex() > 0 ) );
930     }
931
932     boolean isShowTaxonomyCode() {
933         return ( ( _show_taxo_code != null ) && _show_taxo_code.isSelected() );
934     }
935
936     boolean isShowTaxonomyCommonNames() {
937         return ( ( _show_taxo_common_names != null ) && _show_taxo_common_names.isSelected() );
938     }
939
940     boolean isShowTaxonomyScientificNames() {
941         return ( ( _show_taxo_scientific_names != null ) && _show_taxo_scientific_names.isSelected() );
942     }
943
944     boolean isWidthBranches() {
945         return ( ( _width_branches != null ) && _width_branches.isSelected() );
946     }
947
948     void phylogenyAdded( final Configuration configuration ) {
949         getIsDrawPhylogramList().add( configuration.isDrawAsPhylogram() );
950     }
951
952     void phylogenyRemoved( final int index ) {
953         getIsDrawPhylogramList().remove( index );
954     }
955
956     void search0() {
957         final MainPanel main_panel = getMainPanel();
958         final Phylogeny tree = main_panel.getCurrentPhylogeny();
959         if ( ( tree == null ) || tree.isEmpty() ) {
960             return;
961         }
962         String query = getSearchTextField0().getText();
963         if ( query != null ) {
964             query = query.trim();
965         }
966         if ( !ForesterUtil.isEmpty( query ) ) {
967             search0( main_panel, tree, query );
968         }
969         else {
970             getSearchFoundCountsLabel0().setVisible( false );
971             getSearchResetButton0().setEnabled( false );
972             getSearchResetButton0().setVisible( false );
973             searchReset0();
974         }
975     }
976
977     void search1() {
978         final MainPanel main_panel = getMainPanel();
979         final Phylogeny tree = main_panel.getCurrentPhylogeny();
980         if ( ( tree == null ) || tree.isEmpty() ) {
981             return;
982         }
983         String query = getSearchTextField1().getText();
984         if ( query != null ) {
985             query = query.trim();
986         }
987         if ( !ForesterUtil.isEmpty( query ) ) {
988             search1( main_panel, tree, query );
989         }
990         else {
991             getSearchFoundCountsLabel1().setVisible( false );
992             getSearchResetButton1().setEnabled( false );
993             getSearchResetButton1().setVisible( false );
994             searchReset1();
995         }
996     }
997
998     void searchReset0() {
999         if ( getMainPanel().getCurrentTreePanel() != null ) {
1000             getMainPanel().getCurrentTreePanel().setFoundNodes0( null );
1001         }
1002     }
1003
1004     void searchReset1() {
1005         if ( getMainPanel().getCurrentTreePanel() != null ) {
1006             getMainPanel().getCurrentTreePanel().setFoundNodes1( null );
1007         }
1008     }
1009
1010     void setActionWhenNodeClicked( final NodeClickAction action ) {
1011         _action_when_node_clicked = action;
1012     }
1013
1014     void setAnnotationColors( final Map<String, Color> annotation_colors ) {
1015         _annotation_colors = annotation_colors;
1016     }
1017
1018     void setCheckbox( final int which, final boolean state ) {
1019         switch ( which ) {
1020             case Configuration.display_as_phylogram:
1021                 if ( getDisplayAsPhylogramCb() != null ) {
1022                     getDisplayAsPhylogramCb().setSelected( state );
1023                 }
1024                 break;
1025             case Configuration.display_internal_data:
1026                 if ( _display_internal_data != null ) {
1027                     _display_internal_data.setSelected( state );
1028                 }
1029                 break;
1030             case Configuration.color_according_to_species:
1031                 if ( _color_acc_species != null ) {
1032                     _color_acc_species.setSelected( state );
1033                 }
1034                 break;
1035             case Configuration.color_according_to_sequence:
1036                 if ( _color_acc_sequence != null ) {
1037                     _color_acc_sequence.setSelected( state );
1038                 }
1039                 break;
1040             case Configuration.color_according_to_annotation:
1041                 if ( _color_according_to_annotation != null ) {
1042                     _color_according_to_annotation.setSelected( state );
1043                 }
1044                 break;
1045             case Configuration.show_node_names:
1046                 if ( _show_node_names != null ) {
1047                     _show_node_names.setSelected( state );
1048                 }
1049                 break;
1050             case Configuration.show_taxonomy_scientific_names:
1051                 if ( _show_taxo_scientific_names != null ) {
1052                     _show_taxo_scientific_names.setSelected( state );
1053                 }
1054                 break;
1055             case Configuration.show_taxonomy_common_names:
1056                 if ( _show_taxo_common_names != null ) {
1057                     _show_taxo_common_names.setSelected( state );
1058                 }
1059                 break;
1060             case Configuration.show_tax_code:
1061                 if ( _show_taxo_code != null ) {
1062                     _show_taxo_code.setSelected( state );
1063                 }
1064                 break;
1065             case Configuration.show_taxonomy_images:
1066                 if ( _show_taxo_images_cb != null ) {
1067                     _show_taxo_images_cb.setSelected( state );
1068                 }
1069                 break;
1070             case Configuration.show_annotation:
1071                 if ( _show_annotation != null ) {
1072                     _show_annotation.setSelected( state );
1073                 }
1074                 break;
1075             case Configuration.show_binary_characters:
1076                 if ( _show_binary_characters != null ) {
1077                     _show_binary_characters.setSelected( state );
1078                 }
1079                 break;
1080             case Configuration.show_binary_character_counts:
1081                 if ( _show_binary_character_counts != null ) {
1082                     _show_binary_character_counts.setSelected( state );
1083                 }
1084                 break;
1085             case Configuration.write_confidence_values:
1086                 if ( getWriteConfidenceCb() != null ) {
1087                     getWriteConfidenceCb().setSelected( state );
1088                 }
1089                 break;
1090             case Configuration.write_events:
1091                 if ( getShowEventsCb() != null ) {
1092                     getShowEventsCb().setSelected( state );
1093                 }
1094                 break;
1095             case Configuration.use_style:
1096                 if ( getUseVisualStylesCb() != null ) {
1097                     getUseVisualStylesCb().setSelected( state );
1098                 }
1099                 break;
1100             case Configuration.width_branches:
1101                 if ( _width_branches != null ) {
1102                     _width_branches.setSelected( state );
1103                 }
1104                 break;
1105             case Configuration.show_domain_architectures:
1106                 if ( _show_domain_architectures != null ) {
1107                     _show_domain_architectures.setSelected( state );
1108                 }
1109                 break;
1110             case Configuration.write_branch_length_values:
1111                 if ( _write_branch_length_values != null ) {
1112                     _write_branch_length_values.setSelected( state );
1113                 }
1114                 break;
1115             case Configuration.show_mol_seqs:
1116                 if ( _show_mol_seqs != null ) {
1117                     _show_mol_seqs.setSelected( state );
1118                 }
1119                 break;
1120             case Configuration.show_seq_names:
1121                 if ( _show_seq_names != null ) {
1122                     _show_seq_names.setSelected( state );
1123                 }
1124                 break;
1125             case Configuration.show_gene_names:
1126                 if ( _show_gene_names != null ) {
1127                     _show_gene_names.setSelected( state );
1128                 }
1129                 break;
1130             case Configuration.show_seq_symbols:
1131                 if ( _show_seq_symbols != null ) {
1132                     _show_seq_symbols.setSelected( state );
1133                 }
1134                 break;
1135             case Configuration.show_vector_data:
1136                 if ( _show_vector_data_cb != null ) {
1137                     _show_vector_data_cb.setSelected( state );
1138                 }
1139                 break;
1140             case Configuration.show_properties:
1141                 if ( _show_properties_cb != null ) {
1142                     _show_properties_cb.setSelected( state );
1143                 }
1144                 break;
1145             case Configuration.show_sequence_acc:
1146                 if ( _show_sequence_acc != null ) {
1147                     _show_sequence_acc.setSelected( state );
1148                 }
1149                 break;
1150             case Configuration.dynamically_hide_data:
1151                 if ( getDynamicallyHideData() != null ) {
1152                     getDynamicallyHideData().setSelected( state );
1153                 }
1154                 break;
1155             case Configuration.node_data_popup:
1156                 if ( getNodeDescPopupCb() != null ) {
1157                     getNodeDescPopupCb().setSelected( state );
1158                 }
1159                 break;
1160             /* GUILHEM_BEG */
1161             case Configuration.show_relation_confidence:
1162                 if ( _seq_relation_confidence_switch != null ) {
1163                     _seq_relation_confidence_switch.setSelected( state );
1164                 }
1165                 break;
1166             /* GUILHEM_END */
1167             default:
1168                 throw new AssertionError( "unknown checkbox: " + which );
1169         }
1170     }
1171
1172     /**
1173      * Set this checkbox state. Not all checkboxes have been instantiated
1174      * depending on the config.
1175      */
1176     void setCheckbox( final JCheckBox cb, final boolean state ) {
1177         if ( cb != null ) {
1178             cb.setSelected( state );
1179         }
1180     }
1181
1182     void setClickToAction( final int action ) {
1183         // Set click-to action
1184         if ( action == _show_data_item ) {
1185             setActionWhenNodeClicked( NodeClickAction.SHOW_DATA );
1186         }
1187         else if ( action == _collapse_cb_item ) {
1188             setActionWhenNodeClicked( NodeClickAction.COLLAPSE );
1189         }
1190         else if ( action == _reroot_cb_item ) {
1191             setActionWhenNodeClicked( NodeClickAction.REROOT );
1192         }
1193         else if ( action == _subtree_cb_item ) {
1194             setActionWhenNodeClicked( NodeClickAction.SUBTREE );
1195         }
1196         else if ( action == _swap_cb_item ) {
1197             setActionWhenNodeClicked( NodeClickAction.SWAP );
1198         }
1199         else if ( action == _color_subtree_cb_item ) {
1200             setActionWhenNodeClicked( NodeClickAction.COLOR_SUBTREE );
1201         }
1202         else if ( action == _open_seq_web_item ) {
1203             setActionWhenNodeClicked( NodeClickAction.OPEN_SEQ_WEB );
1204         }
1205         else if ( action == _sort_descendents_item ) {
1206             setActionWhenNodeClicked( NodeClickAction.SORT_DESCENDENTS );
1207         }
1208         else if ( action == _blast_item ) {
1209             setActionWhenNodeClicked( NodeClickAction.BLAST );
1210         }
1211         else if ( action == _open_tax_web_item ) {
1212             setActionWhenNodeClicked( NodeClickAction.OPEN_TAX_WEB );
1213         }
1214         else if ( action == _cut_subtree_item ) {
1215             setActionWhenNodeClicked( NodeClickAction.CUT_SUBTREE );
1216         }
1217         else if ( action == _copy_subtree_item ) {
1218             setActionWhenNodeClicked( NodeClickAction.COPY_SUBTREE );
1219         }
1220         else if ( action == _delete_node_or_subtree_item ) {
1221             setActionWhenNodeClicked( NodeClickAction.DELETE_NODE_OR_SUBTREE );
1222         }
1223         else if ( action == _paste_subtree_item ) {
1224             setActionWhenNodeClicked( NodeClickAction.PASTE_SUBTREE );
1225         }
1226         else if ( action == _add_new_node_item ) {
1227             setActionWhenNodeClicked( NodeClickAction.ADD_NEW_NODE );
1228         }
1229         else if ( action == _edit_node_data_item ) {
1230             setActionWhenNodeClicked( NodeClickAction.EDIT_NODE_DATA );
1231         }
1232         else if ( action == _select_nodes_item ) {
1233             setActionWhenNodeClicked( NodeClickAction.SELECT_NODES );
1234         }
1235         else if ( action == _get_ext_desc_data ) {
1236             setActionWhenNodeClicked( NodeClickAction.GET_EXT_DESC_DATA );
1237         }
1238         else if ( action == _open_pdb_item ) {
1239             setActionWhenNodeClicked( NodeClickAction.OPEN_PDB_WEB );
1240         }
1241         else if ( action == _color_node_font_item ) {
1242             setActionWhenNodeClicked( NodeClickAction.COLOR_NODE_FONT );
1243         }
1244         else if ( action == _change_node_font_item ) {
1245             setActionWhenNodeClicked( NodeClickAction.CHANGE_NODE_FONT );
1246         }
1247         else {
1248             throw new RuntimeException( "unknown action: " + action );
1249         }
1250         // make sure drop down is displaying the correct action
1251         // in case this was called from outside the class
1252         _click_to_combobox.setSelectedIndex( action );
1253     }
1254
1255     void setColorBranches( final boolean color_branches ) {
1256         _color_branches = color_branches;
1257     }
1258
1259     void setDrawPhylogram( final boolean b ) {
1260         getDisplayAsPhylogramCb().setSelected( b );
1261         setDrawPhylogram( getMainPanel().getCurrentTabIndex(), b );
1262     }
1263
1264     void setDrawPhylogramEnabled( final boolean b ) {
1265         getDisplayAsPhylogramCb().setEnabled( b );
1266     }
1267
1268     void setDynamicHidingIsOn( final boolean is_on ) {
1269         if ( is_on ) {
1270             getDynamicallyHideData().setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
1271         }
1272         else {
1273             if ( !_configuration.isUseNativeUI() ) {
1274                 getDynamicallyHideData().setForeground( getConfiguration().getGuiButtonTextColor() );
1275             }
1276             else {
1277                 getDynamicallyHideData().setForeground( Color.BLACK );
1278             }
1279         }
1280     }
1281
1282     void setSearchFoundCountsOnLabel0( final int counts ) {
1283         getSearchFoundCountsLabel0().setText( "Found: " + counts );
1284     }
1285
1286     void setSearchFoundCountsOnLabel1( final int counts ) {
1287         getSearchFoundCountsLabel1().setText( "Found: " + counts );
1288     }
1289
1290     void setShowEvents( final boolean show_events ) {
1291         if ( getShowEventsCb() == null ) {
1292             _show_events = new JCheckBox( "" );
1293         }
1294         getShowEventsCb().setSelected( show_events );
1295     }
1296
1297     void setSpeciesColors( final Map<String, Color> species_colors ) {
1298         _species_colors = species_colors;
1299     }
1300
1301     void setSequenceColors( final Map<String, Color> sequence_colors ) {
1302         _sequence_colors = sequence_colors;
1303     }
1304
1305     /* GUILHEM_END */
1306     /*
1307      * Set up the controls from the config settings. 11/26/05
1308      */
1309     void setupControls() {
1310         // The tree display options:
1311         setupDisplayCheckboxes();
1312         /* GUILHEM_BEG */
1313         // The sequence relation query selection combo-box
1314         if ( _configuration.displaySequenceRelations() ) {
1315             addSequenceRelationBlock();
1316         }
1317         /* GUILHEM_END */
1318         // Click-to options
1319         startClickToOptions();
1320         setupClickToOptions();
1321         endClickToOptions();
1322         // Zoom and quick edit buttons
1323         addButtons();
1324         setupSearchTools0();
1325         setupSearchTools1();
1326     }
1327
1328     void setUpControlsForDomainStrucures() {
1329         _domain_display_label = new JLabel( "Domain Architectures:" );
1330         add( customizeLabel( _domain_display_label, getConfiguration() ) );
1331         add( _domain_display_label );
1332         _zoom_in_domain_structure = new JButton( "d+" );
1333         _zoom_out_domain_structure = new JButton( "d-" );
1334         _decr_domain_structure_evalue_thr = new JButton( "-" );
1335         _incr_domain_structure_evalue_thr = new JButton( "+" );
1336         _zoom_in_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1337         _zoom_out_domain_structure.setPreferredSize( new Dimension( 10, 10 ) );
1338         _decr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1339         _incr_domain_structure_evalue_thr.setPreferredSize( new Dimension( 10, 10 ) );
1340         _incr_domain_structure_evalue_thr.setToolTipText( "Increase the E-value threshold by a factor of 10" );
1341         _decr_domain_structure_evalue_thr.setToolTipText( "Decrease the E-value threshold by a factor of 10" );
1342         _domain_structure_evalue_thr_tf = new JTextField( 3 );
1343         _domain_structure_evalue_thr_tf.setEditable( false );
1344         if ( !getConfiguration().isUseNativeUI() ) {
1345             _domain_structure_evalue_thr_tf.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1346             _domain_structure_evalue_thr_tf.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1347             _domain_structure_evalue_thr_tf.setBorder( null );
1348         }
1349         final JPanel d1_panel = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1350         final JPanel d2_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
1351         if ( !_configuration.isUseNativeUI() ) {
1352             d1_panel.setBackground( getBackground() );
1353             d2_panel.setBackground( getBackground() );
1354         }
1355         add( d1_panel );
1356         add( d2_panel );
1357         addJButton( _zoom_out_domain_structure, d1_panel );
1358         addJButton( _zoom_in_domain_structure, d1_panel );
1359         addJButton( _decr_domain_structure_evalue_thr, d2_panel );
1360         addJTextField( _domain_structure_evalue_thr_tf, d2_panel );
1361         addJButton( _incr_domain_structure_evalue_thr, d2_panel );
1362     }
1363
1364     void setupSearchTools0() {
1365         final JLabel search_label = new JLabel( "Search (A):" );
1366         search_label.setFont( ControlPanel.jcb_bold_font );
1367         if ( !getConfiguration().isUseNativeUI() ) {
1368             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1369         }
1370         add( search_label );
1371         search_label.setToolTipText( SEARCH_TIP_TEXT );
1372         _search_found_label_0 = new JLabel();
1373         getSearchFoundCountsLabel0().setVisible( false );
1374         _search_found_label_0.setFont( ControlPanel.jcb_bold_font );
1375         if ( !getConfiguration().isUseNativeUI() ) {
1376             _search_found_label_0.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1377         }
1378         _search_tf_0 = new JTextField( 3 );
1379         _search_tf_0.setToolTipText( SEARCH_TIP_TEXT );
1380         _search_tf_0.setEditable( true );
1381         if ( !getConfiguration().isUseNativeUI() ) {
1382             _search_tf_0.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1383             _search_tf_0.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1384             _search_tf_0.setBorder( null );
1385         }
1386         _search_reset_button_0 = new JButton();
1387         getSearchResetButton0().setText( "Reset" );
1388         getSearchResetButton0().setEnabled( false );
1389         getSearchResetButton0().setVisible( false );
1390         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
1391         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1392         s_panel_1.setBackground( getBackground() );
1393         add( s_panel_1 );
1394         s_panel_2.setBackground( getBackground() );
1395         add( s_panel_2 );
1396         final KeyAdapter key_adapter = new KeyAdapter() {
1397
1398             @Override
1399             public void keyReleased( final KeyEvent key_event ) {
1400                 search0();
1401                 displayedPhylogenyMightHaveChanged( true );
1402             }
1403         };
1404         final ActionListener action_listener = new ActionListener() {
1405
1406             @Override
1407             public void actionPerformed( final ActionEvent e ) {
1408                 searchReset0();
1409                 setSearchFoundCountsOnLabel0( 0 );
1410                 getSearchFoundCountsLabel0().setVisible( false );
1411                 getSearchTextField0().setText( "" );
1412                 getSearchResetButton0().setEnabled( false );
1413                 getSearchResetButton0().setVisible( false );
1414                 displayedPhylogenyMightHaveChanged( true );
1415             }
1416         };
1417         _search_reset_button_0.addActionListener( action_listener );
1418         _search_tf_0.addKeyListener( key_adapter );
1419         addJTextField( _search_tf_0, s_panel_1 );
1420         s_panel_2.add( _search_found_label_0 );
1421         addJButton( _search_reset_button_0, s_panel_2 );
1422     }
1423
1424     void setupSearchTools1() {
1425         final JLabel search_label = new JLabel( "Search (B):" );
1426         search_label.setFont( ControlPanel.jcb_bold_font );
1427         if ( !getConfiguration().isUseNativeUI() ) {
1428             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1429         }
1430         add( search_label );
1431         search_label.setToolTipText( SEARCH_TIP_TEXT );
1432         _search_found_label_1 = new JLabel();
1433         getSearchFoundCountsLabel1().setVisible( false );
1434         _search_found_label_1.setFont( ControlPanel.jcb_bold_font );
1435         if ( !getConfiguration().isUseNativeUI() ) {
1436             _search_found_label_1.setForeground( getConfiguration().getGuiCheckboxTextColor() );
1437         }
1438         _search_tf_1 = new JTextField( 3 );
1439         _search_tf_1.setToolTipText( SEARCH_TIP_TEXT );
1440         _search_tf_1.setEditable( true );
1441         if ( !getConfiguration().isUseNativeUI() ) {
1442             _search_tf_1.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
1443             _search_tf_1.setBackground( getConfiguration().getGuiCheckboxTextColor() );
1444             _search_tf_1.setBorder( null );
1445         }
1446         _search_reset_button_1 = new JButton();
1447         getSearchResetButton1().setText( "Reset" );
1448         getSearchResetButton1().setEnabled( false );
1449         getSearchResetButton1().setVisible( false );
1450         final JPanel s_panel_1 = new JPanel( new BorderLayout() );
1451         final JPanel s_panel_2 = new JPanel( new GridLayout( 1, 2, 0, 0 ) );
1452         s_panel_1.setBackground( getBackground() );
1453         add( s_panel_1 );
1454         s_panel_2.setBackground( getBackground() );
1455         add( s_panel_2 );
1456         final KeyAdapter key_adapter = new KeyAdapter() {
1457
1458             @Override
1459             public void keyReleased( final KeyEvent key_event ) {
1460                 search1();
1461                 displayedPhylogenyMightHaveChanged( true );
1462             }
1463         };
1464         final ActionListener action_listener = new ActionListener() {
1465
1466             @Override
1467             public void actionPerformed( final ActionEvent e ) {
1468                 searchReset1();
1469                 setSearchFoundCountsOnLabel1( 0 );
1470                 getSearchFoundCountsLabel1().setVisible( false );
1471                 getSearchTextField1().setText( "" );
1472                 getSearchResetButton1().setEnabled( false );
1473                 getSearchResetButton1().setVisible( false );
1474                 displayedPhylogenyMightHaveChanged( true );
1475             }
1476         };
1477         _search_reset_button_1.addActionListener( action_listener );
1478         _search_tf_1.addKeyListener( key_adapter );
1479         addJTextField( _search_tf_1, s_panel_1 );
1480         s_panel_2.add( _search_found_label_1 );
1481         addJButton( _search_reset_button_1, s_panel_2 );
1482     }
1483
1484     void showAnnotations() {
1485         if ( _show_annotation != null ) {
1486             _show_annotation.setSelected( true );
1487         }
1488         if ( _color_according_to_annotation != null ) {
1489             _color_according_to_annotation.setSelected( true );
1490         }
1491         if ( _color_acc_species != null ) {
1492             _color_acc_species.setSelected( false );
1493         }
1494         if ( _color_acc_sequence != null ) {
1495             _color_acc_sequence.setSelected( false );
1496         }
1497         _mainpanel.getCurrentTreePanel().repaint();
1498     }
1499
1500     /**
1501      * Fit entire tree into window.
1502      */
1503     void showWhole() {
1504         if ( ( _mainpanel.getCurrentScrollPane() == null ) || _mainpanel.getCurrentTreePanel().getPhylogeny().isEmpty() ) {
1505             return;
1506         }
1507         getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
1508         displayedPhylogenyMightHaveChanged( true );
1509         _mainpanel.getCurrentTreePanel().updateOvSettings();
1510         _mainpanel.getCurrentTreePanel().validate();
1511         _mainpanel.validate();
1512         _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
1513                                                                     _mainpanel.getSizeOfViewport().height );
1514         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1515         _mainpanel.adjustJScrollPane();
1516         _mainpanel.getCurrentTreePanel().repaint();
1517         _mainpanel.getCurrentTreePanel().validate();
1518         _mainpanel.validate();
1519         _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
1520                                                                     _mainpanel.getSizeOfViewport().height );
1521         _mainpanel.getCurrentTreePanel().resetPreferredSize();
1522         _mainpanel.adjustJScrollPane();
1523         _mainpanel.getCurrentTreePanel().repaint();
1524         _mainpanel.getCurrentTreePanel().updateOvSizes();
1525     }
1526
1527     void showWholeAll() {
1528         for( final TreePanel tree_panel : _mainpanel.getTreePanels() ) {
1529             if ( tree_panel != null ) {
1530                 tree_panel.validate();
1531                 tree_panel.calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
1532                                                       _mainpanel.getSizeOfViewport().height );
1533                 tree_panel.resetPreferredSize();
1534                 tree_panel.repaint();
1535             }
1536         }
1537     }
1538
1539     // Create header for click-to combo box.
1540     void startClickToOptions() {
1541         final JLabel spacer = new JLabel( "" );
1542         spacer.setFont( ControlPanel.jcb_font );
1543         add( spacer );
1544         _click_to_label = new JLabel( "Click on Node to:" );
1545         add( customizeLabel( _click_to_label, getConfiguration() ) );
1546         _click_to_combobox = new JComboBox<String>();
1547         _click_to_combobox.setFocusable( false );
1548         _click_to_combobox.setMaximumRowCount( 14 );
1549         _click_to_combobox.setFont( ControlPanel.js_font );
1550         if ( !_configuration.isUseNativeUI() ) {
1551             _click_to_combobox.setBackground( getConfiguration().getGuiBackgroundColor() );
1552         }
1553         // don't add listener until all items are set (or each one will trigger
1554         // an event)
1555         // click_to_list.addActionListener(this);
1556         add( _click_to_combobox );
1557         // Correlates option names to titles
1558         _all_click_to_names = new HashMap<Integer, String>();
1559         _click_to_names = new ArrayList<String>();
1560     }
1561
1562     void tabChanged() {
1563         if ( getMainPanel().getTabbedPane().getTabCount() > 0 ) {
1564             if ( getCurrentTreePanel().isPhyHasBranchLengths()
1565                     && ( getCurrentTreePanel().getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
1566                 setDrawPhylogramEnabled( true );
1567                 setDrawPhylogram( isDrawPhylogram() );
1568             }
1569             else {
1570                 setDrawPhylogramEnabled( false );
1571                 setDrawPhylogram( false );
1572             }
1573             if ( getMainPanel().getMainFrame() == null ) {
1574                 // Must be "E" applet version.
1575                 final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
1576                 e.setSelectedTypeInTypeMenu( e.getCurrentTreePanel().getPhylogenyGraphicsType() );
1577             }
1578             else {
1579                 getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel()
1580                         .getPhylogenyGraphicsType() );
1581             }
1582             getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton();
1583             getMainPanel().getControlPanel().search0();
1584             getMainPanel().getControlPanel().search1();
1585             getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
1586             getSequenceRelationTypeBox().removeAllItems();
1587             for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
1588                     .getRelevantSequenceRelationTypes() ) {
1589                 _sequence_relation_type_box.addItem( type );
1590             }
1591             getMainPanel().getCurrentTreePanel().repaint();
1592             //setSequenceRelationQueries( getMainPanel().getCurrentPhylogeny().getSequenceRelationQueries() );
1593             // according to GUILHEM the line above can be removed.
1594         }
1595     }
1596
1597     /**
1598      * Uncollapse all nodes.
1599      */
1600     void uncollapseAll( final TreePanel tp ) {
1601         final Phylogeny t = tp.getPhylogeny();
1602         if ( ( t != null ) && !t.isEmpty() ) {
1603             for( final PhylogenyNodeIterator iter = t.iteratorPreorder(); iter.hasNext(); ) {
1604                 final PhylogenyNode node = iter.next();
1605                 node.setCollapse( false );
1606             }
1607             tp.resetNodeIdToDistToLeafMap();
1608             tp.updateSetOfCollapsedExternalNodes();
1609             t.recalculateNumberOfExternalDescendants( false );
1610             tp.setNodeInPreorderToNull();
1611             t.clearHashIdToNodeMap();
1612             showWhole();
1613         }
1614     }
1615
1616     void updateDomainStructureEvaluethresholdDisplay() {
1617         if ( _domain_structure_evalue_thr_tf != null ) {
1618             _domain_structure_evalue_thr_tf.setText( "10^"
1619                     + getMainPanel().getCurrentTreePanel().getDomainStructureEvalueThresholdExp() );
1620         }
1621     }
1622
1623     void zoomInX( final float factor, final float x_correction_factor ) {
1624         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1625         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1626         treepanel.multiplyUrtFactor( 1f );
1627         if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1628                 || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1629                 || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1630                 || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1631             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1632             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1633             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1634             getMainPanel().adjustJScrollPane();
1635             treepanel.resetPreferredSize();
1636             getMainPanel().getCurrentScrollPane().getViewport().validate();
1637             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1638                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1639         }
1640         else {
1641             final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1642             treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1643             treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1644             getMainPanel().adjustJScrollPane();
1645             treepanel.resetPreferredSize();
1646             getMainPanel().getCurrentScrollPane().getViewport().validate();
1647             sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1648         }
1649         treepanel.resetPreferredSize();
1650         treepanel.updateOvSizes();
1651     }
1652
1653     void zoomInY( final float factor ) {
1654         final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1655         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1656         treepanel.multiplyUrtFactor( 1.1f );
1657         final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1658         treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1659         getMainPanel().adjustJScrollPane();
1660         treepanel.resetPreferredSize();
1661         getMainPanel().getCurrentScrollPane().getViewport().validate();
1662         sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1663                 - ( sb.getVisibleAmount() / 2.0 ) ) );
1664         treepanel.resetPreferredSize();
1665         treepanel.updateOvSizes();
1666     }
1667
1668     void zoomOutX( final float factor, final float x_correction_factor ) {
1669         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1670         treepanel.multiplyUrtFactor( 1f );
1671         if ( ( treepanel.getXdistance() * factor ) > 0.0 ) {
1672             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar();
1673             if ( ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
1674                     || ( treepanel.getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
1675                     || isDrawPhylogram( getMainPanel().getCurrentTabIndex() )
1676                     || ( getOptions().getCladogramType() == CLADOGRAM_TYPE.NON_LINED_UP ) ) {
1677                 getMainPanel().adjustJScrollPane();
1678                 treepanel.resetPreferredSize();
1679                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1680                 final double x = ( sb.getMaximum() - sb.getMinimum() )
1681                         / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1682                 treepanel.setXdistance( ( treepanel.getXdistance() * factor ) );
1683                 treepanel.setXcorrectionFactor( ( treepanel.getXcorrectionFactor() * x_correction_factor ) );
1684                 getMainPanel().adjustJScrollPane();
1685                 treepanel.resetPreferredSize();
1686                 getMainPanel().getCurrentScrollPane().getViewport().validate();
1687                 sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1688                         - ( sb.getVisibleAmount() / 2.0 ) ) );
1689             }
1690             else {
1691                 final int x = sb.getMaximum() - sb.getMinimum() - sb.getVisibleAmount() - sb.getValue();
1692                 treepanel.setXdistance( treepanel.getXdistance() * factor );
1693                 treepanel.setXcorrectionFactor( treepanel.getXcorrectionFactor() * x_correction_factor );
1694                 if ( x > 0 ) {
1695                     getMainPanel().adjustJScrollPane();
1696                     treepanel.resetPreferredSize();
1697                     getMainPanel().getCurrentScrollPane().getViewport().validate();
1698                     sb.setValue( sb.getMaximum() - sb.getMinimum() - x - sb.getVisibleAmount() );
1699                 }
1700             }
1701             treepanel.resetPreferredSize();
1702             treepanel.updateOvSizes();
1703         }
1704     }
1705
1706     void zoomOutY( final float factor ) {
1707         final TreePanel treepanel = getMainPanel().getCurrentTreePanel();
1708         treepanel.multiplyUrtFactor( 0.9f );
1709         if ( ( treepanel.getYdistance() * factor ) > 0.0 ) {
1710             final JScrollBar sb = getMainPanel().getCurrentScrollPane().getVerticalScrollBar();
1711             final double x = ( sb.getMaximum() - sb.getMinimum() ) / ( sb.getValue() + ( sb.getVisibleAmount() / 2.0 ) );
1712             treepanel.setYdistance( ( treepanel.getYdistance() * factor ) );
1713             getMainPanel().adjustJScrollPane();
1714             treepanel.resetPreferredSize();
1715             getMainPanel().getCurrentScrollPane().getViewport().validate();
1716             sb.setValue( ForesterUtil.roundToInt( ( ( sb.getMaximum() - sb.getMinimum() ) / x )
1717                     - ( sb.getVisibleAmount() / 2.0 ) ) );
1718             treepanel.resetPreferredSize();
1719             treepanel.updateOvSizes();
1720         }
1721     }
1722
1723     private void addClickToOption( final int which, final String title ) {
1724         _click_to_combobox.addItem( title );
1725         _click_to_names.add( title );
1726         _all_click_to_names.put( new Integer( which ), title );
1727         if ( !_configuration.isUseNativeUI() ) {
1728             _click_to_combobox.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
1729             _click_to_combobox.setForeground( getConfiguration().getGuiButtonTextColor() );
1730         }
1731     }
1732
1733     /* GUILHEM_BEG */
1734     private void addSequenceRelationBlock() {
1735         final JLabel spacer = new JLabel( "" );
1736         spacer.setSize( 1, 1 );
1737         add( spacer );
1738         final JLabel mainLabel = new JLabel( "Sequence relations to display" );
1739         final JLabel typeLabel = customizeLabel( new JLabel( "(type) " ), getConfiguration() );
1740         typeLabel.setFont( ControlPanel.js_font.deriveFont( 7 ) );
1741         getSequenceRelationTypeBox().setFocusable( false );
1742         _sequence_relation_type_box.setFont( ControlPanel.js_font );
1743         if ( !_configuration.isUseNativeUI() ) {
1744             _sequence_relation_type_box.setBackground( getConfiguration().getGuiButtonBackgroundColor() );
1745             _sequence_relation_type_box.setForeground( getConfiguration().getGuiButtonTextColor() );
1746         }
1747         _sequence_relation_type_box.setRenderer( new ListCellRenderer<Object>() {
1748
1749             @Override
1750             public Component getListCellRendererComponent( final JList<?> list,
1751                                                            final Object value,
1752                                                            final int index,
1753                                                            final boolean isSelected,
1754                                                            final boolean cellHasFocus ) {
1755                 final Component component = new DefaultListCellRenderer().getListCellRendererComponent( list,
1756                                                                                                         value,
1757                                                                                                         index,
1758                                                                                                         isSelected,
1759                                                                                                         cellHasFocus );
1760                 if ( ( value != null ) && ( value instanceof SequenceRelation.SEQUENCE_RELATION_TYPE ) ) {
1761                     ( ( DefaultListCellRenderer ) component ).setText( SequenceRelation
1762                             .getPrintableNameByType( ( SequenceRelation.SEQUENCE_RELATION_TYPE ) value ) );
1763                 }
1764                 return component;
1765             }
1766         } );
1767         final GridBagLayout gbl = new GridBagLayout();
1768         _sequence_relation_type_box.setMinimumSize( new Dimension( 115, 17 ) );
1769         _sequence_relation_type_box.setPreferredSize( new Dimension( 115, 20 ) );
1770         final JPanel horizGrid = new JPanel( gbl );
1771         horizGrid.setBackground( getBackground() );
1772         horizGrid.add( typeLabel );
1773         horizGrid.add( _sequence_relation_type_box );
1774         add( customizeLabel( mainLabel, getConfiguration() ) );
1775         add( horizGrid );
1776         add( getSequenceRelationBox() );
1777         if ( _configuration.doDisplayOption( Configuration.show_relation_confidence ) ) {
1778             addCheckbox( Configuration.show_relation_confidence,
1779                          _configuration.getDisplayTitle( Configuration.show_relation_confidence ) );
1780             setCheckbox( Configuration.show_relation_confidence,
1781                          _configuration.doCheckOption( Configuration.show_relation_confidence ) );
1782         }
1783     }// addSequenceRelationBlock
1784
1785     /* GUILHEM_END */
1786     private List<Boolean> getIsDrawPhylogramList() {
1787         return _draw_phylogram;
1788     }
1789
1790     private void init() {
1791         _draw_phylogram = new ArrayList<Boolean>();
1792         setSpeciesColors( new HashMap<String, Color>() );
1793         setSequenceColors( new HashMap<String, Color>() );
1794         setAnnotationColors( new HashMap<String, Color>() );
1795     }
1796
1797     private boolean isDrawPhylogram( final int index ) {
1798         return getIsDrawPhylogramList().get( index );
1799     }
1800
1801     private void search0( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
1802         getSearchFoundCountsLabel0().setVisible( true );
1803         getSearchResetButton0().setEnabled( true );
1804         getSearchResetButton0().setVisible( true );
1805         String[] queries = null;
1806         List<PhylogenyNode> nodes = null;
1807         if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
1808             queries = query_str.split( ",+" );
1809         }
1810         else {
1811             queries = new String[ 1 ];
1812             queries[ 0 ] = query_str.trim();
1813         }
1814         if ( ( queries != null ) && ( queries.length > 0 ) ) {
1815             nodes = new ArrayList<PhylogenyNode>();
1816             for( String query : queries ) {
1817                 if ( ForesterUtil.isEmpty( query ) ) {
1818                     continue;
1819                 }
1820                 query = query.trim();
1821                 if ( ( query.indexOf( '+' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
1822                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
1823                                                                          tree,
1824                                                                          getOptions().isSearchCaseSensitive(),
1825                                                                          !getOptions().isMatchWholeTermsOnly(),
1826                                                                          isShowDomainArchitectures() ) );
1827                 }
1828                 else {
1829                     nodes.addAll( PhylogenyMethods.searchData( query,
1830                                                                tree,
1831                                                                getOptions().isSearchCaseSensitive(),
1832                                                                !getOptions().isMatchWholeTermsOnly(),
1833                                                                getOptions().isSearchWithRegex(),
1834                                                                isShowDomainArchitectures() ) );
1835                 }
1836             }
1837             if ( getOptions().isInverseSearchResult() ) {
1838                 final List<PhylogenyNode> all = PhylogenyMethods.obtainAllNodesAsList( tree );
1839                 all.removeAll( nodes );
1840                 nodes = all;
1841             }
1842         }
1843         if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
1844             main_panel.getCurrentTreePanel().setFoundNodes0( new HashSet<Long>() );
1845             for( final PhylogenyNode node : nodes ) {
1846                 main_panel.getCurrentTreePanel().getFoundNodes0().add( node.getId() );
1847             }
1848             setSearchFoundCountsOnLabel0( nodes.size() );
1849         }
1850         else {
1851             setSearchFoundCountsOnLabel0( 0 );
1852             searchReset0();
1853         }
1854     }
1855
1856     private void search1( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
1857         getSearchFoundCountsLabel1().setVisible( true );
1858         getSearchResetButton1().setEnabled( true );
1859         getSearchResetButton1().setVisible( true );
1860         String[] queries = null;
1861         List<PhylogenyNode> nodes = null;
1862         if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
1863             queries = query_str.split( ",+" );
1864         }
1865         else {
1866             queries = new String[ 1 ];
1867             queries[ 0 ] = query_str.trim();
1868         }
1869         if ( ( queries != null ) && ( queries.length > 0 ) ) {
1870             nodes = new ArrayList<PhylogenyNode>();
1871             for( String query : queries ) {
1872                 if ( ForesterUtil.isEmpty( query ) ) {
1873                     continue;
1874                 }
1875                 query = query.trim();
1876                 if ( ( query.indexOf( '+' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
1877                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
1878                                                                          tree,
1879                                                                          getOptions().isSearchCaseSensitive(),
1880                                                                          !getOptions().isMatchWholeTermsOnly(),
1881                                                                          isShowDomainArchitectures() ) );
1882                 }
1883                 else {
1884                     nodes.addAll( PhylogenyMethods.searchData( query,
1885                                                                tree,
1886                                                                getOptions().isSearchCaseSensitive(),
1887                                                                !getOptions().isMatchWholeTermsOnly(),
1888                                                                getOptions().isSearchWithRegex(),
1889                                                                isShowDomainArchitectures() ) );
1890                 }
1891             }
1892             if ( getOptions().isInverseSearchResult() ) {
1893                 final List<PhylogenyNode> all = PhylogenyMethods.obtainAllNodesAsList( tree );
1894                 all.removeAll( nodes );
1895                 nodes = all;
1896             }
1897         }
1898         if ( ( nodes != null ) && ( nodes.size() > 0 ) ) {
1899             main_panel.getCurrentTreePanel().setFoundNodes1( new HashSet<Long>() );
1900             for( final PhylogenyNode node : nodes ) {
1901                 main_panel.getCurrentTreePanel().getFoundNodes1().add( node.getId() );
1902             }
1903             setSearchFoundCountsOnLabel1( nodes.size() );
1904         }
1905         else {
1906             setSearchFoundCountsOnLabel1( 0 );
1907             searchReset1();
1908         }
1909     }
1910
1911     private void setDrawPhylogram( final int index, final boolean b ) {
1912         getIsDrawPhylogramList().set( index, b );
1913     }
1914
1915     private void setupClickToOptions() {
1916         final int default_option = _configuration.getDefaultDisplayClicktoOption();
1917         int selected_index = 0;
1918         int cb_index = 0;
1919         if ( _configuration.doDisplayClickToOption( Configuration.display_node_data ) ) {
1920             _show_data_item = cb_index;
1921             addClickToOption( Configuration.display_node_data,
1922                               _configuration.getClickToTitle( Configuration.display_node_data ) );
1923             if ( default_option == Configuration.display_node_data ) {
1924                 selected_index = cb_index;
1925             }
1926             cb_index++;
1927         }
1928         if ( _configuration.doDisplayClickToOption( Configuration.collapse_uncollapse ) ) {
1929             _collapse_cb_item = cb_index;
1930             addClickToOption( Configuration.collapse_uncollapse,
1931                               _configuration.getClickToTitle( Configuration.collapse_uncollapse ) );
1932             if ( default_option == Configuration.collapse_uncollapse ) {
1933                 selected_index = cb_index;
1934             }
1935             cb_index++;
1936         }
1937         if ( _configuration.doDisplayClickToOption( Configuration.reroot ) ) {
1938             _reroot_cb_item = cb_index;
1939             addClickToOption( Configuration.reroot, _configuration.getClickToTitle( Configuration.reroot ) );
1940             if ( default_option == Configuration.reroot ) {
1941                 selected_index = cb_index;
1942             }
1943             cb_index++;
1944         }
1945         if ( _configuration.doDisplayClickToOption( Configuration.subtree ) ) {
1946             _subtree_cb_item = cb_index;
1947             addClickToOption( Configuration.subtree, _configuration.getClickToTitle( Configuration.subtree ) );
1948             if ( default_option == Configuration.subtree ) {
1949                 selected_index = cb_index;
1950             }
1951             cb_index++;
1952         }
1953         if ( _configuration.doDisplayClickToOption( Configuration.swap ) ) {
1954             _swap_cb_item = cb_index;
1955             addClickToOption( Configuration.swap, _configuration.getClickToTitle( Configuration.swap ) );
1956             if ( default_option == Configuration.swap ) {
1957                 selected_index = cb_index;
1958             }
1959             cb_index++;
1960         }
1961         if ( _configuration.doDisplayClickToOption( Configuration.sort_descendents ) ) {
1962             _sort_descendents_item = cb_index;
1963             addClickToOption( Configuration.sort_descendents,
1964                               _configuration.getClickToTitle( Configuration.sort_descendents ) );
1965             if ( default_option == Configuration.sort_descendents ) {
1966                 selected_index = cb_index;
1967             }
1968             cb_index++;
1969         }
1970         if ( _configuration.doDisplayClickToOption( Configuration.color_node_font ) ) {
1971             _color_node_font_item = cb_index;
1972             addClickToOption( Configuration.color_node_font,
1973                               _configuration.getClickToTitle( Configuration.color_node_font ) );
1974             if ( default_option == Configuration.color_node_font ) {
1975                 selected_index = cb_index;
1976             }
1977             cb_index++;
1978         }
1979         if ( _configuration.doDisplayClickToOption( Configuration.change_node_font ) ) {
1980             _change_node_font_item = cb_index;
1981             addClickToOption( Configuration.change_node_font,
1982                               _configuration.getClickToTitle( Configuration.change_node_font ) );
1983             if ( default_option == Configuration.change_node_font ) {
1984                 selected_index = cb_index;
1985             }
1986             cb_index++;
1987         }
1988         if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) {
1989             _color_subtree_cb_item = cb_index;
1990             addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) );
1991             if ( default_option == Configuration.color_subtree ) {
1992                 selected_index = cb_index;
1993             }
1994             cb_index++;
1995         }
1996         if ( _configuration.doDisplayClickToOption( Configuration.open_seq_web ) ) {
1997             _open_seq_web_item = cb_index;
1998             addClickToOption( Configuration.open_seq_web, _configuration.getClickToTitle( Configuration.open_seq_web ) );
1999             if ( default_option == Configuration.open_seq_web ) {
2000                 selected_index = cb_index;
2001             }
2002             cb_index++;
2003         }
2004         if ( _configuration.doDisplayClickToOption( Configuration.open_pdb_web ) ) {
2005             _open_pdb_item = cb_index;
2006             addClickToOption( Configuration.open_pdb_web, _configuration.getClickToTitle( Configuration.open_pdb_web ) );
2007             if ( default_option == Configuration.open_pdb_web ) {
2008                 selected_index = cb_index;
2009             }
2010             cb_index++;
2011         }
2012         if ( _configuration.doDisplayClickToOption( Configuration.open_tax_web ) ) {
2013             _open_tax_web_item = cb_index;
2014             addClickToOption( Configuration.open_tax_web, _configuration.getClickToTitle( Configuration.open_tax_web ) );
2015             if ( default_option == Configuration.open_tax_web ) {
2016                 selected_index = cb_index;
2017             }
2018             cb_index++;
2019         }
2020         if ( _configuration.doDisplayClickToOption( Configuration.blast ) ) {
2021             _blast_item = cb_index;
2022             addClickToOption( Configuration.blast, _configuration.getClickToTitle( Configuration.blast ) );
2023             if ( default_option == Configuration.blast ) {
2024                 selected_index = cb_index;
2025             }
2026             cb_index++;
2027         }
2028         if ( _configuration.doDisplayClickToOption( Configuration.select_nodes ) ) {
2029             _select_nodes_item = cb_index;
2030             addClickToOption( Configuration.select_nodes, _configuration.getClickToTitle( Configuration.select_nodes ) );
2031             if ( default_option == Configuration.select_nodes ) {
2032                 selected_index = cb_index;
2033             }
2034             cb_index++;
2035         }
2036         if ( _configuration.doDisplayClickToOption( Configuration.get_ext_desc_data ) ) {
2037             _get_ext_desc_data = cb_index;
2038             if ( !ForesterUtil.isEmpty( getConfiguration().getLabelForGetExtDescendentsData() ) ) {
2039                 addClickToOption( Configuration.get_ext_desc_data, getConfiguration()
2040                         .getLabelForGetExtDescendentsData() );
2041             }
2042             else {
2043                 String s = ";";
2044                 switch ( getConfiguration().getExtDescNodeDataToReturn() ) {
2045                     case NODE_NAME:
2046                         s = "Node Names";
2047                         break;
2048                     case SEQUENCE_ACC:
2049                         s = "Sequence Accessors";
2050                         break;
2051                     case SEQUENCE_MOL_SEQ:
2052                         s = "Molecular Sequence";
2053                         break;
2054                     case SEQUENCE_MOL_SEQ_FASTA:
2055                         s = "Molecular Sequence (Fasta)";
2056                         break;
2057                     case SEQUENCE_NAME:
2058                         s = "Sequence Names";
2059                         break;
2060                     case GENE_NAME:
2061                         s = "Gene Names";
2062                         break;
2063                     case SEQUENCE_SYMBOL:
2064                         s = "Sequence Symbols";
2065                         break;
2066                     case TAXONOMY_CODE:
2067                         s = "Taxonomy Codes";
2068                         break;
2069                     case TAXONOMY_COMM0N_NAME:
2070                         s = "Taxonomy Common Names";
2071                         break;
2072                     case TAXONOMY_SCIENTIFIC_NAME:
2073                         s = "Scientific Names";
2074                         break;
2075                     case UNKNOWN:
2076                         s = "User Selected Data";
2077                         break;
2078                     default:
2079                         throw new IllegalStateException( "dont know how to deal with "
2080                                 + getConfiguration().getExtDescNodeDataToReturn() );
2081                 }
2082                 final String label = _configuration.getClickToTitle( Configuration.get_ext_desc_data ) + " " + s;
2083                 addClickToOption( Configuration.get_ext_desc_data, label );
2084             }
2085             if ( default_option == Configuration.get_ext_desc_data ) {
2086                 selected_index = cb_index;
2087             }
2088             cb_index++;
2089         }
2090         if ( getOptions().isEditable() ) {
2091             if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) {
2092                 _cut_subtree_item = cb_index;
2093                 addClickToOption( Configuration.cut_subtree, _configuration.getClickToTitle( Configuration.cut_subtree ) );
2094                 if ( default_option == Configuration.cut_subtree ) {
2095                     selected_index = cb_index;
2096                 }
2097                 cb_index++;
2098             }
2099             if ( _configuration.doDisplayClickToOption( Configuration.copy_subtree ) ) {
2100                 _copy_subtree_item = cb_index;
2101                 addClickToOption( Configuration.copy_subtree,
2102                                   _configuration.getClickToTitle( Configuration.copy_subtree ) );
2103                 if ( default_option == Configuration.copy_subtree ) {
2104                     selected_index = cb_index;
2105                 }
2106                 cb_index++;
2107             }
2108             if ( _configuration.doDisplayClickToOption( Configuration.paste_subtree ) ) {
2109                 _paste_subtree_item = cb_index;
2110                 addClickToOption( Configuration.paste_subtree,
2111                                   _configuration.getClickToTitle( Configuration.paste_subtree ) );
2112                 if ( default_option == Configuration.paste_subtree ) {
2113                     selected_index = cb_index;
2114                 }
2115                 cb_index++;
2116             }
2117             if ( _configuration.doDisplayClickToOption( Configuration.delete_subtree_or_node ) ) {
2118                 _delete_node_or_subtree_item = cb_index;
2119                 addClickToOption( Configuration.delete_subtree_or_node,
2120                                   _configuration.getClickToTitle( Configuration.delete_subtree_or_node ) );
2121                 if ( default_option == Configuration.delete_subtree_or_node ) {
2122                     selected_index = cb_index;
2123                 }
2124                 cb_index++;
2125             }
2126             if ( _configuration.doDisplayClickToOption( Configuration.add_new_node ) ) {
2127                 _add_new_node_item = cb_index;
2128                 addClickToOption( Configuration.add_new_node,
2129                                   _configuration.getClickToTitle( Configuration.add_new_node ) );
2130                 if ( default_option == Configuration.add_new_node ) {
2131                     selected_index = cb_index;
2132                 }
2133                 cb_index++;
2134             }
2135             if ( _configuration.doDisplayClickToOption( Configuration.edit_node_data ) ) {
2136                 _edit_node_data_item = cb_index;
2137                 addClickToOption( Configuration.edit_node_data,
2138                                   _configuration.getClickToTitle( Configuration.edit_node_data ) );
2139                 if ( default_option == Configuration.edit_node_data ) {
2140                     selected_index = cb_index;
2141                 }
2142                 cb_index++;
2143             }
2144         }
2145         // Set default selection and its action
2146         _click_to_combobox.setSelectedIndex( selected_index );
2147         setClickToAction( selected_index );
2148     }
2149
2150     private void setupDisplayCheckboxes() {
2151         if ( _configuration.doDisplayOption( Configuration.display_as_phylogram ) ) {
2152             addCheckbox( Configuration.display_as_phylogram,
2153                          _configuration.getDisplayTitle( Configuration.display_as_phylogram ) );
2154             setCheckbox( Configuration.display_as_phylogram,
2155                          _configuration.doCheckOption( Configuration.display_as_phylogram ) );
2156         }
2157         if ( _configuration.doDisplayOption( Configuration.dynamically_hide_data ) ) {
2158             addCheckbox( Configuration.dynamically_hide_data,
2159                          _configuration.getDisplayTitle( Configuration.dynamically_hide_data ) );
2160             setCheckbox( Configuration.dynamically_hide_data,
2161                          _configuration.doCheckOption( Configuration.dynamically_hide_data ) );
2162         }
2163         if ( _configuration.doDisplayOption( Configuration.node_data_popup ) ) {
2164             addCheckbox( Configuration.node_data_popup, _configuration.getDisplayTitle( Configuration.node_data_popup ) );
2165             setCheckbox( Configuration.node_data_popup, _configuration.doCheckOption( Configuration.node_data_popup ) );
2166         }
2167         if ( _configuration.doDisplayOption( Configuration.display_internal_data ) ) {
2168             addCheckbox( Configuration.display_internal_data,
2169                          _configuration.getDisplayTitle( Configuration.display_internal_data ) );
2170             setCheckbox( Configuration.display_internal_data,
2171                          _configuration.doCheckOption( Configuration.display_internal_data ) );
2172         }
2173         if ( _configuration.doDisplayOption( Configuration.color_according_to_sequence ) ) {
2174             addCheckbox( Configuration.color_according_to_sequence,
2175                          _configuration.getDisplayTitle( Configuration.color_according_to_sequence ) );
2176             setCheckbox( Configuration.color_according_to_sequence,
2177                          _configuration.doCheckOption( Configuration.color_according_to_sequence ) );
2178         }
2179         if ( _configuration.doDisplayOption( Configuration.color_according_to_species ) ) {
2180             addCheckbox( Configuration.color_according_to_species,
2181                          _configuration.getDisplayTitle( Configuration.color_according_to_species ) );
2182             setCheckbox( Configuration.color_according_to_species,
2183                          _configuration.doCheckOption( Configuration.color_according_to_species ) );
2184         }
2185         if ( _configuration.doDisplayOption( Configuration.color_according_to_annotation ) ) {
2186             addCheckbox( Configuration.color_according_to_annotation,
2187                          _configuration.getDisplayTitle( Configuration.color_according_to_annotation ) );
2188             setCheckbox( Configuration.color_according_to_annotation,
2189                          _configuration.doCheckOption( Configuration.color_according_to_annotation ) );
2190         }
2191         if ( _configuration.doDisplayOption( Configuration.use_style ) ) {
2192             addCheckbox( Configuration.use_style, _configuration.getDisplayTitle( Configuration.use_style ) );
2193             setCheckbox( Configuration.use_style, _configuration.doCheckOption( Configuration.use_style ) );
2194         }
2195         if ( _configuration.doDisplayOption( Configuration.width_branches ) ) {
2196             addCheckbox( Configuration.width_branches, _configuration.getDisplayTitle( Configuration.width_branches ) );
2197             setCheckbox( Configuration.width_branches, _configuration.doCheckOption( Configuration.width_branches ) );
2198         }
2199         final JLabel label = new JLabel( "Display Data:" );
2200         label.setFont( ControlPanel.jcb_bold_font );
2201         if ( !getConfiguration().isUseNativeUI() ) {
2202             label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
2203         }
2204         add( label );
2205         if ( _configuration.doDisplayOption( Configuration.show_node_names ) ) {
2206             addCheckbox( Configuration.show_node_names, _configuration.getDisplayTitle( Configuration.show_node_names ) );
2207             setCheckbox( Configuration.show_node_names, _configuration.doCheckOption( Configuration.show_node_names ) );
2208         }
2209         if ( _configuration.doDisplayOption( Configuration.show_tax_code ) ) {
2210             addCheckbox( Configuration.show_tax_code, _configuration.getDisplayTitle( Configuration.show_tax_code ) );
2211             setCheckbox( Configuration.show_tax_code, _configuration.doCheckOption( Configuration.show_tax_code ) );
2212         }
2213         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_scientific_names ) ) {
2214             addCheckbox( Configuration.show_taxonomy_scientific_names,
2215                          _configuration.getDisplayTitle( Configuration.show_taxonomy_scientific_names ) );
2216             setCheckbox( Configuration.show_taxonomy_scientific_names,
2217                          _configuration.doCheckOption( Configuration.show_taxonomy_scientific_names ) );
2218         }
2219         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_common_names ) ) {
2220             addCheckbox( Configuration.show_taxonomy_common_names,
2221                          _configuration.getDisplayTitle( Configuration.show_taxonomy_common_names ) );
2222             setCheckbox( Configuration.show_taxonomy_common_names,
2223                          _configuration.doCheckOption( Configuration.show_taxonomy_common_names ) );
2224         }
2225         if ( _configuration.doDisplayOption( Configuration.show_seq_names ) ) {
2226             addCheckbox( Configuration.show_seq_names, _configuration.getDisplayTitle( Configuration.show_seq_names ) );
2227             setCheckbox( Configuration.show_seq_names, _configuration.doCheckOption( Configuration.show_seq_names ) );
2228         }
2229         if ( _configuration.doDisplayOption( Configuration.show_gene_names ) ) {
2230             addCheckbox( Configuration.show_gene_names, _configuration.getDisplayTitle( Configuration.show_gene_names ) );
2231             setCheckbox( Configuration.show_gene_names, _configuration.doCheckOption( Configuration.show_gene_names ) );
2232         }
2233         if ( _configuration.doDisplayOption( Configuration.show_seq_symbols ) ) {
2234             addCheckbox( Configuration.show_seq_symbols,
2235                          _configuration.getDisplayTitle( Configuration.show_seq_symbols ) );
2236             setCheckbox( Configuration.show_seq_symbols, _configuration.doCheckOption( Configuration.show_seq_symbols ) );
2237         }
2238         if ( _configuration.doDisplayOption( Configuration.show_sequence_acc ) ) {
2239             addCheckbox( Configuration.show_sequence_acc,
2240                          _configuration.getDisplayTitle( Configuration.show_sequence_acc ) );
2241             setCheckbox( Configuration.show_sequence_acc,
2242                          _configuration.doCheckOption( Configuration.show_sequence_acc ) );
2243         }
2244         if ( _configuration.doDisplayOption( Configuration.show_annotation ) ) {
2245             addCheckbox( Configuration.show_annotation, _configuration.getDisplayTitle( Configuration.show_annotation ) );
2246             setCheckbox( Configuration.show_annotation, _configuration.doCheckOption( Configuration.show_annotation ) );
2247         }
2248         if ( _configuration.doDisplayOption( Configuration.write_confidence_values ) ) {
2249             addCheckbox( Configuration.write_confidence_values,
2250                          _configuration.getDisplayTitle( Configuration.write_confidence_values ) );
2251             setCheckbox( Configuration.write_confidence_values,
2252                          _configuration.doCheckOption( Configuration.write_confidence_values ) );
2253         }
2254         if ( _configuration.doDisplayOption( Configuration.write_branch_length_values ) ) {
2255             addCheckbox( Configuration.write_branch_length_values,
2256                          _configuration.getDisplayTitle( Configuration.write_branch_length_values ) );
2257             setCheckbox( Configuration.write_branch_length_values,
2258                          _configuration.doCheckOption( Configuration.write_branch_length_values ) );
2259         }
2260         if ( _configuration.doDisplayOption( Configuration.show_binary_characters ) ) {
2261             addCheckbox( Configuration.show_binary_characters,
2262                          _configuration.getDisplayTitle( Configuration.show_binary_characters ) );
2263             setCheckbox( Configuration.show_binary_characters,
2264                          _configuration.doCheckOption( Configuration.show_binary_characters ) );
2265         }
2266         if ( _configuration.doDisplayOption( Configuration.show_binary_character_counts ) ) {
2267             addCheckbox( Configuration.show_binary_character_counts,
2268                          _configuration.getDisplayTitle( Configuration.show_binary_character_counts ) );
2269             setCheckbox( Configuration.show_binary_character_counts,
2270                          _configuration.doCheckOption( Configuration.show_binary_character_counts ) );
2271         }
2272         if ( _configuration.doDisplayOption( Configuration.show_domain_architectures ) ) {
2273             addCheckbox( Configuration.show_domain_architectures,
2274                          _configuration.getDisplayTitle( Configuration.show_domain_architectures ) );
2275             setCheckbox( Configuration.show_domain_architectures,
2276                          _configuration.doCheckOption( Configuration.show_domain_architectures ) );
2277         }
2278         if ( _configuration.doDisplayOption( Configuration.show_mol_seqs ) ) {
2279             addCheckbox( Configuration.show_mol_seqs, _configuration.getDisplayTitle( Configuration.show_mol_seqs ) );
2280             setCheckbox( Configuration.show_mol_seqs, _configuration.doCheckOption( Configuration.show_mol_seqs ) );
2281         }
2282         if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
2283             addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
2284             setCheckbox( Configuration.write_events, _configuration.doCheckOption( Configuration.write_events ) );
2285         }
2286         if ( _configuration.doDisplayOption( Configuration.show_vector_data ) ) {
2287             addCheckbox( Configuration.show_vector_data,
2288                          _configuration.getDisplayTitle( Configuration.show_vector_data ) );
2289             setCheckbox( Configuration.show_vector_data, _configuration.doCheckOption( Configuration.show_vector_data ) );
2290         }
2291         if ( _configuration.doDisplayOption( Configuration.show_properties ) ) {
2292             addCheckbox( Configuration.show_properties, _configuration.getDisplayTitle( Configuration.show_properties ) );
2293             setCheckbox( Configuration.show_properties, _configuration.doCheckOption( Configuration.show_properties ) );
2294         }
2295         if ( _configuration.doDisplayOption( Configuration.show_taxonomy_images ) ) {
2296             addCheckbox( Configuration.show_taxonomy_images,
2297                          _configuration.getDisplayTitle( Configuration.show_taxonomy_images ) );
2298             setCheckbox( Configuration.show_taxonomy_images,
2299                          _configuration.doCheckOption( Configuration.show_taxonomy_images ) );
2300         }
2301     }
2302
2303     private void setVisibilityOfDomainStrucureControls() {
2304         if ( _zoom_in_domain_structure != null ) {
2305             final MainFrame mf = getMainFrame();
2306             if ( mf != null ) {
2307                 if ( isShowDomainArchitectures() ) {
2308                     _domain_display_label.setVisible( true );
2309                     _zoom_in_domain_structure.setVisible( true );
2310                     _zoom_out_domain_structure.setVisible( true );
2311                     _decr_domain_structure_evalue_thr.setVisible( true );
2312                     _incr_domain_structure_evalue_thr.setVisible( true );
2313                     _domain_structure_evalue_thr_tf.setVisible( true );
2314                     if ( mf._right_line_up_domains_cbmi != null ) {
2315                         mf._right_line_up_domains_cbmi.setVisible( true );
2316                     }
2317                     if ( mf._show_domain_labels != null ) {
2318                         mf._show_domain_labels.setVisible( true );
2319                     }
2320                 }
2321                 else {
2322                     _domain_display_label.setVisible( false );
2323                     _zoom_in_domain_structure.setVisible( false );
2324                     _zoom_out_domain_structure.setVisible( false );
2325                     _decr_domain_structure_evalue_thr.setVisible( false );
2326                     _incr_domain_structure_evalue_thr.setVisible( false );
2327                     _domain_structure_evalue_thr_tf.setVisible( false );
2328                     if ( mf._right_line_up_domains_cbmi != null ) {
2329                         mf._right_line_up_domains_cbmi.setVisible( false );
2330                     }
2331                     if ( mf._show_domain_labels != null ) {
2332                         mf._show_domain_labels.setVisible( false );
2333                     }
2334                 }
2335             }
2336         }
2337     }
2338
2339     // This takes care of ArchaeopteryxE-issue.
2340     // Can, and will, return null prior to  ArchaeopteryxE initialization completion.
2341     final private MainFrame getMainFrame() {
2342         MainFrame mf = getMainPanel().getMainFrame();
2343         if ( mf == null ) {
2344             // Must be "E" applet version.
2345             final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
2346             if ( e.getMainPanel() == null ) {
2347                 return null;
2348             }
2349             mf = e.getMainPanel().getMainFrame();
2350         }
2351         return mf;
2352     }
2353
2354     void setVisibilityOfX() {
2355         final MainFrame mf = getMainFrame();
2356         if ( mf != null ) {
2357             if ( ( getCurrentTreePanel() != null ) && ( getCurrentTreePanel().getPhylogeny() != null ) ) {
2358                 if ( AptxUtil.isHasAtLeastOneBranchWithSupportSD( getCurrentTreePanel().getPhylogeny() ) ) {
2359                     if ( mf._show_confidence_stddev_cbmi != null ) {
2360                         mf._show_confidence_stddev_cbmi.setVisible( true );
2361                     }
2362                 }
2363                 else {
2364                     if ( mf._show_confidence_stddev_cbmi != null ) {
2365                         mf._show_confidence_stddev_cbmi.setVisible( false );
2366                     }
2367                 }
2368                 if ( AptxUtil.isHasAtLeastOneNodeWithScientificName( getCurrentTreePanel().getPhylogeny() ) ) {
2369                     if ( mf._abbreviate_scientific_names != null ) {
2370                         mf._abbreviate_scientific_names.setVisible( true );
2371                     }
2372                 }
2373                 else {
2374                     if ( mf._abbreviate_scientific_names != null ) {
2375                         mf._abbreviate_scientific_names.setVisible( false );
2376                     }
2377                 }
2378                 if ( AptxUtil.isHasAtLeastOneNodeWithSequenceAnnotation( getCurrentTreePanel().getPhylogeny() ) ) {
2379                     if ( mf._show_annotation_ref_source != null ) {
2380                         mf._show_annotation_ref_source.setVisible( true );
2381                     }
2382                 }
2383                 else {
2384                     if ( mf._show_annotation_ref_source != null ) {
2385                         mf._show_annotation_ref_source.setVisible( false );
2386                     }
2387                 }
2388             }
2389             if ( isDrawPhylogram()
2390                     || ( ( getCurrentTreePanel() != null ) && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel()
2391                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) ) {
2392                 if ( mf._non_lined_up_cladograms_rbmi != null ) {
2393                     mf._non_lined_up_cladograms_rbmi.setVisible( false );
2394                 }
2395                 if ( mf._uniform_cladograms_rbmi != null ) {
2396                     mf._uniform_cladograms_rbmi.setVisible( false );
2397                 }
2398                 if ( mf._ext_node_dependent_cladogram_rbmi != null ) {
2399                     mf._ext_node_dependent_cladogram_rbmi.setVisible( false );
2400                 }
2401             }
2402             else {
2403                 if ( mf._non_lined_up_cladograms_rbmi != null ) {
2404                     mf._non_lined_up_cladograms_rbmi.setVisible( true );
2405                 }
2406                 if ( mf._uniform_cladograms_rbmi != null ) {
2407                     mf._uniform_cladograms_rbmi.setVisible( true );
2408                 }
2409                 if ( mf._ext_node_dependent_cladogram_rbmi != null ) {
2410                     mf._ext_node_dependent_cladogram_rbmi.setVisible( true );
2411                 }
2412             }
2413             if ( isDrawPhylogram() ) {
2414                 if ( mf._show_scale_cbmi != null ) {
2415                     mf._show_scale_cbmi.setVisible( true );
2416                 }
2417             }
2418             else {
2419                 if ( mf._show_scale_cbmi != null ) {
2420                     mf._show_scale_cbmi.setVisible( false );
2421                 }
2422             }
2423             if ( getCurrentTreePanel() != null ) {
2424                 if ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
2425                         || ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
2426                     if ( mf._label_direction_cbmi != null ) {
2427                         mf._label_direction_cbmi.setVisible( true );
2428                     }
2429                 }
2430                 else {
2431                     if ( mf._label_direction_cbmi != null ) {
2432                         mf._label_direction_cbmi.setVisible( false );
2433                     }
2434                 }
2435             }
2436         }
2437     }
2438
2439     void setVisibilityOfDomainStrucureCB() {
2440         try {
2441             if ( ( getCurrentTreePanel() != null )
2442                     && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel()
2443                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) {
2444                 if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
2445                     getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( false );
2446                 }
2447                 if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
2448                     getMainPanel().getMainFrame()._show_domain_labels.setVisible( false );
2449                 }
2450             }
2451             else if ( isShowDomainArchitectures() ) {
2452                 if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
2453                     getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( true );
2454                 }
2455                 if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
2456                     getMainPanel().getMainFrame()._show_domain_labels.setVisible( true );
2457                 }
2458             }
2459             else {
2460                 if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
2461                     getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( false );
2462                 }
2463                 if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
2464                     getMainPanel().getMainFrame()._show_domain_labels.setVisible( false );
2465                 }
2466             }
2467         }
2468         catch ( final Exception ignore ) {
2469             //not important...
2470         }
2471     }
2472
2473     static JLabel customizeLabel( final JLabel label, final Configuration configuration ) {
2474         label.setFont( ControlPanel.jcb_bold_font );
2475         if ( !configuration.isUseNativeUI() ) {
2476             label.setForeground( configuration.getGuiCheckboxTextColor() );
2477             label.setBackground( configuration.getGuiBackgroundColor() );
2478         }
2479         return label;
2480     }
2481
2482     enum NodeClickAction {
2483         ADD_NEW_NODE,
2484         BLAST,
2485         COLLAPSE,
2486         COLOR_SUBTREE,
2487         COPY_SUBTREE,
2488         CUT_SUBTREE,
2489         DELETE_NODE_OR_SUBTREE,
2490         EDIT_NODE_DATA,
2491         GET_EXT_DESC_DATA,
2492         OPEN_PDB_WEB,
2493         OPEN_SEQ_WEB,
2494         OPEN_TAX_WEB,
2495         PASTE_SUBTREE,
2496         REROOT,
2497         SELECT_NODES,
2498         SHOW_DATA,
2499         SORT_DESCENDENTS,
2500         SUBTREE,
2501         SWAP,
2502         CHANGE_NODE_FONT,
2503         COLOR_NODE_FONT;
2504     }
2505 }